Jump to content
  • Advertisement
Sign in to follow this  
Frederick

OpenGL Does OpenGL remember vertex buffer formats in its state ?

This topic is 3775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ;-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!