# What is the difference between Constant Vertex Attributes and Uniforms?

According to the OpenGL ES 2.0 Programming Guide:

A constant vertex attribute is the same for all vertices of a primitive, and
therefore only one value needs to be specified for all the vertices of a
primitive.


For uniforms the book states:

...any parameter to a shader that is constant across either all vertices or
fragments (but that is not known at compile time) should be passed in as
a uniform.


I've always used uniforms for data that is constant for a primitive but now it appears that attributes can also be used in the same way. Is there more to constant vertex attribute than simply 'they are the same as uniforms'?

• Are you clear on what a primitive is? A primitive is a single triangle (or line or point). If you are using GL even remotely correctly/efficiently, you're rendering many primitives with each draw call. Nov 19 '12 at 17:48
• How does this book define the term "constant vertex attribute"? How are such attributes provided to the shader. Nov 19 '12 at 23:29
• @SeanMiddleditch: Yes, that part I am clear about. Nov 21 '12 at 0:05
• @NicolBolas: The first quote is from the book directly followed by "A constant vertex attribute value is specified using any of the following functions:" where the functions listed are (I am ommiting the numbers) glVertexAttrib#f() and glVertexAttrib#fv() Nov 21 '12 at 0:07
• Apple's docs mirror this with “OpenGL ES 2.0 and 3.0 apps can either set a constant vertex attribute or use a uniform shader value to hold the value instead.” source: developer.apple.com/library/ios/documentation/3DDrawing/… Jan 17 '16 at 20:32

This is the first time I've heard of a constant vertex attribute, but from it's definition it's clear that it's a vertex attribute. Vertex attributes are defined per vertex ( whether they're the same for every vertex or not ). That means you only have access to them in the vertex shader. Uniforms on the other hand are kept in a separate space, and they are accessible to both the fragment and the vertex shader.

Also, since we're comparing vertex attributes to uniforms:

1. there's a limited number of attributes you can use per vertex ( usually small ) and they map to things like position, normal, color, etc., where as the space for uniforms is much larger.
2. There are type constraints to what you can pass as a vertex attribute. You can't use a texture as a vertex attribute.
3. If you try to pass the attribute to the fragment shader through a varying, you'll get an interpolated value for each fragment.

Try to think of them like this:

A vertex attribute is exactly what it's name implies: an attribute corresponding to vertex. Every vertex has that attribute. If that attribute is the same for every vertex, you can use it as a constant vertex attribute. The set of vertex attributes are the input for a vertex shader.

A uniform is something that is stored separate from the vertex or fragment shaders and it's accessible from both. You can store numbers, matrices, textures and even structures. They are not used as input but rather as a pool of resources you can access whenever and wherever you want. They're also treated differently by the video card.

• My nit to pick is that since this question asks about constant vertex attributes, they will not interpolate to anything other than that constant value. Also, one reason you might use a constant vertex attribute (like I am doing now) is if you have a shader which uses more attributes than some particular geometry that you'd like to render with that shader. It helps for stubbing that attribute. Sep 14 '13 at 6:10