diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-07-05 11:09:59 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-09-27 10:42:10 +0200 |
commit | ffa8a7668bcff7fd95ae5cd4b971f8330efbb3f0 (patch) | |
tree | d4f3ded50238d76c4875a837f642fa7afb8e4470 /src/mbgl/gl | |
parent | 0f5b194617e0250280e0536794625a733a7d447e (diff) | |
download | qtlocation-mapboxgl-ffa8a7668bcff7fd95ae5cd4b971f8330efbb3f0.tar.gz |
[core] store viewport and FBO binding
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/gl_config.hpp | 29 | ||||
-rw-r--r-- | src/mbgl/gl/object_store.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/gl/object_store.hpp | 17 |
3 files changed, 54 insertions, 3 deletions
diff --git a/src/mbgl/gl/gl_config.hpp b/src/mbgl/gl/gl_config.hpp index 1e0f25a0f3..225f4f8de6 100644 --- a/src/mbgl/gl/gl_config.hpp +++ b/src/mbgl/gl/gl_config.hpp @@ -9,6 +9,20 @@ namespace mbgl { namespace gl { + +template <typename T, typename = void> +struct DefaultValue { + static typename T::Type Get() { + return T::Get(); + } +}; +template <typename T> +struct DefaultValue<T, decltype((void)T::Default, void())> { + static typename T::Type Get() { + return T::Default; + } +}; + template <typename T> class Value { public: @@ -25,7 +39,7 @@ public: } void reset() { - *this = T::Default; + *this = defaultValue; } void setDirty() { @@ -40,8 +54,13 @@ public: return dirty; } + void setDefaultValue(const typename T::Type& value) { + defaultValue = value; + } + private: - typename T::Type current = T::Default; + typename T::Type defaultValue = DefaultValue<T>::Get(); + typename T::Type current = defaultValue; bool dirty = false; }; @@ -66,6 +85,8 @@ public: program.reset(); lineWidth.reset(); activeTexture.reset(); + bindFramebuffer.reset(); + viewport.reset(); #ifndef GL_ES_VERSION_2_0 pixelZoom.reset(); rasterPos.reset(); @@ -94,6 +115,8 @@ public: program.setDirty(); lineWidth.setDirty(); activeTexture.setDirty(); + bindFramebuffer.setDirty(); + viewport.setDirty(); #ifndef GL_ES_VERSION_2_0 pixelZoom.setDirty(); rasterPos.setDirty(); @@ -121,6 +144,8 @@ public: Value<Program> program; Value<LineWidth> lineWidth; Value<ActiveTexture> activeTexture; + Value<BindFramebuffer> bindFramebuffer; + Value<Viewport> viewport; #ifndef GL_ES_VERSION_2_0 Value<PixelZoom> pixelZoom; Value<RasterPos> rasterPos; diff --git a/src/mbgl/gl/object_store.cpp b/src/mbgl/gl/object_store.cpp index 4139854f61..9ddbaa7c8c 100644 --- a/src/mbgl/gl/object_store.cpp +++ b/src/mbgl/gl/object_store.cpp @@ -34,6 +34,11 @@ void VAODeleter::operator()(GLuint id) const { store->abandonedVAOs.push_back(id); } +void FBODeleter::operator()(GLuint id) const { + assert(store); + store->abandonedFBOs.push_back(id); +} + ObjectStore::~ObjectStore() { assert(pooledTextures.empty()); assert(abandonedPrograms.empty()); @@ -41,6 +46,7 @@ ObjectStore::~ObjectStore() { assert(abandonedBuffers.empty()); assert(abandonedTextures.empty()); assert(abandonedVAOs.empty()); + assert(abandonedFBOs.empty()); } void ObjectStore::reset() { @@ -74,6 +80,11 @@ void ObjectStore::performCleanup() { MBGL_CHECK_ERROR(gl::DeleteVertexArrays(int(abandonedVAOs.size()), abandonedVAOs.data())); abandonedVAOs.clear(); } + + if (!abandonedFBOs.empty()) { + MBGL_CHECK_ERROR(glDeleteFramebuffers(int(abandonedFBOs.size()), abandonedFBOs.data())); + abandonedFBOs.clear(); + } } } // namespace gl diff --git a/src/mbgl/gl/object_store.hpp b/src/mbgl/gl/object_store.hpp index 96bb8008f1..ad9725c556 100644 --- a/src/mbgl/gl/object_store.hpp +++ b/src/mbgl/gl/object_store.hpp @@ -41,11 +41,17 @@ struct VAODeleter { void operator()(GLuint) const; }; +struct FBODeleter { + ObjectStore* store; + void operator()(GLuint) const; +}; + using UniqueProgram = std_experimental::unique_resource<GLuint, ProgramDeleter>; using UniqueShader = std_experimental::unique_resource<GLuint, ShaderDeleter>; using UniqueBuffer = std_experimental::unique_resource<GLuint, BufferDeleter>; using UniqueTexture = std_experimental::unique_resource<GLuint, TextureDeleter>; using UniqueVAO = std_experimental::unique_resource<GLuint, VAODeleter>; +using UniqueFBO = std_experimental::unique_resource<GLuint, FBODeleter>; class ObjectStore : private util::noncopyable { public: @@ -82,6 +88,12 @@ public: return UniqueVAO { std::move(id), { this } }; } + UniqueFBO createFBO() { + GLuint id = 0; + MBGL_CHECK_ERROR(glGenFramebuffers(1, &id)); + return UniqueFBO { std::move(id), { this } }; + } + // Actually remove the objects we marked as abandoned with the above methods. // Only call this while the OpenGL context is exclusive to this thread. void performCleanup(); @@ -96,7 +108,8 @@ public: && abandonedShaders.empty() && abandonedBuffers.empty() && abandonedTextures.empty() - && abandonedVAOs.empty(); + && abandonedVAOs.empty() + && abandonedFBOs.empty(); } private: @@ -105,6 +118,7 @@ private: friend BufferDeleter; friend TextureDeleter; friend VAODeleter; + friend FBODeleter; std::vector<GLuint> pooledTextures; @@ -113,6 +127,7 @@ private: std::vector<GLuint> abandonedBuffers; std::vector<GLuint> abandonedTextures; std::vector<GLuint> abandonedVAOs; + std::vector<GLuint> abandonedFBOs; }; } // namespace gl |