Does OpenGL remember vertex buffer formats in its state ?

Started by
1 comment, last by Frederick 16 years, 1 month ago
Hi, I have some questions about state changes in OpenGL. Usually if I want to bring something on screen, I will 1) activate a vertex / fragment shader pair 2) fetch uniform and attribute ids 3) bind a vertex and an index buffer, eventually textures 4) apply a vertex format (by the glPointer functions) So thats no problem and works happily for me :) Then I will move on the next state: 1)load a new program 2)fetch different uniform ids 3)bind a vertex buffer 4)apply a vertex format Lets say after activating the second effect, I want to go back to the first one, the next frame. Will I have to repeat steps 1-4 ? -May I reuse the uniform and attribute ids or will I have to requery them ? -Will I have to specify the vertex format for another time or does OpenGL associate this information with the buffers and thus remember it ? My current experience with OpenGL would advise me to redo all steps, everything else did not work out for me. But things get illogical then: -why do I need to bind a buffer before invoking the glPointer methods ? The API suggests at this point, that all subsequent calls will refer to this particular buffer. But strangely I will get wrong results, if I don´t issue the glPointer functions after each and every buffer change. I am puzzled about this, I tried to find information on gamedev and in several books, so I really hope you can help me out, so that I may finally get that right in my engine ;) Thanks a lot, Frederick
Advertisement
because, when in VBO mode, the gl*Pointer() functions effectively say 'for the current buffer which is bound, offset X bytes into it and use it as source data'.

Much like how Vertex Arrays from ram say 'start reading at this address in memory'.

And yes, you have to respecify because GL is a state system and it only remembers the 'current' state.

btw, I hope you aren't performing a uniform and attribute id look up on the string name EVERY time you want to get the ids back? You should do it once at startup and then cache the results for later.
Hey thanks phantom !

I believe I understand now. The glBindBuffer will also switch OpenGL into buffer-object mode. Otherwise it will stay in vertex-array mode, which will try to retrieve the data from system memory.
Thanks that is clearing it up.

"btw, I hope you aren't performing a uniform and attribute id look up on the string name EVERY time you want to get the ids back? You should do it once at startup and then cache the results for later."

=) Oh no I am not doing that. I am caching the results and it already works - by the time of writing I confused some things.

So I am completely happy now ;-)

This topic is closed to new replies.

Advertisement