From 5508665f13cb2d56c65bd8fd2b334da78e0cd612 Mon Sep 17 00:00:00 2001 From: rachytski Date: Fri, 1 Apr 2011 17:17:38 +0300 Subject: [PATCH] * implemented runtime choice of renderTarget format. * fixed parasite "empty model" message at start. --- iphone/Maps/Classes/EAGLView.mm | 3 ++- iphone/Maps/Classes/MapViewController.mm | 19 +++++++++++-------- map/framework.hpp | 16 +++++++--------- map/navigator.cpp | 3 ++- map/render_queue_routine.cpp | 16 +++++++++++++--- qt/draw_widget.cpp | 7 ++++++- qt/widgets.cpp | 3 ++- qt_tstfrm/tstwidgets.cpp | 3 ++- yg/render_state_updater.cpp | 1 - yg/resource_manager.cpp | 19 +++++++++++++++++-- yg/resource_manager.hpp | 13 ++++++++++++- yg/texture.hpp | 4 ++-- yg/yg_tests/skin_loader_test.cpp | 2 +- yg/yg_tests/skin_test.cpp | 2 +- 14 files changed, 78 insertions(+), 33 deletions(-) diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 0d954247dc..a73f79a551 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -94,7 +94,8 @@ GetPlatform().ReadPathForFile("unicode_blocks.txt").c_str(), GetPlatform().ReadPathForFile("fonts_whitelist.txt").c_str(), GetPlatform().ReadPathForFile("fonts_blacklist.txt").c_str(), - 2000000)); + 2000000, + yg::Rt4Bpp)); resourceManager->addFonts(GetPlatform().GetFontNames()); diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 9ebfaa02ea..5a6e444f5a 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -119,19 +119,22 @@ typedef FrameWork framework_t; m_StickyThreshold = 10; m_CurrentAction = NOTHING; - m_isDirtyPosition = false; + m_isDirtyPosition = false; // initialize with currently active screen orientation - [self didRotateFromInterfaceOrientation: self.interfaceOrientation]; + [self didRotateFromInterfaceOrientation: self.interfaceOrientation]; - m_framework->initializeGL([(EAGLView*)self.view renderContext], resourceManager); + // to perform a proper resize + [(EAGLView*)self.view layoutSubviews]; + // restore previous screen position + bool res = m_framework->LoadState(); - // to perform a proper resize - [(EAGLView*)self.view layoutSubviews]; + m_framework->initializeGL([(EAGLView*)self.view renderContext], resourceManager); - // restore previous screen position - if (!m_framework->LoadState()) - m_framework->ShowAll(); + if (!res) + m_framework->ShowAll(); + else + m_framework->UpdateNow(); } return self; diff --git a/map/framework.hpp b/map/framework.hpp index 7d08749c77..a333c9ab3a 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -130,12 +130,6 @@ class FrameWork AddRedrawCommandSure(); } - void UpdateNow() - { - AddRedrawCommand(); - Invalidate(); - } - void SetMaxWorldRect() { m_navigator.SetFromRect(m_model.GetWorldRect()); @@ -271,6 +265,12 @@ public: //@{ public: + void UpdateNow() + { + AddRedrawCommand(); + Invalidate(); + } + void Invalidate() { m_windowHandle->invalidate(); @@ -286,7 +286,6 @@ public: if (!m_navigator.LoadState()) return false; - UpdateNow(); return true; } //@} @@ -310,8 +309,6 @@ public: m_isBenchmarkInitialized = true; InitBenchmark(); } - - UpdateNow(); } bool SetUpdatesEnabled(bool doEnable) @@ -388,6 +385,7 @@ public: catch (redraw_operation_cancelled const &) { m_renderQueue.renderStatePtr()->m_isEmptyModelCurrent = false; + m_renderQueue.renderStatePtr()->m_isEmptyModelActual = false; } if (m_navigator.Update(GetPlatform().TimeInSec())) diff --git a/map/navigator.cpp b/map/navigator.cpp index 0830d82407..018c868957 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -59,7 +59,7 @@ void Navigator::CenterViewport(m2::PointD const & p) void Navigator::SaveState() { - Settings::Set("ScreenClipRect", m_Screen.ClipRect()); + Settings::Set("ScreenClipRect", m_Screen.GlobalRect()); } bool Navigator::LoadState() @@ -67,6 +67,7 @@ bool Navigator::LoadState() m2::RectD rect; if (!Settings::Get("ScreenClipRect", rect)) return false; + SetFromRect(rect); return true; } diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index cef87f33ff..1c1757426f 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -78,7 +78,7 @@ void RenderQueueRoutine::processResize(ScreenBase const & frameScreen) shared_ptr oldActualTarget = m_renderState->m_actualTarget; m_renderState->m_actualTarget.reset(); - m_renderState->m_actualTarget = make_shared_ptr(new yg::gl::Texture(texW, texH)); + m_renderState->m_actualTarget = m_resourceManager->createRenderTarget(texW, texH); m_auxScreen->onSize(texW, texH); m_auxScreen->setRenderTarget(m_renderState->m_actualTarget); @@ -98,8 +98,7 @@ void RenderQueueRoutine::processResize(ScreenBase const & frameScreen) { shared_ptr oldBackBuffer = m_renderState->m_backBufferLayers[i]; m_renderState->m_backBufferLayers[i].reset(); - m_renderState->m_backBufferLayers[i] = make_shared_ptr(new yg::gl::Texture(texW, texH)); - + m_renderState->m_backBufferLayers[i] = m_resourceManager->createRenderTarget(texW, texH); m_auxScreen->setRenderTarget(m_renderState->m_backBufferLayers[i]); m_auxScreen->beginFrame(); m_auxScreen->clear(); @@ -258,6 +257,7 @@ void RenderQueueRoutine::Do() bool isPanning = false; bool doRedrawAll = false; + bool fullRectRepaint = false; /// update areas in pixel coordinates. vector areas; @@ -315,19 +315,26 @@ void RenderQueueRoutine::Do() doRedrawAll = m_renderState->m_doRepaintAll; + fullRectRepaint = false; + if (m_renderState->m_doRepaintAll) { areas.clear(); areas.push_back(curRect); + fullRectRepaint = true; m_threadDrawer->screen()->clearTextTree(); m_renderState->m_doRepaintAll = false; } else + { getUpdateAreas(prevScreen, prevRect, m_currentRenderCommand->m_frameScreen, curRect, areas); + if ((areas.size() == 1) && (areas[0] == curRect)) + fullRectRepaint = true; + } isPanning = IsPanning(prevScreen, m_renderState->m_currentScreen); @@ -403,6 +410,9 @@ void RenderQueueRoutine::Do() } } + if (fullRectRepaint) + m_renderState->m_isEmptyModelActual = m_renderState->m_isEmptyModelCurrent; + /// setting the "whole texture" clip rect to render texts opened by panning. m_threadDrawer->screen()->setClipRect(textureRect); m_threadDrawer->endFrame(); diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 6c255f0a15..2423f5ecf4 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -42,7 +42,11 @@ namespace qt m_framework.OnSize(widthAndHeight.first, widthAndHeight.second); - if (!m_framework.LoadState()) + bool res = m_framework.LoadState(); + + m_framework.UpdateNow(); + + if (!res) return false; UpdateScaleControl(); @@ -136,6 +140,7 @@ namespace qt void DrawWidget::DoResize(int w, int h) { m_framework.OnSize(w, h); + m_framework.UpdateNow(); UpdateScaleControl(); } diff --git a/qt/widgets.cpp b/qt/widgets.cpp index 08cb6e9c97..8bbbe0a3b0 100644 --- a/qt/widgets.cpp +++ b/qt/widgets.cpp @@ -47,7 +47,8 @@ namespace qt GetPlatform().ReadPathForFile("unicode_blocks.txt").c_str(), GetPlatform().ReadPathForFile("fonts_whitelist.txt").c_str(), GetPlatform().ReadPathForFile("fonts_blacklist.txt").c_str(), - 2000000)); + 2000000, + yg::Rt8Bpp)); m_resourceManager->addFonts(GetPlatform().GetFontNames()); diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index ab953228af..352c051674 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -52,7 +52,8 @@ void GLDrawWidget::initializeGL() GetPlatform().ReadPathForFile("unicode_blocks.txt").c_str(), GetPlatform().ReadPathForFile("fonts_whitelist.txt").c_str(), GetPlatform().ReadPathForFile("fonts_blacklist.txt").c_str(), - 2000000)); + 2000000, + yg::Rt8Bpp)); m_resourceManager->addFonts(GetPlatform().GetFontNames()); diff --git a/yg/render_state_updater.cpp b/yg/render_state_updater.cpp index fc43b62b23..6a84cf02ea 100644 --- a/yg/render_state_updater.cpp +++ b/yg/render_state_updater.cpp @@ -55,7 +55,6 @@ namespace yg threads::MutexGuard guard(*m_renderState->m_mutex.get()); swap(m_renderState->m_actualTarget, m_renderState->m_backBufferLayers.front()); m_renderState->m_actualScreen = m_renderState->m_currentScreen; - m_renderState->m_isEmptyModelActual = m_renderState->m_isEmptyModelCurrent; } /// blitting will be performed through diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index ae606b5b0f..25beb78eb8 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -21,12 +21,14 @@ namespace yg 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, - char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxGlyphCacheSize) + char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxGlyphCacheSize, + RtFormat fmt) : m_textureWidth(texWidth), m_textureHeight(texHeight), m_vbSize(vbSize), m_ibSize(ibSize), m_smallVBSize(smallVBSize), m_smallIBSize(smallIBSize), m_blitVBSize(blitVBSize), m_blitIBSize(blitIBSize), - m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize)) + m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize)), + m_format(fmt) { for (size_t i = 0; i < storagesCount; ++i) m_storages.push_back(gl::Storage(vbSize, ibSize)); @@ -234,4 +236,17 @@ namespace yg for (list >::iterator it = m_dynamicTextures.begin(); it != m_dynamicTextures.end(); ++it) *it = shared_ptr(new TDynamicTexture(m_textureWidth, m_textureHeight)); } + + shared_ptr ResourceManager::createRenderTarget(unsigned w, unsigned h) + { + switch (m_format) + { + case Rt8Bpp: + return make_shared_ptr(new gl::Texture(w, h)); + case Rt4Bpp: + return make_shared_ptr(new gl::Texture(w, h)); + default: + throw std::runtime_error("unknows render target format"); + }; + } } diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index c25a0d9d74..141bc77418 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -22,6 +22,12 @@ namespace yg struct GlyphInfo; + enum RtFormat + { + Rt8Bpp, + Rt4Bpp + }; + class ResourceManager { private: @@ -55,13 +61,16 @@ namespace yg GlyphCache m_glyphCache; + RtFormat m_format; + public: 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, - char const * blocksFile, char const * whileListFile, char const * blackListFile, size_t maxGlyphCacheSize); + char const * blocksFile, char const * whileListFile, char const * blackListFile, size_t maxGlyphCacheSize, + RtFormat fmt); shared_ptr const & getTexture(string const & fileName); @@ -88,6 +97,8 @@ namespace yg void memoryWarning(); void enterBackground(); void enterForeground(); + + shared_ptr createRenderTarget(unsigned w, unsigned h); }; Skin * loadSkin(shared_ptr const & resourceManager, diff --git a/yg/texture.hpp b/yg/texture.hpp index adcd442c43..eeb5d8c417 100644 --- a/yg/texture.hpp +++ b/yg/texture.hpp @@ -96,7 +96,7 @@ namespace yg Traits::gl_pixel_format_type, Traits::gl_pixel_data_type, &gil::view(image)(0, 0))); - boost::gil::lodepng_write_view(fullPath.c_str(), gil::view(image)); +// boost::gil::lodepng_write_view(fullPath.c_str(), gil::view(image)); #endif @@ -274,7 +274,7 @@ namespace yg readback(); std::string const fullPath = GetPlatform().WritablePathForFile(fileName); #ifndef OMIM_GL_ES - boost::gil::lodepng_write_view(fullPath.c_str(), view(width(), height())); +// boost::gil::lodepng_write_view(fullPath.c_str(), view(width(), height())); #endif unlock(); } diff --git a/yg/yg_tests/skin_loader_test.cpp b/yg/yg_tests/skin_loader_test.cpp index 32935441d6..fa97d1672d 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, 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::Rt8Bpp)); /*yg::Skin * skin = */loadSkin(rm, "basic.skn", 2, 2); }; diff --git a/yg/yg_tests/skin_test.cpp b/yg/yg_tests/skin_test.cpp index 5230f229a0..b936692d79 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, 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::Rt8Bpp)); yg::Skin * skin = loadSkin(rm, "test.skn", 2, 2); double p0 [] = {1, 1};