From af3d842e6096c3ecd9da8ea2964b5882852cb79e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 28 Jan 2016 15:22:42 +1300 Subject: [PATCH] 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.