Results 1 to 4 of 4

Thread: Difference between uniform and constant vertex attribute?

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1

    Difference between uniform and constant vertex attribute?

    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

  2. #2
    Junior Member
    Join Date
    Jun 2011
    Location
    New Bloomfield, Missouri
    Posts
    1

    Re: Difference between uniform and constant vertex attribute

    Why isn't anybody responding to this one? Should we contact the admin with this question?

  3. #3
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Difference between uniform and constant vertex attribute

    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.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  4. #4

    Re: Difference between uniform and constant vertex attribute

    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.

Similar Threads

  1. Uniform buffer objects or constant registers in OpenGL ES 2.
    By doteater in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 03-21-2012, 08:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •