diff options
-rw-r--r-- | android/jni/com/mapswithme/core/render_context.cpp | 11 | ||||
-rw-r--r-- | android/jni/com/mapswithme/core/render_context.hpp | 9 | ||||
-rw-r--r-- | graphics/graphics.pro | 3 | ||||
-rw-r--r-- | graphics/opengl/gl_render_context.cpp | 17 | ||||
-rw-r--r-- | graphics/opengl/gl_render_context.hpp | 16 | ||||
-rw-r--r-- | graphics/opengl/renderer.cpp | 1 | ||||
-rw-r--r-- | graphics/render_context.cpp | 30 | ||||
-rw-r--r-- | graphics/render_context.hpp | 56 | ||||
-rw-r--r-- | iphone/Maps/Classes/RenderContext.hpp | 4 | ||||
-rw-r--r-- | iphone/Maps/Classes/RenderContext.mm | 6 | ||||
-rw-r--r-- | map/coverage_generator.cpp | 4 | ||||
-rw-r--r-- | map/coverage_generator.hpp | 4 | ||||
-rw-r--r-- | map/framework.cpp | 4 | ||||
-rw-r--r-- | map/qgl_render_context.cpp | 4 | ||||
-rw-r--r-- | map/qgl_render_context.hpp | 4 | ||||
-rw-r--r-- | map/render_policy.cpp | 4 | ||||
-rw-r--r-- | map/render_policy.hpp | 9 | ||||
-rw-r--r-- | map/tile_renderer.cpp | 4 | ||||
-rw-r--r-- | map/tile_renderer.hpp | 6 | ||||
-rw-r--r-- | map/window_handle.cpp | 4 | ||||
-rw-r--r-- | map/window_handle.hpp | 11 |
21 files changed, 131 insertions, 80 deletions
diff --git a/android/jni/com/mapswithme/core/render_context.cpp b/android/jni/com/mapswithme/core/render_context.cpp index f1de5ca5e4..4bb2a33699 100644 --- a/android/jni/com/mapswithme/core/render_context.cpp +++ b/android/jni/com/mapswithme/core/render_context.cpp @@ -9,19 +9,14 @@ namespace android { - RenderContext::RenderContext() - {} - void RenderContext::makeCurrent() - {} - - shared_ptr<graphics::gl::RenderContext> RenderContext::createShared() { - return make_shared_ptr(new RenderContext()); + startThreadDrawing(); } - void RenderContext::endThreadDrawing() + shared_ptr<graphics::RenderContext> RenderContext::createShared() { + return make_shared_ptr(new RenderContext()); } } diff --git a/android/jni/com/mapswithme/core/render_context.hpp b/android/jni/com/mapswithme/core/render_context.hpp index f878cd7be1..3edba0868c 100644 --- a/android/jni/com/mapswithme/core/render_context.hpp +++ b/android/jni/com/mapswithme/core/render_context.hpp @@ -7,7 +7,7 @@ #pragma once -#include "../../../../../graphics/opengl/rendercontext.hpp" +#include "../../../../../graphics/opengl/gl_render_context.hpp" #include "../../../../../std/shared_ptr.hpp" @@ -16,12 +16,9 @@ namespace android class RenderContext : public graphics::gl::RenderContext { public: - RenderContext(); - virtual void makeCurrent(); + void makeCurrent(); - virtual shared_ptr<graphics::gl::RenderContext> createShared(); - - virtual void endThreadDrawing(); + shared_ptr<graphics::RenderContext> createShared(); }; } diff --git a/graphics/graphics.pro b/graphics/graphics.pro index 9aa46d03a6..d09471721c 100644 --- a/graphics/graphics.pro +++ b/graphics/graphics.pro @@ -75,7 +75,7 @@ HEADERS += \ opengl/renderbuffer.hpp \ opengl/base_texture.hpp \ opengl/managed_texture.hpp \ - opengl/rendercontext.hpp \ + opengl/gl_render_context.hpp \ opengl/clipper.hpp \ opengl/renderer.hpp \ opengl/geometry_renderer.hpp \ @@ -121,6 +121,7 @@ HEADERS += \ image_renderer.hpp \ image_info.hpp \ display_list_renderer.hpp + render_context.hpp \ win32* { SOURCES += opengl/opengl_win32.cpp diff --git a/graphics/opengl/gl_render_context.cpp b/graphics/opengl/gl_render_context.cpp new file mode 100644 index 0000000000..39074228e3 --- /dev/null +++ b/graphics/opengl/gl_render_context.cpp @@ -0,0 +1,17 @@ +#include "gl_render_context.hpp" +#include "opengl.hpp" + +namespace graphics +{ + namespace gl + { + void RenderContext::startThreadDrawing() + { + OGLCHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + OGLCHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1)); + } + + void RenderContext::endThreadDrawing() + {} + } +} diff --git a/graphics/opengl/gl_render_context.hpp b/graphics/opengl/gl_render_context.hpp new file mode 100644 index 0000000000..1d4f25e855 --- /dev/null +++ b/graphics/opengl/gl_render_context.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "../render_context.hpp" + +namespace graphics +{ + namespace gl + { + class RenderContext : public graphics::RenderContext + { + public: + void startThreadDrawing(); + void endThreadDrawing(); + }; + } +} diff --git a/graphics/opengl/renderer.cpp b/graphics/opengl/renderer.cpp index c976164ba1..92a4482d8f 100644 --- a/graphics/opengl/renderer.cpp +++ b/graphics/opengl/renderer.cpp @@ -1,4 +1,5 @@ #include "../base/logging.hpp" +#include "../render_context.hpp" #include "renderer.hpp" #include "data_traits.hpp" diff --git a/graphics/render_context.cpp b/graphics/render_context.cpp index eca9c14636..0821112b5d 100644 --- a/graphics/render_context.cpp +++ b/graphics/render_context.cpp @@ -1,21 +1,25 @@ #include "../base/SRC_FIRST.hpp" -#include "rendercontext.hpp" -#include "opengl.hpp" +#include "render_context.hpp" namespace graphics { - namespace gl + void RenderContext::setMatrix(EMatrix mt, math::Matrix<float, 4, 4> const & m) { - void RenderContext::initParams() - { - OGLCHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); - OGLCHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1)); - graphics::gl::InitializeThread(); - } + m_matrices[mt] = m; + } + + math::Matrix<float, 4, 4> const & RenderContext::matrix(EMatrix m) const + { + map<EMatrix, math::Matrix<float, 4, 4> >::const_iterator it = m_matrices.find(m); + return it->second; + } - void RenderContext::endThreadDrawing() - { - graphics::gl::FinalizeThread(); - } + RenderContext::RenderContext() + { + setMatrix(EModelView, math::Identity<float, 4>()); + setMatrix(EProjection, math::Identity<float, 4>()); } + + RenderContext::~RenderContext() + {} } diff --git a/graphics/render_context.hpp b/graphics/render_context.hpp index 6ce645f78d..f9ddb584f6 100644 --- a/graphics/render_context.hpp +++ b/graphics/render_context.hpp @@ -1,25 +1,51 @@ #pragma once #include "../../std/shared_ptr.hpp" +#include "../../std/map.hpp" +#include "../../base/matrix.hpp" +#include "defines.hpp" namespace graphics { namespace gl { - class RenderContext - { - public: - virtual ~RenderContext() {} - /// Make this context current for the specified thread - virtual void makeCurrent() = 0; - /// Create a render context which is shared with this one. - virtual shared_ptr<RenderContext> createShared() = 0; - /// called at the end of thread - virtual void endThreadDrawing(); - /// !! IMPORTANT !! - /// this function must be called from each opengl - /// thread to setup texture related params - static void initParams(); - }; + class Program; + class BaseTexture; } + + /// base class for render contexts. + /// contains current render state data. + class RenderContext + { + private: + + /// Rendering states + /// @{ + map<EMatrix, math::Matrix<float, 4, 4> > m_matrices; + /// @} + + public: + + /// Working with rendering states. + /// @{ + math::Matrix<float, 4, 4> const & matrix(EMatrix m) const; + void setMatrix(EMatrix mt, math::Matrix<float, 4, 4> const & m); + /// @} + + /// Constructor. + RenderContext(); + /// Destructor. + virtual ~RenderContext(); + /// Make this context current for the specified thread. + virtual void makeCurrent() = 0; + /// Create a render context which is shared with this one. + /// Context sharing means that all resources created in one context + /// can be used in shared context and vice versa. + virtual shared_ptr<RenderContext> createShared() = 0; + /// this function should be called from each opengl thread + /// to setup some thread parameters. + virtual void startThreadDrawing() = 0; + /// called at the end of thread + virtual void endThreadDrawing() = 0; + }; } diff --git a/iphone/Maps/Classes/RenderContext.hpp b/iphone/Maps/Classes/RenderContext.hpp index d83dddec2d..e58740d85e 100644 --- a/iphone/Maps/Classes/RenderContext.hpp +++ b/iphone/Maps/Classes/RenderContext.hpp @@ -13,7 +13,7 @@ #include <OpenGLES/ES1/gl.h> #include <OpenGLES/ES1/glext.h> -#include "../../../graphics/opengl/rendercontext.hpp" +#include "../../../graphics/opengl/gl_render_context.hpp" #include "../../../std/shared_ptr.hpp" @@ -34,7 +34,7 @@ namespace iphone /// Make this rendering context current void makeCurrent(); /// create a shared render context - shared_ptr<graphics::gl::RenderContext> createShared(); + shared_ptr<graphics::RenderContext> createShared(); /// @TODO void endThreadDrawing() {} diff --git a/iphone/Maps/Classes/RenderContext.mm b/iphone/Maps/Classes/RenderContext.mm index f35fea07d8..38fbaf51de 100644 --- a/iphone/Maps/Classes/RenderContext.mm +++ b/iphone/Maps/Classes/RenderContext.mm @@ -29,12 +29,12 @@ namespace iphone void RenderContext::makeCurrent() { [EAGLContext setCurrentContext:m_context]; - graphics::gl::RenderContext::initParams(); + startThreadDrawing(); } - shared_ptr<graphics::gl::RenderContext> RenderContext::createShared() + shared_ptr<graphics::RenderContext> RenderContext::createShared() { - return shared_ptr<graphics::gl::RenderContext>(new RenderContext(this)); + return shared_ptr<graphics::RenderContext>(new RenderContext(this)); } EAGLContext * RenderContext::getEAGLContext() diff --git a/map/coverage_generator.cpp b/map/coverage_generator.cpp index 7779746527..a2f8c9d465 100644 --- a/map/coverage_generator.cpp +++ b/map/coverage_generator.cpp @@ -6,7 +6,7 @@ #include "tile_set.hpp" #include "../graphics/skin.hpp" -#include "../graphics/opengl/rendercontext.hpp" +#include "../graphics/opengl/gl_render_context.hpp" #include "../base/logging.hpp" @@ -18,7 +18,7 @@ CoverageGenerator::CoverageGenerator( string const & skinName, TileRenderer * tileRenderer, shared_ptr<WindowHandle> const & windowHandle, - shared_ptr<graphics::gl::RenderContext> const & primaryRC, + shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, graphics::PacketsQueue * glQueue, RenderPolicy::TCountryNameFn countryNameFn) diff --git a/map/coverage_generator.hpp b/map/coverage_generator.hpp index b3b68b8e9f..3a89292d32 100644 --- a/map/coverage_generator.hpp +++ b/map/coverage_generator.hpp @@ -46,7 +46,7 @@ private: TileRenderer * m_tileRenderer; shared_ptr<graphics::ResourceManager> m_resourceManager; - shared_ptr<graphics::gl::RenderContext> m_renderContext; + shared_ptr<graphics::RenderContext> m_renderContext; ScreenCoverage * m_workCoverage; ScreenCoverage * m_currentCoverage; @@ -76,7 +76,7 @@ public: CoverageGenerator(string const & skinName, TileRenderer * tileRenderer, shared_ptr<WindowHandle> const & windowHandle, - shared_ptr<graphics::gl::RenderContext> const & primaryRC, + shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, graphics::PacketsQueue * glQueue, RenderPolicy::TCountryNameFn countryNameFn); diff --git a/map/framework.cpp b/map/framework.cpp index bd0dbce5fb..f9b53e3065 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -27,8 +27,6 @@ #include "../coding/internal/file_data.hpp" -#include "../graphics/opengl/rendercontext.hpp" - #include "../geometry/angles.hpp" #include "../geometry/distance_on_sphere.hpp" @@ -1265,8 +1263,6 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy) m_navigator.SetMinScreenParams(static_cast<unsigned>(m_minRulerWidth * renderPolicy->VisualScale()), m_metresMinWidth); - - graphics::gl::RenderContext::initParams(); } m_guiController->ResetRenderParams(); diff --git a/map/qgl_render_context.cpp b/map/qgl_render_context.cpp index b666ec54a4..da9efd51b5 100644 --- a/map/qgl_render_context.cpp +++ b/map/qgl_render_context.cpp @@ -29,10 +29,10 @@ namespace qt void RenderContext::makeCurrent() { m_context->makeCurrent(); - graphics::gl::RenderContext::initParams(); + startThreadDrawing(); } - shared_ptr<graphics::gl::RenderContext> RenderContext::createShared() + shared_ptr<graphics::RenderContext> RenderContext::createShared() { return shared_ptr<graphics::gl::RenderContext>(new RenderContext(this)); } diff --git a/map/qgl_render_context.hpp b/map/qgl_render_context.hpp index 0e091443a5..69faff2fa3 100644 --- a/map/qgl_render_context.hpp +++ b/map/qgl_render_context.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../graphics/opengl/rendercontext.hpp" +#include "../graphics/opengl/gl_render_context.hpp" #include "../std/shared_ptr.hpp" @@ -30,7 +30,7 @@ namespace qt /// Make this rendering context current void makeCurrent(); - shared_ptr<graphics::gl::RenderContext> createShared(); + shared_ptr<graphics::RenderContext> createShared(); /// Leave previous logic, but fix thread widget deletion error. void endThreadDrawing(); diff --git a/map/render_policy.cpp b/map/render_policy.cpp index 467662d556..d098ce0136 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -11,6 +11,7 @@ #include "../anim/task.hpp" #include "../graphics/opengl/opengl.hpp" +#include "../graphics/opengl/gl_render_context.hpp" #include "../graphics/skin.hpp" #include "../indexer/scales.hpp" @@ -39,9 +40,12 @@ RenderPolicy::RenderPolicy(Params const & p, { LOG(LDEBUG, ("each BaseRule will hold up to", idCacheSize, "cached values")); drule::rules().ResizeCaches(idCacheSize); + graphics::gl::InitExtensions(); graphics::gl::InitializeThread(); graphics::gl::CheckExtensionSupport(); + + m_primaryRC->startThreadDrawing(); } void RenderPolicy::InitCacheScreen() diff --git a/map/render_policy.hpp b/map/render_policy.hpp index 34eed05765..0c4908967e 100644 --- a/map/render_policy.hpp +++ b/map/render_policy.hpp @@ -20,10 +20,7 @@ namespace anim namespace graphics { - namespace gl - { - class RenderContext; - } + class RenderContext; class Skin; class GlyphCache; @@ -58,7 +55,7 @@ protected: shared_ptr<graphics::ResourceManager> m_resourceManager; shared_ptr<graphics::Skin> m_skin; shared_ptr<graphics::Screen> m_cacheScreen; - shared_ptr<graphics::gl::RenderContext> m_primaryRC; + shared_ptr<graphics::RenderContext> m_primaryRC; shared_ptr<WindowHandle> m_windowHandle; shared_ptr<Drawer> m_drawer; TRenderFn m_renderFn; @@ -82,7 +79,7 @@ public: VideoTimer * m_videoTimer; bool m_useDefaultFB; graphics::ResourceManager::Params m_rmParams; - shared_ptr<graphics::gl::RenderContext> m_primaryRC; + shared_ptr<graphics::RenderContext> m_primaryRC; double m_visualScale; string m_skinName; size_t m_screenWidth; diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp index 8367e6c118..991e56eb8b 100644 --- a/map/tile_renderer.cpp +++ b/map/tile_renderer.cpp @@ -4,7 +4,7 @@ #include "window_handle.hpp" #include "../graphics/opengl/opengl.hpp" -#include "../graphics/opengl/rendercontext.hpp" +#include "../graphics/opengl/gl_render_context.hpp" #include "../graphics/opengl/base_texture.hpp" #include "../graphics/packets_queue.hpp" @@ -24,7 +24,7 @@ TileRenderer::TileRenderer( unsigned executorsCount, graphics::Color const & bgColor, RenderPolicy::TRenderFn const & renderFn, - shared_ptr<graphics::gl::RenderContext> const & primaryRC, + shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, double visualScale, graphics::PacketsQueue ** packetsQueues diff --git a/map/tile_renderer.hpp b/map/tile_renderer.hpp index 96e6d97b3f..7dd47a040c 100644 --- a/map/tile_renderer.hpp +++ b/map/tile_renderer.hpp @@ -42,13 +42,13 @@ protected: Drawer * m_drawer; Drawer::Params m_drawerParams; shared_ptr<graphics::gl::BaseTexture> m_dummyRT; - shared_ptr<graphics::gl::RenderContext> m_renderContext; + shared_ptr<graphics::RenderContext> m_renderContext; shared_ptr<graphics::gl::RenderBuffer> m_depthBuffer; }; buffer_vector<ThreadData, 4> m_threadData; - shared_ptr<graphics::gl::RenderContext> m_primaryContext; + shared_ptr<graphics::RenderContext> m_primaryContext; TileCache m_tileCache; @@ -88,7 +88,7 @@ public: unsigned tasksCount, graphics::Color const & bgColor, RenderPolicy::TRenderFn const & renderFn, - shared_ptr<graphics::gl::RenderContext> const & primaryRC, + shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, double visualScale, graphics::PacketsQueue ** packetsQueue); diff --git a/map/window_handle.cpp b/map/window_handle.cpp index df2a4c0a52..7650d91d91 100644 --- a/map/window_handle.cpp +++ b/map/window_handle.cpp @@ -71,12 +71,12 @@ void WindowHandle::setNeedRedraw(bool flag) checkTimer(); } -shared_ptr<graphics::gl::RenderContext> const & WindowHandle::renderContext() +shared_ptr<graphics::RenderContext> const & WindowHandle::renderContext() { return m_renderContext; } -void WindowHandle::setRenderContext(shared_ptr<graphics::gl::RenderContext> const & renderContext) +void WindowHandle::setRenderContext(shared_ptr<graphics::RenderContext> const & renderContext) { m_renderContext = renderContext; } diff --git a/map/window_handle.hpp b/map/window_handle.hpp index c6e5e26a32..f2cb9c13b2 100644 --- a/map/window_handle.hpp +++ b/map/window_handle.hpp @@ -12,17 +12,14 @@ namespace graphics { - namespace gl - { - class RenderContext; - } + class RenderContext; } class RenderPolicy; class WindowHandle { - shared_ptr<graphics::gl::RenderContext> m_renderContext; + shared_ptr<graphics::RenderContext> m_renderContext; RenderPolicy * m_renderPolicy; bool m_hasPendingUpdates; @@ -49,9 +46,9 @@ public: void setNeedRedraw(bool flag); - shared_ptr<graphics::gl::RenderContext> const & renderContext(); + shared_ptr<graphics::RenderContext> const & renderContext(); - void setRenderContext(shared_ptr<graphics::gl::RenderContext> const & renderContext); + void setRenderContext(shared_ptr<graphics::RenderContext> const & renderContext); bool setUpdatesEnabled(bool doEnable); |