Advertisement

How many VAO can OpenGL bind at the same time?

Started by August 26, 2017 08:28 PM
4 comments, last by TheChubu 7 years, 3 months ago

How many VAOs are allowed to be bound to OpenGL at one time. I'm asking this because I recently saw code that looked like the following


while(running){

bindVAO1   // Cube with lighting

draw


bindVAO2  // Cube

draw

}

 

When I ran the program, both rendered without problems. My previous understanding was that OpenGL was restricted to one VAO at a time (Being a state machine). I originally expected to be some flickering between the two VAOs, as glDrawArray wouldn't have the other VAO binding to it for drawing. So how many VAO does OpenGL allow? Does glDrawArray keep track of previous renderings of objects?

 

 

When you issue the second binding call, you overwrite the existing binding with the new one, so VAO 1 gets unbound, and VAO 2 gets bound.

What I mean is that doing:


bind(vao1);

bind(vao2);

And doing:


bind(vao1);

unbind(vao1);

bind(vao2);

Work practically the same. There is only one VAO binding point, and further bindings will overwrite it.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Advertisement

Thanks TheChubu,

Though I have to ask how is there no flickering occurring. Wouldn't the second drawing,


bindVAO2  // Cube

draw

overrwrite what was there before. Does glDrawArray maintain state from previous renderings?

Your draw command draws what's in the VAO to the target render buffer (probably the colour buffer in most cases).  Your flow is something like this.

clear the colour buffer
bind VAO
draw what's in the VAO to the colour buffer
bind another VAO
draw what's in the other VAO to the colour buffer
flip the colour buffer to the front so it's drawn on the screen

I don't really see any reason for flickering, since it's a complete serial operation.  Sure, if the second VAO holds vertexes that will overwrite or occlude what's in the first VAO, you might not see what you expect, but maybe that's just your expectations that are wrong.

Stephen M. Webb
Professional Free Software Developer

Think of it as Photoshop/Gimp layers if it helps.

You draw to a render target, a texture. Each draw you add a new layer to the render target with something new to paste over the stuff it is already there (it gets more complicated with depth/stencil tests but bear with me).

Once you draw everything, you call swap buffers and the target you were drawing to gets shown in the screen, while you get back the old target to draw on top of.

Thats why you call glClear in between swap buffer calls, so you clean the existing target for further drawing. Otherwise what you draw before gets stuck there in the target and each object you draw would appear smeared over the screen when you move the camera.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

This topic is closed to new replies.

Advertisement