Do not add GLSL line statements for old drivers
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Tue, 11 Aug 2015 13:09:47 +0000 (15:09 +0200)
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Mon, 17 Aug 2015 13:17:51 +0000 (13:17 +0000)
Older VMware virtual machines do not like the #line statements. These
were introduced in 5.5.0, meaning that when upgrading from 5.4 in such
a VM, shader compilation via QOpenGLShaderProgram stops working. This
should be avoided.

Task-number: QTBUG-47598
Change-Id: I8cccd76119350e7ce40da96d24a7a6e9eb399052
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
src/gui/opengl/qopenglshaderprogram.cpp

index 5de79c9e1eef36ac412c70f10ef270f9d809e2d2..04b796ddb037b56af2a60b2e6f17009e2453c777 100644 (file)
@@ -525,7 +525,8 @@ bool QOpenGLShader::compileSourceCode(const char *source)
 
         // The precision qualifiers are useful on OpenGL/ES systems,
         // but usually not present on desktop systems.
-        const QSurfaceFormat currentSurfaceFormat = QOpenGLContext::currentContext()->format();
+        QOpenGLContext *ctx = QOpenGLContext::currentContext();
+        const QSurfaceFormat currentSurfaceFormat = ctx->format();
         QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(QOpenGLContext::currentContext());
         if (currentSurfaceFormat.renderableType() == QSurfaceFormat::OpenGL
                 || ctx_d->workaround_missingPrecisionQualifiers
@@ -545,10 +546,16 @@ bool QOpenGLShader::compileSourceCode(const char *source)
         }
 #endif
 
-        // Append #line directive in order to compensate for text insertion
-        QByteArray lineDirective = QStringLiteral("#line %1\n").arg(versionDirectivePosition.line).toUtf8();
-        sourceChunks.append(lineDirective.constData());
-        sourceChunkLengths.append(GLint(lineDirective.length()));
+        QByteArray lineDirective;
+        // #line is rejected by some drivers:
+        // "2.1 Mesa 8.1-devel (git-48a3d4e)" or "MESA 2.1 Mesa 8.1-devel"
+        const char *version = reinterpret_cast<const char *>(ctx->functions()->glGetString(GL_VERSION));
+        if (!version || !strstr(version, "2.1 Mesa 8")) {
+            // Append #line directive in order to compensate for text insertion
+            lineDirective = QStringLiteral("#line %1\n").arg(versionDirectivePosition.line).toUtf8();
+            sourceChunks.append(lineDirective.constData());
+            sourceChunkLengths.append(GLint(lineDirective.length()));
+        }
 
         // Append rest of shader code
         sourceChunks.append(source + versionDirectivePosition.position);