OpenGL:渲染一批几何图形的有效方法? [英] OpenGL: efficient way to render a batch of geometry?

查看:176
本文介绍了OpenGL:渲染一批几何图形的有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直在寻找的东西,但是我还没有找到任何具体的信息或好的例子.我有很多未连接的对象(例如,三角带).呈现这些内容的有效方法是什么?

我听说过将多个对象放在一个VBO中以减少openGL调用的情况,但是还没有看到如何执行此操作的正确示例.我也看到过与这个想法相矛盾的帖子.所以现在,我基本上只是感到困惑.

解决方案

首先,您可能应该一直使用VBO.适用于大小物体.

然后,第二个问题是如何将几个单独的对象组合成一个大对象?" -这样可以减少必须进行的OpenGL调用的次数.通常,可以将使用相同纹理,材质设置和着色器的对象组合在一起.例如.如果您周围有成千上万相同的板条箱,则可以将它们组合成几个更大的板条箱堆".

如果对象是三角形列表,则合并很容易-只需从源列表中创建一个大三角形列表即可.如果对象是三角形带,则必须使用简并三角形"将其连接起来(对于单个对象,如果不能将其表示为单个带,这也是非常有用的优化方法).

简并三角形"是具有两个或三个相同的顶点索引的三角形.图形硬件可以识别它们并非常快地跳过它们.

例如,如果有的话两个带,每个带一个三角形,总共六个顶点.

条带的原始三角形索引为:

1) 0, 1, 2
2) 0, 1, 2

现在将所有顶点连接在一起,因此最终得到6个顶点.

1) 0, 1, 2 (unchanged)
2) 3, 4, 5

到现在,您拥有一个顶点阵列,但仍然有两个单独的条带.必须通过插入退化三角形来加入它们:

1) 0, 1, 2, 2, 2, 3, 4, 5

(我认为以上是正确的,但尚未实际验证)

想法是这样的:在上面的条带中,图形卡将从这些顶点中绘制出三角形:

0, 1, 2
1, 2, 2 <- degenerate! won't be drawn
2, 2, 2 <- degenerate! won't be drawn
2, 2, 3 <- degenerate! won't be drawn
3, 4, 5

通常情况下,您必须根据原始带材的长度插入两个或三个退化的三角形,以使三角形缠绕保持正确.

This is something I've been looking into for while, but I have yet to find any concrete information or good examples. I have, say, a bunch of unconnected objects (triangle strips for instance). What is the efficient way to render these?

I've heard about putting several objects in one VBO to reduce openGL calls, but have not seen a proper example of how to do this. I've also seen posts that contradict this idea. So right now, I'm mostly just confused.

解决方案

First off, you should probably use VBO all the time. For small and large objects.

Then, the second issue is "how to combine several separate objects into one large object?" - so to reduce the number of OpenGL calls that have to be made. Generally, objects that use the same texture(s), material settings and shaders can be combined. E.g. if you have tons of identical crates lying around, it might make sense to combine them into several larger "crate piles".

If an object is a triangle list, then combining is easy - just create a large triangle list out of the source lists. If an object is a triangle strip, then you have to use "degenerate triangles" to join the strips (this is a very useful optimization for a single object as well, if it can't be represented as a single strip).

A "degenerate triangle" is a triangle that has two or three identical vertex indices. Graphics hardware can recognize them and skip them very fast.

So if you have, e.g. two strips with one triangle each, for a total of six vertices.

The original triangle indices of the strips would be:

1) 0, 1, 2
2) 0, 1, 2

Now you join all vertices together, so you end up with 6 vertices.

1) 0, 1, 2 (unchanged)
2) 3, 4, 5

By now you have one vertex array, but still two separate strips. Have to join them by inserting degenerate triangles:

1) 0, 1, 2, 2, 2, 3, 4, 5

(I think the above is correct, but haven't actually verified)

The idea is this: with the above strip, the graphics card would draw triangles out of these vertices:

0, 1, 2
1, 2, 2 <- degenerate! won't be drawn
2, 2, 2 <- degenerate! won't be drawn
2, 2, 3 <- degenerate! won't be drawn
3, 4, 5

In general case, you either have to insert two or three degenerate triangles based on the original strip length, so that triangle winding remains correct.

这篇关于OpenGL:渲染一批几何图形的有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