Sign in to follow this  
frogtag

glBindVertexArray structure/protocol

Recommended Posts

frogtag    121

Sorry that this is a basic question, but i've recently come back to programming opengl only to find 2.0 is now obsolete.

 

I understand that when setting up a VAO, you use this command

 

glBindVertexArray(array[0])

 

and the subsequent code is bound to it. but the tutorial i'm following just sets up the next VAO as follows

 

glBindVertexArray(array[1])

 

is this how VAOs work? you just use a glBindVertexArray command and what ever follows is bound to it? doesn't this mean the last used VBA is always open? can it (should it) be closed after setting it?

 

Cheers for any reply

Share this post


Link to post
Share on other sites
Jan2go    2057

Yes, the last VAO that you bound using glBindVertexArray will be active (I guess that's what you mean by "open") until you bind another one. You can also call glBindVertexArray(0) to unbind the current VAO.

It's not required to unbind a VAO after use but you can do it if you want to for some reason (e.g. debugging purposes).

Share this post


Link to post
Share on other sites
frogtag    121

That answered my question perfectly, Was just looking further into learning the tutorials rather than just cut+paste. Thank you for your reply biggrin.png

Share this post


Link to post
Share on other sites
Matias Goldberg    9580

It shall be noted that you can modify a bound VAO. You can unbind it. You can bind it again and the previous settings will be restored, but you can still modify it.

 

The idea is that you should create a VAO, bind it, modify it once; and never modify it again (i.e. you "bake" the parameters into each VAO). However there's contradicting real-world performance results, and therefore some recommend to just bind one global VAO, leave it bound, and modify it on the go.

Good reads:

Cheers

Share this post


Link to post
Share on other sites
Misantes    2092

Is there any sort of consensus on that Matias? Genuine question and curiosity, I'm not challenging the claim (and you mention there are conflicting tests). I've gone back and forth. Multiple VAO's is seemingly easier, except I run into cases that need to change/adapt the VAO, then things begin getting messier and I find myself wishing I had stayed with a single VAO. I get the impression it's a bit of a wash, and I should probably run with what's most convenient (I'm likely not going to benchmark for various graphics cards for my own projects). I was just curious if there were pros/cons other than performance I should be aware of.

Edited by Misantes

Share this post


Link to post
Share on other sites
Matias Goldberg    9580

No... sort of, there is no consensus... but the tendency is that GL driver developers tend to suggest multiple VAOs, while game developers (with real world scenario experience) tend to suggest one global VAO.

 

 

Multiple VAO's is seemingly easier, except I run into cases that need to change/adapt the VAO, then things begin getting messier and I find myself wishing I had stayed with a single VAO.

Mmmm... that's a red flag. You shouldn't be needting to change/adapt a VAO.

Shader explicit locations was added to solve the problem that a mesh with position (0), normals (1) and uvs (2) couldn't be used with a shader that only used position (0) and uv (1) unless you modify the vao to set the uv to 1 and disable the normals. With shader explicit locations, there's no longer need to change the VAO.

 

It also shall be noted on modern GL, the AZDO (Approaching Zero Driver Overhead) techniques recommend to preallocate a very large buffer object and batch all your meshe data there (combining the vertex and index data into the same buffer object; then bind the same buffer object into both the ARRAYS and ELEMENTS_ARRAYS bind point, this is legal). Therefore you would only need one VAO per vertex format since the vbo and ebo always stay the same.

And then use glDrawElementsBaseVertex to offset both the starting vertex in the vbo and the starting index in the ebo.

 

In the context of AZDO techniques; the driver overhead is so low (and switching/modifying VAOs is so infrequent) that it is probably more convenient to choose to use multiple Vaos (due to their convenience and simplicity) rather than use a global VAO; since performance stops being the determining factor.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this