【问题标题】:What does stride mean in OpenGL|ESOpenGL|ES中的stride是什么意思
【发布时间】:2014-03-10 09:36:11
【问题描述】:

我正在检查方法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).

我无法理解这是什么意思?如果有人借助示例进行解释,那将非常有帮助。

谢谢。

【问题讨论】:

    标签: opengl-es stride


    【解决方案1】:

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

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

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

    这是一个紧密打包的例子,因为数组只包含一种类型的数据——你可以将步幅设置为零,OpenGL 会愉快地一次一个浮点地遍历数组。然而,数组不必只包含坐标数据——您也可以在数组中的坐标旁边存储法线和颜色数据:

    {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 个字节。

    【讨论】:

      猜你喜欢
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 2015-12-07
      • 1970-01-01
      • 2011-08-12
      相关资源
      最近更新 更多