如何使updateGL()实时在QT [英] how to make updateGL() realtime in QT

查看:1251
本文介绍了如何使updateGL()实时在QT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果在固定的定时器间隔调用updateGL()可能会降低渲染过程。所以,我想尝试使渲染实时。我没有使它自动执行的功能。任何人都知道?



其次,我在程序中评论了updateGL(),CPU使用率降低到1%和0%。现在,当我点击显示窗口部件,它跳到14%,为什么?是不是GPU做所有的渲染工作?如果是为什么CPU跳到14?如何解决这个问题?

解决方案

是的,你可以使其实时,没有撕裂(例如,

为此,您必须启用V_sync,并使用 QTimer计时器; 启用V_sync将使自动调用 swapBuffers()命令到CPU,等待来自显示器的垂直刷新信号。然后,定时器实际上将与监视器刷新率同步。



相关信息可以在这里找到: http://blog.qt.digia.com/blog/2010/12/02/velvet-and-the-qml-scene-graph/ 。请注意 QGLFormat :: setSwapInterval(1)以启用V_sync,如果没有通过您的驱动程序设置自动完成:

  class MyGLWidget:public QGLWidget 
{
// ...
private:
QTimer timer;
}

QGLFormat desiredFormat()
{
QGLFormat fmt;
fmt.setSwapInterval(1);
return fmt;
}

MyGLWidget :: MyGLWidget():
QGLWidget(desiredFormat())
{
//配置定时器
connect & timer,SIGNAL(timeout()),this,SLOT(updateGL()));
if(format()。swapInterval()== -1)
{
// V_blank同步不可用(可能发生撕裂)
qDebug不可用:以约60fps刷新。
timer.setInterval(17);
}
else
{
// V_blank同步可用
timer.setInterval(0);
}
timer.start();
}

同时,您可以运行 QElapsedTimer 来测量两次绘制之间的时间(通常约为16.6ms),并使用此信息更新您的场景。


I wonder if calling updateGL() in fixed timer intervals may slow down the rendering process. So, I want to try making the render real time. I do not the function to make it execute automatically. Anyone knows that?

secondly, I commented updateGL() in my program, CPU usage reduced to 1% and 0%. Now, when I click on the display widget it jumps to 14%, why? isn't GPU doing all the rendering job? if yes why CPU jumps to 14? how can I resolve this?

解决方案

Yes, you can make it realtime, with no tearing (e.g., redrawing at exactly 60fps, the refresh rate of your monitor).

For this, you have to enable V_sync, and using a QTimer timer; of interval 0. Enabling V_sync will make the automatically called swapBuffers() command to CPU-wait for the vertical refresh signal from your monitor. Then, the timer will actually be synchronized with the monitor refresh rate.

A related info can be found here: http://blog.qt.digia.com/blog/2010/12/02/velvet-and-the-qml-scene-graph/ . Note the QGLFormat::setSwapInterval(1) to enable V_sync, if not done automatically by your driver settings:

class MyGLWidget: public QGLWidget
{
    // ...
private:
    QTimer timer;
}

QGLFormat desiredFormat()
{
    QGLFormat fmt;
    fmt.setSwapInterval(1);
    return fmt;
}

MyGLWidget::MyGLWidget() :
    QGLWidget(desiredFormat())
{
    // Configure the timer
    connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    if(format().swapInterval() == -1)
    {
        // V_blank synchronization not available (tearing likely to happen)
        qDebug("Swap Buffers at v_blank not available: refresh at approx 60fps.");
        timer.setInterval(17);
    }
    else
    {
        // V_blank synchronization available
        timer.setInterval(0);
    }
    timer.start();
}

In parallel, you can run a QElapsedTimer to measure how much time has passed between two drawing (normally approx 16.6ms), and use this information to update your scene, for instance.

这篇关于如何使updateGL()实时在QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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