From af3d842e6096c3ecd9da8ea2964b5882852cb79e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 28 Jan 2016 15:22:42 +1300 Subject: [PATCH 1/4] Warn user if OpenGL version is too low (< 4.1) --- interface/src/OpenGLInfo.cpp | 60 ++++++++++++++++++++++++++++++++++++ interface/src/OpenGLInfo.h | 25 +++++++++++++++ interface/src/main.cpp | 13 ++++++++ 3 files changed, 98 insertions(+) create mode 100644 interface/src/OpenGLInfo.cpp create mode 100644 interface/src/OpenGLInfo.h diff --git a/interface/src/OpenGLInfo.cpp b/interface/src/OpenGLInfo.cpp new file mode 100644 index 0000000000..b61863c1bf --- /dev/null +++ b/interface/src/OpenGLInfo.cpp @@ -0,0 +1,60 @@ +// +// OpenGLInfo.cpp +// interface/src +// +// Created by David Rowe on 28 Jan 2016. +// Copyright 2016 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 "OpenGLInfo.h" + +#include +#include + +#include "GLCanvas.h" + +OpenGLInfo::OpenGLInfo(int& argc, char** argv) : + QApplication(argc, argv) +{ +} + +bool OpenGLInfo::isValidVersion() { + bool valid = true; + + // Retrieve OpenGL version + GLCanvas* glCanvas = new GLCanvas(); + glCanvas->initializeGL(); + QString glVersion = QString((const char*)glGetString(GL_VERSION)); + delete glCanvas; + + // Compare against minimum + // The GL_VERSION string begins with a version number in one of these forms: + // - major_number.minor_number + // - major_number.minor_number.release_number + // Reference: https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glGetString.xml + const int MINIMUM_OPENGL_MAJOR_VERSION = 4; + const int MINIMUM_OPENGL_MINOR_VERSION = 1; + QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); + int majorNumber = versionParts[0].toInt(); + int minorNumber = versionParts[1].toInt(); + valid = (majorNumber > MINIMUM_OPENGL_MAJOR_VERSION + || (majorNumber == MINIMUM_OPENGL_MAJOR_VERSION && minorNumber >= MINIMUM_OPENGL_MINOR_VERSION)); + + // Prompt user if below minimum + if (!valid) { + QMessageBox messageBox; + messageBox.setWindowTitle("OpenGL Version Too Low"); + messageBox.setIcon(QMessageBox::Warning); + messageBox.setText(QString().sprintf("Your OpenGL version of %i.%i is lower than the minimum of %i.%i.", + majorNumber, minorNumber, MINIMUM_OPENGL_MAJOR_VERSION, MINIMUM_OPENGL_MINOR_VERSION)); + messageBox.setInformativeText("Press OK to exit; Ignore to continue."); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Ignore); + messageBox.setDefaultButton(QMessageBox::Ok); + valid = messageBox.exec() == QMessageBox::Ignore; + } + + return valid; +} diff --git a/interface/src/OpenGLInfo.h b/interface/src/OpenGLInfo.h new file mode 100644 index 0000000000..8df44c72b1 --- /dev/null +++ b/interface/src/OpenGLInfo.h @@ -0,0 +1,25 @@ +// +// OpenGLInfo.h +// interface/src +// +// Created by David Rowe on 28 Jan 2016. +// Copyright 2016 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_OpenGLInfo_h +#define hifi_OpenGLInfo_h + +#include + +class OpenGLInfo : public QApplication { + +public: + OpenGLInfo(int& argc, char** argv); + + static bool isValidVersion(); +}; + +#endif // hifi_OpenGLInfo_h diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 15da88023b..db02994a19 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -22,6 +22,7 @@ #include "AddressManager.h" #include "Application.h" #include "InterfaceLogging.h" +#include "OpenGLInfo.h" #include "MainWindow.h" int main(int argc, const char* argv[]) { @@ -83,6 +84,17 @@ int main(int argc, const char* argv[]) { #endif } + // Check OpenGL version. + // This is done separately from the main Application so that start-up and shut-down logic within the main Application is + // not made more complicated than it already is. + { + OpenGLInfo openGLInfo(argc, const_cast(argv)); + if (!openGLInfo.isValidVersion()) { + qCDebug(interfaceapp, "Early exit due to OpenGL version."); + return 0; + } + } + QElapsedTimer startupTime; startupTime.start(); @@ -96,6 +108,7 @@ int main(int argc, const char* argv[]) { usecTimestampNowForceClockSkew(clockSkew); qCDebug(interfaceapp, "clockSkewOption=%s clockSkew=%d", clockSkewOption, clockSkew); } + // Oculus initialization MUST PRECEDE OpenGL context creation. // The nature of the Application constructor means this has to be either here, // or in the main window ctor, before GL startup. From b7134c75c390a89b57616aaaf6ef0f97b020cbbb Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 29 Jan 2016 12:14:47 +1300 Subject: [PATCH 2/4] Rename OpenGLInfo to OpenGLVersionChecker --- .../src/{OpenGLInfo.cpp => OpenGLVersionChecker.cpp} | 8 ++++---- .../src/{OpenGLInfo.h => OpenGLVersionChecker.h} | 12 ++++++------ interface/src/main.cpp | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) rename interface/src/{OpenGLInfo.cpp => OpenGLVersionChecker.cpp} (91%) rename interface/src/{OpenGLInfo.h => OpenGLVersionChecker.h} (58%) diff --git a/interface/src/OpenGLInfo.cpp b/interface/src/OpenGLVersionChecker.cpp similarity index 91% rename from interface/src/OpenGLInfo.cpp rename to interface/src/OpenGLVersionChecker.cpp index b61863c1bf..d509d6aaab 100644 --- a/interface/src/OpenGLInfo.cpp +++ b/interface/src/OpenGLVersionChecker.cpp @@ -1,5 +1,5 @@ // -// OpenGLInfo.cpp +// OpenGLVersionChecker.cpp // interface/src // // Created by David Rowe on 28 Jan 2016. @@ -9,19 +9,19 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "OpenGLInfo.h" +#include "OpenGLVersionChecker.h" #include #include #include "GLCanvas.h" -OpenGLInfo::OpenGLInfo(int& argc, char** argv) : +OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) { } -bool OpenGLInfo::isValidVersion() { +bool OpenGLVersionChecker::isValidVersion() { bool valid = true; // Retrieve OpenGL version diff --git a/interface/src/OpenGLInfo.h b/interface/src/OpenGLVersionChecker.h similarity index 58% rename from interface/src/OpenGLInfo.h rename to interface/src/OpenGLVersionChecker.h index 8df44c72b1..a46020031c 100644 --- a/interface/src/OpenGLInfo.h +++ b/interface/src/OpenGLVersionChecker.h @@ -1,5 +1,5 @@ // -// OpenGLInfo.h +// OpenGLVersionChecker.h // interface/src // // Created by David Rowe on 28 Jan 2016. @@ -9,17 +9,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_OpenGLInfo_h -#define hifi_OpenGLInfo_h +#ifndef hifi_OpenGLVersionChecker_h +#define hifi_OpenGLVersionChecker_h #include -class OpenGLInfo : public QApplication { +class OpenGLVersionChecker : public QApplication { public: - OpenGLInfo(int& argc, char** argv); + OpenGLVersionChecker(int& argc, char** argv); static bool isValidVersion(); }; -#endif // hifi_OpenGLInfo_h +#endif // hifi_OpenGLVersionChecker_h diff --git a/interface/src/main.cpp b/interface/src/main.cpp index db02994a19..745bf94b8c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -22,7 +22,7 @@ #include "AddressManager.h" #include "Application.h" #include "InterfaceLogging.h" -#include "OpenGLInfo.h" +#include "OpenGLVersionChecker.h" #include "MainWindow.h" int main(int argc, const char* argv[]) { @@ -88,8 +88,8 @@ int main(int argc, const char* argv[]) { // This is done separately from the main Application so that start-up and shut-down logic within the main Application is // not made more complicated than it already is. { - OpenGLInfo openGLInfo(argc, const_cast(argv)); - if (!openGLInfo.isValidVersion()) { + OpenGLVersionChecker openGLVersionChecker(argc, const_cast(argv)); + if (!openGLVersionChecker.isValidVersion()) { qCDebug(interfaceapp, "Early exit due to OpenGL version."); return 0; } From 20205149745452043015078c2bdad78ee6722b5b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 29 Jan 2016 12:29:21 +1300 Subject: [PATCH 3/4] Move OpenGLVersionChecker to gl library --- interface/src/main.cpp | 2 +- .../gl/src/gl}/OpenGLVersionChecker.cpp | 10 +++++----- .../src => libraries/gl/src/gl}/OpenGLVersionChecker.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename {interface/src => libraries/gl/src/gl}/OpenGLVersionChecker.cpp (93%) rename {interface/src => libraries/gl/src/gl}/OpenGLVersionChecker.h (95%) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 745bf94b8c..a57e53b384 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -17,12 +17,12 @@ #include #include +#include #include #include "AddressManager.h" #include "Application.h" #include "InterfaceLogging.h" -#include "OpenGLVersionChecker.h" #include "MainWindow.h" int main(int argc, const char* argv[]) { diff --git a/interface/src/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp similarity index 93% rename from interface/src/OpenGLVersionChecker.cpp rename to libraries/gl/src/gl/OpenGLVersionChecker.cpp index d509d6aaab..f1a40bde8d 100644 --- a/interface/src/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -1,6 +1,6 @@ // // OpenGLVersionChecker.cpp -// interface/src +// libraries/gl/src/gl // // Created by David Rowe on 28 Jan 2016. // Copyright 2016 High Fidelity, Inc. @@ -14,7 +14,7 @@ #include #include -#include "GLCanvas.h" +#include "GLWidget.h" OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) @@ -25,10 +25,10 @@ bool OpenGLVersionChecker::isValidVersion() { bool valid = true; // Retrieve OpenGL version - GLCanvas* glCanvas = new GLCanvas(); - glCanvas->initializeGL(); + GLWidget* glWidget = new GLWidget(); + glWidget->initializeGL(); QString glVersion = QString((const char*)glGetString(GL_VERSION)); - delete glCanvas; + delete glWidget; // Compare against minimum // The GL_VERSION string begins with a version number in one of these forms: diff --git a/interface/src/OpenGLVersionChecker.h b/libraries/gl/src/gl/OpenGLVersionChecker.h similarity index 95% rename from interface/src/OpenGLVersionChecker.h rename to libraries/gl/src/gl/OpenGLVersionChecker.h index a46020031c..3e16c3a32d 100644 --- a/interface/src/OpenGLVersionChecker.h +++ b/libraries/gl/src/gl/OpenGLVersionChecker.h @@ -1,6 +1,6 @@ // // OpenGLVersionChecker.h -// interface/src +// libraries/gl/src/gl // // Created by David Rowe on 28 Jan 2016. // Copyright 2016 High Fidelity, Inc. From 6232a83f43e5e46beb2bd0d4467bef831bf635bd Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 29 Jan 2016 13:03:54 +1300 Subject: [PATCH 4/4] Specify minimum OpenGL version in gl library's config Note: Defines minimum OpenGL version as 4.1 in anticipation of Interface soon properly supporting both 4.1 and 4.3 on Windows. --- libraries/gl/src/gl/Config.h | 1 + libraries/gl/src/gl/OpenGLVersionChecker.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/gl/src/gl/Config.h b/libraries/gl/src/gl/Config.h index fe693d8c65..2e42e85122 100644 --- a/libraries/gl/src/gl/Config.h +++ b/libraries/gl/src/gl/Config.h @@ -19,6 +19,7 @@ #define GPU_LEGACY 0 #define GPU_CORE_41 410 #define GPU_CORE_43 430 +#define GPU_CORE_MINIMUM GPU_CORE_41 #if defined(__APPLE__) diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index f1a40bde8d..761c27a302 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -14,6 +14,7 @@ #include #include +#include "Config.h" #include "GLWidget.h" OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : @@ -35,13 +36,13 @@ bool OpenGLVersionChecker::isValidVersion() { // - major_number.minor_number // - major_number.minor_number.release_number // Reference: https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glGetString.xml - const int MINIMUM_OPENGL_MAJOR_VERSION = 4; - const int MINIMUM_OPENGL_MINOR_VERSION = 1; QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); int majorNumber = versionParts[0].toInt(); int minorNumber = versionParts[1].toInt(); - valid = (majorNumber > MINIMUM_OPENGL_MAJOR_VERSION - || (majorNumber == MINIMUM_OPENGL_MAJOR_VERSION && minorNumber >= MINIMUM_OPENGL_MINOR_VERSION)); + int minimumMajorNumber = GPU_CORE_MINIMUM / 100; + int minimumMinorNumber = (GPU_CORE_MINIMUM - minimumMajorNumber * 100) / 10; + valid = (majorNumber > minimumMajorNumber + || (majorNumber == minimumMajorNumber && minorNumber >= minimumMinorNumber)); // Prompt user if below minimum if (!valid) { @@ -49,7 +50,7 @@ bool OpenGLVersionChecker::isValidVersion() { messageBox.setWindowTitle("OpenGL Version Too Low"); messageBox.setIcon(QMessageBox::Warning); messageBox.setText(QString().sprintf("Your OpenGL version of %i.%i is lower than the minimum of %i.%i.", - majorNumber, minorNumber, MINIMUM_OPENGL_MAJOR_VERSION, MINIMUM_OPENGL_MINOR_VERSION)); + majorNumber, minorNumber, minimumMajorNumber, minimumMinorNumber)); messageBox.setInformativeText("Press OK to exit; Ignore to continue."); messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Ignore); messageBox.setDefaultButton(QMessageBox::Ok);