Qt 5:禁用vsync

时间:2016-05-19 09:37:05

标签: qt vsync

我想从QOpenGLContext格式中禁用vsync,以便于集成第三方渲染系统。

QSurfaceFormat::swapInterval似乎是Qt中唯一的相关参数。

我尝试了几种方法来实现这一点,但即使我在早期阶段(QSurfaceFormat::swapInterval(0)构建之前)设置了QMainWindow,那么QOpenGLContext::create()调用也会恢复它。 / p>

// at application startup, before creating the Qt windows (or in MyQWindow constructor)
QSurfaceFormat format;
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format.setRedBufferSize(8);
format.setGreenBufferSize(8);
format.setBlueBufferSize(8);
format.setAlphaBufferSize(8);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format);

QMainWindow *w = new QMainWindow;
w->show();
// at QWindow with QOpenGLContext creation, at the first frame update (or at the constructor)
MyQWindow::initialization() {
    WbOpenGLContext *c = new WbOpenGLContext(this);
    c->setFormat(requestedFormat());
    qDebug() << "requested format:" << c->format();
    c->create();
    qDebug() << "actual format:" << c->format();
}
# output
requested format: QSurfaceFormat(
    version 2.0,
    options QFlags(),
    depthBufferSize 24,
    redBufferSize 8,
    greenBufferSize 8,
    blueBufferSize 8,
    alphaBufferSize 8,
    stencilBufferSize 8,
    samples -1,
    swapBehavior 2,
    swapInterval 0,
    profile 0
)
context format: QSurfaceFormat(
    version 3.0,
    options QFlags(0x4),
    depthBufferSize 24,
    redBufferSize 8,
    greenBufferSize 8,
    blueBufferSize 8,
    alphaBufferSize 8,
    stencilBufferSize 8,
    samples 0,
    swapBehavior 2,
    swapInterval 1, # Not what I asked
    profile 0
)

有没有办法强制禁用vsync?

1 个答案:

答案 0 :(得分:2)

正如peppe在问题的评论中提出的那样,遗憾的是,QOpenGLContext实例创建后的QSurfaceFormat格式与内部使用的实际格式不匹配。

这意味着我实现的代码可能正常工作,但第二个调试语句显示错误的值。