diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2015-11-27 16:05:52 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2015-12-29 16:36:10 +0300 |
commit | 82683cbfaa978ca997eec88a105ed5f923e5d547 (patch) | |
tree | ae473b43aa54a723583ac7388b31e88fb56c9423 /drape_frontend/text_layout.cpp | |
parent | e1bde330986d77b9dd37b792aba94530352b0cf0 (diff) |
Move text position to TextDynamicVertex.
Conflicts:
drape_frontend/path_text_shape.cpp
Diffstat (limited to 'drape_frontend/text_layout.cpp')
-rw-r--r-- | drape_frontend/text_layout.cpp | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp index 7743a6e750..af91f939d9 100644 --- a/drape_frontend/text_layout.cpp +++ b/drape_frontend/text_layout.cpp @@ -21,11 +21,9 @@ float const kValidSplineTurn = 0.96f; class TextGeometryGenerator { public: - TextGeometryGenerator(glsl::vec3 const & pivot, - dp::TextureManager::ColorRegion const & color, + TextGeometryGenerator(dp::TextureManager::ColorRegion const & color, gpu::TTextStaticVertexBuffer & buffer) - : m_pivot(pivot) - , m_colorCoord(glsl::ToVec2(color.GetTexRect().Center())) + : m_colorCoord(glsl::ToVec2(color.GetTexRect().Center())) , m_buffer(buffer) { } @@ -33,14 +31,14 @@ public: void operator() (dp::TextureManager::GlyphRegion const & glyph) { m2::RectF const & mask = glyph.GetTexRect(); - m_buffer.push_back(gpu::TextStaticVertex(m_pivot, m_colorCoord, glsl::ToVec2(mask.LeftTop()))); - m_buffer.push_back(gpu::TextStaticVertex(m_pivot, m_colorCoord, glsl::ToVec2(mask.LeftBottom()))); - m_buffer.push_back(gpu::TextStaticVertex(m_pivot, m_colorCoord, glsl::ToVec2(mask.RightTop()))); - m_buffer.push_back(gpu::TextStaticVertex(m_pivot, m_colorCoord, glsl::ToVec2(mask.RightBottom()))); + + m_buffer.push_back(gpu::TextStaticVertex(m_colorCoord, glsl::ToVec2(mask.LeftTop()))); + m_buffer.push_back(gpu::TextStaticVertex(m_colorCoord, glsl::ToVec2(mask.LeftBottom()))); + m_buffer.push_back(gpu::TextStaticVertex(m_colorCoord, glsl::ToVec2(mask.RightTop()))); + m_buffer.push_back(gpu::TextStaticVertex(m_colorCoord, glsl::ToVec2(mask.RightBottom()))); } protected: - glsl::vec3 const & m_pivot; glsl::vec2 m_colorCoord; gpu::TTextStaticVertexBuffer & m_buffer; }; @@ -54,7 +52,8 @@ public: dp::TextureManager::ColorRegion const & color, gpu::TTextStaticVertexBuffer & staticBuffer, gpu::TTextDynamicVertexBuffer & dynBuffer) - : TBase(pivot, color, staticBuffer) + : TBase(color, staticBuffer) + , m_pivot(pivot) , m_penPosition(pixelOffset) , m_buffer(dynBuffer) , m_textRatio(textRatio) @@ -79,16 +78,17 @@ public: m_penPosition += glsl::vec2(-xOffset, 0.0f); } - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(xOffset, bottomVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(xOffset, upVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(pixelSize.x + xOffset, bottomVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(pixelSize.x + xOffset, upVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(xOffset, bottomVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(xOffset, upVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(pixelSize.x + xOffset, bottomVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(pixelSize.x + xOffset, upVector))); m_penPosition += glsl::vec2(glyph.GetAdvanceX() * m_textRatio, glyph.GetAdvanceY() * m_textRatio); TBase::operator()(glyph); } private: + glsl::vec3 const & m_pivot; glsl::vec2 m_penPosition; gpu::TTextDynamicVertexBuffer & m_buffer; float m_textRatio = 0.0f; @@ -98,12 +98,10 @@ private: class TextOutlinedGeometryGenerator { public: - TextOutlinedGeometryGenerator(glsl::vec3 const & pivot, - dp::TextureManager::ColorRegion const & color, - dp::TextureManager::ColorRegion const & outline, - gpu::TTextOutlinedStaticVertexBuffer & buffer) - : m_pivot(pivot) - , m_colorCoord(glsl::ToVec2(color.GetTexRect().Center())) + TextOutlinedGeometryGenerator(dp::TextureManager::ColorRegion const & color, + dp::TextureManager::ColorRegion const & outline, + gpu::TTextOutlinedStaticVertexBuffer & buffer) + : m_colorCoord(glsl::ToVec2(color.GetTexRect().Center())) , m_outlineCoord(glsl::ToVec2(outline.GetTexRect().Center())) , m_buffer(buffer) { @@ -112,14 +110,13 @@ public: void operator() (dp::TextureManager::GlyphRegion const & glyph) { m2::RectF const & mask = glyph.GetTexRect(); - m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_pivot, m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.LeftTop()))); - m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_pivot, m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.LeftBottom()))); - m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_pivot, m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.RightTop()))); - m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_pivot, m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.RightBottom()))); + m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.LeftTop()))); + m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.LeftBottom()))); + m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.RightTop()))); + m_buffer.push_back(gpu::TextOutlinedStaticVertex(m_colorCoord, m_outlineCoord, glsl::ToVec2(mask.RightBottom()))); } protected: - glsl::vec3 const & m_pivot; glsl::vec2 m_colorCoord; glsl::vec2 m_outlineCoord; gpu::TTextOutlinedStaticVertexBuffer & m_buffer; @@ -135,7 +132,8 @@ public: dp::TextureManager::ColorRegion const & outline, gpu::TTextOutlinedStaticVertexBuffer & staticBuffer, gpu::TTextDynamicVertexBuffer & dynBuffer) - : TBase(pivot, color, outline, staticBuffer) + : TBase(color, outline, staticBuffer) + , m_pivot(pivot) , m_penPosition(pixelOffset) , m_buffer(dynBuffer) , m_textRatio(textRatio) @@ -160,16 +158,17 @@ public: m_penPosition += glsl::vec2(-xOffset, 0.0f); } - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(xOffset, bottomVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(xOffset, upVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(pixelSize.x + xOffset, bottomVector))); - m_buffer.push_back(gpu::TextDynamicVertex(m_penPosition + glsl::vec2(pixelSize.x + xOffset, upVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(xOffset, bottomVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(xOffset, upVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(pixelSize.x + xOffset, bottomVector))); + m_buffer.push_back(gpu::TextDynamicVertex(m_pivot, m_penPosition + glsl::vec2(pixelSize.x + xOffset, upVector))); m_penPosition += glsl::vec2(glyph.GetAdvanceX() * m_textRatio, glyph.GetAdvanceY() * m_textRatio); TBase::operator()(glyph); } private: + glsl::vec3 const & m_pivot; glsl::vec2 m_penPosition; gpu::TTextDynamicVertexBuffer & m_buffer; float m_textRatio = 0.0f; @@ -442,23 +441,23 @@ PathTextLayout::PathTextLayout(strings::UniString const & text, float fontSize, Init(fribidi::log2vis(text), fontSize, textures); } -void PathTextLayout::CacheStaticGeometry(glm::vec3 const & pivot, - dp::TextureManager::ColorRegion const & colorRegion, +void PathTextLayout::CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion, dp::TextureManager::ColorRegion const & outlineRegion, gpu::TTextOutlinedStaticVertexBuffer & staticBuffer) const { - TextOutlinedGeometryGenerator gen(pivot, colorRegion, outlineRegion, staticBuffer); + TextOutlinedGeometryGenerator gen(colorRegion, outlineRegion, staticBuffer); for_each(m_metrics.begin(), m_metrics.end(), gen); } -void PathTextLayout::CacheStaticGeometry(glm::vec3 const & pivot, dp::TextureManager::ColorRegion const & colorRegion, +void PathTextLayout::CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion, gpu::TTextStaticVertexBuffer & staticBuffer) const { - TextGeometryGenerator gen(pivot, colorRegion, staticBuffer); + TextGeometryGenerator gen(colorRegion, staticBuffer); for_each(m_metrics.begin(), m_metrics.end(), gen); } -bool PathTextLayout::CacheDynamicGeometry(m2::Spline::iterator const & iter, ScreenBase const & screen, +bool PathTextLayout::CacheDynamicGeometry(m2::Spline::iterator const & iter, const float depth, + ScreenBase const & screen, gpu::TTextDynamicVertexBuffer & buffer) const { float const scalePtoG = screen.GetScale(); @@ -502,11 +501,11 @@ bool PathTextLayout::CacheDynamicGeometry(m2::Spline::iterator const & iter, Scr size_t baseIndex = 4 * i; - buffer[baseIndex + 0] = gpu::TextDynamicVertex(formingVector + normal * bottomVector + tangent * xOffset); - buffer[baseIndex + 1] = gpu::TextDynamicVertex(formingVector + normal * upVector + tangent * xOffset); - buffer[baseIndex + 2] = gpu::TextDynamicVertex(formingVector + normal * bottomVector + tangent * (pxSize.x + xOffset)); - buffer[baseIndex + 3] = gpu::TextDynamicVertex(formingVector + normal * upVector + tangent * (pxSize.x + xOffset)); - + glsl::vec3 pivot(glsl::ToVec2(iter.m_pos), depth); + buffer[baseIndex + 0] = gpu::TextDynamicVertex(pivot, formingVector + normal * bottomVector + tangent * xOffset); + buffer[baseIndex + 1] = gpu::TextDynamicVertex(pivot, formingVector + normal * upVector + tangent * xOffset); + buffer[baseIndex + 2] = gpu::TextDynamicVertex(pivot, formingVector + normal * bottomVector + tangent * (pxSize.x + xOffset)); + buffer[baseIndex + 3] = gpu::TextDynamicVertex(pivot, formingVector + normal * upVector + tangent * (pxSize.x + xOffset)); float const xAdvance = g.GetAdvanceX() * m_textSizeRatio; glsl::vec2 currentTangent = glsl::ToVec2(penIter.m_dir); |