From edc1e07cf2d487063be9d08ab42fe56690141a97 Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 22 Feb 2011 00:04:35 +0200 Subject: [PATCH] switching on/off different parts of rendering pipeline. statistics collection code. --- iphone/Maps/Platform/IPhonePlatform.mm | 4 - map/render_queue_routine.cpp | 5 +- yg/area_renderer.cpp | 91 +++++++++++++++ yg/area_renderer.hpp | 39 +++++++ yg/geometry_batcher.cpp | 149 +++++++++++++------------ yg/geometry_batcher.hpp | 56 +++++----- yg/path_renderer.cpp | 26 ++++- yg/path_renderer.hpp | 21 +++- yg/renderer.cpp | 7 +- yg/renderer.hpp | 4 + yg/text_renderer.cpp | 10 +- yg/text_renderer.hpp | 2 + yg/yg.pro | 6 +- yg/yg_tests/screengl_test.cpp | 6 +- 14 files changed, 306 insertions(+), 120 deletions(-) create mode 100644 yg/area_renderer.cpp create mode 100644 yg/area_renderer.hpp diff --git a/iphone/Maps/Platform/IPhonePlatform.mm b/iphone/Maps/Platform/IPhonePlatform.mm index 0037b9e720..4f7544cb2d 100644 --- a/iphone/Maps/Platform/IPhonePlatform.mm +++ b/iphone/Maps/Platform/IPhonePlatform.mm @@ -186,10 +186,6 @@ vector IPhonePlatform::GetFontNames() const for (size_t i = 0; i < res.size(); ++i) res[i] = fontFolder + res[i]; -/* res.push_back(ReadPathForFile("wqy-microhei.ttf")); - res.push_back(ReadPathForFile("dejavusans.ttf")); - res.push_back(ReadPathForFile("mangal.ttf")); -*/ return res; } diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index 241047cfcd..0e0430a207 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -236,7 +236,10 @@ void RenderQueueRoutine::Do() params.m_updateInterval = m_updateInterval; params.m_textTreeAutoClean = false; params.m_useTextTree = true; - params.m_doLogFlushes = true; +/* params.m_isDebugging = true; + params.m_drawPathes = false; + params.m_drawAreas = false; + params.m_drawTexts = false;*/ m_threadDrawer = make_shared_ptr(new DrawerYG(m_skinName, params)); diff --git a/yg/area_renderer.cpp b/yg/area_renderer.cpp new file mode 100644 index 0000000000..060edb9a82 --- /dev/null +++ b/yg/area_renderer.cpp @@ -0,0 +1,91 @@ +#include "area_renderer.hpp" +#include "resource_style.hpp" +#include "skin.hpp" +#include "../base/logging.hpp" + +namespace yg +{ + namespace gl + { + AreaRenderer::Params::Params() + : m_drawAreas(true) + { + } + + AreaRenderer::AreaRenderer(Params const & params) + : base_t(params), + m_drawAreas(params.m_drawAreas) + {} + + void AreaRenderer::beginFrame() + { + base_t::beginFrame(); + m_areasCount = 0; + m_trianglesCount = 0; + }; + + void AreaRenderer::endFrame() + { + if (isDebugging()) + LOG(LINFO, ("Drawing ", m_areasCount, " areas comprised of ", m_trianglesCount, " triangles total")); + base_t::endFrame(); + } + + void AreaRenderer::drawTrianglesList(m2::PointD const * points, size_t pointsCount, uint32_t styleID, double depth) + { + ++m_areasCount; + m_trianglesCount += pointsCount; + + if (!m_drawAreas) + return; + + ResourceStyle const * style = skin()->fromID(styleID); + + if (style == 0) + { + LOG(LINFO, ("styleID=", styleID, " wasn't found on current skin.")); + return; + } + + if (!hasRoom(pointsCount, pointsCount, style->m_pageID)) + flush(style->m_pageID); + + ASSERT_GREATER_OR_EQUAL(pointsCount, 2, ()); + + float texX = style->m_texRect.minX() + 1.0f; + float texY = style->m_texRect.minY() + 1.0f; + + skin()->pages()[style->m_pageID]->texture()->mapPixel(texX, texY); + + size_t pointsLeft = pointsCount; + size_t batchOffset = 0; + + while (true) + { + size_t batchSize = pointsLeft; + + if (batchSize > verticesLeft(style->m_pageID)) + /// Rounding to the boundary of 3 vertices + batchSize = verticesLeft(style->m_pageID) / 3 * 3; + + if (batchSize > indicesLeft(style->m_pageID)) + batchSize = indicesLeft(style->m_pageID) / 3 * 3; + + bool needToFlush = (batchSize < pointsLeft); + + m2::PointF texCoord(texX, texY); + addTexturedListStrided(&points[batchOffset], sizeof(m2::PointD), &texCoord, 0, batchSize, depth, style->m_pageID); + + batchOffset += batchSize; + pointsLeft -= batchSize; + + if (needToFlush) + flush(style->m_pageID); + + if (pointsLeft == 0) + break; + } + } + + } +} diff --git a/yg/area_renderer.hpp b/yg/area_renderer.hpp new file mode 100644 index 0000000000..707cbb525c --- /dev/null +++ b/yg/area_renderer.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "geometry_batcher.hpp" + +namespace yg +{ + namespace gl + { + class AreaRenderer : public GeometryBatcher + { + private: + + unsigned m_trianglesCount; + unsigned m_areasCount; + bool m_drawAreas; + + public: + + typedef GeometryBatcher base_t; + + struct Params : base_t::Params + { + bool m_drawAreas; + Params(); + }; + + AreaRenderer(Params const & params); + + /// drawing triangles list. assuming that each 3 points compose a triangle + void drawTrianglesList(m2::PointD const * points, + size_t pointsCount, + uint32_t styleID, + double depth); + + void beginFrame(); + void endFrame(); + }; + } +} diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index 2fa442da8c..69379210cf 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -28,11 +28,8 @@ namespace yg { namespace gl { - GeometryBatcher::Params::Params() : m_doLogFlushes(false) - {} - - GeometryBatcher::GeometryBatcher(Params const & params) - : base_t(params), m_isAntiAliased(!params.m_isMultiSampled), m_doLogFlushes(params.m_doLogFlushes) + GeometryBatcher::GeometryBatcher(base_t::Params const & params) + : base_t(params), m_isAntiAliased(!params.m_isMultiSampled) { reset(-1); applyStates(); @@ -176,7 +173,7 @@ namespace yg pipeline.m_currentIndex); - if (m_doLogFlushes) + if (isDebugging()) LOG(LINFO, ("Pipeline #", i - 1, "draws ", pipeline.m_currentIndex / 3, "/", pipeline.m_maxIndices / 3," triangles")); renderedData = true; @@ -209,72 +206,6 @@ namespace yg // } } - - - void GeometryBatcher::drawTrianglesList(m2::PointD const * points, size_t pointsCount, uint32_t styleID, double depth) - { - ResourceStyle const * style = m_skin->fromID(styleID); - - if (style == 0) - { - LOG(LINFO, ("styleID=", styleID, " wasn't found on current skin.")); - return; - } - - if (!hasRoom(pointsCount, pointsCount, style->m_pageID)) - flush(style->m_pageID); - - ASSERT_GREATER_OR_EQUAL(pointsCount, 2, ()); - - float texX = style->m_texRect.minX() + 1.0f; - float texY = style->m_texRect.minY() + 1.0f; - - m_skin->pages()[style->m_pageID]->texture()->mapPixel(texX, texY); - - size_t pointsLeft = pointsCount; - size_t batchOffset = 0; - - while (true) - { - size_t batchSize = pointsLeft; - - if (batchSize > verticesLeft(style->m_pageID)) - /// Rounding to the boundary of 3 vertices - batchSize = verticesLeft(style->m_pageID) / 3 * 3; - - if (batchSize > indicesLeft(style->m_pageID)) - batchSize = indicesLeft(style->m_pageID) / 3 * 3; - - bool needToFlush = (batchSize < pointsLeft); - - int vOffset = m_pipelines[style->m_pageID].m_currentVertex; - int iOffset = m_pipelines[style->m_pageID].m_currentIndex; - - for (size_t i = 0; i < batchSize; ++i) - { - m_pipelines[style->m_pageID].m_vertices[vOffset + i].pt = points[batchOffset + i]; - m_pipelines[style->m_pageID].m_vertices[vOffset + i].tex = m2::PointF(texX, texY); - m_pipelines[style->m_pageID].m_vertices[vOffset + i].depth = depth; - } - - for (size_t i = 0; i < batchSize; ++i) - m_pipelines[style->m_pageID].m_indices[iOffset + i] = vOffset + i; - - batchOffset += batchSize; - - m_pipelines[style->m_pageID].m_currentVertex += batchSize; - m_pipelines[style->m_pageID].m_currentIndex += batchSize; - - pointsLeft -= batchSize; - - if (needToFlush) - flush(style->m_pageID); - - if (pointsLeft == 0) - break; - } - } - void GeometryBatcher::drawTexturedPolygon( m2::PointD const & ptShift, float angle, @@ -399,6 +330,80 @@ namespace yg m_pipelines[pageID].m_currentIndex += (size - 2) * 3; } + void GeometryBatcher::addTexturedListStrided( + m2::PointD const * coords, + size_t coordsStride, + m2::PointF const * texCoords, + size_t texCoordsStride, + unsigned size, + double depth, + int pageID) + { + if (!hasRoom(size, size, pageID)) + flush(pageID); + + ASSERT(size > 2, ()); + + size_t vOffset = m_pipelines[pageID].m_currentVertex; + size_t iOffset = m_pipelines[pageID].m_currentIndex; + + for (size_t i = 0; i < size; ++i) + { + m_pipelines[pageID].m_vertices[vOffset + i].pt = m2::PointF(coords->x, coords->y); + m_pipelines[pageID].m_vertices[vOffset + i].tex = *texCoords; + m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + coords = reinterpret_cast(reinterpret_cast(coords) + coordsStride); + texCoords = reinterpret_cast(reinterpret_cast(texCoords) + texCoordsStride); + } + + m_pipelines[pageID].m_currentVertex += size; + + for (size_t i = 0; i < size; ++i) + m_pipelines[pageID].m_indices[iOffset + i] = vOffset + i; + + m_pipelines[pageID].m_currentIndex += size; + } + + + void GeometryBatcher::addTexturedListStrided( + m2::PointF const * coords, + size_t coordsStride, + m2::PointF const * texCoords, + size_t texCoordsStride, + unsigned size, + double depth, + int pageID) + { + if (!hasRoom(size, size, pageID)) + flush(pageID); + + ASSERT(size > 2, ()); + + size_t vOffset = m_pipelines[pageID].m_currentVertex; + size_t iOffset = m_pipelines[pageID].m_currentIndex; + + for (size_t i = 0; i < size; ++i) + { + m_pipelines[pageID].m_vertices[vOffset + i].pt = *coords; + m_pipelines[pageID].m_vertices[vOffset + i].tex = *texCoords; + m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + coords = reinterpret_cast(reinterpret_cast(coords) + coordsStride); + texCoords = reinterpret_cast(reinterpret_cast(texCoords) + texCoordsStride); + } + + m_pipelines[pageID].m_currentVertex += size; + + for (size_t i = 0; i < size; ++i) + m_pipelines[pageID].m_indices[iOffset + i] = vOffset + i; + + m_pipelines[pageID].m_currentIndex += size; + } + + void GeometryBatcher::addTexturedList(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, int pageID) + { + addTexturedListStrided(coords, sizeof(m2::PointF), texCoords, sizeof(m2::PointF), size, depth, pageID); + } + void GeometryBatcher::enableClipRect(bool flag) { flush(-1); diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index b546ed15ca..cffc02a544 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -73,11 +73,6 @@ namespace yg vector m_pipelines; - bool hasRoom(size_t verticesCount, size_t indicesCount, int pageID) const; - - size_t verticesLeft(int pageID); - size_t indicesLeft(int pageID); - void reset(int pageID); void switchTextures(int pageID); @@ -86,7 +81,6 @@ namespace yg void applyStates(); bool m_isAntiAliased; - bool m_doLogFlushes; int m_aaShift; @@ -95,14 +89,11 @@ namespace yg /// INTERNAL API! USE WITH CAUTION void flush(int pageID); + bool hasRoom(size_t verticesCount, size_t indicesCount, int pageID) const; + size_t verticesLeft(int pageID); + size_t indicesLeft(int pageID); - struct Params : base_t::Params - { - bool m_doLogFlushes; - Params(); - }; - - GeometryBatcher(Params const & params); + GeometryBatcher(base_t::Params const & params); ~GeometryBatcher(); void setSkin(shared_ptr skin); @@ -111,23 +102,6 @@ namespace yg void beginFrame(); void endFrame(); - void drawPoint(m2::PointD const & pt, - uint32_t styleID, - EPosition pos, - double depth); - - void drawPath(m2::PointD const * points, - size_t pointsCount, - uint32_t styleID, - double depth); - - /// drawing triangles list. assuming that each 3 points compose a triangle - void drawTrianglesList(m2::PointD const * points, - size_t pointsCount, - uint32_t styleID, - double depth); - - public: /// This functions hide the base_t functions with the same name and signature @@ -154,6 +128,28 @@ namespace yg double depth, int pageID); + void addTexturedListStrided(m2::PointD const * coords, + size_t coordsStride, + m2::PointF const * texCoords, + size_t texCoordsStride, + unsigned size, + double depth, + int pageID); + + void addTexturedListStrided(m2::PointF const * coords, + size_t coordsStride, + m2::PointF const * texCoords, + size_t texCoordsStride, + unsigned size, + double depth, + int pageID); + + void addTexturedList(m2::PointF const * coords, + m2::PointF const * texCoords, + unsigned size, + double depth, + int pageID); + int aaShift() const; /// drawing textured polygon with antialiasing diff --git a/yg/path_renderer.cpp b/yg/path_renderer.cpp index 3e53ae1158..79ff899356 100644 --- a/yg/path_renderer.cpp +++ b/yg/path_renderer.cpp @@ -10,12 +10,21 @@ namespace yg { namespace gl { + PathRenderer::Params::Params() : m_drawPathes(true) + {} - PathRenderer::PathRenderer(base_t::Params const & params) : base_t(params) + PathRenderer::PathRenderer(Params const & params) + : base_t(params), m_drawPathes(params.m_drawPathes) {} void PathRenderer::drawPath(m2::PointD const * points, size_t pointsCount, uint32_t styleID, double depth) { + ++m_pathCount; + m_pointsCount += pointsCount; + + if (!m_drawPathes) + return; + #ifdef PROFILER_YG prof::block draw_path_block; #endif @@ -239,6 +248,21 @@ namespace yg addTexturedStrip(coords, texCoords, 8, depth, lineStyle->m_pageID); } } + + void PathRenderer::beginFrame() + { + base_t::beginFrame(); + m_pathCount = 0; + m_pointsCount = 0; + } + + void PathRenderer::endFrame() + { + if (isDebugging()) + LOG(LINFO, ("Drawing ", m_pathCount, " pathes comprised of ", m_pointsCount, " points total")); + + base_t::endFrame(); + } } } diff --git a/yg/path_renderer.hpp b/yg/path_renderer.hpp index bfff514045..6cb8b069cb 100644 --- a/yg/path_renderer.hpp +++ b/yg/path_renderer.hpp @@ -1,25 +1,38 @@ #pragma once -#include "geometry_batcher.hpp" +#include "area_renderer.hpp" #include "../geometry/point2d.hpp" namespace yg { namespace gl { - class PathRenderer : public GeometryBatcher + class PathRenderer : public AreaRenderer { private: + unsigned m_pathCount; + unsigned m_pointsCount; + bool m_drawPathes; + void drawSolidPath(m2::PointD const * points, size_t pointsCount, uint32_t styleID, double depth); public: - typedef GeometryBatcher base_t; + typedef AreaRenderer base_t; - PathRenderer(base_t::Params const & params); + struct Params : base_t::Params + { + bool m_drawPathes; + Params(); + }; + + PathRenderer(Params const & params); void drawPath(m2::PointD const * points, size_t pointsCount, uint32_t styleID, double depth); + + void beginFrame(); + void endFrame(); }; } } diff --git a/yg/renderer.cpp b/yg/renderer.cpp index c7d178b2af..e5221eee4a 100644 --- a/yg/renderer.cpp +++ b/yg/renderer.cpp @@ -10,12 +10,13 @@ namespace yg { namespace gl { - Renderer::Params::Params() : m_isMultiSampled(false) + Renderer::Params::Params() : m_isMultiSampled(false), m_isDebugging(false) {} Renderer::Renderer(Params const & params) : m_frameBuffer(params.m_frameBuffer), m_isMultiSampled(params.m_isMultiSampled), + m_isDebugging(params.m_isDebugging), m_isRendering(false) { if (m_isMultiSampled) @@ -174,5 +175,9 @@ namespace yg return m_height; } + bool Renderer::isDebugging() const + { + return m_isDebugging; + } } } diff --git a/yg/renderer.hpp b/yg/renderer.hpp index e23a68c7e6..70859cf0a2 100644 --- a/yg/renderer.hpp +++ b/yg/renderer.hpp @@ -22,6 +22,7 @@ namespace yg shared_ptr m_resourceManager; shared_ptr m_frameBuffer; bool m_isMultiSampled; + bool m_isDebugging; Params(); }; @@ -38,6 +39,7 @@ namespace yg shared_ptr m_multiSampledDepthBuffer; bool m_isMultiSampled; + bool m_isDebugging; bool m_isRendering; @@ -79,6 +81,8 @@ namespace yg unsigned int width() const; unsigned int height() const; + + bool isDebugging() const; }; } } diff --git a/yg/text_renderer.cpp b/yg/text_renderer.cpp index 4818b610bf..6470a6da7f 100644 --- a/yg/text_renderer.cpp +++ b/yg/text_renderer.cpp @@ -24,14 +24,15 @@ namespace yg namespace gl { TextRenderer::Params::Params() - : m_textTreeAutoClean(true), m_useTextTree(false) + : m_textTreeAutoClean(true), m_useTextTree(false), m_drawTexts(true) {} TextRenderer::TextRenderer(Params const & params) : base_t(params), m_needTextRedraw(false), m_textTreeAutoClean(params.m_textTreeAutoClean), - m_useTextTree(params.m_useTextTree) + m_useTextTree(params.m_useTextTree), + m_drawTexts(params.m_drawTexts) {} TextRenderer::TextObj::TextObj(m2::PointD const & pt, string const & txt, uint8_t sz, yg::Color const & c, bool isMasked, yg::Color const & maskColor, double d, bool isFixedFont, bool log2vis) @@ -85,6 +86,9 @@ namespace yg bool isFixedFont, bool log2vis) { + if (!m_drawTexts) + return; + if (!m_useTextTree || isFixedFont) drawTextImpl(pt, angle, fontSize, color, utf8Text, true, maskColor, depth, isFixedFont, log2vis); else @@ -328,6 +332,8 @@ namespace yg m2::PointD const * path, size_t s, uint8_t fontSize, yg::Color const & color, string const & utf8Text, double fullLength, double pathOffset, TextPos pos, bool isMasked, yg::Color const & maskColor, double depth, bool isFixedFont) { + if (!m_drawTexts) + return false; if (m_useTextTree) checkTextRedraw(); diff --git a/yg/text_renderer.hpp b/yg/text_renderer.hpp index 7702113fb7..02c68104e7 100644 --- a/yg/text_renderer.hpp +++ b/yg/text_renderer.hpp @@ -90,6 +90,7 @@ namespace yg bool m_textTreeAutoClean; bool m_useTextTree; + bool m_drawTexts; public: @@ -99,6 +100,7 @@ namespace yg { bool m_textTreeAutoClean; bool m_useTextTree; + bool m_drawTexts; Params(); }; diff --git a/yg/yg.pro b/yg/yg.pro index 794414f853..8d82d791a4 100644 --- a/yg/yg.pro +++ b/yg/yg.pro @@ -60,7 +60,8 @@ SOURCES += \ path_renderer.cpp \ shape_renderer.cpp \ symbol_renderer.cpp \ - circle_info.cpp + circle_info.cpp \ + area_renderer.cpp HEADERS += \ internal/opengl.hpp \ @@ -108,7 +109,8 @@ HEADERS += \ path_renderer.hpp \ shape_renderer.hpp \ symbol_renderer.hpp \ - circle_info.hpp + circle_info.hpp \ + area_renderer.hpp !iphonesimulator-g++42 { !iphonedevice-g++42 { diff --git a/yg/yg_tests/screengl_test.cpp b/yg/yg_tests/screengl_test.cpp index 4ebc8ced85..3ded703517 100644 --- a/yg/yg_tests/screengl_test.cpp +++ b/yg/yg_tests/screengl_test.cpp @@ -21,9 +21,9 @@ namespace { void DoDraw(shared_ptr p) { - p->drawPoint(m2::PointD(40, 40), 0, yg::EPosCenter, 0); - p->drawPoint(m2::PointD(40.5, 60), 0, yg::EPosCenter, 0); - p->drawPoint(m2::PointD(41, 80), 0, yg::EPosCenter, 0); + p->drawSymbol(m2::PointD(40, 40), 0, yg::EPosCenter, 0); + p->drawSymbol(m2::PointD(40.5, 60), 0, yg::EPosCenter, 0); + p->drawSymbol(m2::PointD(41, 80), 0, yg::EPosCenter, 0); } };