mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 03:53:52 +02:00
Cleanup GL helpers and debug logging
This commit is contained in:
parent
619158b6f2
commit
479b9a9f2b
7 changed files with 47 additions and 94 deletions
|
@ -2,20 +2,16 @@
|
|||
|
||||
#include <mutex>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtCore/QProcessEnvironment>
|
||||
|
||||
#include <QtGui/QSurfaceFormat>
|
||||
#include <QtGui/QOpenGLContext>
|
||||
#include <QtGui/QOpenGLDebugLogger>
|
||||
|
||||
#include <QtOpenGL/QGL>
|
||||
#include <QOpenGLContext>
|
||||
|
||||
#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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include "GLWindow.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QOpenGLContext>
|
||||
#include <QtGui/QOpenGLDebugLogger>
|
||||
|
||||
#include "GLHelpers.h"
|
||||
|
||||
|
|
|
@ -13,31 +13,16 @@
|
|||
#include "OffscreenGLCanvas.h"
|
||||
|
||||
#include <QtCore/QProcessEnvironment>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QOffscreenSurface>
|
||||
#include <QtGui/QOpenGLDebugLogger>
|
||||
#include <QtGui/QOpenGLContext>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ protected:
|
|||
std::once_flag _reportOnce;
|
||||
QOpenGLContext* _context{ nullptr };
|
||||
QOffscreenSurface* _offscreenSurface{ nullptr };
|
||||
QOpenGLDebugLogger* _logger{ nullptr };
|
||||
};
|
||||
|
||||
#endif // hifi_OffscreenGLCanvas_h
|
||||
|
|
|
@ -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 <QObject>
|
||||
#include <QOpenGLDebugLogger>
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
}
|
|
@ -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
|
Loading…
Reference in a new issue