简体   繁体   English

OpenGL:OpenGL-ES之外的Triangle Strip中的退化三角形是可以接受的吗?

[英]OpenGL: Are degenerate triangles in a Triangle Strip acceptable outside of OpenGL-ES?

In this tutorial for OpenGL ES, techniques for optimizing models are explained and one of those is to use triangle strips to define your mesh, using "degenerate" triangles to end one strip and begin another without ending the primitive. 在OpenGL ES的本教程中,解释了优化模型的技术,其中之一是使用三角形条来定义网格,使用“简并”三角形结束一个条带并开始另一个条带而不结束基元。 http://www.learnopengles.com/tag/degenerate-triangles/ http://www.learnopengles.com/tag/degenerate-triangles/

However, this guide is very specific to mobile platforms, and I wanted to know if this technique held for modern desktop hardware. 但是,本指南非常适用于移动平台,我想知道这种技术是否适用于现代桌面硬件。 Specifically, would it hurt ? 具体来说,它会受伤吗? Would it either cause graphical artifacts or degrade performance (opposed to splitting the strips into separate primatives?) 它会导致图形伪像还是降低性能(相反将条带分成单独的原型?)

If it causes no artifacts and performs at least as well, I aim to use it solely because it makes organizing vertices in a certain mesh I want to draw easier. 如果它没有造成任何伪影并至少执行,我的目的是仅仅因为它使组织顶点在我想要绘制的某个网格中更容易。

Degenerate triangles work pretty well on all platforms. 退化三角形在所有平台上都能很好地工作。 I'm aware of an old fixed-function console that struggled with degenerate triangles, but anything vaguely modern will be fine. 我知道一个旧的固定功能控制台挣扎着堕落的三角形,但任何模糊的现代都会很好。 Reducing the number of draw calls is always good and I would certainly use degenerates rather than multiple calls to glDrawArrays. 减少绘制调用的数量总是很好,我当然会使用退化而不是多次调用glDrawArrays。

However, an alternative that usually performs better is indexed draws of triangle lists. 但是,通常表现更好的替代方案是三角形列表的索引绘制。 With a triangle list you have a lot of flexibility to reorder the triangles to take maximum advantage of the post-transform cache. 使用三角形列表,您可以灵活地重新排序三角形,以最大限度地利用变换后缓存。 The post-transform cache is a hardware cache of the last few vertices that went through the vertex shader, the GPU can spot if you've re-issued the same vertex and skip the entire vertex shader for that vertex. 变换后缓存是通过顶点着色器的最后几个顶点的硬件缓存,GPU可以发现您是否重新发出相同的顶点并跳过该顶点的整个顶点着色器。

In addition to the above answers (no it shouldn't hurt at all unless you do something mad in terms of the ratio of real triangles to the degenerates), also note that the newer versions of OpenGL and OpenGL ES (3.x or higher) APIs support a means to insert breaks into index lists without needing an actual degenerate triangle, which is called primitive restart. 除了上面的答案(除非你根据真实三角形与退化的比例做一些疯狂的事情,否则它根本不应该受到伤害),同时请注意更新版本的OpenGL和OpenGL ES(3.x或更高版本) )API支持将断点插入索引列表而不需要实际的简并三角形的方法,这称为原始重启。

https://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml https://www.khronos.org/opengles/sdk/docs/man3/html/glEnable.xhtml

When enabled you can encode "MAX_INT" for the index type, and when detected that forces the GPU to restart building a new tristrip from the next index value. 启用后,您可以为索引类型编码“MAX_INT”,并在检测到时强制GPU重新开始从下一个索引值构建新的tristrip。

It will not cause artifacts. 它不会导致伪影。 As to "degrading performance"... relative to what? 至于“降低性能”......相对于什么? Relative to a random assortment of triangles with no indexing? 相对于没有索引的随机分类的三角形? Yes, it will be faster than that. 是的,它会比那更快。

But there are plenty of other things one can do. 但是还有很多其他事情可以做。 For example, primitive restarting, which removes the need for degenerate triangles. 例如,原始重启,这消除了对退化三角形的需要。 Then there's using ordered lists of triangles for improved cache coherency. 然后使用有序的三角形列表来提高缓存一致性。 Will triangle strips be faster than that? 三角形条纹会比那更快吗?

It rather depends on what you're rendering, how expensive your vertex shaders are, and various other things. 它取决于您渲染的内容,顶点着色器的价格以及其他各种因素。

But at the end of the day, if you care about maximum performance on particular platforms, then you should profile for each platform and pick the vertex data based on what platform you're running on. 但最终,如果您关心特定平台上的最高性能,那么您应该为每个平台进行分析,并根据您正在运行的平台选择顶点数据。 If performance is really that important to you, then you're going to have to put forth some effort. 如果性能是真的对你那么重要,那么你将不得不提出一些努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM