由OpenGLWidget和QOpenGLFunctions_2_0派生了類,試圖使用雙幀緩沖(Double Buffer)進行渲染。下面是部分功能代碼:
initializeGL()中:
QSurfaceFormat uformat;
uformat.setDepthBufferSize(24);
uformat.setStencilBufferSize(8);
uformat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
this->context()->setFormat(uformat);
PaintGL()中繪制完成后:
this->context()->swapBuffers(this->context()->surface());
后發現沒有使用swapBuffers和glFlush,繪制不受影響,照樣完成動畫的繪制,很奇怪。於是在initializeGL()的前部加入如下代碼測試:
QSurfaceFormat format = this->context()->surface()->format();
QSurfaceFormat::SwapBehavior b = format.swapBehavior();
發現系統一開始b就是double_buffer。可見本例程不需要進行任何設置就在使用雙緩沖,可以用glFlush,但swapBuffers好像不太需要
