在 OpenGL 中对单个对象使用显示列表有什么问题吗?

发布于 2024-11-07 23:33:31 字数 770 浏览 0 评论 0原文

首先,我知道显示列表在 OpenGL 3.0 中已被弃用,并在 3.1 中被删除。但我仍然必须在这个使用 OpenGL 2.1 的大学项目中使用它们。

我在显示列表上读到的每一篇文章或教程都将它们用于某种多次绘制的对象,例如树。为单个对象创建一个列表有什么问题吗?

例如,我有一个建筑物的对象(.obj 格式)。该特定建筑物仅绘制一次。对于基本性能分析,我在窗口标题栏上显示了当前的每秒帧数。

这样做:

glmDraw(objBuilding.model, GLM_SMOOTH | GLM_TEXTURE);

我得到了大约 260 FPS。如果您不了解 GLM 库,则 glmDraw 函数基本上会进行一堆 glVertex 调用。

但这样做:

glNewList(gameDisplayLists.building, GL_COMPILE);
    glmDraw(objBuilding.model, GLM_SMOOTH | GLM_TEXTURE);
glEndList();

glCallList(gameDisplayLists.building);

我得到了大约 420 FPS。当然,屏幕刷新率不会刷新那么快,但正如我所说,这只是衡量性能的一种简单而基本的方法。

对我来说看起来好多了。

当我有某种类型的重复多次的对象(例如防御塔)时,我也会使用显示列表。再说一遍,对单个对象这样做有什么问题吗?或者我可以继续这样做吗?

First of all, I know that displays lists were deprecated in OpenGL 3.0 and removed on 3.1. But I still have to use them on this university project for which OpenGL 2.1 is being used.

Every article or tutorial I read on display lists use them on some kind of object that is drawn multiple times, for instance, trees. Is there anything wrong in creating one list for a single object?

For instance, I have an object (in .obj format) for a building. This specific building is only drawn once. For basic performance analysis I have the current frames per second on the window title bar.

Doing it like this:

glmDraw(objBuilding.model, GLM_SMOOTH | GLM_TEXTURE);

I get around 260 FPS. If you don't about the GLM library, the glmDraw function basically makes a bunch of glVertex calls.

But doing it like this:

glNewList(gameDisplayLists.building, GL_COMPILE);
    glmDraw(objBuilding.model, GLM_SMOOTH | GLM_TEXTURE);
glEndList();

glCallList(gameDisplayLists.building);

I get around 420 FPS. Of course, the screen refresh rate doesn't refresh that fast but like I said, it's just a simple and basic way to measure performance.

It looks much better to me.

I'm also using display lists for when I have some type of object that I repeat many times, like defense towers. Again, is there anything wrong doing this for a single object or can I keep doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔落惊风雨 2024-11-14 23:33:31

使用显示列表来处理这些东西是非常好的,在顶点数组出现之前,它们是将几何图形放置在快速内存中的事实上的标准。放置显示列表有一些有趣的陷阱。例如,在 OpenGL-1.0 中没有纹理对象;相反,将 glTexImage 调用放在显示列表中是模拟这一点的方法。而且这种行为仍然普遍存在,因此每当调用显示列表时,在显示列表中绑定纹理并调用 glTexImage 将有效地使用显示列表编译中完成的操作重新初始化纹理对象。另一方面,显示列表不适用于顶点数组。

TL;DR:如果您的几何体是静态的,您不会期望随时转换到 OpenGL-3 核心,它会给您带来巨大的性能提升(就像它为您所做的那样),那么就使用它们吧!

Using display lists for this stuff is perfectly fine and before Vertex Arrays were around they were the de-facto standard to place geometry in fast memory. Put display lists have a few interesting pitfalls. For example in OpenGL-1.0 there were no texture objects; instead placing the glTexImage call in a display list was the way to emulate this. And this behaviour still prevails, so binding a texture and calling glTexImage in a display list will effectively re-initialize the texture object with what's been done in the display list compilation, whenever the display list is called. On the other hand display lists don't work with vertex arrays.

TL;DR: If your geometry is static, you don't expect to transistion to OpenGL-3 core anytime and it gives you a huge performance increase (like it did for you), then just use them!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文