Skip to content

Commit

Permalink
Qt5OpenGL: use OpenGL debug logger to locate problems, fix a couple o…
Browse files Browse the repository at this point in the history
…f errors
  • Loading branch information
wwmayer committed Mar 21, 2017
1 parent 2c6f1fd commit 3ac834c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/Gui/Flag.cpp
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Gui/GLPainter.cpp
Expand Up @@ -61,6 +61,7 @@ bool GLPainter::begin(QPaintDevice * device)

glMatrixMode(GL_PROJECTION);
glPushMatrix();

glLoadIdentity();
glOrtho(0, this->width, 0, this->height, -1, 1);

Expand All @@ -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;
}
Expand Down Expand Up @@ -110,7 +113,6 @@ bool GLPainter::end()
glPopAttrib();
glPopMatrix();

viewer->doneCurrent();
viewer = 0;
return true;
}
Expand Down
28 changes: 21 additions & 7 deletions src/Gui/Quarter/QuarterWidget.cpp
Expand Up @@ -65,6 +65,11 @@
#include <QPaintEvent>
#include <QResizeEvent>

#if defined(HAVE_QT5_OPENGL)
#include <QOpenGLDebugMessage>
#include <QOpenGLDebugLogger>
#endif

#include <Inventor/SbViewportRegion.h>
#include <Inventor/system/gl.h>
#include <Inventor/events/SoEvents.h>
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/Gui/Thumbnail.cpp
Expand Up @@ -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<QtGLWidget*>(this->viewer->getGLWidget())->doneCurrent();
}
}
2 changes: 0 additions & 2 deletions src/Gui/View3DInventor.cpp
Expand Up @@ -603,8 +603,6 @@ void View3DInventor::previewFromFramebuffer(const QRect& rect, QImage& img)
_viewer->setBackgroundColor(col);
_viewer->setGradientBackground(on);
img = fbo.toImage();

static_cast<QtGLWidget*>(_viewer->getGLWidget())->doneCurrent();
}

// **********************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -1351,7 +1351,6 @@ void View3DInventorViewer::setRenderType(const RenderType type)
framebuffer = fbo;
}
#endif
gl->doneCurrent();
}
break;
case Image:
Expand Down Expand Up @@ -1405,7 +1404,7 @@ QImage View3DInventorViewer::grabFramebuffer()
res = fbo.toImage(false);
}
#endif
gl->doneCurrent();

return res;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Gui/View3DPy.cpp
Expand Up @@ -729,8 +729,6 @@ void View3DInventorPy::createImageFromFramebuffer(int width, int height, const Q
viewer->setBackgroundColor(col);
viewer->setGradientBackground(on);
img = fbo.toImage();

static_cast<QtGLWidget*>(viewer->getGLWidget())->doneCurrent();
}

Py::Object View3DInventorPy::saveImage(const Py::Tuple& args)
Expand Down
17 changes: 2 additions & 15 deletions src/Mod/Image/Gui/OpenGLImageBox.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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<std::string> 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);
Expand Down

0 comments on commit 3ac834c

Please sign in to comment.