switching on/off different parts of rendering pipeline. statistics collection code.

This commit is contained in:
rachytski 2011-02-22 00:04:35 +02:00 committed by Alex Zolotarev
parent d778e137bf
commit edc1e07cf2
14 changed files with 306 additions and 120 deletions

View file

@ -186,10 +186,6 @@ vector<string> 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;
}

View file

@ -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));

91
yg/area_renderer.cpp Normal file
View file

@ -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;
}
}
}
}

39
yg/area_renderer.hpp Normal file
View file

@ -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();
};
}
}

View file

@ -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<m2::PointD const*>(reinterpret_cast<unsigned char const*>(coords) + coordsStride);
texCoords = reinterpret_cast<m2::PointF const*>(reinterpret_cast<unsigned char const*>(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<m2::PointF const*>(reinterpret_cast<unsigned char const*>(coords) + coordsStride);
texCoords = reinterpret_cast<m2::PointF const*>(reinterpret_cast<unsigned char const*>(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);

View file

@ -73,11 +73,6 @@ namespace yg
vector<GeometryPipeline> 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> 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

View file

@ -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<prof::yg_draw_path> 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();
}
}
}

View file

@ -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();
};
}
}

View file

@ -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;
}
}
}

View file

@ -22,6 +22,7 @@ namespace yg
shared_ptr<ResourceManager> m_resourceManager;
shared_ptr<FrameBuffer> m_frameBuffer;
bool m_isMultiSampled;
bool m_isDebugging;
Params();
};
@ -38,6 +39,7 @@ namespace yg
shared_ptr<RenderBuffer> 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;
};
}
}

View file

@ -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();

View file

@ -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();
};

View file

@ -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 {

View file

@ -21,9 +21,9 @@ namespace
{
void DoDraw(shared_ptr<yg::gl::Screen> 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);
}
};