سؤال

Hi I have a problem drawing with VBO. So I asked a question a here .I could not find the answer of my problem. But by discussing one answer given there I have now another question about strides in VBO. I am confused about what it is and does.

In here I found someone answered

If you have all your vertex data in one array (array : read as malloc''ed pointer), all your normals in another array, etc. Then your stride is 0. For instance if vertex, normals, etc are stored like that :

[vertex0][vertex1][vertex2]...

[normal0][normal1][normal2]...

[texcoord0][texcoord1][texcoord2]...

If your vertex, normal, etc is packed like that :

[vertex0][normal0][texcoord0][vertex1][normal1][texcoord1][vertex2][normal2][texcoord2]...

Then you should set a non-null stride, which corresponds to the offset needed to switch from one element to the next. (this stride is counted as bytes btw)

From that explanation I thought the stride actually means the distance between end of one vertex and the start of another vertex in the buffer. In the first case its 0 because all the vertexes are stored contiguously. Same goes for the textures. But then I read another answer about the definition of strides in that same thread.

There tends to be a bit of confusion regarding VBO stride, mostly because of its special meaning for 0.

"Stride" in this context means the distance between the beginning of a value in memory, and the beginning of the next value in memory. It is not the distance between the end of one and the beginning of the next. So in a VBO that is an array of a structure, the stride for each element of that structure will be the sizeof the structure as a whole. Keep in mind that struct padding can affect this.

which just says the opposite of what the other answer says. Or I am wrong about what the first answer meant? Can anyone please help me solve the problem. I will really appreciate if anyone can give an answer with example. I have given the link of my implementation of VBO in the start of this question which is not solved yet. Thanks.

هل كانت مفيدة؟

المحلول

What the first answer is trying to say is that the "stride" between two elements is the offset in bytes between the beginning of one element and the beginning of the next.
However, if the elements you're passing are contiguous (i.e. there's no space between them), you can pass 0 for the stride parameter.

I would say that it's wrong to claim that "stride is 0" in this case - the stride is sizeof(element), but the value 0 gets special treatment and is taken to mean sizeof(element).
This is most likely done so the poor programmer doesn't have to use two (bug-prone) sizeof parameters in the common case when they are the same.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top