summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/vao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/geometry/vao.cpp')
-rw-r--r--src/mbgl/geometry/vao.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp
new file mode 100644
index 0000000000..66822ba5ce
--- /dev/null
+++ b/src/mbgl/geometry/vao.cpp
@@ -0,0 +1,55 @@
+#include <mbgl/geometry/vao.hpp>
+#include <mbgl/platform/log.hpp>
+#include <mbgl/util/string.hpp>
+
+namespace mbgl {
+
+VertexArrayObject::~VertexArrayObject() {
+ if (!gl::DeleteVertexArrays) return;
+
+ if (vao) {
+ gl::DeleteVertexArrays(1, &vao);
+ }
+}
+
+void VertexArrayObject::bindVertexArrayObject() {
+ if (!gl::GenVertexArrays || !gl::BindVertexArray) {
+ static bool reported = false;
+ if (!reported) {
+ Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
+ reported = true;
+ }
+ return;
+ }
+
+ if (!vao) {
+ gl::GenVertexArrays(1, &vao);
+ }
+ gl::BindVertexArray(vao);
+}
+
+void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer,
+ char *offset) {
+ if (bound_shader != shader.getID()) {
+ throw std::runtime_error(std::string("trying to rebind VAO to another shader from " +
+ util::toString(bound_shader) + "(" + bound_shader_name + ") to " +
+ util::toString(shader.getID()) + "(" + shader.name + ")" ));
+ } else if (bound_offset != offset) {
+ throw std::runtime_error("trying to bind VAO to another offset");
+ } else if (bound_vertex_buffer != vertexBuffer) {
+ throw std::runtime_error("trying to bind VAO to another vertex buffer");
+ } else if (bound_elements_buffer != elementsBuffer) {
+ throw std::runtime_error("trying to bind VAO to another elements buffer");
+ }
+}
+
+void VertexArrayObject::storeBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer,
+ char *offset) {
+ bound_shader = shader.getID();
+ bound_shader_name = shader.name;
+ bound_offset = offset;
+ bound_vertex_buffer = vertexBuffer;
+ bound_elements_buffer = elementsBuffer;
+}
+
+}