diff options
author | Adam Hunter <adam@mapbox.com> | 2015-11-16 16:26:02 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-12-01 09:15:05 -0800 |
commit | e1091db45ea5e921337f1cfccb36f46ab01dd54e (patch) | |
tree | f8c9f98ffeb84e1ec698961aed432a1b5ae32bee /src/mbgl/sprite | |
parent | 58886842bc381cd30bac7102d4f70497c0128aa7 (diff) | |
download | qtlocation-mapboxgl-e1091db45ea5e921337f1cfccb36f46ab01dd54e.tar.gz |
[core] Use a separate atlas and store for annotation sprites
Fixes #1488
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.hpp | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index 45b0511c68..ae71f18f03 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -24,9 +24,7 @@ SpriteAtlas::SpriteAtlas(dimension width_, dimension height_, float pixelRatio_, pixelRatio(pixelRatio_), store(store_), bin(width_, height_), - data(std::make_unique<uint32_t[]>(pixelWidth * pixelHeight)), dirty(true) { - std::fill(data.get(), data.get() + pixelWidth * pixelHeight, 0); } Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const size_t pixel_width, const size_t pixel_height) { @@ -103,6 +101,11 @@ SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, bool repea } void SpriteAtlas::copy(const Holder& holder, const bool wrap) { + if (!data) { + data = std::make_unique<uint32_t[]>(pixelWidth * pixelHeight); + std::fill(data.get(), data.get() + pixelWidth * pixelHeight, 0); + } + const uint32_t *srcData = reinterpret_cast<const uint32_t *>(holder.texture->data.data()); if (!srcData) return; const vec2<uint32_t> srcSize { holder.texture->pixelWidth, holder.texture->pixelHeight }; @@ -189,6 +192,10 @@ void SpriteAtlas::updateDirty() { } void SpriteAtlas::bind(bool linear) { + if (!data) { + return; // Empty atlas + } + if (!texture) { MBGL_CHECK_ERROR(glGenTextures(1, &texture)); MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index 0d86279e2d..0e3e8cf225 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -66,6 +66,8 @@ public: inline dimension getTextureWidth() const { return pixelWidth; } inline dimension getTextureHeight() const { return pixelHeight; } inline float getPixelRatio() const { return pixelRatio; } + + // Only for use in tests. inline const uint32_t* getData() const { return data.get(); } private: @@ -90,7 +92,7 @@ private: BinPack<dimension> bin; std::map<Key, Holder> images; std::set<std::string> uninitialized; - const std::unique_ptr<uint32_t[]> data; + std::unique_ptr<uint32_t[]> data; std::atomic<bool> dirty; bool fullUploadRequired = true; GLuint texture = 0; |