QT OpenGLWidget的surfaceFormat

由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好像不太需要

 
posted @ 2019-07-14 11:48  小船1968  阅读(4529)  评论(0编辑  收藏  举报