2 #include "glfVertexArrayObject.hh"
3 #include "glfException.hh"
10 glfVertexArrayObject::
11 glfVertexArrayObject() :
12 vertexArrayObjID_(0), boundRevertably_(false), previousBinding_(0)
15 glfVertexArrayObject::~glfVertexArrayObject()
17 glDeleteVertexArrays(1, &vertexArrayObjID_);
18 GLF_THROW_ON_OPENGL_ERROR_DEBUG;
24 void glfVertexArrayObject::
28 if(GLEW_VERSION_3_0 != GLEW_OK) GLF_THROW_EXCEPTION(
"glfVertexArrayObject is only functional with OpenGL 3.0 up!");
30 if(vertexArrayObjID_==0)
31 glGenVertexArrays(1, &vertexArrayObjID_);
32 GLF_THROW_ON_OPENGL_ERROR_DEBUG;
35 void glfVertexArrayObject::
38 BIASASSERT(vertexArrayObjID_!=0);
39 glBindVertexArray(vertexArrayObjID_);
40 boundRevertably_ =
false;
41 GLF_THROW_ON_OPENGL_ERROR_DEBUG;
45 void glfVertexArrayObject::
48 BIASASSERT(vertexArrayObjID_!=0);
49 glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previousBinding_);
50 boundRevertably_ =
true;
51 glBindVertexArray(vertexArrayObjID_);
52 GLF_THROW_ON_OPENGL_ERROR_DEBUG;
56 void glfVertexArrayObject::
59 if(boundRevertably_) {
60 glBindVertexArray(previousBinding_);
61 boundRevertably_ =
false;
62 GLF_THROW_ON_OPENGL_ERROR_DEBUG;
64 BIASWARN(
"Unable to revert binding! Use BindRevertable() without subsequent call to Bind()!");
69 void glfVertexArrayObject::
70 UploadData(GLuint slotIndex,
71 GLint numValuesPerVertex,
72 float* data,
unsigned int numValues,
75 BIASASSERT(vertexArrayObjID_!=0);
76 BIASASSERT(numValuesPerVertex>=1 && numValuesPerVertex<=4);
77 map<GLuint, glfArrayBufferObject>::iterator it = internalArrayBufferObjects_.find(slotIndex);
78 if(it != internalArrayBufferObjects_.end()) {
79 it->second.UploadData(data, numValues, usageHint);
82 internalArrayBufferObjects_[slotIndex].Create();
83 internalArrayBufferObjects_[slotIndex].UploadData(data, numValues*numValuesPerVertex, usageHint);
88 internalArrayBufferObjects_[slotIndex].Bind();
89 glVertexAttribPointer(slotIndex, numValuesPerVertex, GL_FLOAT, GL_FALSE, 0, 0);
91 glEnableVertexAttribArray(slotIndex);
98 glfVertexArrayObject& glfVertexArrayObject::
99 operator=(
const glfVertexArrayObject& b)