From 92a588b0603af4811082f609f192f4fcea68465c Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 6 Mar 2016 10:48:34 +0100 Subject: [PATCH] OpenGL modernization: GLScope: enhance openGL context checking and debugging at initializeGL time --- include/gui/glshadersimple.h | 1 + sdrbase/gui/glscope.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/gui/glshadersimple.h b/include/gui/glshadersimple.h index 65b370f5f..633f621f8 100644 --- a/include/gui/glshadersimple.h +++ b/include/gui/glshadersimple.h @@ -19,6 +19,7 @@ #define INCLUDE_GUI_GLSHADERSIMPLE_H_ #include +#include class QOpenGLShaderProgram; class QMatrix4x4; diff --git a/sdrbase/gui/glscope.cpp b/sdrbase/gui/glscope.cpp index a928d2aab..4c13a93c0 100644 --- a/sdrbase/gui/glscope.cpp +++ b/sdrbase/gui/glscope.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "gui/glscope.h" #include "dsp/dspengine.h" @@ -239,6 +240,7 @@ void GLScope::newTrace(const std::vector& trace, int sampleRate) void GLScope::initializeGL() { QOpenGLContext *glCurrentContext = QOpenGLContext::currentContext(); + //QOpenGLContext *glCurrentContext = context(); if (glCurrentContext) { if (QOpenGLContext::currentContext()->isValid()) { @@ -255,6 +257,28 @@ void GLScope::initializeGL() return; } + QSurface *surface = glCurrentContext->surface(); + + if (surface == 0) + { + qCritical() << "GLScope::initializeGL: no surface attached"; + return; + } + else + { + if (surface->surfaceType() != QSurface::OpenGLSurface) + { + qCritical() << "GLScope::initializeGL: surface is not an OpenGLSurface: " << surface->surfaceType() + << " cannot use an OpenGL context"; + return; + } + else + { + qDebug() << "GLScope::initializeGL: OpenGL surface:" + << " class: " << (surface->surfaceClass() == QSurface::Window ? "Window" : "Offscreen"); + } + } + connect(glCurrentContext, &QOpenGLContext::aboutToBeDestroyed, this, &GLScope::cleanup); // TODO: when migrating to QOpenGLWidget QOpenGLFunctions *glFunctions = QOpenGLContext::currentContext()->functions(); @@ -2825,12 +2849,12 @@ void GLScope::connectTimer(const QTimer& timer) void GLScope::cleanup() { - makeCurrent(); + //makeCurrent(); m_glShaderSimple.cleanup(); m_glShaderBottom1Scale.cleanup(); m_glShaderBottom2Scale.cleanup(); m_glShaderLeft1Scale.cleanup(); m_glShaderPowerOverlay.cleanup(); - doneCurrent(); + //doneCurrent(); }