Jump to content
  • Advertisement
Sign in to follow this  
B_old

OpenGL Proper use of VAO

This topic is 1815 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

I have some experience with D3D11 but am currently looking into OpenGL.

 

I noticed that in OpenGL both the vertex buffers and the vertex layout are encapsulated together in a vertex array object.

Suppose I have a properly set up VAO and now decide that I want to use different vertex buffers that contain data in the same layout as before. At first I though I have to create a new VAO for this.

 

But then I stumbled over this quote in a text about vertex specifiation:

 

 

Better yet, if you want to use the same format but move the buffer around, it only takes one function call; namely glBindVertexBuffer? with a buffer binding of 0. [...] Note again that all of the above state is still VAO state. It is all encapsulated in vertex array objects.
regarding the usage of glVertexAttribBinding and glVertexAttribFormat. So I assume there muss be a better way.
 
My new theory on the proper usage of VAO is that I set them up with glVertexAttribFormat according to my vertex layout once and when I want switch buffers I bind the VAO but only change the glVertexAttribBinding.
Is this correct?

Share this post


Link to post
Share on other sites
Advertisement

Phrases like "move the buffer around" and "switch buffers" and "proper usage" are vaguer than they seem, considering that vertex array objects are an entirely optional superstructure to organize buffers and other objects: you can put into a VAO the vertex drawing state that used to be global, with a few new VAO-aware functions.

 

The quoted wiki passage means only that you can bind any VBO to the same "binding point" of a VAO, and it will be interpreted according to the VAO's layout, specified once independently of what buffers are bound. You need to call glVertexAttribBinding when you bind different buffers only if they are laid out differently after all.

 

If you want to define a vertex and vertex buffer layout once and use it with different buffer content, you it's very likely that since they have the same layout your data sets can live together in the same VBOs in, letting you use indexes to draw one or the other without binding or memory tricks.

glVertexAttribBinding

Share this post


Link to post
Share on other sites

Phrases like "move the buffer around" and "switch buffers" and "proper usage" are vaguer than they seem, considering that vertex array objects are an entirely optional superstructure to organize buffers and other objects: you can put into a VAO the vertex drawing state that used to be global, with a few new VAO-aware functions.

Do you mean by optional, that I don't have to use VAOs at all?

 

If you want to define a vertex and vertex buffer layout once and use it with different buffer content, you it's very likely that since they have the same layout your data sets can live together in the same VBOs in, letting you use indexes to draw one or the other without binding or memory tricks.

I was thinking about a scenario where I calculate the lighting for a model and the shader expects normals, tangents etc.. Later I calculate the the shadow where only positions are expected. If the normals and tangents reside in a separate buffer there is no need to bind it in that case.

 

I was thinking along the lines of D3D's InputLayout.

Edited by B_old

Share this post


Link to post
Share on other sites

 

If you want to define a vertex and vertex buffer layout once and use it with different buffer content, you it's very likely that since they have the same layout your data sets can live together in the same VBOs in, letting you use indexes to draw one or the other without binding or memory tricks.

I was thinking about a scenario where I calculate the lighting for a model and the shader expects normals, tangents etc.. Later I calculate the the shadow where only positions are expected. If the normals and tangents reside in a separate buffer there is no need to bind it in that case.

You might set up two vertex array objects, one for the lighting pass state and one for the shadow pass state, and two vertex buffer objects, one containing positions and one containing "normals, tangents, etc."; then you could bind the positions buffer in both vertex array objects and the other buffer in the lighting pass VAO only.

When you bind the appropriate VAO, OpenGL automatically recalls what vertex buffers are in use, and their layout.

Share this post


Link to post
Share on other sites

You might set up two vertex array objects, one for the lighting pass state and one for the shadow pass state, and two vertex buffer objects, one containing positions and one containing "normals, tangents, etc."; then you could bind the positions buffer in both vertex array objects and the other buffer in the lighting pass VAO only.

When you bind the appropriate VAO, OpenGL automatically recalls what vertex buffers are in use, and their layout.

That sounds complicated.

I was hoping there is a method more akin to D3D. It is easier to keep track off many vertex buffers and a few input layouts than many vertex buffers and two times (or more) that many vertex array objects.

Share this post


Link to post
Share on other sites

 


vertex array objects are an entirely optional superstructure to organize buffers

 

This is not true for core OpenGL. See for example http://www.opengl.org/wiki/GLAPI/glVertexAttribPointer which states "GL_INVALID_OPERATION? is generated if no vertex array object is bound."

 

 

At the same time, it remains semi-optional; a common tactic is to create and bind a single VAO after context creation, following which you can continue to code as before and pretend VAOs never existed.

Share this post


Link to post
Share on other sites

 

 


vertex array objects are an entirely optional superstructure to organize buffers

 

This is not true for core OpenGL. See for example http://www.opengl.org/wiki/GLAPI/glVertexAttribPointer which states "GL_INVALID_OPERATION? is generated if no vertex array object is bound."

 

 

At the same time, it remains semi-optional; a common tactic is to create and bind a single VAO after context creation, following which you can continue to code as before and pretend VAOs never existed.

 

I wouldn't really recommend it, but it is possible, yes. Even so you do need at least one VAO, so "entirely optional" isn't entirely true.

Share this post


Link to post
Share on other sites

I wouldn't really recommend it, but it is possible, yes. Even so you do need at least one VAO, so "entirely optional" isn't entirely true.

Would you say, that the proper OpenGL style is to have two VAO per model for instance? One for the lighting/g-buffer passe(s) and another for shadow passes.

 

In that case I don't understand the benefit of the 4.3 glBindVertexBuffer(), because it now seems it should still happen in a initialization phase.

Share this post


Link to post
Share on other sites

 

 

 


vertex array objects are an entirely optional superstructure to organize buffers

 

This is not true for core OpenGL. See for example http://www.opengl.org/wiki/GLAPI/glVertexAttribPointer which states "GL_INVALID_OPERATION? is generated if no vertex array object is bound."

 

 

At the same time, it remains semi-optional; a common tactic is to create and bind a single VAO after context creation, following which you can continue to code as before and pretend VAOs never existed.

 

I wouldn't really recommend it, but it is possible, yes. Even so you do need at least one VAO, so "entirely optional" isn't entirely true.

 

 

Well id do it, Valve do it, so it seems (at least on the surface) to be viable.  Despite that, I do find VAOs useful as a way to avoid having to track lots of state, but I'm still looking forward to GL_ARB_vertex_attrib_binding being more widely available.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!