Don't use reserved keyword "texture" as uniform variable name
authorSean Harmer <sean.harmer@kdab.com>
Sat, 19 Oct 2013 13:21:31 +0000 (14:21 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 21 Oct 2013 17:10:50 +0000 (19:10 +0200)
The "texture" keyword is a function name in OpenGL core profile. This
commit is in preparation for making the Qt Quick 2 renderer and
materials work with a core profile context.

Change-Id: Iad243e64ab8db739fc46b85bb626bdb8b9ceb208
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
src/particles/qquickimageparticle.cpp
src/quick/items/qquickanimatedsprite.cpp
src/quick/items/qquickspritesequence.cpp
src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
src/quick/scenegraph/qsgshareddistancefieldglyphcache.cpp

index c550ef8..fa828d7 100644 (file)
@@ -204,7 +204,7 @@ static const char vertexShaderCode[] =
     "}\n";
 
 static const char fragmentShaderCode[] =
-    "uniform sampler2D texture;\n"
+    "uniform sampler2D _qt_texture;\n"
     "uniform lowp float qt_Opacity;\n"
     "\n"
     "#if defined(SPRITE)\n"
@@ -224,21 +224,21 @@ static const char fragmentShaderCode[] =
     "\n"
     "void main() {\n"
     "#if defined(SPRITE)\n"
-    "    gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), tt.y)\n"
+    "    gl_FragColor = mix(texture2D(_qt_texture, fTexS.xy), texture2D(_qt_texture, fTexS.zw), tt.y)\n"
     "            * fColor\n"
     "            * texture2D(colortable, tt)\n"
     "            * qt_Opacity;\n"
     "#elif defined(TABLE)\n"
-    "    gl_FragColor = texture2D(texture, fTex)\n"
+    "    gl_FragColor = texture2D(_qt_texture, fTex)\n"
     "            * fColor\n"
     "            * texture2D(colortable, tt)\n"
     "            * qt_Opacity;\n"
     "#elif defined(DEFORM)\n"
-    "    gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;\n"
+    "    gl_FragColor = (texture2D(_qt_texture, fTex)) * fColor * qt_Opacity;\n"
     "#elif defined(COLOR)\n"
-    "    gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;\n"
+    "    gl_FragColor = (texture2D(_qt_texture, gl_PointCoord)) * fColor * qt_Opacity;\n"
     "#else\n"
-    "    gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);\n"
+    "    gl_FragColor = texture2D(_qt_texture, gl_PointCoord) * (fFade * qt_Opacity);\n"
     "#endif\n"
     "}\n";
 
@@ -296,7 +296,7 @@ public:
     void initialize() {
         QSGSimpleMaterialShader<TabledMaterialData>::initialize();
         program()->bind();
-        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("_qt_texture", 0);
         program()->setUniformValue("colortable", 1);
         glFuncs = QOpenGLContext::currentContext()->functions();
         m_timestamp_id = program()->uniformLocation("timestamp");
@@ -358,7 +358,7 @@ public:
     void initialize() {
         QSGSimpleMaterialShader<DeformableMaterialData>::initialize();
         program()->bind();
-        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("_qt_texture", 0);
         glFuncs = QOpenGLContext::currentContext()->functions();
         m_timestamp_id = program()->uniformLocation("timestamp");
         m_entry_id = program()->uniformLocation("entry");
@@ -409,7 +409,7 @@ public:
     void initialize() {
         QSGSimpleMaterialShader<SpriteMaterialData>::initialize();
         program()->bind();
-        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("_qt_texture", 0);
         program()->setUniformValue("colortable", 1);
         glFuncs = QOpenGLContext::currentContext()->functions();
         //Don't actually expose the animSheetSize in the shader, it's currently only used for CPU calculations.
@@ -488,7 +488,7 @@ public:
     void initialize() {
         QSGSimpleMaterialShader<ColoredMaterialData>::initialize();
         program()->bind();
-        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("_qt_texture", 0);
         glFuncs = QOpenGLContext::currentContext()->functions();
         m_timestamp_id = program()->uniformLocation("timestamp");
         m_entry_id = program()->uniformLocation("entry");
@@ -552,7 +552,7 @@ public:
     void initialize() {
         QSGSimpleMaterialShader<SimpleMaterialData>::initialize();
         program()->bind();
-        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("_qt_texture", 0);
         glFuncs = QOpenGLContext::currentContext()->functions();
         m_timestamp_id = program()->uniformLocation("timestamp");
         m_entry_id = program()->uniformLocation("entry");
index 3a32169..846de15 100644 (file)
@@ -80,14 +80,14 @@ static const char vertexShaderCode[] =
     "}\n";
 
 static const char fragmentShaderCode[] =
-    "uniform sampler2D texture;\n"
+    "uniform sampler2D _qt_texture;\n"
     "uniform lowp float qt_Opacity;\n"
     "\n"
     "varying highp vec4 fTexS;\n"
     "varying lowp float progress;\n"
     "\n"
     "void main() {\n"
-    "    gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), progress) * qt_Opacity;\n"
+    "    gl_FragColor = mix(texture2D(_qt_texture, fTexS.xy), texture2D(_qt_texture, fTexS.zw), progress) * qt_Opacity;\n"
     "}\n";
 
 class QQuickAnimatedSpriteMaterial : public QSGMaterial
index 3b2b326..3c1492e 100644 (file)
@@ -79,14 +79,14 @@ static const char vertexShaderCode[] =
     "}\n";
 
 static const char fragmentShaderCode[] =
-    "uniform sampler2D texture;\n"
+    "uniform sampler2D _qt_texture;\n"
     "uniform lowp float qt_Opacity;\n"
     "\n"
     "varying highp vec4 fTexS;\n"
     "varying lowp float progress;\n"
     "\n"
     "void main() {\n"
-    "    gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), progress) * qt_Opacity;\n"
+    "    gl_FragColor = mix(texture2D(_qt_texture, fTexS.xy), texture2D(_qt_texture, fTexS.zw), progress) * qt_Opacity;\n"
     "}\n";
 
 class QQuickSpriteSequenceMaterial : public QSGMaterial
index 50009d7..39d9832 100644 (file)
@@ -101,10 +101,10 @@ const char *QSGTextMaskShader::vertexShader() const {
 const char *QSGTextMaskShader::fragmentShader() const {
     return
         "varying highp vec2 sampleCoord;                \n"
-        "uniform sampler2D texture;                     \n"
+        "uniform sampler2D _qt_texture;                 \n"
         "uniform lowp vec4 color;                       \n"
         "void main() {                                  \n"
-        "    lowp vec4 glyph = texture2D(texture, sampleCoord); \n"
+        "    lowp vec4 glyph = texture2D(_qt_texture, sampleCoord); \n"
         "    gl_FragColor = vec4(glyph.rgb * color.a, glyph.a); \n"
         "}";
 }
@@ -389,14 +389,14 @@ const char *QSGStyledTextShader::fragmentShader() const
     return
         "varying highp vec2 sampleCoord;                \n"
         "varying highp vec2 shiftedSampleCoord;         \n"
-        "uniform sampler2D texture;                     \n"
+        "uniform sampler2D _qt_texture;                 \n"
         "uniform lowp vec4 color;                       \n"
         "uniform lowp vec4 styleColor;                  \n"
-        "void main() {                                                                  \n"
-        "    lowp float glyph = texture2D(texture, sampleCoord).a;                      \n"
-        "    lowp float style = clamp(texture2D(texture, shiftedSampleCoord).a - glyph, \n"
-        "                             0.0, 1.0);                                        \n"
-        "    gl_FragColor = style * styleColor + glyph * color;                         \n"
+        "void main() {                                                                      \n"
+        "    lowp float glyph = texture2D(_qt_texture, sampleCoord).a;                      \n"
+        "    lowp float style = clamp(texture2D(_qt_texture, shiftedSampleCoord).a - glyph, \n"
+        "                             0.0, 1.0);                                            \n"
+        "    gl_FragColor = style * styleColor + glyph * color;                             \n"
         "}";
 }
 
@@ -444,18 +444,18 @@ const char *QSGOutlinedTextShader::fragmentShader() const
         "varying highp vec2 sCoordDown;                 \n"
         "varying highp vec2 sCoordLeft;                 \n"
         "varying highp vec2 sCoordRight;                \n"
-        "uniform sampler2D texture;                     \n"
+        "uniform sampler2D _qt_texture;                 \n"
         "uniform lowp vec4 color;                       \n"
         "uniform lowp vec4 styleColor;                  \n"
-        "void main() {                                                            \n"
-            "lowp float glyph = texture2D(texture, sampleCoord).a;                \n"
-        "    lowp float outline = clamp(clamp(texture2D(texture, sCoordUp).a +    \n"
-        "                                     texture2D(texture, sCoordDown).a +  \n"
-        "                                     texture2D(texture, sCoordLeft).a +  \n"
-        "                                     texture2D(texture, sCoordRight).a,  \n"
-        "                                     0.0, 1.0) - glyph,                  \n"
-        "                               0.0, 1.0);                                \n"
-        "    gl_FragColor = outline * styleColor + glyph * color;                 \n"
+        "void main() {                                                                \n"
+            "lowp float glyph = texture2D(_qt_texture, sampleCoord).a;                \n"
+        "    lowp float outline = clamp(clamp(texture2D(_qt_texture, sCoordUp).a +    \n"
+        "                                     texture2D(_qt_texture, sCoordDown).a +  \n"
+        "                                     texture2D(_qt_texture, sCoordLeft).a +  \n"
+        "                                     texture2D(_qt_texture, sCoordRight).a,  \n"
+        "                                     0.0, 1.0) - glyph,                      \n"
+        "                               0.0, 1.0);                                    \n"
+        "    gl_FragColor = outline * styleColor + glyph * color;                     \n"
         "}";
 }
 
index 0cf7abe..1252438 100644 (file)
@@ -96,15 +96,15 @@ const char *QSGDistanceFieldTextMaterialShader::vertexShader() const {
 
 const char *QSGDistanceFieldTextMaterialShader::fragmentShader() const {
     return
-        "varying highp vec2 sampleCoord;                                             \n"
-        "uniform mediump sampler2D texture;                                          \n"
-        "uniform lowp vec4 color;                                                    \n"
-        "uniform mediump float alphaMin;                                             \n"
-        "uniform mediump float alphaMax;                                             \n"
-        "void main() {                                                               \n"
-        "    gl_FragColor = color * smoothstep(alphaMin,                             \n"
-        "                                      alphaMax,                             \n"
-        "                                      texture2D(texture, sampleCoord).a);   \n"
+        "varying highp vec2 sampleCoord;                                                \n"
+        "uniform mediump sampler2D _qt_texture;                                         \n"
+        "uniform lowp vec4 color;                                                       \n"
+        "uniform mediump float alphaMin;                                                \n"
+        "uniform mediump float alphaMax;                                                \n"
+        "void main() {                                                                  \n"
+        "    gl_FragColor = color * smoothstep(alphaMin,                                \n"
+        "                                      alphaMax,                                \n"
+        "                                      texture2D(_qt_texture, sampleCoord).a);  \n"
         "}";
 }
 
@@ -366,7 +366,7 @@ protected:
 const char *DistanceFieldOutlineTextMaterialShader::fragmentShader() const {
     return
             "varying highp vec2 sampleCoord;                                                      \n"
-            "uniform sampler2D texture;                                                           \n"
+            "uniform sampler2D _qt_texture;                                                       \n"
             "uniform lowp vec4 color;                                                             \n"
             "uniform lowp vec4 styleColor;                                                        \n"
             "uniform mediump float alphaMin;                                                      \n"
@@ -374,7 +374,7 @@ const char *DistanceFieldOutlineTextMaterialShader::fragmentShader() const {
             "uniform mediump float outlineAlphaMax0;                                              \n"
             "uniform mediump float outlineAlphaMax1;                                              \n"
             "void main() {                                                                        \n"
-            "    mediump float d = texture2D(texture, sampleCoord).a;                             \n"
+            "    mediump float d = texture2D(_qt_texture, sampleCoord).a;                         \n"
             "    gl_FragColor = mix(styleColor, color, smoothstep(alphaMin, alphaMax, d))         \n"
             "                       * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d);          \n"
             "}";
@@ -514,19 +514,19 @@ const char *DistanceFieldShiftedStyleTextMaterialShader::vertexShader() const
 
 const char *DistanceFieldShiftedStyleTextMaterialShader::fragmentShader() const {
     return
-            "varying highp vec2 sampleCoord;                                                       \n"
-            "varying highp vec2 shiftedSampleCoord;                                                \n"
-            "uniform sampler2D texture;                                                            \n"
-            "uniform lowp vec4 color;                                                              \n"
-            "uniform lowp vec4 styleColor;                                                         \n"
-            "uniform mediump float alphaMin;                                                       \n"
-            "uniform mediump float alphaMax;                                                       \n"
-            "void main() {                                                                         \n"
-            "    highp float a = smoothstep(alphaMin, alphaMax, texture2D(texture, sampleCoord).a);\n"
-            "    highp vec4 shifted = styleColor * smoothstep(alphaMin,                            \n"
-            "                                                 alphaMax,                            \n"
-            "                                                 texture2D(texture, shiftedSampleCoord).a); \n"
-            "    gl_FragColor = mix(shifted, color, a);                                            \n"
+            "varying highp vec2 sampleCoord;                                                                 \n"
+            "varying highp vec2 shiftedSampleCoord;                                                          \n"
+            "uniform sampler2D _qt_texture;                                                                  \n"
+            "uniform lowp vec4 color;                                                                        \n"
+            "uniform lowp vec4 styleColor;                                                                   \n"
+            "uniform mediump float alphaMin;                                                                 \n"
+            "uniform mediump float alphaMax;                                                                 \n"
+            "void main() {                                                                                   \n"
+            "    highp float a = smoothstep(alphaMin, alphaMax, texture2D(_qt_texture, sampleCoord).a);      \n"
+            "    highp vec4 shifted = styleColor * smoothstep(alphaMin,                                      \n"
+            "                                                 alphaMax,                                      \n"
+            "                                                 texture2D(_qt_texture, shiftedSampleCoord).a); \n"
+            "    gl_FragColor = mix(shifted, color, a);                                                      \n"
             "}";
 }
 
@@ -607,17 +607,17 @@ const char *QSGHiQSubPixelDistanceFieldTextMaterialShader::fragmentShader() cons
         "varying highp vec3 sampleNearLeft;                                     \n"
         "varying highp vec3 sampleNearRight;                                    \n"
         "varying highp vec3 sampleFarRight;                                     \n"
-        "uniform sampler2D texture;                                             \n"
+        "uniform sampler2D _qt_texture;                                         \n"
         "uniform lowp vec4 color;                                               \n"
         "uniform mediump float alphaMin;                                        \n"
         "uniform mediump float alphaMax;                                        \n"
         "void main() {                                                          \n"
         "    highp vec4 n;                                                      \n"
-        "    n.x = texture2DProj(texture, sampleFarLeft).a;                     \n"
-        "    n.y = texture2DProj(texture, sampleNearLeft).a;                    \n"
-        "    highp float c = texture2D(texture, sampleCoord).a;                 \n"
-        "    n.z = texture2DProj(texture, sampleNearRight).a;                   \n"
-        "    n.w = texture2DProj(texture, sampleFarRight).a;                    \n"
+        "    n.x = texture2DProj(_qt_texture, sampleFarLeft).a;                 \n"
+        "    n.y = texture2DProj(_qt_texture, sampleNearLeft).a;                \n"
+        "    highp float c = texture2D(_qt_texture, sampleCoord).a;             \n"
+        "    n.z = texture2DProj(_qt_texture, sampleNearRight).a;               \n"
+        "    n.w = texture2DProj(_qt_texture, sampleFarRight).a;                \n"
 #if 0
         // Blurrier, faster.
         "    n = smoothstep(alphaMin, alphaMax, n);                             \n"
@@ -638,18 +638,18 @@ const char *QSGHiQSubPixelDistanceFieldTextMaterialShader::fragmentShader() cons
 //    return
 //        "#extension GL_OES_standard_derivatives: enable                         \n"
 //        "varying highp vec2 sampleCoord;                                        \n"
-//        "uniform sampler2D texture;                                             \n"
+//        "uniform sampler2D _qt_texture;                                         \n"
 //        "uniform lowp vec4 color;                                               \n"
 //        "uniform highp float alphaMin;                                          \n"
 //        "uniform highp float alphaMax;                                          \n"
 //        "void main() {                                                          \n"
 //        "    highp vec2 delta = dFdx(sampleCoord);                              \n"
 //        "    highp vec4 n;                                                      \n"
-//        "    n.x = texture2D(texture, sampleCoord - 0.667 * delta).a;           \n"
-//        "    n.y = texture2D(texture, sampleCoord - 0.333 * delta).a;           \n"
-//        "    highp float c = texture2D(texture, sampleCoord).a;                 \n"
-//        "    n.z = texture2D(texture, sampleCoord + 0.333 * delta).a;           \n"
-//        "    n.w = texture2D(texture, sampleCoord + 0.667 * delta).a;           \n"
+//        "    n.x = texture2D(_qt_texture, sampleCoord - 0.667 * delta).a;       \n"
+//        "    n.y = texture2D(_qt_texture, sampleCoord - 0.333 * delta).a;       \n"
+//        "    highp float c = texture2D(_qt_texture, sampleCoord).a;             \n"
+//        "    n.z = texture2D(_qt_texture, sampleCoord + 0.333 * delta).a;       \n"
+//        "    n.w = texture2D(_qt_texture, sampleCoord + 0.667 * delta).a;       \n"
 //        "    n = smoothstep(alphaMin, alphaMax, n);                             \n"
 //        "    c = smoothstep(alphaMin, alphaMax, c);                             \n"
 //        "    gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w;     \n"
@@ -746,14 +746,14 @@ const char *QSGLoQSubPixelDistanceFieldTextMaterialShader::fragmentShader() cons
     return
         "varying highp vec3 sampleNearLeft;                                     \n"
         "varying highp vec3 sampleNearRight;                                    \n"
-        "uniform sampler2D texture;                                             \n"
+        "uniform sampler2D _qt_texture;                                         \n"
         "uniform lowp vec4 color;                                               \n"
         "uniform mediump float alphaMin;                                        \n"
         "uniform mediump float alphaMax;                                        \n"
         "void main() {                                                          \n"
         "    highp vec2 n;                                                      \n"
-        "    n.x = texture2DProj(texture, sampleNearLeft).a;                    \n"
-        "    n.y = texture2DProj(texture, sampleNearRight).a;                   \n"
+        "    n.x = texture2DProj(_qt_texture, sampleNearLeft).a;                \n"
+        "    n.y = texture2DProj(_qt_texture, sampleNearRight).a;               \n"
         "    n = smoothstep(alphaMin, alphaMax, n);                             \n"
         "    highp float c = 0.5 * (n.x + n.y);                                 \n"
         "    gl_FragColor = vec4(n.x, c, n.y, c) * color.w;                     \n"
index fb9eebf..34a8843 100644 (file)
@@ -531,7 +531,7 @@ void QSGSharedDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width,
         glEnableVertexAttribArray(0);
         glEnableVertexAttribArray(1);
 
-        int textureUniformLocation = glGetUniformLocation(shaderProgram, "texture");
+        int textureUniformLocation = glGetUniformLocation(shaderProgram, "_qt_texture");
         glUniform1i(textureUniformLocation, 0);
     }