GL_CURRENT_VERTEX_ATTRIB - doc clarification

Viewed 94

The OpenGL 4 docs says:

GL_CURRENT_VERTEX_ATTRIB

params returns four values that represent the current value for the generic vertex attribute specified by index. Generic vertex attribute 0 is unique in that it has no current state, so an error will be generated if index is 0. The initial value for all other generic vertex attributes is (0,0,0,1).

What does it mean in practice that "an error will be generated if index is 0" ?

Let's assume that I have a vertex shader with the following layout:

layout (location = 0) in vec3 pos;

I want to set a generic(constant) vertex attribute. Can I use glVertexAttrib3f with an index which is equal 0 ?

glVertexAttrib3f(0, 1, 0, 0);

Later I would like to check the current vertex attribute this way:

glGetVertexAttribfv(0, GL_CURRENT_VERTEX_ATTRIB, data);

Is it correct ?

1 Answers

The text in the documentation is incorrect, relative to core OpenGL 3.2 or above. In the core profile of OpenGL, attribute 0 has state and that state can be queried.

In the compatibility profile up to 4.5 (and all GL versions before 3.0), attribute 0 does not have state. 4.5 changed the compatibility profile to give attribute 0 state. Indeed, the specification specifically calls this change out:

This is a change in behavior of the compatibilty[sic] profile for increased interoperability with core profile and OpenGL ES.

That all having been said, you really should just pretend that the generic attribute values don't exist. Since they are so rarely used, their performance characteristics are unknown. And the values of them are somewhat ephemeral; if you set a value, render something, then render something that uses an array for that attribute, the value you previously set will not be preserved, requiring you to set it again. This is quite unlike most OpenGL state.

Related