Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is glVertexAttrib (versus glVertexAttribPointer) used for?

Tags:

I understand that glVertexAttribPointer will set the values for a vertex attribute based on the pointed-to array. What is glVertexAttrib for, though? It looks like it just sets a single (possibly vector) value for the vertex attribute, so what happens when you have multiple vertices? Do all of the vertices end up seeing the same value for the attribute?

like image 552
Laurence Gonsalves Avatar asked Oct 10 '11 21:10

Laurence Gonsalves


People also ask

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 does a VAO do?

A Vertex Array Object (VAO) is an object which contains one or more Vertex Buffer Objects and is designed to store the information for a complete rendered object. In our example this is a diamond consisting of four vertices as well as a color for each vertex.

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.


1 Answers

This was mainly used with the old immediate mode (glBegin/glEnd), where you don't use vertex arrays, which is deprecated (and removed in OpenGL ES 2.0 and desktop OpenGL 3+ core).

But this function still has its use with arrays (that's why it's still there in the modern versions). You are right in your assumption that all vertices following this call have the same value for this attribute (only if you don't enable this attribute's array, of course). Or more exactly every used shader attribute that doesn't have its corresponding array enabled sources its value from a single state value and this value can be changed with glVertexAttrib.

This is usefull if you have a general shader with e.g. a color attribute and a position attribute and you have an object with a constant color. So by using glVertexAttrib you neither have to submit a color for each vertex, nor do you have to use a special shader with the color changed to a uniform.

like image 115
Christian Rau Avatar answered Oct 23 '22 23:10

Christian Rau