View Full Version : Core 4.2 and use of VertexAttrib{1234}{sfd}(...)

12-30-2011, 06:11 AM
Reading through the opengl42-quick-reference-card.pdf in the "Vertex Specification" section, I became curious what purpose the glVertexAttrib* serve. It seems that with glVertexAttribPointer in the "Vertex Arrays" section the entire "Vertex Specification" section is pointless in terms of core context.

In the process of reading more, Post268973 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=268973#Post2689 73) showed an example of these glVertexAttrib* functions replacing glVertex, glColor, etc in a more general way. But to be useful the post seemed to demonstrate that glVertexAttrib* require immediate mode (glBegin()/glEnd()) which are no longer in the core.

So the question is what are glVertexAttrib* used for in core without glBegin/glEnd? Note that glVertexAttrib* in the section "Vertex Specification" is different than the glVertexAttribPointer in the "Vertex Arrays" section. I understand the value of glVertexAttribPointer but not the glVertexAttrib{1234}{sfd}(...) function for instance.

12-30-2011, 06:39 AM
The glVertexAttrib methods can be used without glBegin/glEnd. They allow you to set a uniform value for a vertex array input, rather than using an array. This can come in handy if you want to define a vertex shader input that may be varying or constant.

Dan Bartlett
12-30-2011, 07:38 AM
glVertexAttrib sets the current value to be used when an attribute is disabled.

As noted by other people, the behaviour for attribute 0 in the core profile is different to in a compatibility profile. In a compatibility profile glVertexAttrib(0, ...) issues a vertex similar to glVertexNN, so can only be used inside glBegin/glEnd (similar to how you can call glColor/glTexCoord etc outside glBegin/glEnd but not glVertex), but in the core profile it behaves the same way as all the other attributes (it sets a current value), so is usable outside glBegin/glEnd (which don't exist).

Also, I've just noticed that since OpenGL 4.2, the current value for attributes is guaranteed not to be modified when drawing, but prior to 4.2, drawing left the current values for enabled attributes undefined.

12-30-2011, 10:59 AM
Thanks. That helps clarify the use of the glVertexAtrib* functions. I hadn't considered what happens if an attribute is disabled or having a need for a constant attribute sometimes.