c++ - 什么是 glVertexPointer 中的步幅,VBO 中的 glTexCoordPointer

标签 c++ opengl-es vbo blackberry-10 stride

您好,我在使用 VBO 绘图时遇到问题。所以我问了一个问题here .我找不到问题的答案。但是通过讨论那里给出的一个答案,我现在有了另一个关于 VBO 进步的问题。我对它是什么和做什么感到困惑。

here我发现有人回答了

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)

根据该解释,我认为步幅实际上是指缓冲区中一个顶点的末端与另一个顶点的起点之间的距离。在第一种情况下,它是 0,因为所有顶点都是连续存储的。纹理也是如此。但后来我在同一个线程中阅读了另一个关于步幅定义的答案。

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.

这与其他答案所说的正好相反。或者我对第一个答案的意思有误?谁能帮我解决这个问题。如果有人能举例说明,我将不胜感激。我在这个问题的开头给出了我实现 VBO 的链接,这个问题还没有解决。谢谢。

最佳答案

第一个答案试图说的是两个元素之间的“步幅”是一个元素的开头和下一个元素的开头之间的字节偏移量。
但是,如果您传递的元素是连续的(即它们之间没有空格),您可以为 stride 参数传递 0。

我会说在这种情况下声称“步幅为 0”是错误的 - 步幅 sizeof(element),但值 0 得到特殊处理并表示 sizeof(element)
这样做很可能是为了让可怜的程序员不必在常见情况下使用两个(容易出错的)sizeof 参数,当它们相同时。

关于c++ - 什么是 glVertexPointer 中的步幅,VBO 中的 glTexCoordPointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15321867/

相关文章:

c++ - 如何将多个纹理应用于立方体的 VBO?

c++ - 链接列表释放内存 - 段错误

c++ - 从视频纹理中选择源矩形

c - OpenGL VBO 仅在渲染时上传到 GPU

iphone - 在 glDrawArrays() 上调试 SIGKILL。苹果手机

c++ - 如何使用多个统一缓冲区对象

java - LWJGL 3.1.6 在 Win 10 上崩溃

c++ - 为什么我得到未引用的局部变量

c++ - 没有收到来自 parent 的 moveEvent?

c++ - 使用 vector 从c++中的文件中反转字符串