Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-11-30 19:35:37 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:47:45 +0300
commit2de2bdc3a1fe64656fdd720a71e3bbbca85dddde (patch)
tree286411d27036506762a76243f7099bc5783404b4
parente0663bab7e418345061d826fcbdf77044981dd3b (diff)
refactored render states to use only programmable pipeline.
-rw-r--r--android/jni/com/mapswithme/core/render_context.cpp5
-rw-r--r--graphics/blitter.cpp5
-rw-r--r--graphics/display_list.cpp6
-rw-r--r--graphics/display_list.hpp2
-rw-r--r--graphics/display_list_renderer.cpp8
-rw-r--r--graphics/display_list_renderer.hpp3
-rw-r--r--graphics/geometry_batcher.cpp25
-rw-r--r--graphics/geometry_batcher.hpp5
-rw-r--r--graphics/opengl/clipper.cpp4
-rw-r--r--graphics/opengl/geometry_renderer.cpp151
-rw-r--r--graphics/opengl/geometry_renderer.hpp41
-rw-r--r--graphics/opengl/gl_render_context.cpp38
-rw-r--r--graphics/opengl/gl_render_context.hpp37
-rw-r--r--graphics/opengl/renderer.cpp11
-rw-r--r--graphics/opengl/renderer.hpp5
-rw-r--r--graphics/render_context.cpp28
-rw-r--r--graphics/render_context.hpp23
-rw-r--r--iphone/Maps/Classes/RenderContext.hpp2
-rw-r--r--iphone/Maps/Classes/RenderContext.mm5
-rw-r--r--map/coverage_generator.cpp11
-rw-r--r--map/qgl_render_context.cpp9
-rw-r--r--map/qgl_render_context.hpp2
-rw-r--r--map/render_policy.cpp3
-rw-r--r--map/screen_coverage.cpp6
-rw-r--r--map/simple_render_policy.cpp4
-rw-r--r--map/tile_renderer.cpp7
-rw-r--r--map/tile_renderer.hpp1
-rw-r--r--map/tiling_render_policy_mt.cpp4
-rw-r--r--map/tiling_render_policy_st.cpp6
-rw-r--r--qt_tstfrm/tstwidgets.cpp2
30 files changed, 323 insertions, 136 deletions
diff --git a/android/jni/com/mapswithme/core/render_context.cpp b/android/jni/com/mapswithme/core/render_context.cpp
index 4bb2a33699..47b1241458 100644
--- a/android/jni/com/mapswithme/core/render_context.cpp
+++ b/android/jni/com/mapswithme/core/render_context.cpp
@@ -11,12 +11,13 @@ namespace android
{
void RenderContext::makeCurrent()
{
- startThreadDrawing();
}
shared_ptr<graphics::RenderContext> RenderContext::createShared()
{
- return make_shared_ptr(new RenderContext());
+ shared_ptr<RenderContext> rc(new RenderContext());
+ rc->setResourceManager(resourceManager());
+ return rc;
}
}
diff --git a/graphics/blitter.cpp b/graphics/blitter.cpp
index 54f3c3eb2d..3280b1a2b5 100644
--- a/graphics/blitter.cpp
+++ b/graphics/blitter.cpp
@@ -157,7 +157,10 @@ namespace graphics
m2::RectF const & texRect,
shared_ptr<gl::BaseTexture> const & texture)
{
- shared_ptr<IMMDrawTexturedRect> command(new IMMDrawTexturedRect(rect, texRect, texture, resourceManager()));
+ shared_ptr<IMMDrawTexturedRect> command(new IMMDrawTexturedRect(rect,
+ texRect,
+ texture,
+ resourceManager()));
processCommand(command);
}
diff --git a/graphics/display_list.cpp b/graphics/display_list.cpp
index 7bcf0520a0..4206be5c70 100644
--- a/graphics/display_list.cpp
+++ b/graphics/display_list.cpp
@@ -34,6 +34,12 @@ namespace graphics
m_commands.clear();
}
+ void DisplayList::applySharpStates(shared_ptr<ApplySharpStatesCmd> const & cmd)
+ {
+ cmd->setIsDebugging(m_isDebugging);
+ m_commands.push_back(cmd);
+ }
+
void DisplayList::applyBlitStates(shared_ptr<ApplyBlitStatesCmd> const & cmd)
{
cmd->setIsDebugging(m_isDebugging);
diff --git a/graphics/display_list.hpp b/graphics/display_list.hpp
index 68d24af86f..b4c9b5c9b9 100644
--- a/graphics/display_list.hpp
+++ b/graphics/display_list.hpp
@@ -16,6 +16,7 @@ namespace graphics
typedef gl::GeometryRenderer::FreeStorage FreeStorageCmd;
typedef gl::GeometryRenderer::ApplyBlitStates ApplyBlitStatesCmd;
typedef gl::GeometryRenderer::ApplyStates ApplyStatesCmd;
+ typedef gl::GeometryRenderer::ApplySharpStates ApplySharpStatesCmd;
typedef gl::GeometryRenderer::UploadData UploadDataCmd;
list<shared_ptr<Command> > m_commands;
@@ -37,6 +38,7 @@ namespace graphics
void applyStates(shared_ptr<ApplyStatesCmd> const & cmd);
void applyBlitStates(shared_ptr<ApplyBlitStatesCmd> const & cmd);
+ void applySharpStates(shared_ptr<ApplySharpStatesCmd> const & cmd);
void drawGeometry(shared_ptr<DrawGeometryCmd> const & cmd);
void unlockStorage(shared_ptr<UnlockStorageCmd> const & cmd);
void discardStorage(shared_ptr<DiscardStorageCmd> const & cmd);
diff --git a/graphics/display_list_renderer.cpp b/graphics/display_list_renderer.cpp
index 3c00bc84bc..ca8b519d04 100644
--- a/graphics/display_list_renderer.cpp
+++ b/graphics/display_list_renderer.cpp
@@ -149,6 +149,14 @@ namespace graphics
base_t::applyStates();
}
+ void DisplayListRenderer::applySharpStates()
+ {
+ if (m_displayList)
+ m_displayList->applySharpStates(make_shared_ptr(new ApplySharpStates()));
+ else
+ base_t::applySharpStates();
+ }
+
void DisplayListRenderer::addCheckPoint()
{
if (m_displayList)
diff --git a/graphics/display_list_renderer.hpp b/graphics/display_list_renderer.hpp
index f065442616..c0036dc679 100644
--- a/graphics/display_list_renderer.hpp
+++ b/graphics/display_list_renderer.hpp
@@ -59,7 +59,8 @@ namespace graphics
void applyBlitStates();
/// apply geometry rendering states
void applyStates();
-
+ /// apply sharp geometry states
+ void applySharpStates();
/// @}
};
}
diff --git a/graphics/geometry_batcher.cpp b/graphics/geometry_batcher.cpp
index 0fbaae07be..a87dffd3d8 100644
--- a/graphics/geometry_batcher.cpp
+++ b/graphics/geometry_batcher.cpp
@@ -8,6 +8,7 @@
#include "opengl/base_texture.hpp"
#include "opengl/utils.hpp"
#include "opengl/opengl.hpp"
+#include "opengl/gl_render_context.hpp"
#include "../geometry/rect2d.hpp"
@@ -801,12 +802,6 @@ namespace graphics
base_t::drawDisplayList(dl, m);
}
- void GeometryBatcher::setPixelPrecision(bool flag)
- {
- flush(-1);
- base_t::setPixelPrecision(flag);
- }
-
void GeometryBatcher::uploadStyles(shared_ptr<ResourceStyle> const * styles,
size_t count,
shared_ptr<gl::BaseTexture> const & texture)
@@ -841,4 +836,22 @@ namespace graphics
bytesUploaded = 0;
}
}
+
+ void GeometryBatcher::applyStates()
+ {
+ flush(-1);
+ base_t::applyStates();
+ }
+
+ void GeometryBatcher::applyBlitStates()
+ {
+ flush(-1);
+ base_t::applyBlitStates();
+ }
+
+ void GeometryBatcher::applySharpStates()
+ {
+ flush(-1);
+ base_t::applySharpStates();
+ }
} // namespace graphics
diff --git a/graphics/geometry_batcher.hpp b/graphics/geometry_batcher.hpp
index 03bcf05a16..6f339b7bcd 100644
--- a/graphics/geometry_batcher.hpp
+++ b/graphics/geometry_batcher.hpp
@@ -212,10 +212,13 @@ namespace graphics
void setDisplayList(DisplayList * dl);
void drawDisplayList(DisplayList * dl, math::Matrix<double, 3, 3> const & m);
- void setPixelPrecision(bool flag);
void uploadStyles(shared_ptr<ResourceStyle> const * styles,
size_t count,
shared_ptr<gl::BaseTexture> const & texture);
+
+ void applyStates();
+ void applyBlitStates();
+ void applySharpStates();
};
}
diff --git a/graphics/opengl/clipper.cpp b/graphics/opengl/clipper.cpp
index 2c61e18dba..4fb1550117 100644
--- a/graphics/opengl/clipper.cpp
+++ b/graphics/opengl/clipper.cpp
@@ -40,14 +40,14 @@ namespace graphics
{
if (isDebugging())
LOG(LINFO, ("enabling scissor test"));
- OGLCHECK(glEnableFn(GL_SCISSOR_TEST));
+ OGLCHECK(glEnable(GL_SCISSOR_TEST));
}
else
{
if (isDebugging())
{
LOG(LINFO, ("disabling scissor test"));
- OGLCHECK(glDisableFn(GL_SCISSOR_TEST));
+ OGLCHECK(glDisable(GL_SCISSOR_TEST));
}
}
}
diff --git a/graphics/opengl/geometry_renderer.cpp b/graphics/opengl/geometry_renderer.cpp
index bb59cd9675..287e36f210 100644
--- a/graphics/opengl/geometry_renderer.cpp
+++ b/graphics/opengl/geometry_renderer.cpp
@@ -6,7 +6,9 @@
#include "buffer_object.hpp"
#include "managed_texture.hpp"
#include "vertex.hpp"
-#include "opengl/opengl.hpp"
+#include "opengl.hpp"
+#include "gl_render_context.hpp"
+#include "defines_conv.hpp"
#include "../std/bind.hpp"
#include "../base/logging.hpp"
@@ -161,9 +163,17 @@ namespace graphics
}
blitStorage.m_vertices->unlock();
- blitStorage.m_vertices->makeCurrent();
- Vertex::setupLayout(blitStorage.m_vertices->glPtr());
+ gl::RenderContext * rc = static_cast<gl::RenderContext*>(renderContext());
+ ProgramManager * pm = rc->programManager();
+ shared_ptr<Program> prg = pm->getProgram("basic", "noalphatest");
+
+ prg->setParam("ModelViewM", rc->matrix(EModelView));
+ prg->setParam("ProjM", rc->matrix(EProjection));
+ prg->setParam("Texture", 0);
+ prg->setStorage(blitStorage);
+ prg->setVertexDecl(gl::Vertex::getVertexDecl());
+ prg->makeCurrent();
if (m_texture)
m_texture->makeCurrent();
@@ -171,17 +181,14 @@ namespace graphics
unsigned short idxData[4] = {0, 1, 2, 3};
memcpy(blitStorage.m_indices->data(), idxData, sizeof(idxData));
blitStorage.m_indices->unlock();
- blitStorage.m_indices->makeCurrent();
- OGLCHECK(glDisableFn(GL_ALPHA_TEST_MWM));
- OGLCHECK(glDisableFn(GL_BLEND));
- OGLCHECK(glDisableFn(GL_DEPTH_TEST));
+ OGLCHECK(glDisable(GL_BLEND));
+ OGLCHECK(glDisable(GL_DEPTH_TEST));
OGLCHECK(glDepthMask(GL_FALSE));
- OGLCHECK(glDrawElementsFn(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, blitStorage.m_indices->glPtr()));
- OGLCHECK(glDepthMask(GL_TRUE));
- OGLCHECK(glEnableFn(GL_DEPTH_TEST));
- OGLCHECK(glEnableFn(GL_BLEND));
- OGLCHECK(glEnableFn(GL_ALPHA_TEST_MWM));
+ OGLCHECK(glDrawElements(GL_TRIANGLE_FAN,
+ 4,
+ GL_UNSIGNED_SHORT,
+ blitStorage.m_indices->glPtr()));
blitStorage.m_vertices->discard();
blitStorage.m_indices->discard();
@@ -194,46 +201,33 @@ namespace graphics
if (isDebugging())
LOG(LINFO, ("performing DrawGeometry command"));
- m_storage.m_vertices->makeCurrent();
- /// it's crucial to setupLayout after vertices->makeCurrent
- Vertex::setupLayout(m_storage.m_vertices->glPtr());
- m_storage.m_indices->makeCurrent();
-
if (isDebugging())
LOG(LINFO, ("using", m_texture->id(), "texture"));
if (isDebugging())
LOG(LINFO, ("drawing", m_indicesCount / 3, "triangles"));
+ gl::RenderContext * rc = static_cast<gl::RenderContext*>(renderContext());
+
+ shared_ptr<Program> const & prg = rc->program();
+
+ prg->setStorage(m_storage);
+ prg->setVertexDecl(Vertex::getVertexDecl());
+ prg->makeCurrent();
+
if (m_texture)
m_texture->makeCurrent();
else
LOG(LINFO, ("null texture used in DrawGeometry"));
-// OGLCHECK(glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ));
-
unsigned glPrimType;
+ convert(m_primitiveType, glPrimType);
- switch (m_primitiveType)
- {
- case ETrianglesFan:
- glPrimType = GL_TRIANGLE_FAN;
- break;
- case ETriangles:
- glPrimType = GL_TRIANGLES;
- break;
- case ETrianglesStrip:
- glPrimType = GL_TRIANGLE_STRIP;
- break;
- };
-
- OGLCHECK(glDrawElementsFn(
+ OGLCHECK(glDrawElements(
glPrimType,
m_indicesCount,
GL_UNSIGNED_SHORT,
((unsigned char*)m_storage.m_indices->glPtr()) + m_indicesOffs));
-
-// OGLCHECK(glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ));
}
void GeometryRenderer::DrawGeometry::dump()
@@ -386,20 +380,17 @@ namespace graphics
LOG(LINFO, ("performing ApplyStates command"));
// Disable dither to fix 4-bit textures "grid" issue on Nvidia Tegra cards
- OGLCHECK(glDisableFn(GL_DITHER));
+ OGLCHECK(glDisable(GL_DITHER));
OGLCHECK(glActiveTexture(GL_TEXTURE0));
OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
- OGLCHECK(glEnableFn(GL_DEPTH_TEST));
+ OGLCHECK(glEnable(GL_DEPTH_TEST));
OGLCHECK(glDepthFunc(GL_LEQUAL));
- OGLCHECK(glEnableFn(GL_ALPHA_TEST_MWM));
- OGLCHECK(glAlphaFuncFn(GL_NOTEQUAL, 0.0));
-
- OGLCHECK(glEnableFn(GL_BLEND));
+ OGLCHECK(glEnable(GL_BLEND));
OGLCHECK(glDepthMask(GL_TRUE));
if (graphics::gl::g_isSeparateBlendFuncSupported)
@@ -411,11 +402,16 @@ namespace graphics
OGLCHECK(glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA));
- }
+ /// Applying program
+ gl::RenderContext * rc = static_cast<gl::RenderContext*>(renderContext());
+ ProgramManager * pm = rc->programManager();
+ shared_ptr<Program> prg = pm->getProgram("basic", "alphatest");
- void GeometryRenderer::ApplyStates::cancel()
- {
- perform();
+ prg->setParam("ModelViewM", rc->matrix(EModelView));
+ prg->setParam("ProjM", rc->matrix(EProjection));
+ prg->setParam("Texture", 0);
+
+ rc->setProgram(prg);
}
void GeometryRenderer::applyStates()
@@ -428,15 +424,19 @@ namespace graphics
if (isDebugging())
LOG(LINFO, ("performing ApplyBlitStates command"));
- OGLCHECK(glDisableFn(GL_ALPHA_TEST_MWM));
- OGLCHECK(glDisableFn(GL_BLEND));
- OGLCHECK(glDisableFn(GL_DEPTH_TEST));
+ OGLCHECK(glDisable(GL_DEPTH_TEST));
OGLCHECK(glDepthMask(GL_FALSE));
- }
- void GeometryRenderer::ApplyBlitStates::cancel()
- {
- perform();
+ /// Applying program
+ gl::RenderContext * rc = static_cast<gl::RenderContext*>(renderContext());
+ ProgramManager * pm = rc->programManager();
+ shared_ptr<Program> prg = pm->getProgram("basic", "noalphatest");
+
+ prg->setParam("ModelViewM", rc->matrix(EModelView));
+ prg->setParam("ProjM", rc->matrix(EProjection));
+ prg->setParam("Texture", 0);
+
+ rc->setProgram(prg);
}
void GeometryRenderer::applyBlitStates()
@@ -444,12 +444,49 @@ namespace graphics
processCommand(make_shared_ptr(new ApplyBlitStates()));
}
- void GeometryRenderer::loadMatrix(EMatrix mt,
- math::Matrix<float, 4, 4> const & m)
+ void GeometryRenderer::ApplySharpStates::perform()
+ {
+ if (isDebugging())
+ LOG(LINFO, ("performing ApplySharpStates command"));
+
+ // Disable dither to fix 4-bit textures "grid" issue on Nvidia Tegra cards
+ OGLCHECK(glDisable(GL_DITHER));
+
+ OGLCHECK(glActiveTexture(GL_TEXTURE0));
+
+ OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
+ OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
+
+ OGLCHECK(glEnable(GL_DEPTH_TEST));
+ OGLCHECK(glDepthFunc(GL_LEQUAL));
+
+ OGLCHECK(glEnable(GL_BLEND));
+ OGLCHECK(glDepthMask(GL_TRUE));
+
+ if (graphics::gl::g_isSeparateBlendFuncSupported)
+ OGLCHECK(glBlendFuncSeparateFn(GL_SRC_ALPHA,
+ GL_ONE_MINUS_SRC_ALPHA,
+ GL_ZERO,
+ GL_ONE));
+ else
+ OGLCHECK(glBlendFunc(GL_SRC_ALPHA,
+ GL_ONE_MINUS_SRC_ALPHA));
+
+ /// Applying program
+ gl::RenderContext * rc = static_cast<gl::RenderContext*>(renderContext());
+ ProgramManager * pm = rc->programManager();
+ shared_ptr<Program> prg = pm->getProgram("sharp", "alphatest");
+
+ prg->setParam("ModelViewM", rc->matrix(EModelView));
+ prg->setParam("ProjM", rc->matrix(EProjection));
+ prg->setParam("Texture", 0);
+
+ rc->setProgram(prg);
+ }
+
+ void GeometryRenderer::applySharpStates()
{
- OGLCHECK(glMatrixModeFn(GL_MODELVIEW_MWM));
- OGLCHECK(glLoadIdentityFn());
- OGLCHECK(glLoadMatrixfFn(&m(0, 0)));
+ processCommand(make_shared_ptr(new ApplySharpStates()));
}
}
}
diff --git a/graphics/opengl/geometry_renderer.hpp b/graphics/opengl/geometry_renderer.hpp
index bdb691e179..e543aa2dec 100644
--- a/graphics/opengl/geometry_renderer.hpp
+++ b/graphics/opengl/geometry_renderer.hpp
@@ -39,6 +39,18 @@ namespace graphics
void dump();
};
+ struct DrawGeometry : Command
+ {
+ shared_ptr<BaseTexture> m_texture;
+ Storage m_storage;
+ size_t m_indicesCount;
+ size_t m_indicesOffs;
+ EPrimitives m_primitiveType;
+
+ void perform();
+ void dump();
+ };
+
struct IMMDrawTexturedPrimitives : Command
{
buffer_vector<m2::PointF, 8> m_pts;
@@ -48,7 +60,6 @@ namespace graphics
bool m_hasTexture;
graphics::Color m_color;
bool m_hasColor;
-
shared_ptr<ResourceManager> m_resourceManager;
void perform();
@@ -62,18 +73,6 @@ namespace graphics
shared_ptr<ResourceManager> const & rm);
};
- struct DrawGeometry : Command
- {
- shared_ptr<BaseTexture> m_texture;
- Storage m_storage;
- size_t m_indicesCount;
- size_t m_indicesOffs;
- EPrimitives m_primitiveType;
-
- void perform();
- void dump();
- };
-
struct FreeStorage : public Command
{
TStoragePool * m_storagePool;
@@ -109,23 +108,23 @@ namespace graphics
void cancel();
};
+ struct ApplySharpStates : public Command
+ {
+ void perform();
+ };
+
struct ApplyStates : public Command
{
void perform();
- void cancel();
};
struct ApplyBlitStates : public Command
{
void perform();
- void cancel();
};
GeometryRenderer(base_t::Params const & params);
- void applyBlitStates();
- void applyStates();
-
void drawGeometry(shared_ptr<BaseTexture> const & texture,
Storage const & storage,
size_t indicesCount,
@@ -141,9 +140,9 @@ namespace graphics
void unlockStorage(Storage const & storage);
void discardStorage(Storage const & storage);
- /// setup rendering matrix
- void loadMatrix(EMatrix mt,
- math::Matrix<float, 4, 4> const & m);
+ void applySharpStates();
+ void applyBlitStates();
+ void applyStates();
};
}
}
diff --git a/graphics/opengl/gl_render_context.cpp b/graphics/opengl/gl_render_context.cpp
index 39074228e3..111065f990 100644
--- a/graphics/opengl/gl_render_context.cpp
+++ b/graphics/opengl/gl_render_context.cpp
@@ -1,3 +1,5 @@
+#include "../resource_manager.hpp"
+
#include "gl_render_context.hpp"
#include "opengl.hpp"
@@ -5,13 +7,43 @@ namespace graphics
{
namespace gl
{
- void RenderContext::startThreadDrawing()
+ void RenderContext::startThreadDrawing(unsigned ts)
{
OGLCHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
OGLCHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
+ graphics::RenderContext::startThreadDrawing(ts);
+
+ m_programManager = resourceManager()->programManager(threadSlot());
+ }
+
+ void RenderContext::endThreadDrawing(unsigned ts)
+ {
+ graphics::RenderContext::endThreadDrawing(ts);
}
- void RenderContext::endThreadDrawing()
- {}
+ Storage const & RenderContext::storage() const
+ {
+ return m_storage;
+ }
+
+ void RenderContext::setStorage(Storage const & storage)
+ {
+ m_storage = storage;
+ }
+
+ shared_ptr<Program> const & RenderContext::program() const
+ {
+ return m_program;
+ }
+
+ void RenderContext::setProgram(shared_ptr<Program> const & prg)
+ {
+ m_program = prg;
+ }
+
+ ProgramManager * RenderContext::programManager()
+ {
+ return m_programManager;
+ }
}
}
diff --git a/graphics/opengl/gl_render_context.hpp b/graphics/opengl/gl_render_context.hpp
index 1d4f25e855..14b67c572a 100644
--- a/graphics/opengl/gl_render_context.hpp
+++ b/graphics/opengl/gl_render_context.hpp
@@ -1,16 +1,49 @@
#pragma once
+#include "../../std/shared_ptr.hpp"
#include "../render_context.hpp"
+#include "program_manager.hpp"
+#include "storage.hpp"
namespace graphics
{
+ class ResourceManager;
+
namespace gl
{
+ class ProgramManager;
+ class Program;
+
class RenderContext : public graphics::RenderContext
{
+ private:
+ /// Program manager to get Program's from.
+ ProgramManager * m_programManager;
+
+ /// @{ OpenGL specific rendering states
+ /// Current Storage
+ Storage m_storage;
+ /// Current Program
+ shared_ptr<Program> m_program;
+ /// @}
public:
- void startThreadDrawing();
- void endThreadDrawing();
+
+ ProgramManager * programManager();
+
+ /// @{ OpenGL specific rendering states
+
+ Storage const & storage() const;
+ void setStorage(Storage const & storage);
+
+ shared_ptr<Program> const & program() const;
+ void setProgram(shared_ptr<Program> const & prg);
+
+ /// @}
+
+ /// Start rendering in the specified thread
+ void startThreadDrawing(unsigned threadSlot);
+ /// End rendering in the specified thread
+ void endThreadDrawing(unsigned threadSlot);
};
}
}
diff --git a/graphics/opengl/renderer.cpp b/graphics/opengl/renderer.cpp
index 881ad88f53..8c352d6f21 100644
--- a/graphics/opengl/renderer.cpp
+++ b/graphics/opengl/renderer.cpp
@@ -1,4 +1,6 @@
-#include "../base/logging.hpp"
+#include "../../base/logging.hpp"
+
+#include "../resource_manager.hpp"
#include "../render_context.hpp"
#include "../coordinates.hpp"
@@ -7,7 +9,7 @@
#include "utils.hpp"
#include "framebuffer.hpp"
#include "renderbuffer.hpp"
-#include "resource_manager.hpp"
+#include "program.hpp"
#include "opengl.hpp"
namespace graphics
@@ -81,8 +83,6 @@ namespace graphics
processCommand(make_shared_ptr(new ChangeMatrix(EProjection, coordM)));
processCommand(make_shared_ptr(new ChangeMatrix(EModelView, math::Identity<float, 4>())));
}
-
-// checkStatus();
}
bool Renderer::isRendering() const
@@ -367,9 +367,6 @@ namespace graphics
return false;
}
- void Renderer::setPixelPrecision(bool flag)
- {
- glUseSharpGeometryFn(flag);
RenderContext * Renderer::renderContext() const
{
return m_renderContext.get();
diff --git a/graphics/opengl/renderer.hpp b/graphics/opengl/renderer.hpp
index 43964842b5..8628b3113a 100644
--- a/graphics/opengl/renderer.hpp
+++ b/graphics/opengl/renderer.hpp
@@ -21,6 +21,7 @@ namespace graphics
class FrameBuffer;
class RenderBuffer;
class BaseTexture;
+ class Program;
class Renderer
{
@@ -184,8 +185,8 @@ namespace graphics
void setEnvironment(core::CommandsQueue::Environment const * env);
bool isCancelled() const;
- void setPixelPrecision(bool flag);
-
+ void setProgram(shared_ptr<Program> const & prg);
+ shared_ptr<Program> const & program() const;
RenderContext * renderContext() const;
diff --git a/graphics/render_context.cpp b/graphics/render_context.cpp
index 0821112b5d..070e152df7 100644
--- a/graphics/render_context.cpp
+++ b/graphics/render_context.cpp
@@ -14,7 +14,20 @@ namespace graphics
return it->second;
}
+ void RenderContext::startThreadDrawing(unsigned threadSlot)
+ {
+ ASSERT(m_threadSlot == -1, ());
+ m_threadSlot = threadSlot;
+ }
+
+ void RenderContext::endThreadDrawing(unsigned threadSlot)
+ {
+ ASSERT(m_threadSlot != -1, ());
+ m_threadSlot = -1;
+ }
+
RenderContext::RenderContext()
+ : m_threadSlot(-1)
{
setMatrix(EModelView, math::Identity<float, 4>());
setMatrix(EProjection, math::Identity<float, 4>());
@@ -22,4 +35,19 @@ namespace graphics
RenderContext::~RenderContext()
{}
+
+ void RenderContext::setResourceManager(const shared_ptr<ResourceManager> &rm)
+ {
+ m_resourceManager = rm;
+ }
+
+ shared_ptr<ResourceManager> const & RenderContext::resourceManager() const
+ {
+ return m_resourceManager;
+ }
+
+ unsigned RenderContext::threadSlot() const
+ {
+ return m_threadSlot;
+ }
}
diff --git a/graphics/render_context.hpp b/graphics/render_context.hpp
index f9ddb584f6..29ee5d1a7a 100644
--- a/graphics/render_context.hpp
+++ b/graphics/render_context.hpp
@@ -7,11 +7,7 @@
namespace graphics
{
- namespace gl
- {
- class Program;
- class BaseTexture;
- }
+ class ResourceManager;
/// base class for render contexts.
/// contains current render state data.
@@ -24,6 +20,13 @@ namespace graphics
map<EMatrix, math::Matrix<float, 4, 4> > m_matrices;
/// @}
+ unsigned m_threadSlot;
+ shared_ptr<ResourceManager> m_resourceManager;
+
+ protected:
+
+ unsigned threadSlot() const;
+
public:
/// Working with rendering states.
@@ -32,7 +35,7 @@ namespace graphics
void setMatrix(EMatrix mt, math::Matrix<float, 4, 4> const & m);
/// @}
- /// Constructor.
+ /// Constructor
RenderContext();
/// Destructor.
virtual ~RenderContext();
@@ -44,8 +47,12 @@ namespace graphics
virtual shared_ptr<RenderContext> createShared() = 0;
/// this function should be called from each opengl thread
/// to setup some thread parameters.
- virtual void startThreadDrawing() = 0;
+ virtual void startThreadDrawing(unsigned threadSlot);
/// called at the end of thread
- virtual void endThreadDrawing() = 0;
+ virtual void endThreadDrawing(unsigned threadSlot);
+ /// set attached resource manager
+ void setResourceManager(shared_ptr<ResourceManager> const & rm);
+ /// get the attached resource manager
+ shared_ptr<ResourceManager> const & resourceManager() const;
};
}
diff --git a/iphone/Maps/Classes/RenderContext.hpp b/iphone/Maps/Classes/RenderContext.hpp
index e58740d85e..7ce721bdd0 100644
--- a/iphone/Maps/Classes/RenderContext.hpp
+++ b/iphone/Maps/Classes/RenderContext.hpp
@@ -35,8 +35,6 @@ namespace iphone
void makeCurrent();
/// create a shared render context
shared_ptr<graphics::RenderContext> createShared();
- /// @TODO
- void endThreadDrawing() {}
EAGLContext * getEAGLContext();
};
diff --git a/iphone/Maps/Classes/RenderContext.mm b/iphone/Maps/Classes/RenderContext.mm
index 38fbaf51de..c5512e0899 100644
--- a/iphone/Maps/Classes/RenderContext.mm
+++ b/iphone/Maps/Classes/RenderContext.mm
@@ -29,12 +29,13 @@ namespace iphone
void RenderContext::makeCurrent()
{
[EAGLContext setCurrentContext:m_context];
- startThreadDrawing();
}
shared_ptr<graphics::RenderContext> RenderContext::createShared()
{
- return shared_ptr<graphics::RenderContext>(new RenderContext(this));
+ shared_ptr<graphics::RenderContext> res(new RenderContext(this));
+ res->setResourceManager(resourceManager());
+ return res;
}
EAGLContext * RenderContext::getEAGLContext()
diff --git a/map/coverage_generator.cpp b/map/coverage_generator.cpp
index f96f61baf9..a807ac26ea 100644
--- a/map/coverage_generator.cpp
+++ b/map/coverage_generator.cpp
@@ -41,9 +41,6 @@ CoverageGenerator::CoverageGenerator(
if (!m_glQueue)
m_renderContext = primaryRC->createShared();
- m_workCoverage = CreateCoverage();
- m_currentCoverage = CreateCoverage();
-
m_queue.AddInitCommand(bind(&CoverageGenerator::InitializeThreadGL, this));
m_queue.AddFinCommand(bind(&CoverageGenerator::FinalizeThreadGL, this));
@@ -73,13 +70,19 @@ ScreenCoverage * CoverageGenerator::CreateCoverage()
void CoverageGenerator::InitializeThreadGL()
{
if (m_renderContext)
+ {
m_renderContext->makeCurrent();
+ m_renderContext->startThreadDrawing(m_resourceManager->cacheThreadSlot());
+ }
+
+ m_workCoverage = CreateCoverage();
+ m_currentCoverage = CreateCoverage();
}
void CoverageGenerator::FinalizeThreadGL()
{
if (m_renderContext)
- m_renderContext->endThreadDrawing();
+ m_renderContext->endThreadDrawing(m_resourceManager->cacheThreadSlot());
}
CoverageGenerator::~CoverageGenerator()
diff --git a/map/qgl_render_context.cpp b/map/qgl_render_context.cpp
index da9efd51b5..f898e5e5cf 100644
--- a/map/qgl_render_context.cpp
+++ b/map/qgl_render_context.cpp
@@ -29,18 +29,19 @@ namespace qt
void RenderContext::makeCurrent()
{
m_context->makeCurrent();
- startThreadDrawing();
}
shared_ptr<graphics::RenderContext> RenderContext::createShared()
{
- return shared_ptr<graphics::gl::RenderContext>(new RenderContext(this));
+ shared_ptr<graphics::gl::RenderContext> res(new RenderContext(this));
+ res->setResourceManager(resourceManager());
+ return res;
}
- void RenderContext::endThreadDrawing()
+ void RenderContext::endThreadDrawing(unsigned threadSlot)
{
m_context.reset();
- graphics::gl::RenderContext::endThreadDrawing();
+ graphics::gl::RenderContext::endThreadDrawing(threadSlot);
}
RenderContext::RenderContext(RenderContext * renderContext)
diff --git a/map/qgl_render_context.hpp b/map/qgl_render_context.hpp
index 69faff2fa3..e95f73cb53 100644
--- a/map/qgl_render_context.hpp
+++ b/map/qgl_render_context.hpp
@@ -33,7 +33,7 @@ namespace qt
shared_ptr<graphics::RenderContext> createShared();
/// Leave previous logic, but fix thread widget deletion error.
- void endThreadDrawing();
+ void endThreadDrawing(unsigned threadSlot);
shared_ptr<QGLContext> context() const;
};
diff --git a/map/render_policy.cpp b/map/render_policy.cpp
index dd95687117..e744a37fc9 100644
--- a/map/render_policy.cpp
+++ b/map/render_policy.cpp
@@ -44,8 +44,6 @@ RenderPolicy::RenderPolicy(Params const & p,
graphics::gl::InitExtensions();
graphics::gl::InitializeThread();
graphics::gl::CheckExtensionSupport();
-
- m_primaryRC->startThreadDrawing();
}
void RenderPolicy::InitCacheScreen()
@@ -57,6 +55,7 @@ void RenderPolicy::InitCacheScreen()
cp.m_useGuiResources = true;
cp.m_isSynchronized = false;
cp.m_resourceManager = m_resourceManager;
+ cp.m_renderContext = m_primaryRC;
m_cacheScreen = make_shared_ptr(new graphics::Screen(cp));
diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp
index f12ea2b379..5d4a7fdeb4 100644
--- a/map/screen_coverage.cpp
+++ b/map/screen_coverage.cpp
@@ -215,12 +215,14 @@ bool ScreenCoverage::Cache(core::CommandsQueue::Environment const & env)
vector<shared_ptr<graphics::OverlayElement> > sharpElements;
m_overlay->forEach(bind(&FilterElementsBySharpness, _1, ref(sharpElements), true));
+ m_cacheScreen->applySharpStates();
m_cacheScreen->setDisplayList(m_sharpTextDL.get());
for (unsigned i = 0; i < sharpElements.size(); ++i)
sharpElements[i]->draw(m_cacheScreen.get(), idM);
m_cacheScreen->setDisplayList(0);
+ m_cacheScreen->applyStates();
m_cacheScreen->endFrame();
@@ -419,12 +421,10 @@ void ScreenCoverage::Draw(graphics::Screen * s, ScreenBase const & screen)
if (m_primaryDL)
s->drawDisplayList(m_primaryDL.get(), m);
- s->setPixelPrecision(true);
-
if (m_sharpTextDL)
s->drawDisplayList(m_sharpTextDL.get(), m);
- s->setPixelPrecision(false);
+
}
shared_ptr<graphics::Overlay> const & ScreenCoverage::GetOverlay() const
diff --git a/map/simple_render_policy.cpp b/map/simple_render_policy.cpp
index aeedd8e2f7..be0fd5369f 100644
--- a/map/simple_render_policy.cpp
+++ b/map/simple_render_policy.cpp
@@ -6,6 +6,7 @@
#include "../graphics/overlay.hpp"
#include "../graphics/opengl/opengl.hpp"
#include "../graphics/skin.hpp"
+#include "../graphics/render_context.hpp"
#include "../indexer/scales.hpp"
#include "../geometry/screenbase.hpp"
@@ -92,6 +93,9 @@ SimpleRenderPolicy::SimpleRenderPolicy(Params const & p)
m_resourceManager.reset(new graphics::ResourceManager(rmp));
+ m_primaryRC->setResourceManager(m_resourceManager);
+ m_primaryRC->startThreadDrawing(m_resourceManager->guiThreadSlot());
+
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp
index f39d325d90..fe41db585d 100644
--- a/map/tile_renderer.cpp
+++ b/map/tile_renderer.cpp
@@ -72,7 +72,7 @@ TileRenderer::TileRenderer(
m_threadData[i].m_drawerParams = params;
m_threadData[i].m_drawer = 0;
-
+ m_threadData[i].m_threadSlot = params.m_threadSlot;
m_threadData[i].m_dummyRT = m_resourceManager->createRenderTarget(2, 2);
m_threadData[i].m_depthBuffer = make_shared_ptr(new graphics::gl::RenderBuffer(tileWidth, tileHeight, true));
@@ -103,7 +103,10 @@ void TileRenderer::InitializeThreadGL(core::CommandsQueue::Environment const & e
int tileHeight = m_resourceManager->params().m_renderTargetTexturesParams.m_texHeight;
if (threadData.m_renderContext)
+ {
threadData.m_renderContext->makeCurrent();
+ threadData.m_renderContext->startThreadDrawing(threadData.m_threadSlot);
+ }
threadData.m_drawer = new Drawer(threadData.m_drawerParams);
threadData.m_drawer->onSize(tileWidth, tileHeight);
threadData.m_drawer->screen()->setDepthBuffer(threadData.m_depthBuffer);
@@ -114,7 +117,7 @@ void TileRenderer::FinalizeThreadGL(core::CommandsQueue::Environment const & env
ThreadData & threadData = m_threadData[env.threadNum()];
if (threadData.m_renderContext)
- threadData.m_renderContext->endThreadDrawing();
+ threadData.m_renderContext->endThreadDrawing(threadData.m_threadSlot);
}
void TileRenderer::ReadPixels(graphics::PacketsQueue * glQueue, core::CommandsQueue::Environment const & env)
diff --git a/map/tile_renderer.hpp b/map/tile_renderer.hpp
index 7dd47a040c..1c4132430e 100644
--- a/map/tile_renderer.hpp
+++ b/map/tile_renderer.hpp
@@ -41,6 +41,7 @@ protected:
{
Drawer * m_drawer;
Drawer::Params m_drawerParams;
+ unsigned m_threadSlot;
shared_ptr<graphics::gl::BaseTexture> m_dummyRT;
shared_ptr<graphics::RenderContext> m_renderContext;
shared_ptr<graphics::gl::RenderBuffer> m_depthBuffer;
diff --git a/map/tiling_render_policy_mt.cpp b/map/tiling_render_policy_mt.cpp
index 4252382510..ae4beb7a58 100644
--- a/map/tiling_render_policy_mt.cpp
+++ b/map/tiling_render_policy_mt.cpp
@@ -2,6 +2,7 @@
#include "../platform/platform.hpp"
+#include "../graphics/render_context.hpp"
#include "../graphics/skin.hpp"
#include "window_handle.hpp"
@@ -127,6 +128,9 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(Params const & p)
m_resourceManager.reset(new graphics::ResourceManager(rmp));
+ m_primaryRC->setResourceManager(m_resourceManager);
+ m_primaryRC->startThreadDrawing(m_resourceManager->guiThreadSlot());
+
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
diff --git a/map/tiling_render_policy_st.cpp b/map/tiling_render_policy_st.cpp
index f581de3be9..54259b745b 100644
--- a/map/tiling_render_policy_st.cpp
+++ b/map/tiling_render_policy_st.cpp
@@ -4,6 +4,7 @@
#include "../graphics/opengl/opengl.hpp"
#include "../graphics/skin.hpp"
+#include "../graphics/render_context.hpp"
#include "window_handle.hpp"
#include "queued_renderer.hpp"
@@ -124,8 +125,6 @@ TilingRenderPolicyST::TilingRenderPolicyST(Params const & p)
rmp.m_threadSlotsCount = cpuCores + 2;
rmp.m_renderThreadsCount = cpuCores;
-// delete [] debuggingFlags;
-
rmp.m_useSingleThreadedOGL = true;
rmp.fitIntoLimits();
@@ -133,6 +132,9 @@ TilingRenderPolicyST::TilingRenderPolicyST(Params const & p)
m_resourceManager.reset(new graphics::ResourceManager(rmp));
+ m_primaryRC->setResourceManager(m_resourceManager);
+ m_primaryRC->startThreadDrawing(m_resourceManager->guiThreadSlot());
+
m_QueuedRenderer->SetSinglePipelineProcessing(m_resourceManager->useReadPixelsToSynchronize());
Platform::FilesList fonts;
diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp
index a761246138..b22962da85 100644
--- a/qt_tstfrm/tstwidgets.cpp
+++ b/qt_tstfrm/tstwidgets.cpp
@@ -42,7 +42,7 @@ void GLDrawWidget::initializeGL()
m_primaryContext = make_shared_ptr(new qt::gl::RenderContext(this));
- m_primaryContext->startThreadDrawing();
+ m_primaryContext->startThreadDrawing(0);
graphics::ResourceManager::Params rmp;