From 528a17422d4d32b29915191b71417375272d9e90 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 10:33:10 -0800 Subject: [PATCH] Last of the OpenGL warnings on OS X --- .../src/QOpenGLContextWrapper.cpp | 40 +++++++++++++++++++ .../render-utils/src/QOpenGLContextWrapper.h | 33 +++++++++++++++ .../src/QOpenGLDebugLoggerWrapper.cpp | 24 +++++++++++ .../src/QOpenGLDebugLoggerWrapper.h | 19 +++++++++ tests/gpu-test/src/main.cpp | 24 ++++------- tests/render-utils/src/main.cpp | 25 ++++-------- tests/shaders/src/main.cpp | 25 +++++------- 7 files changed, 141 insertions(+), 49 deletions(-) create mode 100644 libraries/render-utils/src/QOpenGLContextWrapper.cpp create mode 100644 libraries/render-utils/src/QOpenGLContextWrapper.h create mode 100644 libraries/render-utils/src/QOpenGLDebugLoggerWrapper.cpp create mode 100644 libraries/render-utils/src/QOpenGLDebugLoggerWrapper.h diff --git a/libraries/render-utils/src/QOpenGLContextWrapper.cpp b/libraries/render-utils/src/QOpenGLContextWrapper.cpp new file mode 100644 index 0000000000..64233ea413 --- /dev/null +++ b/libraries/render-utils/src/QOpenGLContextWrapper.cpp @@ -0,0 +1,40 @@ +// +// QOpenGLContextWrapper.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 "QOpenGLContextWrapper.h" + +#include + + +QOpenGLContextWrapper::QOpenGLContextWrapper() : + _context(new QOpenGLContext) +{ +} + +void QOpenGLContextWrapper::setFormat(const QSurfaceFormat& format) { + _context->setFormat(format); +} + +bool QOpenGLContextWrapper::create() { + return _context->create(); +} + +void QOpenGLContextWrapper::swapBuffers(QSurface* surface) { + _context->swapBuffers(surface); +} + +bool QOpenGLContextWrapper::makeCurrent(QSurface* surface) { + return _context->makeCurrent(surface); +} + +void QOpenGLContextWrapper::doneCurrent() { + _context->doneCurrent(); +} \ No newline at end of file diff --git a/libraries/render-utils/src/QOpenGLContextWrapper.h b/libraries/render-utils/src/QOpenGLContextWrapper.h new file mode 100644 index 0000000000..6c50d5f438 --- /dev/null +++ b/libraries/render-utils/src/QOpenGLContextWrapper.h @@ -0,0 +1,33 @@ +// +// QOpenGLContextWrapper.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_QOpenGLContextWrapper_h +#define hifi_QOpenGLContextWrapper_h + +class QOpenGLContext; +class QSurface; +class QSurfaceFormat; + +class QOpenGLContextWrapper { +public: + QOpenGLContextWrapper(); + + void setFormat(const QSurfaceFormat& format); + bool create(); + void swapBuffers(QSurface* surface); + bool makeCurrent(QSurface* surface); + void doneCurrent(); + +private: + QOpenGLContext* _context { nullptr }; +}; + +#endif // hifi_QOpenGLContextWrapper_h \ No newline at end of file diff --git a/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.cpp b/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.cpp new file mode 100644 index 0000000000..bd185034f4 --- /dev/null +++ b/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.cpp @@ -0,0 +1,24 @@ +// +// 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 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) { + qDebug() << debugMessage; + }); +} \ No newline at end of file diff --git a/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.h b/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.h new file mode 100644 index 0000000000..e2b1c5d9d4 --- /dev/null +++ b/libraries/render-utils/src/QOpenGLDebugLoggerWrapper.h @@ -0,0 +1,19 @@ +// +// 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; + +void setupDebugLogger(QObject* window); + +#endif // hifi_QOpenGLDebugLoggerWrapper_h \ No newline at end of file diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 80c2dbf8e9..fbfb49aace 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -33,9 +33,8 @@ #include #include -// Must come after GL headers -#include -#include +#include +#include #include #include @@ -118,7 +117,7 @@ gpu::Stream::FormatPointer& getInstancedSolidStreamFormat(); class QTestWindow : public QWindow { Q_OBJECT - QOpenGLContext* _qGlContext{ nullptr }; + QOpenGLContextWrapper _qGlContext; QSize _size; gpu::ContextPointer _context; @@ -151,19 +150,12 @@ public: setFormat(format); - _qGlContext = new QOpenGLContext; - _qGlContext->setFormat(format); - _qGlContext->create(); + _qGlContext.setFormat(format); + _qGlContext.create(); show(); makeCurrent(); - QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); - logger->initialize(); // initializes in the current context, i.e. ctx - connect(logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message){ - qDebug() << message; - }); - logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); - + setupDebugLogger(this); gpu::Context::init(); _context = std::make_shared(); @@ -371,7 +363,7 @@ public: geometryCache->renderWireCube(batch); _context->render(batch); - _qGlContext->swapBuffers(this); + _qGlContext.swapBuffers(this); fps.increment(); if (fps.elapsed() >= 0.5f) { @@ -381,7 +373,7 @@ public: } void makeCurrent() { - _qGlContext->makeCurrent(this); + _qGlContext.makeCurrent(this); } protected: diff --git a/tests/render-utils/src/main.cpp b/tests/render-utils/src/main.cpp index 0fa261db8d..43778c5c56 100644 --- a/tests/render-utils/src/main.cpp +++ b/tests/render-utils/src/main.cpp @@ -14,8 +14,8 @@ #include -#include -#include +#include +#include #include #include @@ -77,7 +77,7 @@ const QString& getQmlDir() { class QTestWindow : public QWindow { Q_OBJECT - QOpenGLContext* _context{ nullptr }; + QOpenGLContextWrapper _context; QSize _size; //TextRenderer* _textRenderer[4]; RateCounter fps; @@ -104,9 +104,8 @@ public: setFormat(format); - _context = new QOpenGLContext; - _context->setFormat(format); - _context->create(); + _context.setFormat(format); + _context.create(); show(); makeCurrent(); @@ -114,15 +113,7 @@ public: gpu::Context::init(); - { - QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); - logger->initialize(); // initializes in the current context, i.e. ctx - logger->enableMessages(); - connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { - qDebug() << debugMessage; - }); - // logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); - } + setupDebugLogger(this); qDebug() << (const char*)glGetString(GL_VERSION); //_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); @@ -147,7 +138,7 @@ public: void draw(); void makeCurrent() { - _context->makeCurrent(this); + _context.makeCurrent(this); } protected: @@ -185,7 +176,7 @@ void QTestWindow::draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio()); - _context->swapBuffers(this); + _context.swapBuffers(this); glFinish(); fps.increment(); diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index f65cd9b5aa..658bc9c236 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -10,8 +10,6 @@ #include -#include - #include #include #include @@ -22,6 +20,9 @@ #include +#include +#include + #include "../model/Skybox_vert.h" #include "../model/Skybox_frag.h" @@ -120,7 +121,7 @@ // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { Q_OBJECT - QOpenGLContext* _context{ nullptr }; + QOpenGLContextWrapper _context; protected: void renderText(); @@ -130,22 +131,14 @@ public: setSurfaceType(QSurface::OpenGLSurface); QSurfaceFormat format = getDefaultOpenGLSurfaceFormat(); setFormat(format); - _context = new QOpenGLContext; - _context->setFormat(format); - _context->create(); + _context.setFormat(format); + _context.create(); show(); makeCurrent(); gpu::Context::init(); - { - QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); - logger->initialize(); // initializes in the current context, i.e. ctx - logger->enableMessages(); - connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { - qDebug() << debugMessage; - }); - } + setupDebugLogger(this); makeCurrent(); resize(QSize(800, 600)); } @@ -155,7 +148,7 @@ public: void draw(); void makeCurrent() { - _context->makeCurrent(this); + _context.makeCurrent(this); } }; @@ -248,7 +241,7 @@ void QTestWindow::draw() { testShaderBuild(polyvox_vert, polyvox_frag); }); - _context->swapBuffers(this); + _context.swapBuffers(this); } void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {