PDA

View Full Version : VBO remembers theirs offsets ?



addmx
07-16-2009, 06:40 AM
Hi

Quick question:

glBindBuffer(GL_ARRAY_BUFFER, BuffID);

glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (4, GL_FLOAT, 64, 0);
glEnableVertexAttribArray(12);
glVertexAttribPointer(12, 4, GL_UNSIGNED_BYTE, FALSE, 64, 16);

glDrawArrays(...);
glDisableClientState (GL_VERTEX_ARRAY);
glDisableVertexAttribArray(12);

// now other draw commands
// ... and again I want to use my buffer with identical layout
// do I need to repeat glVertexPointer and
// glVertexAttribPointer - or the code below is enough - and // information about what offset maps to what output is
// stored in VBO ?

glBindBuffer(GL_ARRAY_BUFFER, BuffID);

glEnableClientState (GL_VERTEX_ARRAY);
glEnableVertexAttribArray(12);

glDrawArrays(...);

DmitryM
07-16-2009, 07:13 AM
AFAIK, the VertexArray objects was designed to store information about binded attributes. I imagine the scheme to be the following:

OpenGL context has bind point for each vertex attribute. When you bind VBO - nothing happens. When you call gl*Pointer - the bind slot for a particular attribute is connected to some data in the current VBO according to semantics given.

So, changing the VBO doesn't change the vertex attrib bindings. Changing VAO, however, does.

Michael Gold
07-16-2009, 10:42 AM
The context remembers both the buffer and the offset. After calling VertexAttribPointer, both the offset and the buffer are latched in the context. You can now unbind the buffer.

Next time you enable the arrays, the pointer and buffer are still valid - assuming you haven't called VertexAttribPointer in the interim.