[英]How does OpenGL actually read indices?
I trying to figure out how to draw a flat terrain with triangle_strips, and while I was writing the loop for creating indices array I thought how does OpenGL know to parse the indices because so far I have seen everybody when creating indices write them like that:我试图弄清楚如何使用triangle_strips 绘制平坦的地形,当我编写用于创建索引数组的循环时,我想OpenGL 如何知道解析索引,因为到目前为止我已经看到每个人在创建索引时都这样写:
0 3 1 4 2 5 0xFFFF 3 6 4 7 5 8 0 3 1 4 2 5 0xFFFF 3 6 4 7 5 8
(here being 0xFFFF primitive restart that marks the end of the strip) (这里是 0xFFFF 原语重新启动,标志着条带的结束)
and so technically as I understand this should be parsed with offset +1 for every triangle...so the first triangle would use first three indices (0 3 1) and the next with offset +1 (3 1 4)...next (1 4 2) and so on.所以从技术上讲,据我所知,这应该用每个三角形的偏移量 +1 来解析......所以第一个三角形将使用前三个索引(0 3 1),下一个使用偏移量 +1(3 1 4)......下一个(1 4 2) 等等。 Here's the picture in case I didn't explain well:
这是图片,以防我没有很好地解释:
But other way that I have seen is creating indices for every triangle separately .... so: 0 3 1 3 1 4 1 4 2 4 2 5但我见过的另一种方式是分别为每个三角形创建索引......所以:0 3 1 3 1 4 1 4 2 4 2 5
So my question is how to specify the layout...does OpenGL do this automatically as I set draw call to GL_TRIANGLE_STRIP or else?所以我的问题是如何指定布局...当我将绘制调用设置为 GL_TRIANGLE_STRIP 或其他时,OpenGL 是否会自动执行此操作?
There are three kinds of triangle primitives:三角形基元分为三种:
GL_TRIANGLES
: Vertices 0, 1, and 2 form a triangle. GL_TRIANGLES
:顶点 0、1 和 2 形成一个三角形。 Vertices 3, 4, and 5 form a triangle.顶点 3、4 和 5 形成一个三角形。 And so on.
等等。
GL_TRIANGLE_STRIP
: Every group of 3 adjacent vertices forms a triangle. GL_TRIANGLE_STRIP
:每组 3 个相邻顶点形成一个三角形。 A vertex stream of n length will generate n-2 triangles. n 长度的顶点流将生成 n-2 个三角形。
GL_TRIANGLE_FAN
: The first vertex is always held fixed. GL_TRIANGLE_FAN
:第一个顶点始终保持固定。 From there on, every group of 2 adjacent vertices form a triangle with the first.从那以后,每组 2 个相邻顶点与第一个顶点形成一个三角形。 So with a vertex stream, you get a list of triangles like so: (0, 1, 2) (0, 2, 3), (0, 3, 4), etc. A vertex stream of n length will generate n-2 triangles.
因此,对于顶点流,您会得到一个三角形列表,如下所示:(0, 1, 2) (0, 2, 3), (0, 3, 4) 等。 n 长度的顶点流将生成 n- 2个三角形。
Your first scenario describes a GL_TRIANGLE_STRIP
, while your second scenario describes GL_TRIANGLES
.您的第一个场景描述了
GL_TRIANGLE_STRIP
,而您的第二个场景描述了GL_TRIANGLES
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.