# glVertexAttribPointer stride ambiguity

As a hobbyist junior game programmer, I have done multiple small OpenGL projects just to have fun with 3D. I've tested VBOs in C++ and in Java and I found something or rather understood Java tutorials differently than the C++ ones. When using the glVertexAttribPointer function in Java, it is told that the parameter stride (second from the end) is the size of an entire vertex.

void glVertexAttribPointer( GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid * pointer);


Considering the following my interpretation of the Java/OpenGL tutorial, this is what should be done (as example) in C++:

glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(0));
glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(sizeof(float)*3));
glVertexAttribPointer(texCoord0Loc, 2, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(sizeof(float)*6));

struct MyVertex
{
float x, y, z;
float nx, ny, nz;
float s0, t0;
};


Now I'm really confused because this works in my Java code. However, in my old C++ code, I was something like this:

glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex) - sizeof(aPosition), BUFFER_OFFSET(0));
glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex) - sizeof(aNormal), BUFFER_OFFSET(sizeof(float)*3));
glVertexAttribPointer(texCoord0Loc, 2, GL_FLOAT, GL_FALSE, sizeof(MyVertex) - sizeof(aTextCoord), BUFFER_OFFSET(sizeof(float)*6));


My question is: should the stride parameter be the size of an entire vertex in bytes or should it be the number of bytes separating another vertex attribute of the same type, i.e. the size between two normals, positions, texture coordinates, ect?

I have successfully used stride as the size of the row (with interleaved attribute buffers), that is, size of entire vertex data struct. I know this is not a good answer, but even the description in documentation is bit unclear:

"Specifies the byte offset between consecutive generic vertex attributes."

• Unless we're both wrong, I second that it's the size of the entire vertex structure. I tested this on AMD/ATI, Intel, nVidia, PowerVR, Broadcom, and MESA3D drivers. It's also what makes the most sense in terms of performance and hardware simplicity: the direct value to add to the pointer for the next data. And yes, the GL documentation is unclear. – Stephane Hockenhull Jan 1 '15 at 0:36