diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-18 11:19:24 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-18 15:15:24 -0800 |
commit | 9c26f063187b129218910dbb86eb21215a2cdf40 (patch) | |
tree | 189f84f90cef341a0a084fefde40f4f07da117cb /src/mbgl/util | |
parent | 7b39ce95210ceb6640b3a3399dacd1d0e826ac1f (diff) | |
download | qtlocation-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/util')
-rw-r--r-- | src/mbgl/util/raster.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/util/raster.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/util/thread_context.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/util/thread_context.hpp | 8 |
4 files changed, 6 insertions, 30 deletions
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 49c013ba08..a74b73a016 100644 --- a/src/mbgl/util/raster.cpp +++ b/src/mbgl/util/raster.cpp @@ -37,14 +37,14 @@ void Raster::load(PremultipliedImage image) { } -void Raster::bind(bool linear) { +void Raster::bind(bool linear, gl::GLObjectStore& glObjectStore) { if (!width || !height) { Log::Error(Event::OpenGL, "trying to bind texture without dimension"); return; } if (img.data && !textured) { - upload(); + upload(glObjectStore); } else if (textured) { MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID)); } @@ -57,9 +57,9 @@ void Raster::bind(bool linear) { } } -void Raster::upload() { +void Raster::upload(gl::GLObjectStore& glObjectStore) { if (img.data && !textured) { - textureID = texturePool.getTextureID(); + textureID = texturePool.getTextureID(glObjectStore); MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID)); #ifndef GL_ES_VERSION_2_0 MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp index e47fe665f6..0a275a197c 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -21,10 +21,10 @@ public: void load(PremultipliedImage); // bind current texture - void bind(bool linear = false); + void bind(bool linear, gl::GLObjectStore&); // uploads the texture if it hasn't been uploaded yet. - void upload(); + void upload(gl::GLObjectStore&); // loaded status bool isLoaded() const; diff --git a/src/mbgl/util/thread_context.cpp b/src/mbgl/util/thread_context.cpp index a60f2c9ab5..d6ddda2e8e 100644 --- a/src/mbgl/util/thread_context.cpp +++ b/src/mbgl/util/thread_context.cpp @@ -44,22 +44,6 @@ ThreadPriority ThreadContext::getPriority() { } } -gl::GLObjectStore* ThreadContext::getGLObjectStore() { - if (current.get() != nullptr) { - return current.get()->glObjectStore; - } else { - return nullptr; - } -} - -void ThreadContext::setGLObjectStore(gl::GLObjectStore* glObjectStore) { - if (current.get() != nullptr) { - current.get()->glObjectStore = glObjectStore; - } else { - throw std::runtime_error("Current thread has no current ThreadContext."); - } -} - class MainThreadContextRegistrar { public: MainThreadContextRegistrar() : context("Main", ThreadType::Main, ThreadPriority::Regular) { diff --git a/src/mbgl/util/thread_context.hpp b/src/mbgl/util/thread_context.hpp index 7558400184..dea98fe3fa 100644 --- a/src/mbgl/util/thread_context.hpp +++ b/src/mbgl/util/thread_context.hpp @@ -6,9 +6,6 @@ #include <thread> namespace mbgl { - -namespace gl { class GLObjectStore; } - namespace util { enum class ThreadPriority : bool { @@ -33,14 +30,9 @@ public: static std::string getName(); static ThreadPriority getPriority(); - static gl::GLObjectStore* getGLObjectStore(); - static void setGLObjectStore(gl::GLObjectStore* glObjectStore); - std::string name; ThreadType type; ThreadPriority priority; - - gl::GLObjectStore* glObjectStore = nullptr; }; } // namespace util |