Sign in to follow this  

What stride parameter in Vertex Arrays exactly does??

This topic is 4202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Stride is the size of the structure that you are storing in the array. Since the array is prolly a contiguous block of memory, you have to tell it how big each chunk is.

That's how it is in DirectX, no doubt similar in OGL.

Hope that helps,

Dave

Share this post


Link to post
Share on other sites
It's not exactly how Dave suggested. Yes, it is the size of one vertex (texcoord, normals, tangent, binormal, position added together). However, since these are normally stored sequentially, OpenGL allows you to pass in a size of 0 in that case, which is read as 'continuous'. If you had for example texture coordinates in your data structure, but don't require them in this draw call, you would have to use the stride parameter do jump to the correct start of the next vertex.

Share this post


Link to post
Share on other sites
No no no, this is how it works:

Say you have a structure that holds all your verts:

struct myVert
{
float position[3];
float texcoord[2];
};

And for each vertex of your model, you have one of these. Basically, you have an array of myVert structures, all filled out with all your data:

myVert *verts = new myVert[numVerts];
setupVerts(verts);

Now, when you want to go through and draw using this data, this is where the stride comes into play:

glVertexPointer (3, GL_FLOAT, sizeof(myVert), (void *)((float *)verts + 0));
glEnableClientState (GL_VERTEX_ARRAY);

glClientActiveTextureARB (GL_TEXTURE0_ARB);
glTexCoordPointer (2, GL_FLOAT, sizeof(myVert), (void *)((float *)verts + 3));
glEnableClientState (GL_TEXTURE_COORD_ARRAY);

Notice, the stride parameter is basically "How many bytes do I need to go to get to the beginning of the next set of this data?" Since all our vertices are packed neatly together in an array, it's simply the size of an element of the array (myVert).

The last parameter is where the FIRST element is, so for the position, it's just the beginning of the array (since the position is first), and for the texcoord, it's 3 floats into the array (since the texcoords are directly after the position).

Hope that helps!

Oh, one more thing: If the stride parameter is zero, then it is implied that the data is tightly packed in the array, with nothing in between. If, for example, you only had position in your struct, like:

struct myVert
{
float pos[3];
}

Then you could pass in zero, instead of passing in sizeof(myVert), because there is nothing inbetween successive elements. This is generally worthless, though, because you'll rarely (if ever!) have just one big array full of the same type of data, and if you pass in zero the API will just calculate the value for you anyway (using the first two parameters - 2 and GL_FLOAT = 2 * sizeof(float) ).

Share this post


Link to post
Share on other sites

This topic is 4202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this