OpenGL 执行速度非常慢

发布于 2024-12-06 09:30:34 字数 365 浏览 0 评论 0原文

在开发一款游戏时,我正在测试我的渲染器。不幸的是,它的运行速度约为每秒 4 帧。分析显示,令人惊讶的是,该运行时中只有 5% 属于我的代码,总运行时间的其余 95% 花费在 nvoglnt.dll 中。

不过,只使用了一个 256x256 纹理,除此之外,我在一些相机转换之外使用的唯一 openGL 代码是以下代码模板。它只执行了 134217728 次,总共 33554432 个四元组。

glTexCoord2f(u, v);
glColor3f(r, g, b);
glVertex3f(x, y, z);

我可能做错了什么导致 OpenGL 变得如此缓慢?我可以使用任何常见的性能技术来改进它吗?

Working on a game, and I was testing out my renderer. It unfortunately only runs at about 4 frames per second. Profiling reveals that surprisingly, only 5% of that runtime belongs to my code, and the remaining 95% of the total run time was spent in nvoglnt.dll.

Only one 256x256 texture is used though, and beyond that, the only openGL code I use outside of a few camera transformations is this following template of code. It is executed only 134217728 times for a total of 33554432 quads.

glTexCoord2f(u, v);
glColor3f(r, g, b);
glVertex3f(x, y, z);

What could I be doing wrong that's causing OpenGL to become so slow? Are there any common performance techniques I could use to improve it?

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

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

发布评论

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

评论(2

吖咩 2024-12-13 09:30:34

正如 datenwolf 所说,134217728 是很多次。如果您使用顶点数组,3300 万个四边形甚至很多。但现代卡应该可以很好地处理它。

这里的瓶颈完全是 CPU,每帧调用 1.34 亿 x 3 个函数。因为你以 4FPS 运行。也就是说每秒 16 亿次函数调用!怪不得跑得这么慢。

你应该做的是使用顶点缓冲区对象。无论您的数据有多不稳定,即使您必须每帧更新它,它都会更快。

有了这个,我很好奇为什么需要渲染 3300 万个易失性四边形?如果您向我们提供有关您正在做的事情的更广泛的概述,我们可以提出其他优化技术。

As datenwolf said, 134217728 is a lot of times. 33 million quads is even a lot if you were using vertex arrays. But modern cards should handle it pretty well.

The bottleneck here is completely the CPU, you're calling 134 million x 3 functions every frame. Since you're running at 4FPS. That's 1.6 billion function calls a second! No wonder it's running so slow.

What you should do is use Vertex Buffer Objects. It doesn't matter how volatile your data is, even if you have to update it every frame, it will be faster.

With that out of the way, I'm curious as to why you need to render 33 million volatile quads? If you give us a broader overview of what you are doing, we could propose other optimisation techniques.

紅太極 2024-12-13 09:30:34

它只执行了 134217728 次,总共 33554432 个四边形。

这些“少数”调用中的每一个都会使您的系统在程序和 OpenGL 驱动程序之间切换执行上下文。这并不是“少数”。老实说,我认为这个问题是一些很好的恶作剧,因为现在每个 OpenGL 教程都会告诉你不要使用立即模式来处理你观察到的立即模式导致的严重性能影响,即 glBegin 、glEnd、glVertex 等。

使用顶点数组或更好的顶点缓冲区对象

It is executed only 134217728 times for a total of 33554432 quads.

Each of those "few" calls makes your system to switch execution context between your program and the OpenGL driver. This is not "few". Honestly I'd consider this question some fine trolling, because each and every OpenGL tutorial these days will tell you not to use immediate mode for excactly that serious performance hit you observed, which immediate mode causes, i.e. glBegin, glEnd, glVertex and so on.

Use Vertex Arrays or better yet Vertex Buffer Objects.

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