Move text position to TextDynamicVertex.

Conflicts:
	drape_frontend/path_text_shape.cpp
This commit is contained in:
Daria Volvenkova 2015-11-27 16:05:52 +03:00
parent e1bde33098
commit 82683cbfaa
5 changed files with 80 additions and 87 deletions

View file

@ -55,11 +55,9 @@ dp::BindingInfo SolidTexturingBindingInit()
dp::BindingInfo TextStaticBindingInit()
{
static_assert(sizeof(TextStaticVertex) == (sizeof(TextOutlinedStaticVertex::TPosition) +
2 * sizeof(TextOutlinedStaticVertex::TTexCoord)), "");
static_assert(sizeof(TextStaticVertex) == (2 * sizeof(TextStaticVertex::TTexCoord)), "");
dp::BindingFiller<TextStaticVertex> filler(3);
filler.FillDecl<TextStaticVertex::TPosition>("a_position");
dp::BindingFiller<TextStaticVertex> filler(2);
filler.FillDecl<TextStaticVertex::TTexCoord>("a_colorTexCoord");
filler.FillDecl<TextStaticVertex::TTexCoord>("a_maskTexCoord");
@ -68,11 +66,9 @@ dp::BindingInfo TextStaticBindingInit()
dp::BindingInfo TextOutlinedStaticBindingInit()
{
static_assert(sizeof(TextOutlinedStaticVertex) == (sizeof(TextOutlinedStaticVertex::TPosition) +
3 * sizeof(TextOutlinedStaticVertex::TTexCoord)), "");
static_assert(sizeof(TextOutlinedStaticVertex) == (3 * sizeof(TextOutlinedStaticVertex::TTexCoord)), "");
dp::BindingFiller<TextOutlinedStaticVertex> filler(4);
filler.FillDecl<TextOutlinedStaticVertex::TPosition>("a_position");
dp::BindingFiller<TextOutlinedStaticVertex> filler(3);
filler.FillDecl<TextOutlinedStaticVertex::TTexCoord>("a_colorTexCoord");
filler.FillDecl<TextOutlinedStaticVertex::TTexCoord>("a_outlineColorTexCoord");
filler.FillDecl<TextOutlinedStaticVertex::TTexCoord>("a_maskTexCoord");
@ -82,9 +78,11 @@ dp::BindingInfo TextOutlinedStaticBindingInit()
dp::BindingInfo TextDynamicBindingInit()
{
static_assert(sizeof(TextDynamicVertex) == sizeof(TextDynamicVertex::TNormal), "");
static_assert(sizeof(TextDynamicVertex) == (sizeof(TextStaticVertex::TPosition) +
sizeof(TextDynamicVertex::TNormal)), "");
dp::BindingFiller<TextDynamicVertex> filler(1, TextDynamicVertex::GetDynamicStreamID());
dp::BindingFiller<TextDynamicVertex> filler(2, TextDynamicVertex::GetDynamicStreamID());
filler.FillDecl<TextStaticVertex::TPosition>("a_position");
filler.FillDecl<TextDynamicVertex::TNormal>("a_normal");
return filler.m_info;
@ -198,17 +196,16 @@ dp::BindingInfo const & SolidTexturingVertex::GetBindingInfo()
}
TextOutlinedStaticVertex::TextOutlinedStaticVertex()
: m_position(0.0, 0.0, 0.0)
, m_colorTexCoord(0.0, 0.0)
: m_colorTexCoord(0.0, 0.0)
, m_outlineTexCoord(0.0, 0.0)
, m_maskTexCoord(0.0, 0.0)
{
}
TextOutlinedStaticVertex::TextOutlinedStaticVertex(TPosition const & position, TTexCoord const & colorTexCoord,
TTexCoord const & outlineTexCoord, TTexCoord const & maskTexCoord)
: m_position(position)
, m_colorTexCoord(colorTexCoord)
TextOutlinedStaticVertex::TextOutlinedStaticVertex(TTexCoord const & colorTexCoord,
TTexCoord const & outlineTexCoord,
TTexCoord const & maskTexCoord)
: m_colorTexCoord(colorTexCoord)
, m_outlineTexCoord(outlineTexCoord)
, m_maskTexCoord(maskTexCoord)
{
@ -220,12 +217,14 @@ dp::BindingInfo const & TextOutlinedStaticVertex::GetBindingInfo()
}
TextDynamicVertex::TextDynamicVertex()
: m_normal(0.0, 0.0)
: m_position(0.0, 0.0, 0.0)
, m_normal(0.0, 0.0)
{
}
TextDynamicVertex::TextDynamicVertex(TNormal const & normal)
: m_normal(normal)
TextDynamicVertex::TextDynamicVertex(TPosition const & position, TNormal const & normal)
: m_position(position),
m_normal(normal)
{
}
@ -295,20 +294,15 @@ dp::BindingInfo const & RouteVertex::GetBindingInfo()
}
TextStaticVertex::TextStaticVertex()
: m_position(0.0, 0.0, 0.0)
, m_colorTexCoord(0.0, 0.0)
: m_colorTexCoord(0.0, 0.0)
, m_maskTexCoord(0.0, 0.0)
{
}
TextStaticVertex::TextStaticVertex(TPosition const & position, TTexCoord const & colorTexCoord,
TTexCoord const & maskTexCoord)
: m_position(position)
, m_colorTexCoord(colorTexCoord)
TextStaticVertex::TextStaticVertex(TTexCoord const & colorTexCoord, TTexCoord const & maskTexCoord)
: m_colorTexCoord(colorTexCoord)
, m_maskTexCoord(maskTexCoord)
{
}
dp::BindingInfo const & TextStaticVertex::GetBindingInfo()

View file

@ -43,9 +43,8 @@ typedef buffer_vector<SolidTexturingVertex, 128> TSolidTexVertexBuffer;
struct TextStaticVertex : BaseVertex
{
TextStaticVertex();
TextStaticVertex(TPosition const & position, TTexCoord const & colorTexCoord, TTexCoord const & maskTexCoord);
TextStaticVertex(TTexCoord const & colorTexCoord, TTexCoord const & maskTexCoord);
TPosition m_position;
TTexCoord m_colorTexCoord;
TTexCoord m_maskTexCoord;
@ -58,10 +57,9 @@ struct TextOutlinedStaticVertex : BaseVertex
{
public:
TextOutlinedStaticVertex();
TextOutlinedStaticVertex(TPosition const & position, TTexCoord const & colorTexCoord,
TTexCoord const & outlineTexCoord, TTexCoord const & maskTexCoord);
TextOutlinedStaticVertex(TTexCoord const & colorTexCoord, TTexCoord const & outlineTexCoord,
TTexCoord const & maskTexCoord);
TPosition m_position;
TTexCoord m_colorTexCoord;
TTexCoord m_outlineTexCoord;
TTexCoord m_maskTexCoord;
@ -74,8 +72,9 @@ typedef buffer_vector<TextOutlinedStaticVertex, 128> TTextOutlinedStaticVertexBu
struct TextDynamicVertex : BaseVertex
{
TextDynamicVertex();
TextDynamicVertex(TNormal const & normal);
TextDynamicVertex(TPosition const & position, TNormal const & normal);
TPosition m_position;
TNormal m_normal;
static dp::BindingInfo const & GetBindingInfo();

View file

@ -32,11 +32,13 @@ class PathTextHandle : public df::TextHandle
public:
PathTextHandle(m2::SharedSpline const & spl,
df::SharedTextLayout const & layout,
float const mercatorOffset, uint64_t priority,
float const mercatorOffset, float const depth,
uint64_t priority,
ref_ptr<dp::TextureManager> textureManager)
: TextHandle(FeatureID(), layout->GetText(), dp::Center, priority, textureManager)
, m_spline(spl)
, m_layout(layout)
, m_depth(depth)
{
m_centerPointIter = m_spline.CreateIterator();
m_centerPointIter.Advance(mercatorOffset);
@ -52,7 +54,7 @@ public:
if (m_normals.empty())
m_normals.resize(4 * m_layout->GetGlyphCount());
return m_layout->CacheDynamicGeometry(m_centerPointIter, screen, m_normals);
return m_layout->CacheDynamicGeometry(m_centerPointIter, m_depth, screen, m_normals);
}
m2::RectD GetPixelRect(ScreenBase const & screen, bool perspective) const override
@ -104,7 +106,7 @@ public:
private:
m2::SharedSpline m_spline;
m2::Spline::iterator m_centerPointIter;
float const m_depth;
df::SharedTextLayout m_layout;
};
@ -155,16 +157,16 @@ void PathTextShape::DrawPathTextPlain(ref_ptr<dp::TextureManager> textures,
Spline::iterator iter = m_spline.CreateIterator();
iter.Advance(offset);
layoutPtr->CacheStaticGeometry(glsl::vec3(glsl::ToVec2(iter.m_pos), m_params.m_depth),
color, staticBuffer);
layoutPtr->CacheStaticGeometry(color, staticBuffer);
dynBuffer.resize(staticBuffer.size(), gpu::TextDynamicVertex(glsl::vec2(0.0, 0.0)));
dynBuffer.resize(staticBuffer.size());
dp::AttributeProvider provider(2, staticBuffer.size());
provider.InitStream(0, gpu::TextStaticVertex::GetBindingInfo(), make_ref(staticBuffer.data()));
provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(dynBuffer.data()));
drape_ptr<dp::OverlayHandle> handle = make_unique_dp<PathTextHandle>(m_spline, layoutPtr, offset,
m_params.m_depth,
GetOverlayPriority(),
textures);
batcher->InsertListOfStrip(state, make_ref(&provider), move(handle), 4);
@ -196,16 +198,16 @@ void PathTextShape::DrawPathTextOutlined(ref_ptr<dp::TextureManager> textures,
Spline::iterator iter = m_spline.CreateIterator();
iter.Advance(offset);
layoutPtr->CacheStaticGeometry(glsl::vec3(glsl::ToVec2(iter.m_pos), m_params.m_depth),
color, outline, staticBuffer);
layoutPtr->CacheStaticGeometry(color, outline, staticBuffer);
dynBuffer.resize(staticBuffer.size(), gpu::TextDynamicVertex(glsl::vec2(0.0, 0.0)));
dynBuffer.resize(staticBuffer.size());
dp::AttributeProvider provider(2, staticBuffer.size());
provider.InitStream(0, gpu::TextOutlinedStaticVertex::GetBindingInfo(), make_ref(staticBuffer.data()));
provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(dynBuffer.data()));
drape_ptr<dp::OverlayHandle> handle = make_unique_dp<PathTextHandle>(m_spline, layoutPtr, offset,
m_params.m_depth,
GetOverlayPriority(),
textures);
batcher->InsertListOfStrip(state, make_ref(&provider), move(handle), 4);

View file

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

View file

@ -87,16 +87,15 @@ public:
PathTextLayout(strings::UniString const & text,
float fontSize, ref_ptr<dp::TextureManager> textures);
void CacheStaticGeometry(glsl::vec3 const & pivot,
dp::TextureManager::ColorRegion const & colorRegion,
void CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion,
dp::TextureManager::ColorRegion const & outlineRegion,
gpu::TTextOutlinedStaticVertexBuffer & staticBuffer) const;
void CacheStaticGeometry(glsl::vec3 const & pivot,
dp::TextureManager::ColorRegion const & colorRegion,
void CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion,
gpu::TTextStaticVertexBuffer & staticBuffer) const;
bool CacheDynamicGeometry(m2::Spline::iterator const & iter,
float const depth,
ScreenBase const & screen,
gpu::TTextDynamicVertexBuffer & buffer) const;
};