summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-09-01 03:57:30 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-09-01 03:57:30 (GMT)
commitb2d9dc8c487a8b87347a7d45a6c4f9dc827ddbfe (patch)
tree1d226f4fac22c5ba7e44d5460d6a078d2431680a /src/opengl
parent8ff041dab354609b730849320f4f31659089b37e (diff)
downloadQt-b2d9dc8c487a8b87347a7d45a6c4f9dc827ddbfe.zip
Qt-b2d9dc8c487a8b87347a7d45a6c4f9dc827ddbfe.tar.gz
Qt-b2d9dc8c487a8b87347a7d45a6c4f9dc827ddbfe.tar.bz2
Add #define's for highp/mediump after #version/#extension headers
GLSL shaders require that #version and #extension must appear before any other code. The #define's we insert for highp/mediump/etc must therefore be moved down to just after them. Reviewed-by: Gunnar Sletta
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qglshaderprogram.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp
index c4d9322..56b55d0 100644
--- a/src/opengl/qglshaderprogram.cpp
+++ b/src/opengl/qglshaderprogram.cpp
@@ -501,6 +501,25 @@ bool QGLShader::compile(const char *source)
return d->compile(this);
} else if (d->shader) {
QVarLengthArray<const char *> src;
+ int headerLen = 0;
+ while (source && source[headerLen] == '#') {
+ // Skip #version and #extension directives at the start of
+ // the shader code. We need to insert the qualifierDefines
+ // and redefineHighp just after them.
+ if (qstrncmp(source + headerLen, "#version", 8) != 0 &&
+ qstrncmp(source + headerLen, "#extension", 10) != 0) {
+ break;
+ }
+ while (source[headerLen] != '\0' && source[headerLen] != '\n')
+ ++headerLen;
+ if (source[headerLen] == '\n')
+ ++headerLen;
+ }
+ QByteArray header;
+ if (headerLen > 0) {
+ header = QByteArray(source, headerLen);
+ src.append(header.constData());
+ }
#ifdef QGL_DEFINE_QUALIFIERS
src.append(qualifierDefines);
#endif
@@ -509,7 +528,7 @@ bool QGLShader::compile(const char *source)
d->shaderType == PartialFragmentShader)
src.append(redefineHighp);
#endif
- src.append(source);
+ src.append(source + headerLen);
QGLContextGroup *ctx = d->ctx;
glShaderSource(d->shader, src.size(), src.data(), 0);
return d->compile(this);