如何获得游戏? FPS(使用 OpenGL)达到 800 FPS
我们如何才能以更高的帧速率(例如 500 - 800 FPS)运行 OpenGL 应用程序(例如游戏)?
例如,AOE 2 的运行速度超过 700 FPS(我知道它与 DirectX 有关)。 尽管我只是在游戏循环中清除缓冲区和交换缓冲区,但我只能获得大约 200(最大)FPS。 我知道 FPS 不是一个好的衡量标准(并且还取决于硬件),但我觉得我错过了 OpenGL 中的一些概念。 我有吗? 请问有人可以给我提示吗?
How can we run a OpenGL applications (say a games) in higher frame rate like 500 - 800 FPS ?
For a example AOE 2 is running with more than 700 FPS (I know it is about DirectX). Eventhough I just clear buffers and swap buffers within the game loop, I can only get about 200 (max) FPS. I know that FPS isn't a good messurenment (and also depend on the hardware), but I feel I missed some concepts in OpenGL. Did I ? Pls anyone can give me a hint ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在空显示循环(GeForce 260 GTX,1920x1080)的情况下,我得到了大约 5.600 FPS。 添加 glClear 会将其降低至 4.000 FPS,但仍远高于 200...
一个简单的图形引擎(AoE2 风格)应以大约 100-200 FPS 运行(GeForce 8 或类似引擎)。 如果它是多线程且完全优化的,可能会更多。
我不知道你在循环中到底做了什么,也不知道运行在什么硬件上,但是 200 FPS 听起来除了什么都不画之外你还在做其他事情(睡眠?游戏逻辑的东西?贪婪的框架?Aero?)。 即使必须复制两个帧缓冲区,交换缓冲区功能也不应花费 5 毫秒。 您可以使用配置文件来检查花费最多 CPU 时间的地方(尽管 gl* 函数的计时结果大多无用)
如果您正在使用 OpenGL 做一些事情(绘图、创建纹理等),那么有一个很好的扩展可以测量调用GL_EXT_timer_query的时间。
一些一般的优化技巧:
I'm getting roughly 5.600 FPS with an empty display loop (GeForce 260 GTX, 1920x1080). Adding glClear lowers it to 4.000 FPS which is still way over 200...
A simple graphics engine (AoE2 style) should run at about 100-200 FPS (GeForce 8 or similar). Probably more if it's multi-threaded and fully optimized.
I don't know what exactly you do in your loop or what hardware that is running on, but 200 FPS sounds like you are doing something else besides drawing nothing (sleep? game logic stuff? greedy framework? Aero?). The swapbuffer function should not take 5ms even if both framebuffers have to be copied. You can use a profile to check where the most CPU time is spent (timing results from gl* functions are mostly useless though)
If you are doing something with OpenGL (drawing stuff, creating textures, etc.) there is a nice extension to measure times called GL_EXT_timer_query.
Some general optimization tips:
AOE 2 是 DirectDraw 应用程序,而不是 Direct3D。 没有办法比较 OpenGL 和 DirectDraw。
另外,检查您用于交换缓冲区的方法。 Direct3D中有flip方法、copy方法、discard方法。 最好的一种是丢弃,这意味着您不关心缓冲区中以前的内容,并允许驱动程序有效地管理它们。
AOE 2 is a DirectDraw application, not Direct3D. There is no way to compare OpenGL and DirectDraw.
Also, check the method you're using for swapping buffers. In Direct3D there are flip method, copy method, and discard method. The best one is discard, which means that you don't care about previous contents in the buffer, and allow the driver to manage them efficiently.
您似乎错过的一件事(从您的回答/评论来看,如果我错了,请纠正我)是您需要确定要渲染的内容。
例如,正如您所说,您有多个图层等,那么您需要做的第一件事就是不要渲染屏幕外的任何内容(这是可能的,有时会完成)。 您还应该做的是不要渲染您确定不可见的内容,例如,如果顶层的某些区域不透明(或填充),您不应该渲染其下面的图层。
总的来说,我想说的是,在大多数情况下,消除逻辑中不可见的东西比渲染所有东西并让顶部的东西最终出现在渲染图像中更好。
One of the things you seem to miss (judging from your answer/comments, so correct me if I'm wrong) is that you need to determine what to render.
For example as you said you have multiple layers and such, well the first thing you need to do is not render anything that is off screen (which is possible and is sometimes done). What you should also do is not render things that you are certain are not visible, for example if some area of the top layer is not transparent (or filled up) you should not render the layers below it.
In general what I'm trying to say is that it is in most cases better to eliminate invisible things in the logic than to render all things and just let the things on top end up in the rendered image.
如果您的纹理很小,请尝试将它们组合成一个更大的纹理,并通过纹理坐标来解决它们。 这将为您节省大量状态更改。 例如,如果您的纹理为 128x128,您可以将其中 16 个纹理放入一个 512x512 纹理中,从而使与纹理相关的状态变化降低 16 倍。
If your textures are small, try to combine them in one bigger texture and address them via texture coordinates. That will save you a lot of state changes. If your textures are e.g. 128x128, you can put 16 of them in one 512x512 texture, bringing your texture related state changes down by a factor of 16.