summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-07-08 15:41:54 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-26 11:14:40 +0200
commitafb93d4d3adc9bfb4b3f9b78584e1c2c66c11919 (patch)
tree8a4c9924a6ff847abab1fdd8dbd6c74874e959ae /src/mbgl/geometry
parentadcb449ff348a3ae5f74c38824ae43718122dafa (diff)
downloadqtlocation-mapboxgl-afb93d4d3adc9bfb4b3f9b78584e1c2c66c11919.tar.gz
[core] track VAOs and Buffers
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/buffer.hpp29
-rw-r--r--src/mbgl/geometry/vao.cpp12
-rw-r--r--src/mbgl/geometry/vao.hpp28
3 files changed, 43 insertions, 26 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index d372a040bf..f1b493eb41 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -2,6 +2,7 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
+#include <mbgl/gl/gl_config.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -15,11 +16,14 @@ namespace mbgl {
template <
GLsizei item_size,
- GLenum bufferType = GL_ARRAY_BUFFER,
+ GLenum target = GL_ARRAY_BUFFER,
GLsizei defaultLength = 8192,
bool retainAfterUpload = false
>
class Buffer : private util::noncopyable {
+ static_assert(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER,
+ "target must be one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER");
+
public:
~Buffer() {
cleanup();
@@ -36,17 +40,24 @@ public:
}
// Transfers this buffer to the GPU and binds the buffer to the GL context.
- void bind(gl::ObjectStore& store) {
- if (buffer) {
- MBGL_CHECK_ERROR(glBindBuffer(bufferType, *buffer));
- } else {
+ void bind(gl::ObjectStore& store, gl::Config& config) {
+ const bool initialized { buffer };
+ if (!initialized) {
buffer = store.createBuffer();
- MBGL_CHECK_ERROR(glBindBuffer(bufferType, *buffer));
+ }
+
+ if (target == GL_ARRAY_BUFFER) {
+ config.vertexBuffer = *buffer;
+ } else {
+ config.elementBuffer = *buffer;
+ }
+
+ if (!initialized) {
if (array == nullptr) {
Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
pos = 0;
}
- MBGL_CHECK_ERROR(glBufferData(bufferType, pos, array, GL_STATIC_DRAW));
+ MBGL_CHECK_ERROR(glBufferData(target, pos, array, GL_STATIC_DRAW));
if (!retainAfterUpload) {
cleanup();
}
@@ -65,9 +76,9 @@ public:
}
// Uploads the buffer to the GPU to be available when we need it.
- void upload(gl::ObjectStore& store) {
+ void upload(gl::ObjectStore& store, gl::Config& config) {
if (!buffer) {
- bind(store);
+ bind(store, config);
}
}
diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp
index 30f5484896..e475f43273 100644
--- a/src/mbgl/geometry/vao.cpp
+++ b/src/mbgl/geometry/vao.cpp
@@ -5,17 +5,12 @@
namespace mbgl {
-void VertexArrayObject::Unbind() {
- if (!gl::BindVertexArray) return;
- MBGL_CHECK_ERROR(gl::BindVertexArray(0));
-}
-
VertexArrayObject::VertexArrayObject() {
}
VertexArrayObject::~VertexArrayObject() = default;
-void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store) {
+void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store, gl::Config& config) {
if (!gl::GenVertexArrays || !gl::BindVertexArray) {
static bool reported = false;
if (!reported) {
@@ -27,8 +22,11 @@ void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store) {
if (!vao) {
vao = store.createVAO();
+ config.vertexBuffer.setDirty();
+ config.elementBuffer.setDirty();
}
- MBGL_CHECK_ERROR(gl::BindVertexArray(*vao));
+
+ config.vertexArrayObject = *vao;
}
void VertexArrayObject::verifyBinding(Shader& shader, GLuint vertexBuffer, GLuint elementsBuffer,
diff --git a/src/mbgl/geometry/vao.hpp b/src/mbgl/geometry/vao.hpp
index aa0a72ec59..5a2486fae1 100644
--- a/src/mbgl/geometry/vao.hpp
+++ b/src/mbgl/geometry/vao.hpp
@@ -3,6 +3,7 @@
#include <mbgl/shader/shader.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
+#include <mbgl/gl/gl_config.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -12,16 +13,18 @@ namespace mbgl {
class VertexArrayObject : public util::noncopyable {
public:
- static void Unbind();
-
VertexArrayObject();
~VertexArrayObject();
template <typename VertexBuffer>
- void bind(Shader& shader, VertexBuffer& vertexBuffer, GLbyte* offset, gl::ObjectStore& store) {
- bindVertexArrayObject(store);
+ void bind(Shader& shader,
+ VertexBuffer& vertexBuffer,
+ GLbyte* offset,
+ gl::ObjectStore& store,
+ gl::Config& config) {
+ bindVertexArrayObject(store, config);
if (bound_shader == 0) {
- vertexBuffer.bind(store);
+ vertexBuffer.bind(store, config);
shader.bind(offset);
if (vao) {
storeBinding(shader, vertexBuffer.getID(), 0, offset);
@@ -32,11 +35,16 @@ public:
}
template <typename VertexBuffer, typename ElementsBuffer>
- void bind(Shader& shader, VertexBuffer& vertexBuffer, ElementsBuffer& elementsBuffer, GLbyte* offset, gl::ObjectStore& store) {
- bindVertexArrayObject(store);
+ void bind(Shader& shader,
+ VertexBuffer& vertexBuffer,
+ ElementsBuffer& elementsBuffer,
+ GLbyte* offset,
+ gl::ObjectStore& store,
+ gl::Config& config) {
+ bindVertexArrayObject(store, config);
if (bound_shader == 0) {
- vertexBuffer.bind(store);
- elementsBuffer.bind(store);
+ vertexBuffer.bind(store, config);
+ elementsBuffer.bind(store, config);
shader.bind(offset);
if (vao) {
storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
@@ -51,7 +59,7 @@ public:
}
private:
- void bindVertexArrayObject(gl::ObjectStore&);
+ void bindVertexArrayObject(gl::ObjectStore&, gl::Config&);
void storeBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset);
void verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset);