Hi
I am using VAO in opengl 4 and I have to bind the indices buffer separately it seems it can not be stored in the VAO?
(Thus a GL_ELEMENT_ARRAY_BUFFER state is not stored in a VAO)
I assume this is so because a index ELEMENT does not have a corresponding attribute?
Am I right? or do I do something wrong ?
Vertex Array Object and Indices
Ok here is some source..
I have a class for buffer objects like this..
Then I have a VAO class..I only show the important part (Bo:s already added before calling CreateVAO() )
Then I have a function for drawing..
If I remove the glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo.object); and do not treat the binding of the IBO separately..thus if I move it inside the glBindVertexArray(vao) glBindVertexArray(0) inside Vao::CreateVAO.. then it crashes on glDrawElements because of the NULL.
And Bind() UnBind just glBindVertexArray(vao); and with 0.
Also found more people saying the same:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showthreaded&Number=251861
Are you sure ?
I have a class for buffer objects like this..
class Bo
{
public:
Bo();
~Bo();
void Dump();
string name;
GLuint object;
GLenum target;
GLuint vertices;
GLint elements_per_vertex;
GLint size_of_element;
GLenum element_type;
bool keep_data;
GLvoid *data;
GLenum usage;
GLint attribute;
GLuint size;
};
Then I have a VAO class..I only show the important part (Bo:s already added before calling CreateVAO() )
// Creates the vertex array object, Buffer Objects must be added first though
void Vao::CreateVAO()
{
map<string,Bo *>::iterator it;
it=bos.begin();
Bo *bo;
GLenum error;
printf("> Creating Vertex Array Object\n");
if(it!=bos.end())
{
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
for(;it!=bos.end();it++)
{
bo=it->second;
//bo->Dump();
glGenBuffers(1,&bo->object);
glBindBuffer(bo->target,bo->object);
printf(" Adding Buffer Object %s to VAO\n",bo->name.c_str());
glBufferData(bo->target,bo->size,bo->data,bo->usage);
if((error = glGetError())!=GL_NO_ERROR)
LogGLError(error,"%s","glBufferData");
if(bo->attribute>=0)
{
glVertexAttribPointer(bo->attribute,bo->elements_per_vertex,bo->element_type,GL_FALSE,0,NULL);
if((error = glGetError())!=GL_NO_ERROR)
LogGLError(error,"glVertexAttribPointer %s",bo->name.c_str());
glEnableVertexAttribArray(bo->attribute);
}
glBindBuffer(bo->target,0);
if(!bo->keep_data)
{
free(bo->data);
bo->data=NULL;
}
}
glBindVertexArray(0);
// Indices buffers are treated separately..they do not store with VAO states ?
if(!ibo.name.empty())
{
glGenBuffers(1,&ibo.object);
glBindBuffer(ibo.target,ibo.object);
glBufferData(ibo.target,ibo.size,ibo.data,ibo.usage);
glBindBuffer(ibo.target,0);
}
}
else
LogError(-1,"%s","No buffer objects added no VAO created.");
}
Then I have a function for drawing..
void Vao::DrawVAO()
{
Bind();
if(!ibo.name.empty())
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo.object);
glDrawElements(GL_TRIANGLE_STRIP,ibo.vertices,ibo.element_type,NULL);
}
else
glDrawArrays(GL_TRIANGLE_STRIP,0,bos["vertices"]->vertices);
UnBind();
}
If I remove the glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo.object); and do not treat the binding of the IBO separately..thus if I move it inside the glBindVertexArray(vao) glBindVertexArray(0) inside Vao::CreateVAO.. then it crashes on glDrawElements because of the NULL.
And Bind() UnBind just glBindVertexArray(vao); and with 0.
Also found more people saying the same:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showthreaded&Number=251861
Are you sure ?
Ok it seems I found the problem..
You should not do:
glBindBuffer(ibo.target,0);
Before glBindVertexArray(0);
It is fine for the other buffers because the states are saved when glVertexAttribPointer() is called..
I am not 100% on that last thing though.
You should not do:
glBindBuffer(ibo.target,0);
Before glBindVertexArray(0);
It is fine for the other buffers because the states are saved when glVertexAttribPointer() is called..
I am not 100% on that last thing though.
Of course, if you are setting up the VAO and suddenly call glBindBuffer(.....,0); then you are messing it up.
This is a good example:
http://www.opengl.org/wiki/Tutorial1:_Rendering_shapes_with_glDrawRangeElements,_VAO,_VBO,_shaders_%28C%2B%2B_/_freeGLUT%29
This is a good example:
http://www.opengl.org/wiki/Tutorial1:_Rendering_shapes_with_glDrawRangeElements,_VAO,_VBO,_shaders_%28C%2B%2B_/_freeGLUT%29
Of course, if you are setting up the VAO and suddenly call glBindBuffer(.....,0); then you are messing it up.
This is a good example:
http://www.opengl.or...B_/_freeGLUT%29
Apparently not for the GL_ARRAY_BUFFER if it is done after glVertexAttribPointer()..
But since the GL_ELEMENT_ARRAY_BUFFER has no attribute this does not work for it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement