Kevin Kofler cdc6229
diff -ur qtbase-opensource-src-5.2.0/src/platformsupport/glxconvenience/qglxconvenience.cpp qtbase-opensource-src-5.2.0-allow-forcing-llvmpipe/src/platformsupport/glxconvenience/qglxconvenience.cpp
Kevin Kofler cdc6229
--- qtbase-opensource-src-5.2.0/src/platformsupport/glxconvenience/qglxconvenience.cpp	2013-12-08 18:09:47.000000000 +0100
Kevin Kofler e6aa6cc
+++ qtbase-opensource-src-5.2.0-allow-forcing-llvmpipe/src/platformsupport/glxconvenience/qglxconvenience.cpp	2014-01-29 17:41:57.000000000 +0100
Kevin Kofler cdc6229
@@ -116,6 +116,27 @@
Kevin Kofler b22f3a7
 
Kevin Kofler cdc6229
 GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat &format, int drawableBit)
Kevin Kofler cdc6229
 {
Kevin Kofler b22f3a7
+    // Allow forcing LIBGL_ALWAYS_SOFTWARE for Qt 5 applications only.
Kevin Kofler b22f3a7
+    // This is most useful with drivers that only support OpenGL 1.
Kevin Kofler b22f3a7
+    // We need OpenGL 2, but the user probably doesn't want
Kevin Kofler b22f3a7
+    // LIBGL_ALWAYS_SOFTWARE in OpenGL 1 apps.
Kevin Kofler b22f3a7
+    static bool checkedForceSoftwareOpenGL = false;
Kevin Kofler b22f3a7
+    static bool forceSoftwareOpenGL = false;
Kevin Kofler b22f3a7
+    if (!checkedForceSoftwareOpenGL) {
Kevin Kofler b22f3a7
+        // If LIBGL_ALWAYS_SOFTWARE is already set, don't mess with it.
Kevin Kofler b22f3a7
+        // We want to unset LIBGL_ALWAYS_SOFTWARE at the end so it does not
Kevin Kofler b22f3a7
+        // get inherited by other processes, of course only if it wasn't
Kevin Kofler b22f3a7
+        // already set before.
Kevin Kofler b22f3a7
+        if (!qEnvironmentVariableIsEmpty("QT_XCB_FORCE_SOFTWARE_OPENGL")
Kevin Kofler e6aa6cc
+            && !qEnvironmentVariableIsSet("LIBGL_ALWAYS_SOFTWARE"))
Kevin Kofler b22f3a7
+            forceSoftwareOpenGL = true;
Kevin Kofler b22f3a7
+
Kevin Kofler b22f3a7
+        checkedForceSoftwareOpenGL = true;
Kevin Kofler b22f3a7
+    }
Kevin Kofler b22f3a7
+
Kevin Kofler b22f3a7
+    if (forceSoftwareOpenGL)
Kevin Kofler e6aa6cc
+        qputenv("LIBGL_ALWAYS_SOFTWARE", QByteArrayLiteral("1"));
Kevin Kofler b22f3a7
+
Kevin Kofler cdc6229
     bool reduced = true;
Kevin Kofler cdc6229
     GLXFBConfig chosenConfig = 0;
Kevin Kofler cdc6229
     QSurfaceFormat reducedFormat = format;
Kevin Kofler cdc6229
@@ -159,6 +180,10 @@
Kevin Kofler cdc6229
             reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced);
Kevin Kofler cdc6229
     }
Kevin Kofler b22f3a7
 
Kevin Kofler b22f3a7
+    // unset LIBGL_ALWAYS_SOFTWARE now so other processes don't inherit it
Kevin Kofler b22f3a7
+    if (forceSoftwareOpenGL)
Kevin Kofler b22f3a7
+        qunsetenv("LIBGL_ALWAYS_SOFTWARE");
Kevin Kofler cdc6229
+
Kevin Kofler cdc6229
     return chosenConfig;
Kevin Kofler b22f3a7
 }
Kevin Kofler b22f3a7