diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-08-11 14:16:03 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-11-30 16:09:59 +0300 |
commit | 4ced7b12508a084e42dd72a376bcceb6e8bfe58f (patch) | |
tree | 9f99de5fe2f512a2b78291f99de53082629605e0 | |
parent | c8726eb6f5bcb58749a9b7c0d1360639837efe06 (diff) |
Added patterns loading
-rw-r--r-- | data/colors.txt | 7 | ||||
-rw-r--r-- | data/patterns.txt | 49 | ||||
-rw-r--r-- | drape/texture_manager.cpp | 90 | ||||
-rw-r--r-- | drape/texture_manager.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/backend_renderer.cpp | 2 |
5 files changed, 138 insertions, 12 deletions
diff --git a/data/colors.txt b/data/colors.txt index a96e595f81..951b267bf7 100644 --- a/data/colors.txt +++ b/data/colors.txt @@ -32,8 +32,8 @@ 4473907 4473924 4473941 -4487133 4491332 +4495803 4504388 4521796 5570560 @@ -77,6 +77,7 @@ 10066329 10075033 10075118 +10079453 10083737 10088089 11141120 @@ -96,7 +97,6 @@ 12303274 12303291 12311978 -12312029 12316398 12320767 13369344 @@ -107,7 +107,6 @@ 13421772 13430459 14483456 -14514005 14518408 14522675 14527061 @@ -136,10 +135,8 @@ 16729156 16733508 16742144 -16742229 16746496 16746751 -16755353 16763904 16763972 16768256 diff --git a/data/patterns.txt b/data/patterns.txt new file mode 100644 index 0000000000..0824471ab9 --- /dev/null +++ b/data/patterns.txt @@ -0,0 +1,49 @@ +4.0 20.0 +1.0 5.2 +3.12 3.12 +12.0 12.0 +2.0 2.0 +1.0 1.0 +5.0 1.0 1.0 1.0 +10.0 2.0 2.0 2.0 +12.0 4.0 4.0 4.0 +8.0 4.0 +1.2 2.0 1.2 2.0 1.2 4.4 +5.0 5.0 +4.0 4.0 +1.0 3.0 +1.0 4.0 +1.0 2.4 +1.0 1.2 +1.6 1.6 +2.4 1.0 +3.0 1.0 +4.0 1.0 +1.0 20.0 +1.0 40.0 +8.0 8.0 +1.5 1.0 +6.0 1.0 +16.0 8.0 +2.4 4.0 2.4 4.0 +4.5 4.5 +9.0 9.0 +3.6 5.4 +7.2 10.8 +9.6 14.4 +3.8 5.4 +7.6 10.8 +5.5 5.5 +11.0 11.0 +14.0 14.0 +14.4 14.4 +2.4 2.4 +2.4 2.4 2.4 2.4 2.4 12.0 +3.0 6.0 +6.0 12.0 +8.0 16.0 +7.2 16.8 +3.0 3.0 +3.0 2.0 +7.0 5.0 +12.0 8.0 diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 1b5b28c881..b246cce8b7 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -13,6 +13,7 @@ #include "base/logging.hpp" #include "base/stl_add.hpp" +#include "base/string_utils.hpp" #include "std/vector.hpp" #include "std/bind.hpp" @@ -20,13 +21,19 @@ namespace dp { -uint32_t const STIPPLE_TEXTURE_SIZE = 1024; -uint32_t const COLOR_TEXTURE_SIZE = 64; +uint32_t const STIPPLE_TEXTURE_WIDTH = 512; +uint32_t const MIN_STIPPLE_TEXTURE_HEIGHT = 64; +uint32_t const MIN_COLOR_TEXTURE_SIZE = 64; size_t const INVALID_GLYPH_GROUP = numeric_limits<size_t>::max(); +size_t const PIXELS_PER_COLOR = 2; + // number of glyphs (since 0) which will be in each texture size_t const DUPLICATED_GLYPHS_COUNT = 128; +size_t const RESERVED_PATTERNS = 10; +size_t const RESERVED_COLORS = 20; + namespace { @@ -68,6 +75,48 @@ void ParseColorsList(string const & colorsFile, ToDo toDo) } } +template <typename ToDo> +void ParsePatternsList(string const & patternsFile, ToDo toDo) +{ + string patternsList; + try + { + ReaderPtr<Reader>(GetPlatform().GetReader(patternsFile)).ReadAsString(patternsList); + } + catch(RootException const & e) + { + LOG(LWARNING, ("Error reading patterns list ", patternsFile, " : ", e.what())); + return; + } + + strings::Tokenize(patternsList, "\n", [&](string const & patternStr) + { + if (patternStr.empty()) + return; + + buffer_vector<double, 8> pattern; + strings::Tokenize(patternStr, " ", [&](string const & token) + { + double d = 0.0; + strings::to_double(token, d); + pattern.push_back(d); + }); + + bool isValid = true; + for (size_t i = 0; i < pattern.size(); i++) + { + if (fabs(pattern[i]) < 1e-5) + { + isValid = false; + break; + } + } + + if (isValid) + toDo(pattern); + }); +} + } // namespace TextureManager::TextureManager() @@ -319,14 +368,41 @@ void TextureManager::Init(Params const & params) GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); m_symbolTexture = make_unique_dp<SymbolsTexture>(params.m_resPostfix); - m_stipplePenTexture = make_unique_dp<StipplePenTexture>(m2::PointU(STIPPLE_TEXTURE_SIZE, STIPPLE_TEXTURE_SIZE)); - m_colorTexture = make_unique_dp<ColorTexture>(m2::PointU(COLOR_TEXTURE_SIZE, COLOR_TEXTURE_SIZE)); - ParseColorsList(params.m_colors, [this](dp::Color const & color) + + // initialize patterns + list<buffer_vector<uint8_t, 8>> patterns; + double const visualScale = params.m_visualScale; + ParsePatternsList(params.m_patterns, [&patterns, visualScale](buffer_vector<double, 8> const & pattern) { - ref_ptr<ColorTexture> colorTexture = make_ref(m_colorTexture); - colorTexture->ReserveColor(color); + buffer_vector<uint8_t, 8> p; + for (size_t i = 0; i < pattern.size(); i++) + p.push_back(pattern[i] * visualScale); + patterns.push_back(move(p)); }); + size_t const stippleTextureHeight = max(my::NextPowOf2(patterns.size() + RESERVED_PATTERNS), MIN_STIPPLE_TEXTURE_HEIGHT); + m_stipplePenTexture = make_unique_dp<StipplePenTexture>(m2::PointU(STIPPLE_TEXTURE_WIDTH, stippleTextureHeight)); + LOG(LDEBUG, ("Pattens texture size = ", m_stipplePenTexture->GetWidth(), m_stipplePenTexture->GetHeight())); + + ref_ptr<ColorTexture> stipplePenTextureTex = make_ref(m_stipplePenTexture); + //for (auto it = patterns.begin(); it != patterns.end(); ++it) + // stipplePenTextureTex->ReservePattern(*it); + + // initialize colors + list<dp::Color> colors; + ParseColorsList(params.m_colors, [&colors](dp::Color const & color) + { + colors.push_back(color); + }); + + size_t const colorTextureSize = max(my::NextPowOf2(floor(sqrt(colors.size() + RESERVED_COLORS)) * PIXELS_PER_COLOR), MIN_COLOR_TEXTURE_SIZE); + m_colorTexture = make_unique_dp<ColorTexture>(m2::PointU(colorTextureSize, colorTextureSize)); + LOG(LDEBUG, ("Colors texture size = ", m_colorTexture->GetWidth(), m_colorTexture->GetHeight())); + + ref_ptr<ColorTexture> colorTex = make_ref(m_colorTexture); + for (auto it = colors.begin(); it != colors.end(); ++it) + colorTex->ReserveColor(*it); + m_glyphManager = make_unique_dp<GlyphManager>(params.m_glyphMngParams); m_maxTextureSize = min(2048, GLFunctions::glGetInteger(gl_const::GLMaxTextureSize)); diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index 9771f6b13a..db4b9a7074 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -66,7 +66,9 @@ public: struct Params { string m_resPostfix; + double m_visualScale; string m_colors; + string m_patterns; GlyphManager::Params m_glyphMngParams; }; diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index 6096b80b99..26e91c37c6 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -257,7 +257,9 @@ void BackendRenderer::InitGLDependentResource() dp::TextureManager::Params params; params.m_resPostfix = VisualParams::Instance().GetResourcePostfix(); + params.m_visualScale = df::VisualParams::Instance().GetVisualScale(); params.m_colors = "colors.txt"; + params.m_patterns = "patterns.txt"; params.m_glyphMngParams.m_uniBlocks = "unicode_blocks.txt"; params.m_glyphMngParams.m_whitelist = "fonts_whitelist.txt"; params.m_glyphMngParams.m_blacklist = "fonts_blacklist.txt"; |