Kevin Krumwiede Kevin Krumwiede - 1 year ago 62
Android Question

What is vertex stride?

The last block of code in the official Drawing Shapes tutorial page uses a variable named

without any explanation of what it is or where it comes from. There is also no documentation for the method it's passed to.

I looked in the sample code and found these declarations:

private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;
private final int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex

I don't know why these aren't
, but that's kind of beside the point. From this I gather that
is the length of one vertex record in the byte buffer, and it's 4 bytes per coordinate (not per vertex as the comment says) because they're actually 32-bit floating point values. Is that correct?

<rhetorical>Is it just me, or did Google put approximately zero effort into this tutorial?</rhetorical>

Answer Source

"stride" in general refers to the spacing of the elements in the array, which might not always be the same as the intrinsic size of the element being stored. In the case of vertexStride, it is the size in bytes used to store the vertex in the array. Here is the documentation for glVertexAttribPointer from OpenGL. As you noted, this is the same as the vertex size itself (number of coords * 4). It is 4 because they are stored as float's as given by type parameter being GL_FLOAT in the sample code you linked to.