From 75c079adb16a24cbd8b8111993a67313fd52718a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 31 Jul 2014 18:14:26 +0200 Subject: [PATCH] move sprite to a use future loading --- include/mbgl/geometry/sprite_atlas.hpp | 17 ++-- include/mbgl/map/map.hpp | 5 +- include/mbgl/map/sprite.hpp | 32 ++++--- include/mbgl/map/tile_parser.hpp | 5 +- include/mbgl/renderer/symbol_bucket.hpp | 5 +- include/mbgl/style/style.hpp | 6 +- src/geometry/sprite_atlas.cpp | 65 ++------------- src/map/map.cpp | 27 +++--- src/map/sprite.cpp | 106 ++++++++++++++---------- src/map/tile_parser.cpp | 6 +- src/map/vector_tile_data.cpp | 2 +- src/renderer/painter_fill.cpp | 4 +- src/renderer/symbol_bucket.cpp | 5 +- src/style/style.cpp | 5 ++ 14 files changed, 144 insertions(+), 146 deletions(-) diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 4b55540cc..dc2378c2f 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -26,17 +26,20 @@ public: // Changes the pixel ratio. bool resize(float newRatio); - // Update uninitialized sprites in this atlas from the given sprite. + // Update uninitialized (= outdated) sprites in this atlas from the given sprite. void update(const Sprite &sprite); - // Returns the coordinates of a square icon. The getter also *creates* new square icons in the - // atlas if they don't exist, but they'll be default-initialized with a a black circle. - Rect getIcon(int size, const std::string &name); + // Returns the coordinates of an image that is sourced from the sprite image. + // This getter attempts to read the image from the sprite if it is already loaded. + // In that case, it copies it into the sprite atlas and returns the dimensions. + // Otherwise, it returns a 0/0/0/0 rect. + Rect getImage(const std::string &name, const Sprite &sprite); // Returns the coordinates of an image that is sourced from the sprite image. - // This getter does not create images, as the dimension of the texture us unknown if the - // sprite is not yet loaded. Instead, it returns a 0/0/0/0 rect. - Rect getImage(const std::string &name, const Sprite &sprite); + // This getter waits until the sprite image was loaded, copies it into the sprite + // image and returns the dimensions. + // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. + Rect waitForImage(const std::string &name, const Sprite &sprite); // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out // of date. diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 81d55b217..0a94fc7ed 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -21,6 +21,7 @@ class GlyphAtlas; class GlyphStore; class LayerDescription; class SpriteAtlas; +class Sprite; class Style; class StyleLayer; class StyleLayerGroup; @@ -110,10 +111,11 @@ public: public: inline const TransformState &getState() const { return state; } - inline std::shared_ptr getStyle() const { return style; } + inline std::shared_ptr