From a5a47250859188bd425ec4397d51d9d51f8b1cc7 Mon Sep 17 00:00:00 2001 From: ExMix Date: Wed, 11 Mar 2015 18:43:00 +0300 Subject: [PATCH] [drape] review fixes --- drape/texture_manager.cpp | 2 +- drape/texture_manager.hpp | 4 +-- drape_gui/gui_text.cpp | 54 +++++++++++++---------------------- drape_head/testing_engine.cpp | 13 +++++---- 4 files changed, 31 insertions(+), 42 deletions(-) diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 70d4cf7f88..8f2447c79c 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -20,7 +20,7 @@ namespace dp uint32_t const STIPPLE_TEXTURE_SIZE = 1024; uint32_t const COLOR_TEXTURE_SIZE = 1024; -size_t const INVALID_GLYPH_GROUP = static_cast(-1); +size_t const INVALID_GLYPH_GROUP = numeric_limits::max(); bool TextureManager::BaseRegion::IsValid() const { diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index c6a0ea1ccd..3839b683a1 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -76,9 +76,9 @@ public: void GetStippleRegion(TStipplePattern const & pen, StippleRegion & region); void GetColorRegion(Color const & color, ColorRegion & region); - typedef buffer_vector TMultilineText; + typedef buffer_vector TMultilineText; typedef buffer_vector TGlyphsBuffer; - typedef buffer_vector TMultilineGlyphsBuffer; + typedef buffer_vector TMultilineGlyphsBuffer; void GetGlyphRegions(TMultilineText const & text, TMultilineGlyphsBuffer & buffers); void GetGlyphRegions(strings::UniString const & text, TGlyphsBuffer & regions); diff --git a/drape_gui/gui_text.cpp b/drape_gui/gui_text.cpp index 039edac204..a9b24b5275 100644 --- a/drape_gui/gui_text.cpp +++ b/drape_gui/gui_text.cpp @@ -41,49 +41,38 @@ namespace return glsl::vec2(xOffset, yOffset); } - void FillPositionDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) + void FillCommonDecl(dp::BindingDecl & decl, string const & name, uint8_t compCount, uint8_t stride, uint8_t offset) { - decl.m_attributeName = "a_position"; - decl.m_componentCount = 3; + decl.m_attributeName = name; + decl.m_componentCount = compCount; decl.m_componentType = gl_const::GLFloatType; decl.m_stride = stride; decl.m_offset = offset; } + void FillPositionDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) + { + FillCommonDecl(decl, "a_position", 3, stride, offset); + } + void FillNormalDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) { - decl.m_attributeName = "a_normal"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_stride = stride; - decl.m_offset = offset; + FillCommonDecl(decl, "a_normal", 2, stride, offset); } void FillColorDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) { - decl.m_attributeName = "a_colorTexCoord"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_stride = stride; - decl.m_offset = offset; + FillCommonDecl(decl, "a_colorTexCoord", 2, stride, offset); } void FillOutlineDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) { - decl.m_attributeName = "a_outlineColorTexCoord"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_stride = stride; - decl.m_offset = offset; + FillCommonDecl(decl, "a_outlineColorTexCoord", 2, stride, offset); } void FillMaskDecl(dp::BindingDecl & decl, uint8_t stride, uint8_t offset) { - decl.m_attributeName = "a_maskTexCoord"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_stride = stride; - decl.m_offset = offset; + FillCommonDecl(decl, "a_maskTexCoord", 2, stride, offset); } } @@ -113,8 +102,8 @@ dp::BindingInfo const & StaticLabel::Vertex::GetBindingInfo() } -void StaticLabel::CacheStaticText(string const & text, const char * delim, - dp::Anchor anchor, const dp::FontDecl & font, +void StaticLabel::CacheStaticText(string const & text, char const * delim, + dp::Anchor anchor, dp::FontDecl const & font, dp::RefPointer mng, LabelResult & result) { ASSERT(!text.empty(), ()); @@ -152,15 +141,15 @@ void StaticLabel::CacheStaticText(string const & text, const char * delim, mng->GetColorRegion(font.m_outlineColor, outline); ASSERT(color.GetTexture().GetRaw() == outline.GetTexture().GetRaw(), ()); - glsl::vec2 cTex = glsl::ToVec2(color.GetTexRect().Center()); - glsl::vec2 oTex = glsl::ToVec2(outline.GetTexRect().Center()); + glsl::vec2 colorTex = glsl::ToVec2(color.GetTexRect().Center()); + glsl::vec2 outlineTex = glsl::ToVec2(outline.GetTexRect().Center()); float textRatio = font.m_size * DrapeGui::Instance().GetScaleFactor() / BASE_GLYPH_HEIGHT; - buffer_vector lineLengths; + buffer_vector lineLengths; lineLengths.resize(buffers.size()); - buffer_vector ranges; + buffer_vector ranges; float fullHeight = 0.0; float prevLineHeight = 0.0; @@ -186,7 +175,7 @@ void StaticLabel::CacheStaticText(string const & text, const char * delim, glsl::vec3 position = glsl::vec3(0.0, 0.0, depth); for (size_t v = 0; v < normals.size(); ++v) - rb.push_back(Vertex(position, pen + normals[v], cTex, oTex, maskTex[v])); + rb.push_back(Vertex(position, pen + normals[v], colorTex, outlineTex, maskTex[v])); float const advance = glyph.GetAdvanceX() * textRatio; currentLineLength += advance; @@ -223,10 +212,7 @@ void StaticLabel::CacheStaticText(string const & text, const char * delim, size_t endIndex = ranges[i]; for (size_t i = startIndex; i < endIndex; ++i) - { - Vertex & v = rb[i]; - v.m_normal = v.m_normal + glsl::vec2(xOffset, yOffset); - } + rb[i].m_normal = rb[i].m_normal + glsl::vec2(xOffset, yOffset); startIndex = endIndex; } diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 5140845798..8242ed1ab0 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -55,14 +55,15 @@ public: for (gui::StaticLabel::Vertex & v : result.m_buffer) v.m_position = glsl::vec3(glsl::ToVec2(m_base), v.m_position.z); - dp::AttributeProvider provider(1, result.m_buffer.size()); - provider.InitStream(0, gui::StaticLabel::Vertex::GetBindingInfo(), dp::MakeStackRefPointer(result.m_buffer.data())); + dp::AttributeProvider provider(1 /* streamCount */, result.m_buffer.size()); + provider.InitStream(0 /* streamIndex */, gui::StaticLabel::Vertex::GetBindingInfo(), + dp::MakeStackRefPointer(result.m_buffer.data())); dp::GLState state(gpu::TEXT_PROGRAM, dp::GLState::OverlayLayer); state.SetColorTexture(result.m_colorTexture); state.SetMaskTexture(result.m_maskTexture); - batcher->InsertListOfStrip(state, dp::MakeStackRefPointer(&provider), 4); + batcher->InsertListOfStrip(state, dp::MakeStackRefPointer(&provider), 4 /* vertexStride */); } private: @@ -100,8 +101,10 @@ public: ASSERT_EQUAL(statData.size(), dynData.size(), ()); dp::AttributeProvider provider(2, dynData.size()); - provider.InitStream(0, gui::MutableLabel::StaticVertex::GetBindingInfo(), dp::MakeStackRefPointer(statData.data())); - provider.InitStream(1, gui::MutableLabel::DynamicVertex::GetBindingInfo(), dp::MakeStackRefPointer(dynData.data())); + provider.InitStream(0 /* streamIndex */, gui::MutableLabel::StaticVertex::GetBindingInfo(), + dp::MakeStackRefPointer(statData.data())); + provider.InitStream(1 /* streamIndex */, gui::MutableLabel::DynamicVertex::GetBindingInfo(), + dp::MakeStackRefPointer(dynData.data())); dp::GLState state(gpu::TEXT_PROGRAM, dp::GLState::OverlayLayer); state.SetColorTexture(colorTexure);