Switch back to disable GL 4.5 by default, add support for logging when enabled

This commit is contained in:
Brad Davis 2016-05-31 13:28:39 -07:00
parent a41de3a60d
commit ab7fed1af8
4 changed files with 26 additions and 15 deletions

View file

@ -6,6 +6,14 @@
#include <QtOpenGL/QGL> #include <QtOpenGL/QGL>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QtCore/QRegularExpression> #include <QtCore/QRegularExpression>
#include <QtCore/QProcessEnvironment>
#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() { const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() {
static QSurfaceFormat format; static QSurfaceFormat format;
@ -15,9 +23,9 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() {
format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS); format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS);
format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS); format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS);
setGLFormatVersion(format); setGLFormatVersion(format);
#ifdef DEBUG if (enableDebug) {
format.setOption(QSurfaceFormat::DebugContext); format.setOption(QSurfaceFormat::DebugContext);
#endif }
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
}); });

View file

@ -12,23 +12,30 @@
#include "OffscreenGLCanvas.h" #include "OffscreenGLCanvas.h"
#include <QtCore/QProcessEnvironment>
#include <QtGui/QOffscreenSurface> #include <QtGui/QOffscreenSurface>
#include <QtGui/QOpenGLDebugLogger> #include <QtGui/QOpenGLDebugLogger>
#include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLContext>
#include "GLHelpers.h" #include "GLHelpers.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() : _context(new QOpenGLContext), _offscreenSurface(new QOffscreenSurface){
} }
OffscreenGLCanvas::~OffscreenGLCanvas() { OffscreenGLCanvas::~OffscreenGLCanvas() {
#ifdef DEBUG
if (_logger) { if (_logger) {
makeCurrent(); makeCurrent();
delete _logger; delete _logger;
_logger = nullptr; _logger = nullptr;
} }
#endif
_context->doneCurrent(); _context->doneCurrent();
} }
@ -60,7 +67,7 @@ bool OffscreenGLCanvas::makeCurrent() {
qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
}); });
#ifdef DEBUG
if (result && !_logger) { if (result && !_logger) {
_logger = new QOpenGLDebugLogger(this); _logger = new QOpenGLDebugLogger(this);
if (_logger->initialize()) { if (_logger->initialize()) {
@ -71,7 +78,6 @@ bool OffscreenGLCanvas::makeCurrent() {
_logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging); _logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging);
} }
} }
#endif
return result; return result;
} }

View file

@ -36,10 +36,7 @@ protected:
std::once_flag _reportOnce; std::once_flag _reportOnce;
QOpenGLContext* _context; QOpenGLContext* _context;
QOffscreenSurface* _offscreenSurface; QOffscreenSurface* _offscreenSurface;
#ifdef DEBUG
QOpenGLDebugLogger* _logger{ nullptr }; QOpenGLDebugLogger* _logger{ nullptr };
#endif
}; };
#endif // hifi_OffscreenGLCanvas_h #endif // hifi_OffscreenGLCanvas_h

View file

@ -32,19 +32,19 @@
using namespace gpu; using namespace gpu;
using namespace gpu::gl; using namespace gpu::gl;
static const QString DEBUG_FLAG("HIFI_DISABLE_OPENGL_45"); static const QString DEBUG_FLAG("HIFI_ENABLE_OPENGL_45");
bool disableOpenGL45 = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); static bool enableOpenGL45 = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG);
Backend* GLBackend::createBackend() { Backend* GLBackend::createBackend() {
// FIXME provide a mechanism to override the backend for testing // FIXME provide a mechanism to override the backend for testing
// Where the gpuContext is initialized and where the TRUE Backend is created and assigned // Where the gpuContext is initialized and where the TRUE Backend is created and assigned
auto version = QOpenGLContextWrapper::currentContextVersion(); auto version = QOpenGLContextWrapper::currentContextVersion();
GLBackend* result; GLBackend* result;
if (!disableOpenGL45 && version >= 0x0405) { if (enableOpenGL45 && version >= 0x0405) {
qDebug() << "OpenGL 4.5 detected"; qDebug() << "Using OpenGL 4.5 backend";
result = new gpu::gl45::GL45Backend(); result = new gpu::gl45::GL45Backend();
} else { } else {
qDebug() << "OpenGL 4.5 not detected / enabled, using compatibility backend"; qDebug() << "Using OpenGL 4.1 backend";
result = new gpu::gl41::GL41Backend(); result = new gpu::gl41::GL41Backend();
} }
result->initInput(); result->initInput();