refactor vao object to use acutal OpenGL IDs rather than object pointers

This commit is contained in:
Konstantin Käfer
2014-08-15 13:37:19 +02:00
parent a81c2efba2
commit ba67fcd830
18 changed files with 123 additions and 77 deletions

46
src/geometry/vao.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include <mbgl/geometry/vao.hpp>
namespace mbgl {
#if GL_ARB_vertex_array_object
VertexArrayObject::~VertexArrayObject() {
if (vao) {
glDeleteVertexArrays(1, &vao);
}
}
void VertexArrayObject::bindVertexArrayObject() {
if (!vao) {
glGenVertexArrays(1, &vao);
}
glBindVertexArray(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 " +
std::to_string(bound_shader) + "(" + bound_shader_name + ") to " +
std::to_string(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;
}
#endif
}

View File

@@ -26,3 +26,7 @@ void VertexBuffer::bind() {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
}
}
uint32_t VertexBuffer::getID() const {
return buffer;
}