PDA

View Full Version : What's the difference between Vertex Attribute stride and relative offset?



ffhighwind
04-23-2013, 06:44 PM
glVertexAttribFormat use the term "relative offset" but all other VertexAttrib functions I've seen use the term "stride."
GL_VERTEX_ATTRIB_ARRAY_STRIDE
GL_VERTEX_ATTRIB_RELATIVE_OFFSET
Both constants are different values, so I might assume they are different things? I've tried searching for information about relative offset but only found a spec that included this function, and that wasn't very clear.

Also, the glGet reference page is missing quite a few constants that I've seen on some other pages. Is there somewhere to post for fixes?

Alfonse Reinheart
04-23-2013, 08:23 PM
The difference is that they're not the same at all. It's like asking the difference between the size of an object and it's alignment.

You're getting confused because you're mixing up two different things. You're mixing data from traditional vertex array specification methods (http://www.opengl.org/wiki/Vertex_Specification#Vertex_Array_Object) with data from the newer separate format/buffer specification method (http://www.opengl.org/wiki/Vertex_Specification#Separate_attribute_format).

GL_VERTEX_ATTRIB_ARRAY_STRIDE is the byte difference from one element in the array to the next (http://www.opengl.org/wiki/Vertex_Specification#Vertex_buffer_offset_and_stri de). It's what allows interleaving.

The GL_VERTEX_ATTRIB_RELATIVE_OFFSET is only relevant when using separate format/buffer stuff. If you use `glVertexAttribPointer`, it's just 0. The relative offset is the byte offset from the base offset of the vertex buffer (as defined by `glBindVertexBuffer`) to the first element in the attribute array.

The stride says how many bytes lie between two array elements. The offset says where the first element starts. They have nothing in common.

ffhighwind
04-23-2013, 09:05 PM
Thanks Alfonse. I have seen this before but I obviously need to do a thorough read.

The reason I'm still confused is probably because the documentation is off.

glVertexAttribFormat
normalized
The distance between elements within the buffer.
relativeoffset
The distance between elements within the buffer.
Note the copy paste typos. Although, it corrects itself later in the page.

relativeoffset is the offset, measured in basic machine units of the first element relative to the start of the vertex buffer binding this attribute fetches from.

EDIT:
Found the actual line that describes it. Thanks again Alfonse.

relativeoffset​ is new. Vertex formats are associated with vertex buffer bindings from glBindVertexBuffer​. So every vertex format that uses the same vertex buffer binding will use the same buffer object and the same offset. In order to allow interleaving (where different attributes need to offset themselves from the base offset), relativeoffset​ is used. It is effectively added to the buffer binding's offset to get the offset for this attribute.

Alfonse Reinheart
04-23-2013, 10:47 PM
That's why you should use the Wiki documentation (http://www.opengl.org/wiki/GLAPI/glVertexAttribFormat). It's never wrong. And no, I didn't just fix that a few seconds ago; it was always like that. Regardless of what the edit history of that page says. (http://www.opengl.org/wiki_132/index.php?title=GLAPI/glVertexAttribFormat&oldid=7405)