diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index f947969772..c5618a2841 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -81,6 +81,7 @@ 15000 * sizeof(yg::gl::Vertex), 30000 * sizeof(unsigned short), 20, 1500 * sizeof(yg::gl::Vertex), 3000 * sizeof(unsigned short), 100, 512, 256, 10, + 2048, 2048, 20, 2000000)); // resourceManager->addFont(GetPlatform().ReadPathForFile("dejavusans.ttf").c_str()); diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 3611916c9b..0c2070bd0e 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -20,7 +20,11 @@ DrawerYG::DrawerYG(shared_ptr const & rm, string const & skinName, bool isAntiAliased) { - m_pScreen = shared_ptr(new yg::gl::Screen(rm, isAntiAliased)); + yg::gl::Screen::Params params; + params.m_resourceManager = rm; + params.m_isAntiAliased = isAntiAliased; + + m_pScreen = shared_ptr(new yg::gl::Screen(params)); m_pSkin = shared_ptr(loadSkin(rm, skinName)); m_pScreen->setSkin(m_pSkin); diff --git a/qt/widgets.cpp b/qt/widgets.cpp index 0866fbf68b..f577ac3c83 100644 --- a/qt/widgets.cpp +++ b/qt/widgets.cpp @@ -40,6 +40,9 @@ namespace qt 5000 * sizeof(yg::gl::Vertex), 10000 * sizeof(unsigned short), 100, + 2048, + 2048, + 30, 512, 256, 15, 2000000)); diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index b2e4aabbca..e10ecfde4b 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -46,6 +46,9 @@ void GLDrawWidget::initializeGL() 3000 * sizeof(yg::gl::Vertex), 5000 * sizeof(unsigned short), 100, + 2048, + 2048, + 30, 512, 256, 15, 2000000)); @@ -57,7 +60,11 @@ void GLDrawWidget::initializeGL() 20, 256, 256, 10));*/ - m_p = make_shared_ptr(new yg::gl::Screen(m_resourceManager, false)); + yg::gl::Screen::Params params; + params.m_resourceManager = m_resourceManager; + params.m_isAntiAliased = false; + + m_p = make_shared_ptr(new yg::gl::Screen(params)); m_primaryFrameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(true)); diff --git a/yg/blitter.cpp b/yg/blitter.cpp index 97c076c91e..7fa270e9ae 100644 --- a/yg/blitter.cpp +++ b/yg/blitter.cpp @@ -5,9 +5,11 @@ #include "framebuffer.hpp" #include "base_texture.hpp" #include "texture.hpp" +#include "resource_manager.hpp" #include "vertexbuffer.hpp" #include "indexbuffer.hpp" #include "utils.hpp" +#include "storage.hpp" #include "../geometry/screenbase.hpp" @@ -15,9 +17,7 @@ namespace yg { namespace gl { - Blitter::Blitter() : - m_blitVertexBuffer(make_shared_ptr(new VertexBuffer(2048))), - m_blitIndexBuffer(make_shared_ptr(new IndexBuffer(2048))) + Blitter::Blitter(base_t::Params const & params) : base_t(params) {} void Blitter::beginFrame() @@ -171,7 +171,9 @@ namespace yg yg::Color const & color, bool hasColor) { - AuxVertex * pointsData = (AuxVertex*)m_blitVertexBuffer->lock(); + yg::gl::Storage blitStorage = resourceManager()->reserveBlitStorage(); + + AuxVertex * pointsData = (AuxVertex*)blitStorage.m_vertices->lock(); for (size_t i = 0; i < size; ++i) { @@ -182,7 +184,7 @@ namespace yg pointsData[i].color = color; } - m_blitVertexBuffer->unlock(); + blitStorage.m_vertices->unlock(); setupAuxVertexLayout(hasColor, hasTexture); @@ -190,9 +192,11 @@ namespace yg texture->makeCurrent(); unsigned short idxData[4] = {0, 1, 2, 3}; - memcpy(m_blitIndexBuffer->lock(), idxData, sizeof(idxData)); - m_blitIndexBuffer->unlock(); - m_blitIndexBuffer->makeCurrent(); + memcpy(blitStorage.m_indices->lock(), idxData, sizeof(idxData)); + blitStorage.m_indices->unlock(); + blitStorage.m_indices->makeCurrent(); + + resourceManager()->freeBlitStorage(blitStorage); OGLCHECK(glDisable(GL_BLEND)); OGLCHECK(glDisable(GL_DEPTH_TEST)); diff --git a/yg/blitter.hpp b/yg/blitter.hpp index b3bef9607a..5ed8e95c7c 100644 --- a/yg/blitter.hpp +++ b/yg/blitter.hpp @@ -24,12 +24,9 @@ namespace yg void setupAuxVertexLayout(bool hasColor, bool hasTexture); - shared_ptr m_blitVertexBuffer; - shared_ptr m_blitIndexBuffer; - public: - Blitter(); + Blitter(base_t::Params const & params); void beginFrame(); void endFrame(); diff --git a/yg/clipper.cpp b/yg/clipper.cpp index 18d862885e..763eae74e8 100644 --- a/yg/clipper.cpp +++ b/yg/clipper.cpp @@ -6,8 +6,9 @@ namespace yg { namespace gl { - Clipper::Clipper() - : m_isClippingEnabled(false) + Clipper::Clipper(base_t::Params const & params) + : base_t(params), + m_isClippingEnabled(false) {} void Clipper::beginFrame() diff --git a/yg/clipper.hpp b/yg/clipper.hpp index 36305937c7..ef1e2544fb 100644 --- a/yg/clipper.hpp +++ b/yg/clipper.hpp @@ -18,7 +18,7 @@ namespace yg public: - Clipper(); + Clipper(base_t::Params const & params); void beginFrame(); void endFrame(); diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index 61f9cc31b9..ee26436362 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -28,8 +28,8 @@ namespace yg { namespace gl { - GeometryBatcher::GeometryBatcher(shared_ptr const & resourceManager, bool isAntiAliased) - : m_resourceManager(resourceManager), m_isAntiAliased(isAntiAliased) + GeometryBatcher::GeometryBatcher(Params const & params) + : base_t(params), m_isAntiAliased(params.m_isAntiAliased) { reset(-1); applyStates(); @@ -87,7 +87,7 @@ namespace yg m_pipelines[i].m_currentVertex = 0; m_pipelines[i].m_currentIndex = 0; - m_pipelines[i].m_storage = m_skin->pages()[i]->isDynamic() ? m_resourceManager->reserveStorage() : m_resourceManager->reserveSmallStorage(); + m_pipelines[i].m_storage = m_skin->pages()[i]->isDynamic() ? resourceManager()->reserveStorage() : resourceManager()->reserveSmallStorage(); m_pipelines[i].m_maxVertices = m_pipelines[i].m_storage.m_vertices->size() / sizeof(Vertex); m_pipelines[i].m_maxIndices = m_pipelines[i].m_storage.m_indices->size() / sizeof(unsigned short); @@ -171,10 +171,10 @@ namespace yg renderedData = true; if (skinPage->isDynamic()) - m_resourceManager->freeStorage(pipeline.m_storage); + resourceManager()->freeStorage(pipeline.m_storage); else - m_resourceManager->freeSmallStorage(pipeline.m_storage); - pipeline.m_storage = skinPage->isDynamic() ? m_resourceManager->reserveStorage() : m_resourceManager->reserveSmallStorage(); + resourceManager()->freeSmallStorage(pipeline.m_storage); + pipeline.m_storage = skinPage->isDynamic() ? resourceManager()->reserveStorage() : resourceManager()->reserveSmallStorage(); pipeline.m_maxVertices = pipeline.m_storage.m_vertices->size() / sizeof(Vertex); pipeline.m_maxIndices = pipeline.m_storage.m_indices->size() / sizeof(unsigned short); diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index 5b660c901c..e6161b210a 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -92,7 +92,13 @@ namespace yg public: - GeometryBatcher(shared_ptr const & resourceManager, bool isAntiAliased = false); + struct Params : base_t::Params + { + bool m_isAntiAliased; + Params() : m_isAntiAliased(false) {} + }; + + GeometryBatcher(Params const & params); ~GeometryBatcher(); void setSkin(shared_ptr skin); diff --git a/yg/geometry_renderer.cpp b/yg/geometry_renderer.cpp index f0390a3135..81526f7be4 100644 --- a/yg/geometry_renderer.cpp +++ b/yg/geometry_renderer.cpp @@ -10,6 +10,9 @@ namespace yg { namespace gl { + GeometryRenderer::GeometryRenderer(base_t::Params const & params) : base_t(params) + {} + void GeometryRenderer::drawGeometry(shared_ptr const & texture, shared_ptr const & vertices, shared_ptr const & indices, diff --git a/yg/geometry_renderer.hpp b/yg/geometry_renderer.hpp index d94590951d..790590dbda 100644 --- a/yg/geometry_renderer.hpp +++ b/yg/geometry_renderer.hpp @@ -15,6 +15,11 @@ namespace yg class GeometryRenderer : public Blitter { public: + + typedef Blitter base_t; + + GeometryRenderer(base_t::Params const & params); + void drawGeometry(shared_ptr const & texture, shared_ptr const & vertices, shared_ptr const & indices, diff --git a/yg/render_state_updater.cpp b/yg/render_state_updater.cpp index 1bf999e0a2..8a9b132502 100644 --- a/yg/render_state_updater.cpp +++ b/yg/render_state_updater.cpp @@ -7,6 +7,9 @@ namespace yg { namespace gl { + RenderStateUpdater::RenderStateUpdater(base_t::Params const & params) : base_t(params) + {} + void RenderStateUpdater::setRenderState(shared_ptr const & renderState) { m_renderState = renderState; diff --git a/yg/render_state_updater.hpp b/yg/render_state_updater.hpp index abb50b0026..4a20cc877e 100644 --- a/yg/render_state_updater.hpp +++ b/yg/render_state_updater.hpp @@ -25,6 +25,8 @@ namespace yg public: + RenderStateUpdater(base_t::Params const & params); + void setRenderState(shared_ptr const & renderState); shared_ptr const & renderState() const; diff --git a/yg/renderer.cpp b/yg/renderer.cpp index 2cac044986..5a5d8a9b20 100644 --- a/yg/renderer.cpp +++ b/yg/renderer.cpp @@ -3,6 +3,7 @@ #include "utils.hpp" #include "framebuffer.hpp" #include "renderbuffer.hpp" +#include "resource_manager.hpp" #include "../base/ptr_utils.hpp" #include "internal/opengl.hpp" @@ -10,9 +11,15 @@ namespace yg { namespace gl { - Renderer::Renderer() : m_isMultiSampled(false), m_isRendering(false) + Renderer::Renderer(Params const & params) : m_isMultiSampled(false), m_isRendering(false) { m_multiSampledFrameBuffer = make_shared_ptr(new FrameBuffer()); + m_resourceManager = params.m_resourceManager; + } + + shared_ptr const & Renderer::resourceManager() const + { + return m_resourceManager; } void Renderer::beginFrame() diff --git a/yg/renderer.hpp b/yg/renderer.hpp index daefbd386c..8fac956b37 100644 --- a/yg/renderer.hpp +++ b/yg/renderer.hpp @@ -6,6 +6,8 @@ namespace yg { + class ResourceManager; + namespace gl { class FrameBuffer; @@ -13,8 +15,17 @@ namespace yg class Renderer { + public: + + struct Params + { + shared_ptr m_resourceManager; + }; + private: + shared_ptr m_resourceManager; + shared_ptr m_frameBuffer; shared_ptr m_renderTarget; shared_ptr m_depthBuffer; @@ -32,13 +43,15 @@ namespace yg public: - Renderer(); + Renderer(Params const & params = Params()); void beginFrame(); void endFrame(); bool isRendering() const; + shared_ptr const & resourceManager() const; + void setIsMultiSampled(bool isMultiSampled); bool isMultiSampled() const; diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index bcb9e05a04..ce013a8541 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -18,6 +18,7 @@ namespace yg ResourceManager::ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount, size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount, + size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount, size_t texWidth, size_t texHeight, size_t texCount, size_t maxGlyphCacheSize) : m_glyphCache(maxGlyphCacheSize) { @@ -27,6 +28,9 @@ namespace yg for (size_t i = 0; i < smallStoragesCount; ++i) m_smallStorages.push_back(gl::Storage(smallVBSize, smallIBSize)); + for (size_t i = 0; i < blitStoragesCount; ++i) + m_blitStorages.push_back(gl::Storage(blitVBSize, blitIBSize)); + for (size_t i = 0; i < texCount; ++i) { m_dynamicTextures.push_back(shared_ptr(new TDynamicTexture(texWidth, texHeight))); @@ -105,6 +109,16 @@ namespace yg return freeStorageImpl(storage, doSignal, m_smallStorages); } + gl::Storage const ResourceManager::reserveBlitStorage(bool doWait) + { + return reserveStorageImpl(doWait, m_blitStorages); + } + + void ResourceManager::freeBlitStorage(gl::Storage const & storage, bool doSignal) + { + return freeStorageImpl(storage, doSignal, m_blitStorages); + } + gl::Storage const ResourceManager::reserveStorage(bool doWait) { return reserveStorageImpl(doWait, m_storages); diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index ec67eb85ea..f17039224c 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -36,6 +36,7 @@ namespace yg list m_storages; list m_smallStorages; + list m_blitStorages; gl::Storage const reserveStorageImpl(bool doWait, list & l); void freeStorageImpl(gl::Storage const & storage, bool doSignal, list & l); @@ -46,6 +47,7 @@ namespace yg ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount, size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount, + size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount, size_t texWidth, size_t texHeight, size_t texCount, size_t maxGlyphCacheSize); @@ -57,6 +59,9 @@ namespace yg gl::Storage const reserveSmallStorage(bool doWait = false); void freeSmallStorage(gl::Storage const & storage, bool doSignal = false); + gl::Storage const reserveBlitStorage(bool doWait = false); + void freeBlitStorage(gl::Storage const & storage, bool doSignal = false); + shared_ptr const reserveTexture(bool doWait = false); void freeTexture(shared_ptr const & texture, bool doSignal = false); diff --git a/yg/screen.hpp b/yg/screen.hpp index 0af455469e..81adfd732a 100644 --- a/yg/screen.hpp +++ b/yg/screen.hpp @@ -12,8 +12,10 @@ namespace yg { private: public: - Screen(shared_ptr const & rm, bool isAntiAliased) - : TextRenderer(rm, isAntiAliased) + + typedef TextRenderer::Params Params; + + Screen(Params const & params) : TextRenderer(params) {} }; } diff --git a/yg/text_renderer.hpp b/yg/text_renderer.hpp index d710ec06b3..c3d36b48b0 100644 --- a/yg/text_renderer.hpp +++ b/yg/text_renderer.hpp @@ -12,8 +12,10 @@ namespace yg { private: public: - TextRenderer(shared_ptr const & rm, bool isAntiAliased) - : GeometryBatcher(rm, isAntiAliased) + + typedef GeometryBatcher::Params Params; + + TextRenderer(Params const & params) : GeometryBatcher(params) {} }; } diff --git a/yg/yg_tests/skin_loader_test.cpp b/yg/yg_tests/skin_loader_test.cpp index bd0f4e56ea..35d2fb6f03 100644 --- a/yg/yg_tests/skin_loader_test.cpp +++ b/yg/yg_tests/skin_loader_test.cpp @@ -8,6 +8,6 @@ UNIT_TEST(SkinLoaderTest_Main) { GL_TEST_START; - shared_ptr rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, 2000000)); + shared_ptr rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, 2000000)); /*yg::Skin * skin = */loadSkin(rm, "basic.skn"); }; diff --git a/yg/yg_tests/skin_test.cpp b/yg/yg_tests/skin_test.cpp index 8a29eb8c3f..2eb679d14e 100644 --- a/yg/yg_tests/skin_test.cpp +++ b/yg/yg_tests/skin_test.cpp @@ -9,7 +9,7 @@ UNIT_TEST(SkinTest_Main) { GL_TEST_START; - shared_ptr rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 128, 128, 15, 2000000)); + shared_ptr rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 100, 100, 1, 128, 128, 15, 2000000)); yg::Skin * skin = loadSkin(rm, "test.skn"); double p0 [] = {1, 1};