Is gl_Vertex and the attribute variable at binding location 0 equivalent?

Is gl_Vertex and the attribute variable at binding location 0 equivalent?

Hi, All,

The OpenGL 2.1 spec has the following statements:

  1. Vertices are specified by giving their coordinates in two, three,
    or four dimensions. This is done using one of several versions of
    the Vertex command
  2. Setting generic vertex attribute zero specifies a vertex
  3. There is no aliasing among generic attributes and conventional attributes.
    In other words, an application can set all MAX VERTEX ATTRIBS generic
    attributes and all conventional attributes without fear of one particular
    attribute overwriting the value of another attribute
  4. Vertex shaders can access built-in vertex attribute variables corresponding
    to the per-vertex state set by commands such as Vertex, Normal, Color.
  5. Vertex shaders can also define named attribute variables, which are bound to
    the generic vertex attributes that are set by VertexAttrib*

So, my understanding is that gl_Vertex and the attribute variable at binding
location 0 are independent (not equivalent).
glVertex specifies a vertex whose vertex coordinate is received in gl_Vertex
glVertexAttrib (0, …) specifies a vertex whose vertex coordinate is received
the attribute variable at binding location 0
glVertex → gl_Vertex
glVertexAttrib (0, …) → attribute attrVar (@ 0)

If we use
glBegin
glVertex
glVertexAttrib (0, …)
glVertex
glVertexAttrib (0, …)
glEnd

Then the vertex shader will be invoked 4 times. But invocation #0 and #2 have
gl_Vertex filled with valid values while #1 and #3 have attribute attrVar (@ 0)
filled with valid values.

If an OpenGL application uses a vertex program using only gl_Vertex but specifies
vertices using glVertexAttrib (0, …) then this should be an application error
(and vice versa).

Am I right? Thanks…

Yes.

Though, in general, you really ought to either use all generic attributes or use no generic attributes. Mixing and matching can cause problems sometimes, particularly if you’re deciding what the numbers mean.

On number 3) in your list, unfortunately that misses the reality slightly. :rolleyes:
The ARB program specs for example just left this behavior undefined.
Read chapter 6.1.2 in this document
http://developer.nvidia.com/object/nv_ogl2_support.html
For least trouble just let the compiler assign attribute slots, query and use those.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.