diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-10-29 18:04:32 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-10-29 11:06:40 -0700 |
commit | c78a864e15c7e070a7233d09c805f66490de7e27 (patch) | |
tree | 5b95f2e7bfd39d08ec4aeb89ebf4ccd1de314254 | |
parent | fd2e4803a07e60f447c5734a39fac561b1fc4407 (diff) | |
download | subsurface-c78a864e15c7e070a7233d09c805f66490de7e27.tar.gz |
desktop-main.cpp: add validateGL()
Add a new static function to validate the availability of OpenGL
on this particular desktop system. It makes some calls to create
a platform agnostic GL context that renders to a offscreen surface.
Then it makes a couple of glGetIntegerv((GL_xxx_VERSION, ...) calls
to see if the GL profile version is at least 2.1.
In case any of the steps fail, a stderr message is shown and all
QtQuick based widgets would be rendered using a software renderer.
Testing was done in the case of the Google maps plugin and the
fallback seems to work on Windows, but further testing will be
required on all OS.
For the time being, the automatic fallback is only supported
on Qt 5.8.0 or later.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
-rw-r--r-- | subsurface-desktop-main.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 029f8569e..0c7f92a4e 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -21,9 +21,14 @@ #include <QStringList> #include <QApplication> #include <QLoggingCategory> +#include <QOpenGLContext> +#include <QOffscreenSurface> +#include <QOpenGLFunctions> +#include <QQuickWindow> #include <git2.h> static bool filesOnCommandLine = false; +static void validateGL(); int main(int argc, char **argv) { @@ -46,6 +51,8 @@ int main(int argc, char **argv) subsurface_console_init(dedicated_console, false); } + validateGL(); + const char *default_directory = system_default_directory(); const char *default_filename = system_default_filename(); subsurface_mkdir(default_directory); @@ -129,3 +136,46 @@ bool haveFilesOnCommandLine() { return filesOnCommandLine; } + +void validateGL() +{ + GLint verMajor, verMinor; + const char *glError = NULL; + QOpenGLContext ctx; + QOffscreenSurface surface; + QOpenGLFunctions *func; + + surface.setFormat(ctx.format()); + surface.create(); + if (!ctx.create()) { + glError = "Cannot create OpenGL context"; + goto exit; + } + ctx.makeCurrent(&surface); + func = ctx.functions(); + if (!func) { + glError = "Cannot obtain QOpenGLFunctions"; + goto exit; + } + func->glGetIntegerv(GL_MAJOR_VERSION, &verMajor); + func->glGetIntegerv(GL_MINOR_VERSION, &verMinor); + if (verMajor * 10 + verMinor < 21) // set 2.1 as the minimal version + glError = "OpenGL 2.1 or later is required"; + +exit: + ctx.makeCurrent(NULL); + surface.destroy(); + if (glError) { +#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) + fprintf(stderr, "ERROR: %s.\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!\n", + glError); + exit(0); +#else + fprintf(stderr, "WARNING: %s. Using a software renderer!\n", glError); + QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software); +#endif + } +} |