Qt双缓冲行为

Qt double buffering behaviour

本文关键字:缓冲 Qt      更新时间:2023-10-16

我正在使用QWidget将一些代码转换为QOpenGLWidget,到目前为止,我想使用双缓冲来呈现小部件:

void clsElevStrip::initializeGL() {
qDebug() << "clsElevStrip::initializeGL()";
initializeOpenGLFunctions();
//Get the openGL context
mpobjContext = context();
if ( mpobjContext != NULL ) {
//Setup surface
mobjFormat.setDepthBufferSize(24);
mobjFormat.setSamples(4);
mobjFormat.setVersion(3, 0);
mobjFormat.setProfile(QSurfaceFormat::NoProfile);
mobjFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
int intSB = (int)mobjFormat.swapBehavior();
qDebug() << "swapBehavour as set-up in format: " << QString::number(intSB);
mpobjContext->setFormat(mobjFormat);
intSB = (int)mpobjContext->format().swapBehavior();
qDebug() << "swapBehavour as set-up in context: " << QString::number(intSB);
}
}

我可以在调试器中看到,在检查格式的交换行为时,intSB 是 2,但是当我检查上下文中设置的 intSB 时,它是 0,而不是 2?

因此,我渲染到上下文的任何内容都是可见的。

已解决:

我修改了代码,添加了

mpobjContext->create();

后:

mpobjContext->setFormat(mobjFormat);

现在它工作了!