forked from organicmaps/organicmaps
refactored RenderContext hierarchy.
This commit is contained in:
parent
bf20bd8216
commit
25e5d82be1
21 changed files with 132 additions and 81 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
17
graphics/opengl/gl_render_context.cpp
Normal file
17
graphics/opengl/gl_render_context.cpp
Normal file
|
@ -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()
|
||||
{}
|
||||
}
|
||||
}
|
16
graphics/opengl/gl_render_context.hpp
Normal file
16
graphics/opengl/gl_render_context.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "../render_context.hpp"
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
namespace gl
|
||||
{
|
||||
class RenderContext : public graphics::RenderContext
|
||||
{
|
||||
public:
|
||||
void startThreadDrawing();
|
||||
void endThreadDrawing();
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "../base/logging.hpp"
|
||||
#include "../render_context.hpp"
|
||||
|
||||
#include "renderer.hpp"
|
||||
#include "data_traits.hpp"
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
void RenderContext::endThreadDrawing()
|
||||
{
|
||||
graphics::gl::FinalizeThread();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
RenderContext::RenderContext()
|
||||
{
|
||||
setMatrix(EModelView, math::Identity<float, 4>());
|
||||
setMatrix(EProjection, math::Identity<float, 4>());
|
||||
}
|
||||
|
||||
RenderContext::~RenderContext()
|
||||
{}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue