Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Vertex Array Objects (glGenVertexArrays )

I am confused with the point in generating/creating a Vertex Array Object (VAO) with:

glGenVertexArrays(GLsizei n, GLuint *arrays);

and

glBindVertexArray(GLuint);

Because I can still create a buffer object, say for vertices, and describe that buffer object with glVertexAttribPointer and glEnableVertexAttribArraywithout ever creating a VAO.

My question is if you do not have to actually create the VAO to describe the data in a buffer object, why would such sources as the OpenGL SuperBible 5ed include a call to create a VAO when creating VBOs? Are they only used for more advanced topics I have yet to discover, am I totally confused?

Also I first encountered this question when reading wikipedias entry on VBOs and their sample code includes no calls to glGenVertexArrays() but they still describe the data with glVertexAttribPointer().Wiki VBO entry -- Example where VAOs are created for what reason?

like image 750
bluth Avatar asked May 11 '11 20:05

bluth


People also ask

What does a vertex array object do?

A Vertex Array Object (or VAO) is an object that describes how the vertex attributes are stored in a Vertex Buffer Object (or VBO). This means that the VAO is not the actual object storing the vertex data, but the descriptor of the vertex data.

What is a vertex array C++?

Detailed Description. Define a set of one or more 2D primitives. sf::VertexArray is a very simple wrapper around a dynamic array of vertices and a primitives type. It inherits sf::Drawable, but unlike other drawables it is not transformable.

What is stored in a VAO?

A Vertex Array Object (VAO) is an OpenGL Object that stores all of the state needed to supply vertex data (with one minor exception noted below). It stores the format of the vertex data as well as the Buffer Objects (see below) providing the vertex data arrays.

What are vertex attributes in OpenGL?

A vertex attribute is an input variable to a shader that is supplied with per-vertex data. In OpenGL core profile, they are specified as in variables in a vertex shader and are backed by a GL_ARRAY_BUFFER . These variable can contain, for example, positions, normals or texture coordinates.


3 Answers

Performance improvements.

In many cases, setting up your attributes on the host require a high number of API calls, and an important amount of validation inside the implementation.

Doing all those once, and using the VAO allow that work to be amortized.

See, for example, Graham Sellers' analysis for actual data.

like image 138
Bahbar Avatar answered Oct 18 '22 00:10

Bahbar


Say you are building an object that needs three VBOs (different data for shading, maybe positions, normals and some fancy effect parameter). Each time you would draw this object, you would have to bind all these VBOs and set any additional parameters. If you use a VAO, you only have to use one call (binding the vertex array), this will set up the entire environment for the specific object.

like image 29
Orka Avatar answered Oct 17 '22 23:10

Orka


The answer is not as hard as you imagined. Just think of it as a funny metaphor; VertexArrayObject is the boss and it manages several staff members which are VetexBufferObjects.

like image 20
ShannonLiu Avatar answered Oct 17 '22 22:10

ShannonLiu