diff --git a/src/Gui/Flag.cpp b/src/Gui/Flag.cpp index ba72f3c16c7c..40b09e346699 100644 --- a/src/Gui/Flag.cpp +++ b/src/Gui/Flag.cpp @@ -125,7 +125,9 @@ void Flag::drawLine (View3DInventorViewer* v, int tox, int toy) GLPainter p; p.begin(v->getGLWidget()); +#if !defined(HAVE_QT5_OPENGL) p.setDrawBuffer(GL_BACK); +#endif // the line p.setLineWidth(1.0f); diff --git a/src/Gui/GLPainter.cpp b/src/Gui/GLPainter.cpp index 79327ccd9c3e..b80a36d7b520 100644 --- a/src/Gui/GLPainter.cpp +++ b/src/Gui/GLPainter.cpp @@ -61,6 +61,7 @@ bool GLPainter::begin(QPaintDevice * device) glMatrixMode(GL_PROJECTION); glPushMatrix(); + glLoadIdentity(); glOrtho(0, this->width, 0, this->height, -1, 1); @@ -80,7 +81,9 @@ bool GLPainter::begin(QPaintDevice * device) glLineWidth(1.0f); glColor4f(1.0, 1.0, 1.0, 0.0); glViewport(0, 0, this->width, this->height); +#if !defined(HAVE_QT5_OPENGL) glDrawBuffer(GL_FRONT); +#endif return true; } @@ -110,7 +113,6 @@ bool GLPainter::end() glPopAttrib(); glPopMatrix(); - viewer->doneCurrent(); viewer = 0; return true; } diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index 3a2cc84319b1..e93ef5dbda39 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -65,6 +65,11 @@ #include #include +#if defined(HAVE_QT5_OPENGL) +#include +#include +#endif + #include #include #include @@ -136,7 +141,7 @@ 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 #if defined(HAVE_QT5_OPENGL) class CustomGLWidget : public QOpenGLWidget { @@ -147,9 +152,18 @@ class CustomGLWidget : public QOpenGLWidget { Q_UNUSED(shareWidget); QSurfaceFormat surfaceFormat(format); surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); + // With the settings below we could determine deprecated OpenGL API + // but can't do this since otherwise it will complain about almost any + // OpenGL call in Coin3d + //surfaceFormat.setMajorVersion(3); + //surfaceFormat.setMinorVersion(2); + //surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); +#if defined (_DEBUG) && 1 + surfaceFormat.setOption(QSurfaceFormat::DebugContext); +#endif setFormat(surfaceFormat); } - }; +}; #else class CustomGLWidget : public QGLWidget { public: @@ -804,7 +818,8 @@ void QuarterWidget::paintEvent(QPaintEvent* event) assert(w->isValid() && "No valid GL context found!"); #if defined(HAVE_QT5_OPENGL) - glDrawBuffer(w->format().swapBehavior() == QSurfaceFormat::DoubleBuffer ? GL_BACK : GL_FRONT); + // Causes an OpenGL error on resize + //glDrawBuffer(w->format().swapBehavior() == QSurfaceFormat::DoubleBuffer ? GL_BACK : GL_FRONT); #else glDrawBuffer(w->doubleBuffer() ? GL_BACK : GL_FRONT); #endif @@ -820,14 +835,13 @@ void QuarterWidget::paintEvent(QPaintEvent* event) glPopAttrib(); #if defined(HAVE_QT5_OPENGL) - if (w->format().swapBehavior() == QSurfaceFormat::DoubleBuffer) - w->context()->swapBuffers(w->context()->surface()); + // Causes an OpenGL error on resize + //if (w->format().swapBehavior() == QSurfaceFormat::DoubleBuffer) + // w->context()->swapBuffers(w->context()->surface()); #else if (w->doubleBuffer()) { w->swapBuffers(); } #endif - w->doneCurrent(); - PRIVATE(this)->autoredrawenabled = true; // process the delay queue the next time we enter this function, diff --git a/src/Gui/Thumbnail.cpp b/src/Gui/Thumbnail.cpp index 3626dd8ff5a5..feb52e035508 100644 --- a/src/Gui/Thumbnail.cpp +++ b/src/Gui/Thumbnail.cpp @@ -147,6 +147,5 @@ void Thumbnail::createThumbnailFromFramebuffer(QImage& img) const QtGLFramebufferObject fbo(this->size, this->size, format); this->viewer->renderToFramebuffer(&fbo); img = fbo.toImage(); - static_cast(this->viewer->getGLWidget())->doneCurrent(); } } diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 71a7c4f66572..ae5521c5cb6a 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -603,8 +603,6 @@ void View3DInventor::previewFromFramebuffer(const QRect& rect, QImage& img) _viewer->setBackgroundColor(col); _viewer->setGradientBackground(on); img = fbo.toImage(); - - static_cast(_viewer->getGLWidget())->doneCurrent(); } // ********************************************************************************** diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index a307d08f23e0..d61fc50afd67 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1351,7 +1351,6 @@ void View3DInventorViewer::setRenderType(const RenderType type) framebuffer = fbo; } #endif - gl->doneCurrent(); } break; case Image: @@ -1405,7 +1404,7 @@ QImage View3DInventorViewer::grabFramebuffer() res = fbo.toImage(false); } #endif - gl->doneCurrent(); + return res; } diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index f10ebffe93f5..7e8f2183a409 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -729,8 +729,6 @@ void View3DInventorPy::createImageFromFramebuffer(int width, int height, const Q viewer->setBackgroundColor(col); viewer->setGradientBackground(on); img = fbo.toImage(); - - static_cast(viewer->getGLWidget())->doneCurrent(); } Py::Object View3DInventorPy::saveImage(const Py::Tuple& args) diff --git a/src/Mod/Image/Gui/OpenGLImageBox.cpp b/src/Mod/Image/Gui/OpenGLImageBox.cpp index 7aeaa06ec8e3..a8fb1a23fa78 100644 --- a/src/Mod/Image/Gui/OpenGLImageBox.cpp +++ b/src/Mod/Image/Gui/OpenGLImageBox.cpp @@ -97,9 +97,8 @@ GLImageBox::GLImageBox(QWidget * parent, Qt::WindowFlags f) _pColorMap = 0; _numMapEntries = 0; -#ifdef _DEBUG +#if defined(_DEBUG) && 0 QSurfaceFormat format; - format.setProfile(QSurfaceFormat::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); this->setFormat(format); #endif @@ -132,19 +131,7 @@ void GLImageBox::initializeGL() haveMesa = (ver.find("Mesa") != std::string::npos); } -#if _DEBUG -#if 0 - QString ext = QString::fromLatin1((const char*)(glGetString(GL_EXTENSIONS))); - QStringList list = ext.split(QLatin1Char(' ')); - std::list extlist; - Q_FOREACH(QString it, list) { - extlist.push_back(it.toStdString()); - } - std::string glRenderer = (const char*)(glGetString(GL_RENDERER)); - std::string glVendor = (const char*)(glGetString(GL_VENDOR)); - std::string glVersion = (const char*)(glGetString(GL_VERSION)); -#endif - +#if defined(_DEBUG) && 0 QOpenGLContext *context = QOpenGLContext::currentContext(); if (context->hasExtension(QByteArrayLiteral("GL_KHR_debug"))) { QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);