Warn user if OpenGL version is too low (< 4.1)

This commit is contained in:
David Rowe 2016-01-28 15:22:42 +13:00
parent 7b5c221ceb
commit af3d842e60
3 changed files with 98 additions and 0 deletions

View file

@ -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 <QMessageBox>
#include <QRegularExpression>
#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;
}

View file

@ -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 <QApplication>
class OpenGLInfo : public QApplication {
public:
OpenGLInfo(int& argc, char** argv);
static bool isValidVersion();
};
#endif // hifi_OpenGLInfo_h

View file

@ -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<char**>(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.