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 

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'?

  • \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 19, 2012 at 17:48
  • \$\begingroup\$ How does this book define the term "constant vertex attribute"? How are such attributes provided to the shader. \$\endgroup\$ Commented Nov 19, 2012 at 23:29
  • \$\begingroup\$ @SeanMiddleditch: Yes, that part I am clear about. \$\endgroup\$
    – Samaursa
    Commented Nov 21, 2012 at 0:05
  • \$\begingroup\$ @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() \$\endgroup\$
    – Samaursa
    Commented Nov 21, 2012 at 0:07
  • \$\begingroup\$ 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/… \$\endgroup\$ Commented Jan 17, 2016 at 20:32

1 Answer 1


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.

  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Steven Lu
    Commented Sep 14, 2013 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .