PDA

View Full Version : Difference between uniform and constant vertex attribute?



andyskinner
01-21-2011, 02:33 PM
What sort of differences in effect, purpose, performance, etc, are there between a uniform and a constant vertex attribute?

I read (OpenGL ES 2.0 Programming Guide, pp 102-103 and 108-110) that if you disable a vertex attribute, it uses the constant attribute, which you can set with glVertexAttrib4fv, etc. So how would it differ from setting it as a uniform?

For example, say I wanted to draw triangles with one constant color per triangle. I think I'd have to draw one triangle at a time, which I'd prefer not to do. But if I did, I could put the color in a uniform and use it from either shader. Or I could put it in a constant vertex attribute and use that from the vertex shader. (There's one difference--I couldn't get to the vertex attribute from the fragment shader.)

I know I could also duplicate the colors per vertex and draw all the triangles together, but I'm curious about the above options.

Is it quicker to set or access one or the other? Am I right that either way I'd have to draw one triangle at a time, changing the color each time?

thanks,
andy

shaely
06-08-2011, 02:58 PM
Why isn't anybody responding to this one? Should we contact the admin with this question?

Xmas
06-09-2011, 04:27 AM
Whether it's quicker to do one or the other is an implementation detail, in reality it's unlikely to make much of a difference.

However, duplicating the colours is likely to be much faster than one draw call per triangle.

valery712
10-17-2011, 04:28 AM
Attributes are passed in from the stream buffers and so change per vertex (or per instance if you use instancing). The vertex position and normal are examples of attributes.

Uniforms are variables which are applied across the whole shader, they contain the same value for each fragment/vertex during the draw call. They are typically used as an interface between your program and the shader. The worldviewprojection matrix and material properties are examples of uniforms.