summaryrefslogtreecommitdiff
path: root/src/mbgl/sprite
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-18 11:19:24 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-18 15:15:24 -0800
commit9c26f063187b129218910dbb86eb21215a2cdf40 (patch)
tree189f84f90cef341a0a084fefde40f4f07da117cb /src/mbgl/sprite
parent7b39ce95210ceb6640b3a3399dacd1d0e826ac1f (diff)
downloadqtlocation-mapboxgl-9c26f063187b129218910dbb86eb21215a2cdf40.tar.gz
[core] Thread GLObjectStore through to Holder objects
This eliminates the reliance on ThreadContext to provide GLObjectStore, and statically enforces that GL cleanup functions happen only when GLObjectStore::performCleanup is called. With the elimination of the Map thread, this becomes important because there may be multiple GLObjectStore's per-thread, and Map will need to ensure that the correct context is active when calling GLObjectStore::performCleanup.
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp15
-rw-r--r--src/mbgl/sprite/sprite_atlas.hpp4
2 files changed, 7 insertions, 12 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index 7137e6d1fc..12d12a53cb 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -143,9 +143,9 @@ void SpriteAtlas::copy(const Holder& holder, const bool wrap) {
dirty = true;
}
-void SpriteAtlas::upload() {
+void SpriteAtlas::upload(gl::GLObjectStore& glObjectStore) {
if (dirty) {
- bind();
+ bind(false, glObjectStore);
}
}
@@ -180,13 +180,13 @@ void SpriteAtlas::updateDirty() {
}
}
-void SpriteAtlas::bind(bool linear) {
+void SpriteAtlas::bind(bool linear, gl::GLObjectStore& glObjectStore) {
if (!data) {
return; // Empty atlas
}
if (!texture) {
- texture.create();
+ texture.create(glObjectStore);
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture.getID()));
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
@@ -246,12 +246,7 @@ void SpriteAtlas::bind(bool linear) {
}
};
-SpriteAtlas::~SpriteAtlas() {
- std::lock_guard<std::recursive_mutex> lock(mtx);
- if (texture) {
- mbgl::util::ThreadContext::getGLObjectStore()->abandon(std::move(texture));
- }
-}
+SpriteAtlas::~SpriteAtlas() = default;
SpriteAtlas::Holder::Holder(const std::shared_ptr<const SpriteImage>& spriteImage_,
const Rect<dimension>& pos_)
diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp
index ff9cb44e4d..ba592c5acb 100644
--- a/src/mbgl/sprite/sprite_atlas.hpp
+++ b/src/mbgl/sprite/sprite_atlas.hpp
@@ -52,14 +52,14 @@ public:
optional<SpriteAtlasPosition> getPosition(const std::string& name, bool repeating = false);
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
- void bind(bool linear = false);
+ void bind(bool linear, gl::GLObjectStore&);
// Updates sprites in the atlas texture that may have changed in the source SpriteStore object.
void updateDirty();
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
- void upload();
+ void upload(gl::GLObjectStore&);
inline dimension getWidth() const { return width; }
inline dimension getHeight() const { return height; }