OpenGL绘图时间
OpenGL 什么时候真正绘制我指示它绘制的东西?是在调用特定的绘图函数还是在缓冲区交换上?
我想知道这一点,看看我是否可以做这样的事情:
SomeTimer Timer;
Timer.Start();
glDrawArrays(...);
long time = Timer.Stop();
看看什么绘图花费最多时间并基于此进行优化。
如果重要的话:我只在二维中绘制,没有模板/深度或任何其他缓冲区测试。
When does OpenGL actually draw things I instruct it to? is it on the call to the specific drawing function or on the buffer swap?
I want to know this to see if I can do something like this:
SomeTimer Timer;
Timer.Start();
glDrawArrays(...);
long time = Timer.Stop();
To see what drawing takes the most time and optimize based on that.
If it matters: I'm drawing only in 2d, no stencil/depth or any other buffer tests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码将不起作用。根据定义,OpenGL 命令被假定为异步行为。 GL 命令需要在完成之前完全写入或读取任何参数。但除此之外,一切皆有可能。
对任何单独的
glDraw*
调用进行计时只会告诉您完成该函数调用需要多长时间。它没有说明渲染需要多长时间才能完成。可以对这个主题进行更彻底的讨论。
好处是您可以计算渲染时间,但必须按照 OpenGL 的方式进行。 ARB_timer_query 允许您准确地做到这一点:计算 OpenGL 需要多长时间命令完成,而不仅仅是交给OpenGL。该扩展是 OpenGL 3.3 的核心,并且广泛适用于各种级别的硬件。几乎所有仍受其所有者支持的 GPU 都实现了这一点。
That code will not work. OpenGL commands are by definition assumed to be asynchronous in behavior. GL commands are required to have fully written to or read from any parameters before they complete. But outside of that, all bets are off.
Timing any individual
glDraw*
call will tell you only how much time it takes that function call to complete. It says nothing about how long the rendering takes to finish.A more thorough discussion of this subject is available.
The upside is that you can time rendering, but you have to do it OpenGL's way. ARB_timer_query allows you to do exactly that: time how long it takes for OpenGL commands to complete, not merely be given to OpenGL. This extension is core in OpenGL 3.3, and it is pretty widely available for various levels of hardware. Pretty much any GPU still being supported by its owner implements this.