opengl-es - 跨步在OpenGL | ES中是什么意思

标签 opengl-es stride

我正在通过glVertexPointer方法的签名
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer)
谁能帮助我了解第三个参数stride的作用。

在谷歌搜索之后,我得到了stride的这个定义
Amount of bytes from the beginning of one element to the beginning of the following element. If you pass a zero as stride, it means they are tightly packed. If you have an array of floats, which contains vertices like this, x1,y1,z1,x2,y2,z2... and so on, you can set stride to either zero (as tightly packed), or 12 (3 floats*4 bytes each from the beginning of vertex one to the beginning of vertex two).
我无法理解这是什么意思?如果有人借助示例进行解释,那将非常有帮助。

谢谢。

最佳答案

最简单的情况是您的数组仅包含顶点坐标数据。假设我们只有两个坐标,因此有6个浮点数:

{x1,y1,z1, x2,y2,y2}

指针(第4个参数)指向数组中第一个顶点的起点(即零,指向x1)。跨度应为12,这意味着从一个顶点移动到下一个顶点,OpenGL需要向前移动12个字节(因为每个顶点中的3个坐标中的每个坐标都占用4个字节)。因此,通过移动12个字节,我们到达第二个顶点的起点x2所在的位置。

这是一个紧密打包的示例,因为数组仅包含一种类型的数据-您可以将跨度设置为零,并且OpenGL会一次愉快地遍历数组一次 float 。但是,数组不必只包含坐标数据-您也可以在数组中的坐标旁边存储法线和颜色数据:
{x1,y1,z1,nx1,ny1,nz1,r1,g1,b1,a1, x2,y2,z2,nx2,ny2,nz2,r2,g2,b2,a2}

它不再紧密包装-坐标数据在数组中不再连续(它们由法线和颜色值分隔)。在这种情况下,跨度为40。要从一个顶点的起点到下一个顶点,OpenGL需要沿40个字节移动:(3个坐标数据浮点数+ 3个普通数据浮点数+ 4个颜色数据浮点数)x每个浮点数4个字节。

关于opengl-es - 跨步在OpenGL | ES中是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22296510/

相关文章:

ios - 如何使用 GLKit 的 GLKMatrixStack 库生成模型 View 矩阵?

c# - 如何从具有负步幅的位图中复制像素数据?

memory - 如何从全局内存到本地内存进行跨步复制?

c# - C# 中 MSpaint 图像的图像步幅为 +1 字节,为什么?

android - Android 上符合 OpenGL-ES 2.0 要求的最小纹理尺寸?

ios - GPUImage 双 channel 过滤器 - 第二个片段着色器从不运行?

Android OpenGL - 简单二维转换的困难

android - OpenGL ES 2.0 - Matrix.looktAtM 究竟如何与 glOrtho 交互?

c++ - 在 C++ 中复制跨步数据