diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-01 14:31:04 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-01 13:58:02 +0100 |
commit | 31e11bc4e83d4d0c407c27cc0abd26b017441c49 (patch) | |
tree | a7d8419e2f8b0ea6d2f369a93f2f6a10324711b3 | |
parent | cb34b33a64318a5f1671027a42494484b02e3800 (diff) | |
download | subsurface-31e11bc4e83d4d0c407c27cc0abd26b017441c49.tar.gz |
desktop-main.cpp: further improve the GL version detection
First, attempt to use glGetString(GL_VERSION), which works
on legacy profiles but has to be parsed (unsafe and vendor specific?).
If the above fails attempt to use the newer version API from
glGetIntegerv().
If both fail, fall back to a software renderer or exit.
If GLES is detected from glGetString() (for some odd reason -
e.g. emulated driver) show a warning and return early as we don't
handle it's versioning.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
-rw-r--r-- | subsurface-desktop-main.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index e8f57ecff..a37fd3cb5 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -152,11 +152,13 @@ void validateGL() } return; } - GLint verMajor, verMinor; + GLint verMajor = -1, verMinor; const char *glError = NULL; QOpenGLContext ctx; QOffscreenSurface surface; QOpenGLFunctions *func; + const char *verChar; + float verFloat; surface.setFormat(ctx.format()); surface.create(); @@ -174,8 +176,32 @@ void validateGL() } if (verbose) qDebug() << QStringLiteral(VALIDATE_GL_PREFIX "obtained QOpenGLFunctions.").toUtf8().data(); - func->glGetIntegerv(GL_MAJOR_VERSION, &verMajor); - func->glGetIntegerv(GL_MINOR_VERSION, &verMinor); + // detect version for legacy profiles + verChar = (const char *)func->glGetString(GL_VERSION); + if (verChar) { + // detect GLES, show a warning and return early as we don't handle it's versioning + if (strstr(verChar, " ES ") != NULL) { + qWarning() << QStringLiteral(VALIDATE_GL_PREFIX "WARNING: Detected OpenGL ES!\n" + "Attempting to run with the available profile!\n" + "If this fails try manually setting the environment variable\n" + "'QT_QUICK_BACKEND' with the value of 'software'\n" + "before running Subsurface!\n").toUtf8().data(); + return; + } + if (sscanf(verChar, "%f", &verFloat) == 1) { + verMajor = (GLint)verFloat; + verMinor = (GLint)((verFloat - verMajor) * 10.f); + } + } + // attempt to detect version using the newer API + if (verMajor == -1) { + func->glGetIntegerv(GL_MAJOR_VERSION, &verMajor); + func->glGetIntegerv(GL_MINOR_VERSION, &verMinor); + } + if (verMajor == -1) { + glError = "Cannot detect OpenGL version"; + goto exit; + } if (verbose) qDebug() << QStringLiteral(VALIDATE_GL_PREFIX "detected OpenGL version %1.%2.").arg(verMajor).arg(verMinor).toUtf8().data(); if (verMajor * 10 + verMinor < 21) { // set 2.1 as the minimal version @@ -191,7 +217,7 @@ exit: qWarning() << QStringLiteral(VALIDATE_GL_PREFIX "ERROR: %1.\n" "Cannot automatically fallback to a software renderer!\n" "Set the environment variable 'QT_QUICK_BACKEND' with the value of 'software'\n" - "before running Subsurface!").arg(glError).toUtf8().data(); + "before running Subsurface!\n").arg(glError).toUtf8().data(); exit(0); #else qWarning() << QStringLiteral(VALIDATE_GL_PREFIX "WARNING: %1. Using a software renderer!").arg(glError).toUtf8().data(); |