Opengl三角形和面顶点限制?

时间:2022-09-10 22:02:23

I am making an opengl-es app and I have always drawn quads by passing in 6 vertex indices per quad thus breaking a quad into two triangles. I thought all you could make in 3d graphics was quads and triangles..? I noticed in blender however if you use the decimate modifier you can make faces with a dozen or more verts. Can opengl-es render this? How do you render a face made up of a dozen verts? I'm not sure how it works from an opengl under the hood perspective. Does opengl just know to draw every time it receives 3 vertex indices? If so that would be convenient.

我正在制作一个opengl-es应用程序,我总是通过在每个四边形中传入6个顶点索引来绘制四边形,从而将四边形分成两个三角形。我认为你在3D图形中所能做的就是四边形和三角形..?我在混合器中注意到,如果你使用decimate修改器,你可以制作具有十几个或更多顶点的面。可以用opengl-es渲染吗?你如何渲染由十几个顶点组成的面孔?我不确定它是如何通过引擎盖视角下的opengl工作的。每次收到3个顶点索引时,opengl是否只知道绘制?如果这样那将是方便的。

1 个解决方案

#1


0  

OpenGL ES, as well as the Core Profile of desktop OpenGL, only support primitive types that consist of triangles. Older version of OpenGL supported additional primitive types like GL_QUADS and GL_POLYGON, but they were not directly supported by recent hardware, and mostly redundant anyway.

OpenGL ES以及桌面OpenGL的核心配置文件仅支持由三角形组成的基本类型。较早版本的OpenGL支持其他原始类型,如GL_QUADS和GL_POLYGON,但最近的硬件并不直接支持它们,并且大多数都是冗余的。

What is supported in addition to separate triangles (GL_TRIANGLES primitive type) are triangle strips (GL_TRIANGLE_STRIP) and triangle fans (GL_TRIANGLE_FAN). They allow you to draw sets of connected triangles without specifying 3 vertices per triangle.

除了单独的三角形(GL_TRIANGLES基本类型)之外,还支持三角形条(GL_TRIANGLE_STRIP)和三角形扇形(GL_TRIANGLE_FAN)。它们允许您绘制连接三角形的集合,而不指定每个三角形的3个顶点。

The following figure (borrowed from the Red Book) shows how triangles are formed from the specified vertices for each of these primitive types:

下图(借用红皮书)显示了如何从每个这些基本类型的指定顶点形成三角形:

Opengl三角形和面顶点限制?

For example, where you currently use 6 vertex indices for a quad, you can use only 4 with a triangle mesh or triangle fan. Some people claim that reducing the number of indices does not generally help performance, as long as you share the vertices.

例如,当前对四边形使用6个顶点索引时,只能使用4个三角形网格或三角形扇形。有些人声称,只要你共享顶点,减少索引的数量通常不会有助于提高性能。

If you have an input format that uses polygons with arbitrary numbers of vertices, that's still easy to handle as long as the polygons are convex. If you look at the triangle fan in the figure above, you will notice that the vertex ordering is actually the same as what it would be for a polygon. So a convex polygon can be represented directly by a triangle fan.

如果您的输入格式使用具有任意数量顶点的多边形,只要多边形是凸的,这仍然很容易处理。如果你看一下上图中的三角形扇形,你会注意到顶点排序实际上与多边形相同。因此凸多边形可以直接用三角形扇形表示。

If you would rather stick with GL_TRIANGLES for your rendering, and the input has n-sided polygons, you'll have to split them into triangles. Again, that's very easy as long as the polygons are convex. You can use the same kind of triangulation as the one shown for the triangle fan, except that you generate indices for each triangle separately. My answer here elaborates on this some more: Converting quadriladerals in an OBJ file into triangles?.

如果您希望坚持使用GL_TRIANGLES进行渲染,并且输入具有n边多边形,则必须将它们分割为三角形。同样,只要多边形是凸的,这就很容易了。除了为每个三角形分别生成索引外,您可以使用与三角形扇形所示相同的三角剖分。我的答案在这里详细阐述了这一点:将OBJ文件中的四边形转换为三角形?

