diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 15da88023b..a57e53b384 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "AddressManager.h" @@ -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. + { + OpenGLVersionChecker openGLVersionChecker(argc, const_cast(argv)); + if (!openGLVersionChecker.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. 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 new file mode 100644 index 0000000000..761c27a302 --- /dev/null +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -0,0 +1,61 @@ +// +// OpenGLVersionChecker.cpp +// libraries/gl/src/gl +// +// 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 "OpenGLVersionChecker.h" + +#include +#include + +#include "Config.h" +#include "GLWidget.h" + +OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : + QApplication(argc, argv) +{ +} + +bool OpenGLVersionChecker::isValidVersion() { + bool valid = true; + + // Retrieve OpenGL version + GLWidget* glWidget = new GLWidget(); + glWidget->initializeGL(); + QString glVersion = QString((const char*)glGetString(GL_VERSION)); + delete glWidget; + + // 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 + QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); + int majorNumber = versionParts[0].toInt(); + int minorNumber = versionParts[1].toInt(); + 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) { + 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, minimumMajorNumber, minimumMinorNumber)); + 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/libraries/gl/src/gl/OpenGLVersionChecker.h b/libraries/gl/src/gl/OpenGLVersionChecker.h new file mode 100644 index 0000000000..3e16c3a32d --- /dev/null +++ b/libraries/gl/src/gl/OpenGLVersionChecker.h @@ -0,0 +1,25 @@ +// +// OpenGLVersionChecker.h +// libraries/gl/src/gl +// +// 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_OpenGLVersionChecker_h +#define hifi_OpenGLVersionChecker_h + +#include + +class OpenGLVersionChecker : public QApplication { + +public: + OpenGLVersionChecker(int& argc, char** argv); + + static bool isValidVersion(); +}; + +#endif // hifi_OpenGLVersionChecker_h