diff --git a/krita/main.cc b/krita/main.cc --- a/krita/main.cc +++ b/krita/main.cc @@ -115,7 +115,6 @@ key = key.replace(":", "_").replace("\\","_"); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); - KisOpenGL::setDefaultFormat(); QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); @@ -123,18 +122,28 @@ const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); bool singleApplication = true; -#if QT_VERSION >= 0x050600 + bool enableOpenGLDebug = false; { QSettings kritarc(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat); singleApplication = kritarc.value("EnableSingleApplication").toBool(); +#if QT_VERSION >= 0x050600 if (kritarc.value("EnableHiDPI", false).toBool()) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); } if (!qgetenv("KRITA_HIDPI").isEmpty()) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); } - } #endif + if (!qgetenv("KRITA_OPENGL_DEBUG").isEmpty()) { + enableOpenGLDebug = true; + } else { + enableOpenGLDebug = kritarc.value("EnableOpenGLDebug", false).toBool(); + } + if (enableOpenGLDebug && (qgetenv("KRITA_OPENGL_DEBUG") == "sync" || kritarc.value("OpenGLDebugSynchronous", false).toBool())) { + KisOpenGL::setDebugSynchronous(true); + } + } + KisOpenGL::setDefaultFormat(enableOpenGLDebug); KLocalizedString::setApplicationDomain("krita"); diff --git a/libs/ui/opengl/kis_opengl.h b/libs/ui/opengl/kis_opengl.h --- a/libs/ui/opengl/kis_opengl.h +++ b/libs/ui/opengl/kis_opengl.h @@ -72,7 +72,9 @@ */ static bool needsPixmapCacheWorkaround(); - static void setDefaultFormat(); + static void setDefaultFormat(bool enableDebug = false); + + static void setDebugSynchronous(bool isSynchronous); private: diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cpp --- a/libs/ui/opengl/kis_opengl.cpp +++ b/libs/ui/opengl/kis_opengl.cpp @@ -19,6 +19,7 @@ #include "opengl/kis_opengl.h" #include +#include #include #include @@ -39,6 +40,8 @@ namespace { bool defaultFormatIsSet = false; + bool isDebugEnabled = false; + bool isDebugSynchronous = false; bool initialized = false; bool NeedsFenceWorkaround = false; bool NeedsPixmapCacheWorkaround = false; @@ -47,6 +50,10 @@ bool supportsDeprecatedFunctions = false; QString Renderer; + + void openglOnMessageLogged(const QOpenGLDebugMessage& debugMessage) { + qDebug() << "OpenGL:" << debugMessage; + } } void KisOpenGL::initialize() @@ -115,6 +122,21 @@ initialize(); dbgUI << "OpenGL: Opening new context"; + if (isDebugEnabled) { + // Passing ctx for ownership management only, not specifying context. + // QOpenGLDebugLogger only function on the current active context. + // FIXME: Do we need to make sure ctx is the active context? + QOpenGLDebugLogger* openglLogger = new QOpenGLDebugLogger(ctx); + if (openglLogger->initialize()) { + qDebug() << "QOpenGLDebugLogger is initialized. Check whether you get a message below."; + QObject::connect(openglLogger, &QOpenGLDebugLogger::messageLogged, &openglOnMessageLogged); + openglLogger->startLogging(isDebugSynchronous ? QOpenGLDebugLogger::SynchronousLogging : QOpenGLDebugLogger::AsynchronousLogging); + openglLogger->logMessage(QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("QOpenGLDebugLogger is logging."))); + } else { + qDebug() << "QOpenGLDebugLogger cannot be initialized."; + delete openglLogger; + } + } // Double check we were given the version we requested QSurfaceFormat format = ctx->format(); @@ -203,7 +225,7 @@ return NeedsPixmapCacheWorkaround; } -void KisOpenGL::setDefaultFormat() +void KisOpenGL::setDefaultFormat(bool enableDebug) { if (defaultFormatIsSet) { return; @@ -223,9 +245,19 @@ format.setStencilBufferSize(8); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSwapInterval(0); // Disable vertical refresh syncing + isDebugEnabled = enableDebug; + if (enableDebug) { + format.setOption(QSurfaceFormat::DebugContext, true); + qDebug() << "QOpenGLDebugLogger will be enabled"; + } QSurfaceFormat::setDefaultFormat(format); } +void KisOpenGL::setDebugSynchronous(bool isSynchronous) +{ + isDebugSynchronous = isSynchronous; +} + bool KisOpenGL::hasOpenGL() { return ((glMajorVersion * 100 + glMinorVersion) >= 201);