From 3cbfb0a5c70f4e80d34274d713472aa4d25da5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sun, 28 Sep 2014 19:44:39 +0200 Subject: [PATCH] Prevent QPainter buffer swap As the QGraphicsScene overlay does not work for all cards/drivers we disable the possible buffer swap of the qpainter, as this could be a potential source of the flickering. If the painter swaps buffers and we do it again the user will see first the correct picture (first swap) and then something uninitalized (second swap) --- src/Gui/Quarter/QuarterWidget.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index 0d82117d4..c224bdfb7 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -126,6 +126,16 @@ using namespace SIM::Coin3D::Quarter; #ifndef GL_MULTISAMPLE_BIT_EXT #define GL_MULTISAMPLE_BIT_EXT 0x20000000 #endif + +//We need to avoid buffer swaping when initializing a QPainter on this widget +class QUARTER_DLL_API CustomGLWidget : public QGLWidget { +public: + CustomGLWidget(const QGLFormat& fo, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0) + : QGLWidget(fo, parent, shareWidget, f) { + + setAutoBufferSwap(false); + }; +}; /*! constructor */ QuarterWidget::QuarterWidget(const QGLFormat & format, QWidget * parent, const QGLWidget * sharewidget, Qt::WindowFlags f) @@ -153,7 +163,7 @@ QuarterWidget::constructor(const QGLFormat & format, const QGLWidget * sharewidg { QGraphicsScene* scene = new QGraphicsScene; setScene(scene); - setViewport(new QGLWidget(format, this, sharewidget)); + setViewport(new CustomGLWidget(format, this, sharewidget)); setFrameStyle(QFrame::NoFrame); setAutoFillBackground(false); @@ -720,12 +730,8 @@ void QuarterWidget::paintEvent(QPaintEvent* event) //start the standard graphics view processing for all widgets and graphic items. As //QGraphicsView initaliizes a QPainter which changes the Opengl context in an unpredictable //manner we need to store the context and recreate it after Qt is done. - glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_MULTISAMPLE_BIT_EXT); - inherited::paintEvent(event); - - glPopAttrib(); glPopAttrib(); if (w->doubleBuffer()) { w->swapBuffers(); }