diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-02-14 18:45:10 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-02-18 13:27:35 +0200 |
commit | 3397398c1f5f05e22219557e0e81cfe61d693b33 (patch) | |
tree | 39f60b3cd5b5c92d2ba783c94274c8f132e5bd3b /src/mbgl/gl | |
parent | a503233d1c8df79b02e74b93e49a7e02f58f182a (diff) | |
download | qtlocation-mapboxgl-3397398c1f5f05e22219557e0e81cfe61d693b33.tar.gz |
[gl] Added mbgl::gl::BufferHolder
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/gl_object_store.cpp | 25 | ||||
-rw-r--r-- | src/mbgl/gl/gl_object_store.hpp | 18 |
2 files changed, 33 insertions, 10 deletions
diff --git a/src/mbgl/gl/gl_object_store.cpp b/src/mbgl/gl/gl_object_store.cpp index 7a6037d505..68d743cd95 100644 --- a/src/mbgl/gl/gl_object_store.cpp +++ b/src/mbgl/gl/gl_object_store.cpp @@ -35,15 +35,28 @@ void ShaderHolder::reset() { id = 0; } +void BufferHolder::create() { + if (id) return; + assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); + MBGL_CHECK_ERROR(glGenBuffers(1, &id)); +} + +void BufferHolder::reset() { + if (!id) return; + assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); + MBGL_CHECK_ERROR(glDeleteBuffers(1, &id)); + id = 0; +} + void GLObjectStore::abandonVAO(GLuint vao) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); abandonedVAOs.emplace_back(vao); } -void GLObjectStore::abandonBuffer(GLuint buffer) { +void GLObjectStore::abandon(BufferHolder&& buffer) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); - abandonedBuffers.emplace_back(buffer); + abandonedBuffers.push_back(std::move(buffer)); } void GLObjectStore::abandonTexture(GLuint texture) { @@ -60,17 +73,13 @@ void GLObjectStore::performCleanup() { abandonedVAOs.clear(); } + abandonedBuffers.clear(); + if (!abandonedTextures.empty()) { MBGL_CHECK_ERROR(glDeleteTextures(static_cast<GLsizei>(abandonedTextures.size()), abandonedTextures.data())); abandonedTextures.clear(); } - - if (!abandonedBuffers.empty()) { - MBGL_CHECK_ERROR(glDeleteBuffers(static_cast<GLsizei>(abandonedBuffers.size()), - abandonedBuffers.data())); - abandonedBuffers.clear(); - } } } // namespace gl diff --git a/src/mbgl/gl/gl_object_store.hpp b/src/mbgl/gl/gl_object_store.hpp index 6c7f3c92f2..7b9409f329 100644 --- a/src/mbgl/gl/gl_object_store.hpp +++ b/src/mbgl/gl/gl_object_store.hpp @@ -51,11 +51,23 @@ private: GLenum type = 0; }; +class BufferHolder : public GLHolder { +public: + BufferHolder() = default; + ~BufferHolder() { reset(); } + + BufferHolder(BufferHolder&& o) noexcept : GLHolder(std::move(o)) {} + BufferHolder& operator=(BufferHolder&& o) noexcept { GLHolder::operator=(std::move(o)); return *this; } + + void create(); + void reset(); +}; + class GLObjectStore : private util::noncopyable { public: // Mark OpenGL objects for deletion void abandonVAO(GLuint vao); - void abandonBuffer(GLuint buffer); + void abandon(BufferHolder&&); void abandonTexture(GLuint texture); // Actually remove the objects we marked as abandoned with the above methods. @@ -63,8 +75,10 @@ public: void performCleanup(); private: + // We split the holder objects in separate containers because each + // GLHolder-derived object can vary in size. std::vector<GLuint> abandonedVAOs; - std::vector<GLuint> abandonedBuffers; + std::vector<BufferHolder> abandonedBuffers; std::vector<GLuint> abandonedTextures; }; |