PaintGL()调用理解 [英] PaintGL() call understanding

查看:787
本文介绍了PaintGL()调用理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 PaintGL()函数的调用频率与屏幕的频率相同(我们说每秒60次)。但是如果没有像素显示在屏幕上(如果另一个窗口隐藏了OpenGL),调用 PaintGL()不再受限制,被称为很多更多.. 。

I know that PaintGL() function is call at the same frequency that the screen's (let's say 60 times per second). But if no pixel is displayed on the screen (if another window hide the OpenGL one) the call to PaintGL() is no longer restrain and is called a lot much more... Which use the CPU at max and is annoying.

那么,有没有办法限制呢?

So, is there a way to restrain it ?

我使用MacOS 10.9和Qt Creator。

I'm using MacOS 10.9 and Qt Creator.

我不知道很多关于vsync。事实是,当我们的软件在forground中时,我的软件使用了30%的CPU,当它隐藏时,它高达95%。

I don't know a lot about vsync. The fact is my software use 30% of the CPU when it's in the forground and when it's hidden, it goes up to 95%.

推荐答案

如果您尚未启用vsync,则框架会尽可能频繁地交换(如果您尚未添加人工暂停)。如果你在显卡上推高负载,那么很可能你的程序是GPU限制的(CPU没有什么可做,站在空闲等待GPU完成绘制)。

If you haven't enabled vsync, frames swap as often as possible (if you haven't added artificial pause). If you pushed high load on graphics card, it is likely that your program is GPU-limited (CPU have nothing to do and standing idle waiting for GPU to finish drawing).

因此,您的问题的答案是 - enable()。当你的程序不可见时,绘制成本接近无效,因为没有人看到结果vsync。它将锁定缓冲区交换间隔以监视器的刷新速率,因此您的帧速率永远不会升高高于刷新速率(实际上,如果您的显示器是60 Hz,它将被锁定到60/30/20 /等。这是非常有用的技术,消除了屏幕撕裂。

So, answer to your question is - enable vsync. It will lock buffer swapping interval to monitor's refresh rate, so your frame rate will never rise higher than refresh rate (in fact, it will be locked to numbers 60/30/20/etc., if your monitor is at 60 Hz). This is very useful technique that e.g. eliminates screen tearing.

这篇关于PaintGL()调用理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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