From c78a864e15c7e070a7233d09c805f66490de7e27 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sun, 29 Oct 2017 18:04:32 +0200 Subject: 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 --- subsurface-desktop-main.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'subsurface-desktop-main.cpp') 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 #include #include +#include +#include +#include +#include #include 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 + } +} -- cgit v1.2.3-70-g09d2