diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2017-03-17 14:59:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-17 14:59:24 +0300 |
commit | aabef62d44264f7f40eedec5aa88cbd0820bec64 (patch) | |
tree | 83d96ed17396192adacce3c3153386d7fb527c63 /drape/texture_manager.cpp | |
parent | 2d2a9768ffade7873719db44df52d51dae545183 (diff) | |
parent | ae5348f4db4d9563cc38dda3292de7cab83a4263 (diff) |
Merge pull request #5617 from rokuz/multiple-symbols-textures
Multiple symbols textures
Diffstat (limited to 'drape/texture_manager.cpp')
-rw-r--r-- | drape/texture_manager.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 531e1215fc..30920845a7 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -37,6 +37,10 @@ size_t const kReservedColors = 20; float const kGlyphAreaMultiplier = 1.2f; float const kGlyphAreaCoverage = 0.9f; +std::string const kDefaultSymbolsTexture = "symbols"; +std::string const kSymbolTextures[] = { kDefaultSymbolsTexture, "symbols-ad" }; +uint32_t const kDefaultSymbolsIndex = 0; + namespace { @@ -145,7 +149,9 @@ void TextureManager::BaseRegion::SetTexture(ref_ptr<Texture> texture) m2::PointF TextureManager::BaseRegion::GetPixelSize() const { - ASSERT(IsValid(), ()); + if (!IsValid()) + return m2::PointF(0.0f, 0.0f); + m2::RectF const & texRect = m_info->GetTexRect(); return m2::PointF(texRect.SizeX() * m_texture->GetWidth(), texRect.SizeY() * m_texture->GetHeight()); @@ -153,11 +159,20 @@ m2::PointF TextureManager::BaseRegion::GetPixelSize() const float TextureManager::BaseRegion::GetPixelHeight() const { + if (!IsValid()) + return 0.0f; + return m_info->GetTexRect().SizeY() * m_texture->GetHeight(); } m2::RectF const & TextureManager::BaseRegion::GetTexRect() const { + if (!IsValid()) + { + static m2::RectF nilRect(0.0f, 0.0f, 0.0f, 0.0f); + return nilRect; + } + return m_info->GetTexRect(); } @@ -207,7 +222,7 @@ void TextureManager::Release() m_glyphGroups.clear(); m_hybridGlyphGroups.clear(); - m_symbolTexture.reset(); + m_symbolTextures.clear(); m_stipplePenTexture.reset(); m_colorTexture.reset(); @@ -380,7 +395,11 @@ void TextureManager::Init(Params const & params) GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); - m_symbolTexture = make_unique_dp<SymbolsTexture>(params.m_resPostfix, make_ref(m_textureAllocator)); + for (size_t i = 0; i < ARRAY_SIZE(kSymbolTextures); ++i) + { + m_symbolTextures.push_back(make_unique_dp<SymbolsTexture>(params.m_resPostfix, kSymbolTextures[i], + make_ref(m_textureAllocator))); + } m_trafficArrowTexture = make_unique_dp<StaticTexture>("traffic-arrow", params.m_resPostfix, make_ref(m_textureAllocator)); @@ -454,9 +473,12 @@ void TextureManager::Init(Params const & params) void TextureManager::Invalidate(string const & resPostfix) { - ASSERT(m_symbolTexture != nullptr, ()); - ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTexture); - symbolsTexture->Invalidate(resPostfix, make_ref(m_textureAllocator)); + for (size_t i = 0; i < m_symbolTextures.size(); ++i) + { + ASSERT(m_symbolTextures[i] != nullptr, ()); + ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTextures[i]); + symbolsTexture->Invalidate(resPostfix, make_ref(m_textureAllocator)); + } ASSERT(m_trafficArrowTexture != nullptr, ()); ref_ptr<StaticTexture> staticTexture = make_ref(m_trafficArrowTexture); @@ -465,7 +487,17 @@ void TextureManager::Invalidate(string const & resPostfix) void TextureManager::GetSymbolRegion(string const & symbolName, SymbolRegion & region) { - GetRegionBase(make_ref(m_symbolTexture), region, SymbolsTexture::SymbolKey(symbolName)); + for (size_t i = 0; i < m_symbolTextures.size(); ++i) + { + ASSERT(m_symbolTextures[i] != nullptr, ()); + ref_ptr<SymbolsTexture> symbolsTexture = make_ref(m_symbolTextures[i]); + if (symbolsTexture->IsSymbolContained(symbolName)) + { + GetRegionBase(symbolsTexture, region, SymbolsTexture::SymbolKey(symbolName)); + return; + } + } + LOG(LWARNING, ("Detected using of unknown symbol ", symbolName)); } void TextureManager::GetStippleRegion(TStipplePattern const & pen, StippleRegion & region) @@ -515,7 +547,8 @@ bool TextureManager::AreGlyphsReady(strings::UniString const & str, int fixedHei ref_ptr<Texture> TextureManager::GetSymbolsTexture() const { - return make_ref(m_symbolTexture); + ASSERT(!m_symbolTextures.empty(), ()); + return make_ref(m_symbolTextures[kDefaultSymbolsIndex]); } ref_ptr<Texture> TextureManager::GetTrafficArrowTexture() const |