diff options
Diffstat (limited to 'src/mbgl/geometry/buffer.hpp')
-rw-r--r-- | src/mbgl/geometry/buffer.hpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp index c7278a1036..143597ed0a 100644 --- a/src/mbgl/geometry/buffer.hpp +++ b/src/mbgl/geometry/buffer.hpp @@ -1,12 +1,13 @@ #ifndef MBGL_GEOMETRY_BUFFER #define MBGL_GEOMETRY_BUFFER -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/platform/log.hpp> -#include <mbgl/util/gl_object_store.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/thread_context.hpp> +#include <memory> #include <cstdlib> #include <cassert> #include <stdexcept> @@ -23,10 +24,6 @@ class Buffer : private util::noncopyable { public: ~Buffer() { cleanup(); - if (buffer != 0) { - util::ThreadContext::getGLObjectStore()->abandonBuffer(buffer); - buffer = 0; - } } // Returns the number of elements in this buffer. This is not the number of @@ -40,12 +37,12 @@ public: } // Transfers this buffer to the GPU and binds the buffer to the GL context. - void bind() { + void bind(gl::GLObjectStore& glObjectStore) { if (buffer) { - MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer)); + MBGL_CHECK_ERROR(glBindBuffer(bufferType, getID())); } else { - MBGL_CHECK_ERROR(glGenBuffers(1, &buffer)); - MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer)); + buffer.create(glObjectStore); + MBGL_CHECK_ERROR(glBindBuffer(bufferType, getID())); if (array == nullptr) { Log::Debug(Event::OpenGL, "Buffer doesn't contain elements"); pos = 0; @@ -64,21 +61,21 @@ public: } } - inline GLuint getID() const { - return buffer; + GLuint getID() const { + return buffer.getID(); } // Uploads the buffer to the GPU to be available when we need it. - inline void upload() { + inline void upload(gl::GLObjectStore& glObjectStore) { if (!buffer) { - bind(); + bind(glObjectStore); } } protected: // increase the buffer size by at least /required/ bytes. inline void *addElement() { - if (buffer != 0) { + if (buffer) { throw std::runtime_error("Can't add elements after buffer was bound to GPU"); } if (length < pos + itemSize) { @@ -118,8 +115,8 @@ private: // Number of bytes that are valid in this buffer. size_t length = 0; - // GL buffer ID - GLuint buffer = 0; + // GL buffer object handle. + gl::BufferHolder buffer; }; } // namespace mbgl |