diff --git a/drape/drape_common.pri b/drape/drape_common.pri index 790180b930..15e7d61b59 100644 --- a/drape/drape_common.pri +++ b/drape/drape_common.pri @@ -27,7 +27,8 @@ SOURCES += \ $$DRAPE_DIR/cpu_buffer.cpp \ $$DRAPE_DIR/utils/lodepng.cpp \ $$DRAPE_DIR/texture_structure_desc.cpp \ - $$DRAPE_DIR/symbols_texture.cpp + $$DRAPE_DIR/symbols_texture.cpp \ + $$DRAPE_DIR/texture_manager.cpp HEADERS += \ $$DRAPE_DIR/data_buffer.hpp \ @@ -58,4 +59,5 @@ HEADERS += \ $$DRAPE_DIR/cpu_buffer.hpp \ $$DRAPE_DIR/utils/lodepng.h \ $$DRAPE_DIR/texture_structure_desc.hpp \ - $$DRAPE_DIR/symbols_texture.hpp + $$DRAPE_DIR/symbols_texture.hpp \ + $$DRAPE_DIR/texture_manager.hpp diff --git a/drape/symbols_texture.cpp b/drape/symbols_texture.cpp index 2c6a58b8b8..c2917365b6 100644 --- a/drape/symbols_texture.cpp +++ b/drape/symbols_texture.cpp @@ -2,20 +2,28 @@ #include "utils/lodepng.h" -SymbolsTexture::SymbolsTexture(const string & skinPathName) +#include "../platform/platform.hpp" + +void SymbolsTexture::Load(const string & skinPathName) { uint32_t width, height; m_desc.Load(skinPathName + ".sdf", width, height); + ReaderPtr reader = GetPlatform().GetReader(skinPathName + ".png"); + uint64_t size = reader.Size(); + vector rawData; + rawData.resize(size); + reader.Read(0, &rawData[0], size); + vector pngData; unsigned w, h; - lodepng::decode(pngData, w, h, skinPathName + ".png"); + lodepng::decode(pngData, w, h, &rawData[0], rawData.size()); ASSERT(width == w && height == h, ()); Create(width, height, Texture::RGBA8, MakeStackRefPointer(&pngData[0])); } -m2::RectD SymbolsTexture::FindSymbol(const string & symbolName) +m2::RectD SymbolsTexture::FindSymbol(const string & symbolName) const { m2::RectU r; if (!m_desc.GetResource(symbolName, r)) diff --git a/drape/symbols_texture.hpp b/drape/symbols_texture.hpp index 058ec25c5a..1d124c4b0d 100644 --- a/drape/symbols_texture.hpp +++ b/drape/symbols_texture.hpp @@ -8,9 +8,8 @@ class SymbolsTexture : public Texture { public: - SymbolsTexture(string const & skinPathName); - - m2::RectD FindSymbol(string const & symbolName); + void Load(string const & skinPathName); + m2::RectD FindSymbol(string const & symbolName) const; private: TextureStructureDesc m_desc; diff --git a/drape/texture.cpp b/drape/texture.cpp index cc38f07f17..dc39a62b08 100644 --- a/drape/texture.cpp +++ b/drape/texture.cpp @@ -36,7 +36,7 @@ void Texture::Create(uint32_t width, uint32_t height, TextureFormat format, RefP GLFunctions::glTexImage2D(m_width, m_height, layout, pixelType, data.GetRaw()); SetFilterParams(GLConst::GLLinear, GLConst::GLLinear); - SetFilterParams(GLConst::GLClampToEdge, GLConst::GLClampToEdge); + SetWrapMode(GLConst::GLClampToEdge, GLConst::GLClampToEdge); } void Texture::SetFilterParams(glConst minFilter, glConst magFilter) diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp new file mode 100644 index 0000000000..c3a7b7f103 --- /dev/null +++ b/drape/texture_manager.cpp @@ -0,0 +1,16 @@ +#include "texture_manager.hpp" + +#include "../coding/file_name_utils.hpp" + +#include "../platform/platform.hpp" + +void TextureManager::LoadExternalResources(const string & resourcePostfix) +{ + m_symbols.Load(my::JoinFoldersToPath(string("resources-") + resourcePostfix, "symbols")); +} + +void TextureManager::GetSymbolRect(const string & symbolName, TextureManager::Symbol & symbol) const +{ + symbol.m_textureBlock = 0; + symbol.m_texCoord = m_symbols.FindSymbol(symbolName); +} diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp new file mode 100644 index 0000000000..db12de37f0 --- /dev/null +++ b/drape/texture_manager.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "symbols_texture.hpp" + +class TextureManager +{ +public: + void LoadExternalResources(const string & resourcePostfix); + + struct Symbol + { + m2::RectD m_texCoord; + uint32_t m_textureBlock; + }; + + void GetSymbolRect(const string & symbolName, Symbol & symbol) const; + +private: + SymbolsTexture m_symbols; +}; diff --git a/drape_frontend/area_shape.cpp b/drape_frontend/area_shape.cpp index c18d319176..4ea16fff74 100644 --- a/drape_frontend/area_shape.cpp +++ b/drape_frontend/area_shape.cpp @@ -19,7 +19,7 @@ namespace df m_vertexes.push_back(Point3D(v3.x, v3.y, m_depth)); } - void AreaShape::Draw(RefPointer batcher) const + void AreaShape::Draw(RefPointer batcher, RefPointer /*textures*/) const { GLState state(gpu::SOLID_AREA_PROGRAM, 0); float r, g, b, a; diff --git a/drape_frontend/area_shape.hpp b/drape_frontend/area_shape.hpp index 3afb8f2f5f..493c74d509 100644 --- a/drape_frontend/area_shape.hpp +++ b/drape_frontend/area_shape.hpp @@ -19,7 +19,7 @@ namespace df const m2::PointF & v2, const m2::PointF & v3); - virtual void Draw(RefPointer batcher) const; + virtual void Draw(RefPointer batcher, RefPointer /*textures*/) const; private: Color m_color; diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index 0d9a1531af..eddfe28034 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -69,7 +69,7 @@ namespace df MapShapeReadedMessage * msg = static_cast(message.GetRaw()); RefPointer batcher = m_batchersPool->GetTileBatcher(msg->GetKey()); MasterPointer shape(msg->GetShape()); - shape->Draw(batcher); + shape->Draw(batcher, MakeStackRefPointer(&m_textureManager)); shape.Destroy(); } @@ -99,6 +99,8 @@ namespace df { m_contextFactory->getResourcesUploadContext()->makeCurrent(); + m_textureManager.LoadExternalResources(VisualParams::Instance().GetResourcePostfix()); + while (!IsCancelled()) ProcessSingleMessage(true); diff --git a/drape_frontend/backend_renderer.hpp b/drape_frontend/backend_renderer.hpp index 61aa63831c..bf99d7c275 100644 --- a/drape_frontend/backend_renderer.hpp +++ b/drape_frontend/backend_renderer.hpp @@ -6,6 +6,7 @@ #include "../drape/pointers.hpp" #include "../drape/oglcontextfactory.hpp" +#include "../drape/texture_manager.hpp" #include "../map/feature_vec_model.hpp" @@ -38,6 +39,7 @@ namespace df EngineContext m_engineContext; MasterPointer m_batchersPool; MasterPointer m_readManager; + TextureManager m_textureManager; ///////////////////////////////////////// // MessageAcceptor // diff --git a/drape_frontend/line_shape.cpp b/drape_frontend/line_shape.cpp index 32969e4cd8..616b425c5a 100644 --- a/drape_frontend/line_shape.cpp +++ b/drape_frontend/line_shape.cpp @@ -23,7 +23,7 @@ namespace df ASSERT_GREATER(m_points.size(), 1, ()); } - void LineShape::Draw(RefPointer batcher) const + void LineShape::Draw(RefPointer batcher, RefPointer /*textures*/) const { //join, cap, segment params // vertex type: diff --git a/drape_frontend/line_shape.hpp b/drape_frontend/line_shape.hpp index 3aefab28be..c599299047 100644 --- a/drape_frontend/line_shape.hpp +++ b/drape_frontend/line_shape.hpp @@ -16,7 +16,7 @@ namespace df float depth, LineViewParams const & params); - virtual void Draw(RefPointer batcher) const; + virtual void Draw(RefPointer batcher, RefPointer /*textures*/) const; float GetWidth() const { return m_params.m_width; } Color const & GetColor() const { return m_params.m_color; } diff --git a/drape_frontend/map_shape.hpp b/drape_frontend/map_shape.hpp index bb5234f8e1..a5db7b321b 100644 --- a/drape_frontend/map_shape.hpp +++ b/drape_frontend/map_shape.hpp @@ -6,6 +6,7 @@ #include "../drape/pointers.hpp" class Batcher; +class TextureManager; namespace df { @@ -33,7 +34,7 @@ namespace df { public: virtual ~MapShape(){} - virtual void Draw(RefPointer batcher) const = 0; + virtual void Draw(RefPointer batcher, RefPointer textures) const = 0; }; class MapShapeReadedMessage : public Message diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index 2e52a0ff00..c20b223f7f 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -1,6 +1,6 @@ # Head project for drape develop and debuging ROOT_DIR = .. -DEPENDENCIES = drape_frontend map drape indexer platform geometry coding base protobuf zlib +DEPENDENCIES = drape_frontend map drape indexer platform geometry coding base expat protobuf zlib include($$ROOT_DIR/common.pri) diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 0b0b527c2d..fd636e8ee9 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -114,7 +114,7 @@ namespace df params1.m_color = Color(255, 255, 50, 255); params1.m_width = 80.f; df::LineShape * line1 = new df::LineShape(linePoints1, 0.0f, params1); - line1->Draw(m_batcher.GetRefPointer()); + line1->Draw(m_batcher.GetRefPointer(), MakeStackRefPointer(NULL)); // //2 @@ -133,7 +133,7 @@ namespace df params2.m_color = Color(0, 255, 255, 255); params2.m_width = 50.f; df::LineShape * line2 = new df::LineShape(linePoints2, 0.0f, params2); - line2->Draw(m_batcher.GetRefPointer()); + line2->Draw(m_batcher.GetRefPointer(), MakeStackRefPointer(NULL)); // //3 @@ -152,7 +152,7 @@ namespace df params3.m_color = Color(255, 0, 255, 255); params3.m_width = 60.f; df::LineShape * line3 = new df::LineShape(linePoints3, 0.0f, params3); - line3->Draw(m_batcher.GetRefPointer()); + line3->Draw(m_batcher.GetRefPointer(), MakeStackRefPointer(NULL)); // }