Non-convex polygons are a different matter. You will have to split them into triangles using algorithms that range from moderately simple to fairly complex. You should be able to find plenty of literature if you use a search term like "polygon triangulation algorithm". It's also possible to draw concave polygons with clever use of the stencil buffer in OpenGL. But I doubt that most modelling programs generate concave polygons, so that's a much rarer use case.

非凸多边形是另一回事。您将不得不使用从中等简单到相当复杂的算法将它们分成三角形。如果您使用像“多边形三角剖分算法”这样的搜索词,您应该能够找到大量文献。也可以在OpenGL中巧妙地使用模板缓冲区来绘制凹多边形。但我怀疑大多数建模程序会生成凹多边形,因此这是一个非常罕见的用例。

#1


0  

OpenGL ES, as well as the Core Profile of desktop OpenGL, only support primitive types that consist of triangles. Older version of OpenGL supported additional primitive types like GL_QUADS and GL_POLYGON, but they were not directly supported by recent hardware, and mostly redundant anyway.

OpenGL ES以及桌面OpenGL的核心配置文件仅支持由三角形组成的基本类型。较早版本的OpenGL支持其他原始类型,如GL_QUADS和GL_POLYGON,但最近的硬件并不直接支持它们,并且大多数都是冗余的。

What is supported in addition to separate triangles (GL_TRIANGLES primitive type) are triangle strips (GL_TRIANGLE_STRIP) and triangle fans (GL_TRIANGLE_FAN). They allow you to draw sets of connected triangles without specifying 3 vertices per triangle.

除了单独的三角形(GL_TRIANGLES基本类型)之外,还支持三角形条(GL_TRIANGLE_STRIP)和三角形扇形(GL_TRIANGLE_FAN)。它们允许您绘制连接三角形的集合,而不指定每个三角形的3个顶点。

The following figure (borrowed from the Red Book) shows how triangles are formed from the specified vertices for each of these primitive types:

下图(借用红皮书)显示了如何从每个这些基本类型的指定顶点形成三角形:

Opengl三角形和面顶点限制?

For example, where you currently use 6 vertex indices for a quad, you can use only 4 with a triangle mesh or triangle fan. Some people claim that reducing the number of indices does not generally help performance, as long as you share the vertices.

例如,当前对四边形使用6个顶点索引时,只能使用4个三角形网格或三角形扇形。有些人声称,只要你共享顶点,减少索引的数量通常不会有助于提高性能。

If you have an input format that uses polygons with arbitrary numbers of vertices, that's still easy to handle as long as the polygons are convex. If you look at the triangle fan in the figure above, you will notice that the vertex ordering is actually the same as what it would be for a polygon. So a convex polygon can be represented directly by a triangle fan.

如果您的输入格式使用具有任意数量顶点的多边形,只要多边形是凸的,这仍然很容易处理。如果你看一下上图中的三角形扇形,你会注意到顶点排序实际上与多边形相同。因此凸多边形可以直接用三角形扇形表示。

If you would rather stick with GL_TRIANGLES for your rendering, and the input has n-sided polygons, you'll have to split them into triangles. Again, that's very easy as long as the polygons are convex. You can use the same kind of triangulation as the one shown for the triangle fan, except that you generate indices for each triangle separately. My answer here elaborates on this some more: Converting quadriladerals in an OBJ file into triangles?.

如果您希望坚持使用GL_TRIANGLES进行渲染,并且输入具有n边多边形,则必须将它们分割为三角形。同样,只要多边形是凸的,这就很容易了。除了为每个三角形分别生成索引外,您可以使用与三角形扇形所示相同的三角剖分。我的答案在这里详细阐述了这一点:将OBJ文件中的四边形转换为三角形?

Non-convex polygons are a different matter. You will have to split them into triangles using algorithms that range from moderately simple to fairly complex. You should be able to find plenty of literature if you use a search term like "polygon triangulation algorithm". It's also possible to draw concave polygons with clever use of the stencil buffer in OpenGL. But I doubt that most modelling programs generate concave polygons, so that's a much rarer use case.

非凸多边形是另一回事。您将不得不使用从中等简单到相当复杂的算法将它们分成三角形。如果您使用像“多边形三角剖分算法”这样的搜索词,您应该能够找到大量文献。也可以在OpenGL中巧妙地使用模板缓冲区来绘制凹多边形。但我怀疑大多数建模程序会生成凹多边形,因此这是一个非常罕见的用例。