From 479b9a9f2bd67baba25246a09343a3c4b1d5ba61 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 5 Aug 2016 16:31:44 -0700 Subject: [PATCH] Cleanup GL helpers and debug logging --- libraries/gl/src/gl/GLHelpers.cpp | 43 ++++++++++++++----- libraries/gl/src/gl/GLHelpers.h | 11 +++++ libraries/gl/src/gl/GLWindow.cpp | 2 +- libraries/gl/src/gl/OffscreenGLCanvas.cpp | 30 +------------ libraries/gl/src/gl/OffscreenGLCanvas.h | 1 - .../gl/src/gl/QOpenGLDebugLoggerWrapper.cpp | 29 ------------- .../gl/src/gl/QOpenGLDebugLoggerWrapper.h | 25 ----------- 7 files changed, 47 insertions(+), 94 deletions(-) delete mode 100644 libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.cpp delete mode 100644 libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.h diff --git a/libraries/gl/src/gl/GLHelpers.cpp b/libraries/gl/src/gl/GLHelpers.cpp index d5d52bdd74..633c4ef0eb 100644 --- a/libraries/gl/src/gl/GLHelpers.cpp +++ b/libraries/gl/src/gl/GLHelpers.cpp @@ -2,20 +2,16 @@ #include +#include #include #include #include + #include +#include +#include + #include -#include - -#ifdef DEBUG -static bool enableDebug = true; -#else -static const QString DEBUG_FLAG("HIFI_ENABLE_OPENGL_45"); -static bool enableDebug = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); -#endif - const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { static QSurfaceFormat format; @@ -25,7 +21,8 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS); format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS); setGLFormatVersion(format); - if (enableDebug) { + if (GLDebug::enabled()) { + qDebug() << "Enabling debug context"; format.setOption(QSurfaceFormat::DebugContext); } format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); @@ -81,3 +78,29 @@ bool isRenderThread() { return QThread::currentThread() == RENDER_THREAD; } + +#ifdef DEBUG +static bool enableDebugLogger = true; +#else +static const QString DEBUG_FLAG("HIFI_DEBUG_OPENGL"); +static bool enableDebugLogger = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); +#endif + +bool GLDebug::enabled() { + return enableDebugLogger; +} + +void GLDebug::log(const QOpenGLDebugMessage & debugMessage) { + qDebug() << debugMessage; +} + +void GLDebug::setupLogger(QObject* window) { + if (enabled()) { + QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(window); + logger->initialize(); // initializes in the current context, i.e. ctx + logger->enableMessages(); + QObject::connect(logger, &QOpenGLDebugLogger::messageLogged, window, [&](const QOpenGLDebugMessage & debugMessage) { + GLDebug::log(debugMessage); + }); + } +} \ No newline at end of file diff --git a/libraries/gl/src/gl/GLHelpers.h b/libraries/gl/src/gl/GLHelpers.h index b73e7803c9..9e185f5845 100644 --- a/libraries/gl/src/gl/GLHelpers.h +++ b/libraries/gl/src/gl/GLHelpers.h @@ -18,6 +18,8 @@ // but GL implementations usually just come with buffer sizes in multiples of 8) #define DEFAULT_GL_STENCIL_BUFFER_BITS 8 +class QObject; +class QOpenGLDebugMessage; class QSurfaceFormat; class QGLFormat; @@ -31,4 +33,13 @@ int glVersionToInteger(QString glVersion); bool isRenderThread(); + +class GLDebug { +public: + static bool enabled(); + static void log(const QOpenGLDebugMessage& debugMessage); + static void setupLogger(QObject* window = nullptr); +}; + + #endif diff --git a/libraries/gl/src/gl/GLWindow.cpp b/libraries/gl/src/gl/GLWindow.cpp index 78c7666d25..e553290a04 100644 --- a/libraries/gl/src/gl/GLWindow.cpp +++ b/libraries/gl/src/gl/GLWindow.cpp @@ -8,8 +8,8 @@ #include "GLWindow.h" +#include #include -#include #include "GLHelpers.h" diff --git a/libraries/gl/src/gl/OffscreenGLCanvas.cpp b/libraries/gl/src/gl/OffscreenGLCanvas.cpp index 672d481d4e..468818d736 100644 --- a/libraries/gl/src/gl/OffscreenGLCanvas.cpp +++ b/libraries/gl/src/gl/OffscreenGLCanvas.cpp @@ -13,31 +13,16 @@ #include "OffscreenGLCanvas.h" #include +#include #include -#include #include #include "GLHelpers.h" -#include "QOpenGLDebugLoggerWrapper.h" - -#ifdef DEBUG -static bool enableDebugLogger = true; -#else -static const QString DEBUG_FLAG("HIFI_ENABLE_OPENGL_45"); -static bool enableDebugLogger = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); -#endif - OffscreenGLCanvas::OffscreenGLCanvas() : _context(new QOpenGLContext), _offscreenSurface(new QOffscreenSurface){ } OffscreenGLCanvas::~OffscreenGLCanvas() { - if (_logger) { - makeCurrent(); - delete _logger; - _logger = nullptr; - } - _context->doneCurrent(); delete _context; _context = nullptr; @@ -76,18 +61,7 @@ bool OffscreenGLCanvas::makeCurrent() { qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); }); - - if (result && !_logger) { - _logger = new QOpenGLDebugLogger(this); - if (_logger->initialize()) { - connect(_logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message) { - OpenGLDebug::log(message); - }); - _logger->disableMessages(QOpenGLDebugMessage::AnySource, QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity); - _logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging); - } - } - + GLDebug::setupLogger(this); return result; } diff --git a/libraries/gl/src/gl/OffscreenGLCanvas.h b/libraries/gl/src/gl/OffscreenGLCanvas.h index 8def09796d..583aa7c60f 100644 --- a/libraries/gl/src/gl/OffscreenGLCanvas.h +++ b/libraries/gl/src/gl/OffscreenGLCanvas.h @@ -36,7 +36,6 @@ protected: std::once_flag _reportOnce; QOpenGLContext* _context{ nullptr }; QOffscreenSurface* _offscreenSurface{ nullptr }; - QOpenGLDebugLogger* _logger{ nullptr }; }; #endif // hifi_OffscreenGLCanvas_h diff --git a/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.cpp b/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.cpp deleted file mode 100644 index 2a351ead7e..0000000000 --- a/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// QOpenGLDebugLoggerWrapper.cpp -// -// -// Created by Clement on 12/4/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "QOpenGLDebugLoggerWrapper.h" - -#include -#include - -void OpenGLDebug::log(const QOpenGLDebugMessage & debugMessage) { - qDebug() << debugMessage; -} - -void setupDebugLogger(QObject* window) { - QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(window); - logger->initialize(); // initializes in the current context, i.e. ctx - logger->enableMessages(); - QObject::connect(logger, &QOpenGLDebugLogger::messageLogged, window, [&](const QOpenGLDebugMessage & debugMessage) { - OpenGLDebug::log(debugMessage); - - }); -} \ No newline at end of file diff --git a/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.h b/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.h deleted file mode 100644 index 2a378a712a..0000000000 --- a/libraries/gl/src/gl/QOpenGLDebugLoggerWrapper.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// QOpenGLDebugLoggerWrapper.h -// -// -// Created by Clement on 12/4/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_QOpenGLDebugLoggerWrapper_h -#define hifi_QOpenGLDebugLoggerWrapper_h - -class QObject; -class QOpenGLDebugMessage; - -void setupDebugLogger(QObject* window); - -class OpenGLDebug { -public: - static void log(const QOpenGLDebugMessage & debugMessage); -}; - -#endif // hifi_QOpenGLDebugLoggerWrapper_h \ No newline at end of file