src/opengl/gl2paintengineex/qglengineshadersource_p.h
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtOpenGL module of the Qt Toolkit.
     7 ** This file is part of the QtOpenGL module of the Qt Toolkit.
     8 **
     8 **
    61 QT_BEGIN_NAMESPACE
    61 QT_BEGIN_NAMESPACE
    62 
    62 
    63 QT_MODULE(OpenGL)
    63 QT_MODULE(OpenGL)
    64 
    64 
    65 
    65 
    66 static const char* const qglslMainVertexShader = "\
    66 static const char* const qglslMainVertexShader = "\n\
    67     uniform   highp float   depth;\
    67     void setPosition(); \n\
    68     void setPosition();\
    68     void main(void) \n\
    69     void main(void)\
    69     { \n\
    70     {\
    70         setPosition(); \n\
    71             setPosition();\
    71     }\n";
    72             gl_Position.z = depth * gl_Position.w;\
    72 
    73     }";
    73 static const char* const qglslMainWithTexCoordsVertexShader = "\n\
    74 
    74     attribute highp   vec2      textureCoordArray; \n\
    75 static const char* const qglslMainWithTexCoordsVertexShader = "\
    75     varying   highp   vec2      textureCoords; \n\
    76     attribute highp  vec2 textureCoordArray; \
    76     void setPosition(); \n\
    77     varying   highp  vec2 textureCoords; \
    77     void main(void) \n\
    78     uniform   highp float   depth;\
    78     { \n\
    79     void setPosition();\
    79         setPosition(); \n\
    80     void main(void) \
    80         textureCoords = textureCoordArray; \n\
    81     {\
    81     }\n";
    82             setPosition();\
    82 
    83             gl_Position.z = depth * gl_Position.w;\
    83 static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\n\
    84             textureCoords = textureCoordArray; \
    84     attribute highp   vec2      textureCoordArray; \n\
    85     }";
    85     attribute lowp    float     opacityArray; \n\
    86 
    86     varying   highp   vec2      textureCoords; \n\
    87 static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\
    87     varying   lowp    float     opacity; \n\
    88     attribute highp vec2  textureCoordArray; \
    88     void setPosition(); \n\
    89     attribute lowp  float opacityArray; \
    89     void main(void) \n\
    90     varying   highp vec2  textureCoords; \
    90     { \n\
    91     varying   lowp  float opacity; \
    91         setPosition(); \n\
    92     uniform   highp float depth; \
    92         textureCoords = textureCoordArray; \n\
    93     void setPosition(); \
    93         opacity = opacityArray; \n\
    94     void main(void) \
    94     }\n";
    95     { \
    95 
    96             setPosition(); \
    96 // NOTE: We let GL do the perspective correction so texture lookups in the fragment
    97             gl_Position.z = depth * gl_Position.w; \
    97 //       shader are also perspective corrected.
    98             textureCoords = textureCoordArray; \
    98 static const char* const qglslPositionOnlyVertexShader = "\n\
    99             opacity = opacityArray; \
    99     attribute highp   vec2      vertexCoordsArray; \n\
   100     }";
   100     attribute highp   vec3      pmvMatrix1; \n\
   101 
   101     attribute highp   vec3      pmvMatrix2; \n\
   102 static const char* const qglslPositionOnlyVertexShader = "\
   102     attribute highp   vec3      pmvMatrix3; \n\
   103     attribute highp vec4    vertexCoordsArray;\
   103     void setPosition(void) \n\
   104     uniform   highp mat4    pmvMatrix;\
   104     { \n\
   105     void setPosition(void)\
   105         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   106     {\
   106         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   107             gl_Position = pmvMatrix * vertexCoordsArray;\
   107         gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \n\
   108     }";
   108     }\n";
   109 
   109 
   110 static const char* const qglslUntransformedPositionVertexShader = "\
   110 static const char* const qglslUntransformedPositionVertexShader = "\n\
   111     attribute highp vec4    vertexCoordsArray;\
   111     attribute highp   vec4      vertexCoordsArray; \n\
   112     void setPosition(void)\
   112     void setPosition(void) \n\
   113     {\
   113     { \n\
   114             gl_Position = vertexCoordsArray;\
   114         gl_Position = vertexCoordsArray; \n\
   115     }";
   115     }\n";
   116 
   116 
   117 // Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
   117 // Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
   118 static const char* const qglslPositionWithPatternBrushVertexShader = "\
   118 static const char* const qglslPositionWithPatternBrushVertexShader = "\n\
   119     attribute highp   vec4  vertexCoordsArray; \
   119     attribute highp   vec2      vertexCoordsArray; \n\
   120     uniform   highp   mat4  pmvMatrix; \
   120     attribute highp   vec3      pmvMatrix1; \n\
   121     uniform   mediump vec2  halfViewportSize; \
   121     attribute highp   vec3      pmvMatrix2; \n\
   122     uniform   highp   vec2  invertedTextureSize; \
   122     attribute highp   vec3      pmvMatrix3; \n\
   123     uniform   highp   mat3  brushTransform; \
   123     uniform   mediump vec2      halfViewportSize; \n\
   124     varying   highp   vec2  patternTexCoords; \
   124     uniform   highp   vec2      invertedTextureSize; \n\
   125     void setPosition(void) { \
   125     uniform   highp   mat3      brushTransform; \n\
   126             gl_Position = pmvMatrix * vertexCoordsArray;\
   126     varying   highp   vec2      patternTexCoords; \n\
   127             gl_Position.xy = gl_Position.xy / gl_Position.w; \
   127     void setPosition(void) \n\
   128             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   128     { \n\
   129             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   129         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   130             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   130         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   131             gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
   131         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   132             gl_Position.w = invertedHTexCoordsZ; \
   132         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   133             patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
   133         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
   134     }";
   134         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
       
   135         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
       
   136         patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \n\
       
   137     }\n";
   135 
   138 
   136 static const char* const qglslAffinePositionWithPatternBrushVertexShader
   139 static const char* const qglslAffinePositionWithPatternBrushVertexShader
   137                  = qglslPositionWithPatternBrushVertexShader;
   140                  = qglslPositionWithPatternBrushVertexShader;
   138 
   141 
   139 static const char* const qglslPatternBrushSrcFragmentShader = "\
   142 static const char* const qglslPatternBrushSrcFragmentShader = "\n\
   140     uniform lowp    sampler2D brushTexture;\
   143     uniform   lowp    sampler2D brushTexture; \n\
   141     uniform lowp    vec4      patternColor; \
   144     uniform   lowp    vec4      patternColor; \n\
   142     varying highp   vec2      patternTexCoords;\
   145     varying   highp   vec2      patternTexCoords;\n\
   143     lowp vec4 srcPixel() { \
   146     lowp vec4 srcPixel() \n\
   144         return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \
   147     { \n\
       
   148         return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \n\
   145     }\n";
   149     }\n";
   146 
   150 
   147 
   151 
   148 // Linear Gradient Brush
   152 // Linear Gradient Brush
   149 static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
   153 static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\n\
   150     attribute highp   vec4  vertexCoordsArray; \
   154     attribute highp   vec2      vertexCoordsArray; \n\
   151     uniform   highp   mat4  pmvMatrix; \
   155     attribute highp   vec3      pmvMatrix1; \n\
   152     uniform   mediump vec2  halfViewportSize; \
   156     attribute highp   vec3      pmvMatrix2; \n\
   153     uniform   highp   vec3  linearData; \
   157     attribute highp   vec3      pmvMatrix3; \n\
   154     uniform   highp   mat3  brushTransform; \
   158     uniform   mediump vec2      halfViewportSize; \n\
   155     varying   mediump float index; \
   159     uniform   highp   vec3      linearData; \n\
   156     void setPosition() { \
   160     uniform   highp   mat3      brushTransform; \n\
   157         gl_Position = pmvMatrix * vertexCoordsArray;\
   161     varying   mediump float     index; \n\
   158         gl_Position.xy = gl_Position.xy / gl_Position.w; \
   162     void setPosition() \n\
   159         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   163     { \n\
   160         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   164         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   161         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   165         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   162         gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
   166         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   163         gl_Position.w = invertedHTexCoordsZ; \
   167         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   164         index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
   168         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   165     }";
   169         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
       
   170         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
       
   171         index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \n\
       
   172     }\n";
   166 
   173 
   167 static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
   174 static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
   168                  = qglslPositionWithLinearGradientBrushVertexShader;
   175                  = qglslPositionWithLinearGradientBrushVertexShader;
   169 
   176 
   170 static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
   177 static const char* const qglslLinearGradientBrushSrcFragmentShader = "\n\
   171     uniform lowp    sampler2D   brushTexture; \
   178     uniform   lowp    sampler2D brushTexture; \n\
   172     varying mediump float       index; \
   179     varying   mediump float     index; \n\
   173     lowp vec4 srcPixel() { \
   180     lowp vec4 srcPixel() \n\
   174         mediump vec2 val = vec2(index, 0.5); \
   181     { \n\
   175         return texture2D(brushTexture, val); \
   182         mediump vec2 val = vec2(index, 0.5); \n\
       
   183         return texture2D(brushTexture, val); \n\
   176     }\n";
   184     }\n";
   177 
   185 
   178 
   186 
   179 // Conical Gradient Brush
   187 // Conical Gradient Brush
   180 static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
   188 static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\n\
   181     attribute highp   vec4  vertexCoordsArray;\
   189     attribute highp   vec2      vertexCoordsArray; \n\
   182     uniform   highp   mat4  pmvMatrix;\
   190     attribute highp   vec3      pmvMatrix1; \n\
   183     uniform   mediump vec2  halfViewportSize; \
   191     attribute highp   vec3      pmvMatrix2; \n\
   184     uniform   highp   mat3  brushTransform; \
   192     attribute highp   vec3      pmvMatrix3; \n\
   185     varying   highp   vec2  A; \
   193     uniform   mediump vec2      halfViewportSize; \n\
   186     void setPosition(void)\
   194     uniform   highp   mat3      brushTransform; \n\
   187     {\
   195     varying   highp   vec2      A; \n\
   188         gl_Position = pmvMatrix * vertexCoordsArray;\
   196     void setPosition(void) \n\
   189         gl_Position.xy = gl_Position.xy / gl_Position.w; \
   197     { \n\
   190         mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   198         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   191         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   199         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   192         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   200         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   193         gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
   201         mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   194         gl_Position.w = invertedHTexCoordsZ; \
   202         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   195         A = hTexCoords.xy * invertedHTexCoordsZ; \
   203         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
   196     }";
   204         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
       
   205         A = hTexCoords.xy * invertedHTexCoordsZ; \n\
       
   206     }\n";
   197 
   207 
   198 static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
   208 static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
   199                  = qglslPositionWithConicalGradientBrushVertexShader;
   209                  = qglslPositionWithConicalGradientBrushVertexShader;
   200 
   210 
   201 static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
   211 static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
   202     #define INVERSE_2PI 0.1591549430918953358 \n\
   212     #define INVERSE_2PI 0.1591549430918953358 \n\
   203     uniform lowp    sampler2D   brushTexture; \n\
   213     uniform   lowp    sampler2D brushTexture; \n\
   204     uniform mediump float       angle; \
   214     uniform   mediump float     angle; \n\
   205     varying highp   vec2        A; \
   215     varying   highp   vec2      A; \n\
   206     lowp vec4 srcPixel() { \
   216     lowp vec4 srcPixel() \n\
   207         highp float t; \
   217     { \n\
   208         if (abs(A.y) == abs(A.x)) \
   218         highp float t; \n\
   209             t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \
   219         if (abs(A.y) == abs(A.x)) \n\
   210         else \
   220             t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \n\
   211             t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \
   221         else \n\
   212         return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
   222             t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \n\
   213     }";
   223         return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \n\
       
   224     }\n";
   214 
   225 
   215 
   226 
   216 // Radial Gradient Brush
   227 // Radial Gradient Brush
   217 static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
   228 static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\n\
   218     attribute highp   vec4 vertexCoordsArray;\
   229     attribute highp   vec2      vertexCoordsArray;\n\
   219     uniform   highp   mat4 pmvMatrix;\
   230     attribute highp   vec3      pmvMatrix1; \n\
   220     uniform   mediump vec2 halfViewportSize; \
   231     attribute highp   vec3      pmvMatrix2; \n\
   221     uniform   highp   mat3 brushTransform; \
   232     attribute highp   vec3      pmvMatrix3; \n\
   222     uniform   highp   vec2 fmp; \
   233     uniform   mediump vec2      halfViewportSize; \n\
   223     varying   highp   float b; \
   234     uniform   highp   mat3      brushTransform; \n\
   224     varying   highp   vec2  A; \
   235     uniform   highp   vec2      fmp; \n\
   225     void setPosition(void) \
   236     varying   highp   float     b; \n\
   226     {\
   237     varying   highp   vec2      A; \n\
   227         gl_Position = pmvMatrix * vertexCoordsArray;\
   238     void setPosition(void) \n\
   228         gl_Position.xy = gl_Position.xy / gl_Position.w; \
   239     {\n\
   229         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   240         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   230         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   241         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   231         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   242         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   232         gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
   243         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   233         gl_Position.w = invertedHTexCoordsZ; \
   244         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   234         A = hTexCoords.xy * invertedHTexCoordsZ; \
   245         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
   235         b = 2.0 * dot(A, fmp); \
   246         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
   236     }";
   247         A = hTexCoords.xy * invertedHTexCoordsZ; \n\
       
   248         b = 2.0 * dot(A, fmp); \n\
       
   249     }\n";
   237 
   250 
   238 static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
   251 static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
   239                  = qglslPositionWithRadialGradientBrushVertexShader;
   252                  = qglslPositionWithRadialGradientBrushVertexShader;
   240 
   253 
   241 static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
   254 static const char* const qglslRadialGradientBrushSrcFragmentShader = "\n\
   242     uniform lowp    sampler2D   brushTexture; \
   255     uniform   lowp    sampler2D brushTexture; \n\
   243     uniform highp   float       fmp2_m_radius2; \
   256     uniform   highp   float     fmp2_m_radius2; \n\
   244     uniform highp   float       inverse_2_fmp2_m_radius2; \
   257     uniform   highp   float     inverse_2_fmp2_m_radius2; \n\
   245     varying highp   float       b; \
   258     varying   highp   float     b; \n\
   246     varying highp   vec2        A; \
   259     varying   highp   vec2      A; \n\
   247     lowp vec4 srcPixel() { \
   260     lowp vec4 srcPixel() \n\
   248         highp float c = -dot(A, A); \
   261     { \n\
   249         highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
   262         highp float c = -dot(A, A); \n\
   250         return texture2D(brushTexture, val); \
   263         highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \n\
   251     }";
   264         return texture2D(brushTexture, val); \n\
       
   265     }\n";
   252 
   266 
   253 
   267 
   254 // Texture Brush
   268 // Texture Brush
   255 static const char* const qglslPositionWithTextureBrushVertexShader = "\
   269 static const char* const qglslPositionWithTextureBrushVertexShader = "\n\
   256     attribute highp   vec4  vertexCoordsArray; \
   270     attribute highp   vec2      vertexCoordsArray; \n\
   257     uniform   highp   mat4  pmvMatrix; \
   271     attribute highp   vec3      pmvMatrix1; \n\
   258     uniform   mediump vec2  halfViewportSize; \
   272     attribute highp   vec3      pmvMatrix2; \n\
   259     uniform   highp   vec2  invertedTextureSize; \
   273     attribute highp   vec3      pmvMatrix3; \n\
   260     uniform   highp   mat3  brushTransform; \
   274     uniform   mediump vec2      halfViewportSize; \n\
   261     varying   highp   vec2  textureCoords; \
   275     uniform   highp   vec2      invertedTextureSize; \n\
   262     void setPosition(void) { \
   276     uniform   highp   mat3      brushTransform; \n\
   263             gl_Position = pmvMatrix * vertexCoordsArray;\
   277     varying   highp   vec2      textureCoords; \n\
   264             gl_Position.xy = gl_Position.xy / gl_Position.w; \
   278     void setPosition(void) \n\
   265             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   279     { \n\
   266             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   280         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   267             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   281         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   268             gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
   282         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   269             gl_Position.w = invertedHTexCoordsZ; \
   283         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   270             textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
   284         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   271     }";
   285         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
       
   286         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
       
   287         textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \n\
       
   288     }\n";
   272 
   289 
   273 static const char* const qglslAffinePositionWithTextureBrushVertexShader
   290 static const char* const qglslAffinePositionWithTextureBrushVertexShader
   274                  = qglslPositionWithTextureBrushVertexShader;
   291                  = qglslPositionWithTextureBrushVertexShader;
   275 
   292 
   276 #if defined(QT_OPENGL_ES_2)
   293 #if defined(QT_OPENGL_ES_2)
   277 // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead,
   294 // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead,
   278 // we emulate GL_REPEAT by only taking the fractional part of the texture coords.
   295 // we emulate GL_REPEAT by only taking the fractional part of the texture coords.
   279 // TODO: Special case POT textures which don't need this emulation
   296 // TODO: Special case POT textures which don't need this emulation
   280 static const char* const qglslTextureBrushSrcFragmentShader = "\
   297 static const char* const qglslTextureBrushSrcFragmentShader = "\n\
   281     varying highp   vec2      textureCoords; \
   298     varying highp   vec2      textureCoords; \n\
   282     uniform lowp    sampler2D brushTexture; \
   299     uniform lowp    sampler2D brushTexture; \n\
   283     lowp vec4 srcPixel() { \
   300     lowp vec4 srcPixel() { \n\
   284         return texture2D(brushTexture, fract(textureCoords)); \
   301         return texture2D(brushTexture, fract(textureCoords)); \n\
   285     }";
   302     }\n";
   286 #else
   303 #else
   287 static const char* const qglslTextureBrushSrcFragmentShader = "\
   304 static const char* const qglslTextureBrushSrcFragmentShader = "\n\
   288     varying highp   vec2      textureCoords; \
   305     varying   highp   vec2      textureCoords; \n\
   289     uniform lowp    sampler2D brushTexture; \
   306     uniform   lowp    sampler2D brushTexture; \n\
   290     lowp vec4 srcPixel() { \
   307     lowp vec4 srcPixel() \n\
   291         return texture2D(brushTexture, textureCoords); \
   308     { \n\
   292     }";
   309         return texture2D(brushTexture, textureCoords); \n\
       
   310     }\n";
   293 #endif
   311 #endif
   294 
   312 
   295 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\
   313 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\n\
   296     varying highp   vec2      textureCoords; \
   314     varying   highp   vec2      textureCoords; \n\
   297     uniform lowp    vec4      patternColor; \
   315     uniform   lowp    vec4      patternColor; \n\
   298     uniform lowp    sampler2D brushTexture; \
   316     uniform   lowp    sampler2D brushTexture; \n\
   299     lowp vec4 srcPixel() { \
   317     lowp vec4 srcPixel() \n\
   300         return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \
   318     { \n\
   301     }";
   319         return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \n\
       
   320     }\n";
   302 
   321 
   303 // Solid Fill Brush
   322 // Solid Fill Brush
   304 static const char* const qglslSolidBrushSrcFragmentShader = "\
   323 static const char* const qglslSolidBrushSrcFragmentShader = "\n\
   305     uniform lowp vec4 fragmentColor; \
   324     uniform   lowp    vec4      fragmentColor; \n\
   306     lowp vec4 srcPixel() { \
   325     lowp vec4 srcPixel() \n\
   307         return fragmentColor; \
   326     { \n\
   308     }";
   327         return fragmentColor; \n\
   309 
   328     }\n";
   310 static const char* const qglslImageSrcFragmentShader = "\
   329 
   311     varying highp   vec2    textureCoords; \
   330 static const char* const qglslImageSrcFragmentShader = "\n\
   312     uniform lowp  sampler2D imageTexture; \
   331     varying   highp   vec2      textureCoords; \n\
   313     lowp vec4 srcPixel() { \
   332     uniform   lowp    sampler2D imageTexture; \n\
   314         return texture2D(imageTexture, textureCoords); \
   333     lowp vec4 srcPixel() \n\
   315     }";
   334     { \n"
   316 
   335 #ifdef QT_OPENGL_ES_2
   317 static const char* const qglslCustomSrcFragmentShader = "\
   336         // work-around for driver bug
   318     varying highp vec2      textureCoords; \
   337         "return 1.0 * texture2D(imageTexture, textureCoords); \n"
   319     uniform lowp  sampler2D imageTexture; \
   338 #else
   320     lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \
   339         "return texture2D(imageTexture, textureCoords); \n"
   321     lowp vec4 srcPixel() { \
   340 #endif
   322         return customShader(imageTexture, textureCoords); \
   341     "}\n";
   323     }";
   342 
   324 
   343 static const char* const qglslCustomSrcFragmentShader = "\n\
   325 static const char* const qglslImageSrcWithPatternFragmentShader = "\
   344     varying   highp   vec2      textureCoords; \n\
   326     varying highp vec2      textureCoords; \
   345     uniform   lowp    sampler2D imageTexture; \n\
   327     uniform lowp  vec4      patternColor; \
   346     lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \n\
   328     uniform lowp  sampler2D imageTexture; \
   347     lowp vec4 srcPixel() \n\
   329     lowp vec4 srcPixel() { \
   348     { \n\
   330         return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \
   349         return customShader(imageTexture, textureCoords); \n\
   331     }\n";
   350     }\n";
   332 
   351 
   333 static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
   352 static const char* const qglslImageSrcWithPatternFragmentShader = "\n\
   334     varying highp vec2      textureCoords; \
   353     varying   highp   vec2      textureCoords; \n\
   335     uniform lowp  sampler2D imageTexture; \
   354     uniform   lowp    vec4      patternColor; \n\
   336     lowp vec4 srcPixel() { \
   355     uniform   lowp    sampler2D imageTexture; \n\
   337         lowp vec4 sample = texture2D(imageTexture, textureCoords); \
   356     lowp vec4 srcPixel() \n\
   338         sample.rgb = sample.rgb * sample.a; \
   357     { \n\
   339         return sample; \
   358         return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \n\
   340     }";
   359     }\n";
   341 
   360 
   342 static const char* const qglslShockingPinkSrcFragmentShader = "\
   361 static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\n\
   343     lowp vec4 srcPixel() { \
   362     varying   highp   vec2      textureCoords; \n\
   344         return vec4(0.98, 0.06, 0.75, 1.0); \
   363     uniform   lowp    sampler2D imageTexture; \n\
   345     }";
   364     lowp vec4 srcPixel() \n\
   346 
   365     { \n\
   347 static const char* const qglslMainFragmentShader_ImageArrays = "\
   366         lowp vec4 sample = texture2D(imageTexture, textureCoords); \n\
   348     varying lowp float opacity; \
   367         sample.rgb = sample.rgb * sample.a; \n\
   349     lowp vec4 srcPixel(); \
   368         return sample; \n\
   350     void main() { \
   369     }\n";
   351         gl_FragColor = srcPixel() * opacity; \
   370 
   352     }";
   371 static const char* const qglslShockingPinkSrcFragmentShader = "\n\
   353 
   372     lowp vec4 srcPixel() \n\
   354 static const char* const qglslMainFragmentShader_CMO = "\
   373     { \n\
   355     uniform lowp float globalOpacity; \
   374         return vec4(0.98, 0.06, 0.75, 1.0); \n\
   356     lowp vec4 srcPixel(); \
   375     }\n";
   357     lowp vec4 applyMask(lowp vec4); \
   376 
   358     lowp vec4 compose(lowp vec4); \
   377 static const char* const qglslMainFragmentShader_ImageArrays = "\n\
   359     void main() { \
   378     varying   lowp    float     opacity; \n\
   360         gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \
   379     lowp vec4 srcPixel(); \n\
   361     }";
   380     void main() \n\
   362 
   381     { \n\
   363 static const char* const qglslMainFragmentShader_CM = "\
   382         gl_FragColor = srcPixel() * opacity; \n\
   364     lowp vec4 srcPixel(); \
   383     }\n";
   365     lowp vec4 applyMask(lowp vec4); \
   384 
   366     lowp vec4 compose(lowp vec4); \
   385 static const char* const qglslMainFragmentShader_CMO = "\n\
   367     void main() { \
   386     uniform   lowp    float     globalOpacity; \n\
   368         gl_FragColor = applyMask(compose(srcPixel())); \
   387     lowp vec4 srcPixel(); \n\
   369     }";
   388     lowp vec4 applyMask(lowp vec4); \n\
   370 
   389     lowp vec4 compose(lowp vec4); \n\
   371 static const char* const qglslMainFragmentShader_MO = "\
   390     void main() \n\
   372     uniform lowp float globalOpacity; \
   391     { \n\
   373     lowp vec4 srcPixel(); \
   392         gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
   374     lowp vec4 applyMask(lowp vec4); \
   393     }\n";
   375     void main() { \
   394 
   376         gl_FragColor = applyMask(srcPixel()*globalOpacity); \
   395 static const char* const qglslMainFragmentShader_CM = "\n\
   377     }";
   396     lowp vec4 srcPixel(); \n\
   378 
   397     lowp vec4 applyMask(lowp vec4); \n\
   379 static const char* const qglslMainFragmentShader_M = "\
   398     lowp vec4 compose(lowp vec4); \n\
   380     lowp vec4 srcPixel(); \
   399     void main() \n\
   381     lowp vec4 applyMask(lowp vec4); \
   400     { \n\
   382     void main() { \
   401         gl_FragColor = applyMask(compose(srcPixel())); \n\
   383         gl_FragColor = applyMask(srcPixel()); \
   402     }\n";
   384     }";
   403 
   385 
   404 static const char* const qglslMainFragmentShader_MO = "\n\
   386 static const char* const qglslMainFragmentShader_CO = "\
   405     uniform   lowp    float     globalOpacity; \n\
   387     uniform lowp float globalOpacity; \
   406     lowp vec4 srcPixel(); \n\
   388     lowp vec4 srcPixel(); \
   407     lowp vec4 applyMask(lowp vec4); \n\
   389     lowp vec4 compose(lowp vec4); \
   408     void main() \n\
   390     void main() { \
   409     { \n\
   391         gl_FragColor = compose(srcPixel()*globalOpacity); \
   410         gl_FragColor = applyMask(srcPixel()*globalOpacity); \n\
   392     }";
   411     }\n";
   393 
   412 
   394 static const char* const qglslMainFragmentShader_C = "\
   413 static const char* const qglslMainFragmentShader_M = "\n\
   395     lowp vec4 srcPixel(); \
   414     lowp vec4 srcPixel(); \n\
   396     lowp vec4 compose(lowp vec4); \
   415     lowp vec4 applyMask(lowp vec4); \n\
   397     void main() { \
   416     void main() \n\
   398         gl_FragColor = compose(srcPixel()); \
   417     { \n\
   399     }";
   418         gl_FragColor = applyMask(srcPixel()); \n\
   400 
   419     }\n";
   401 static const char* const qglslMainFragmentShader_O = "\
   420 
   402     uniform lowp float globalOpacity; \
   421 static const char* const qglslMainFragmentShader_CO = "\n\
   403     lowp vec4 srcPixel(); \
   422     uniform   lowp    float     globalOpacity; \n\
   404     void main() { \
   423     lowp vec4 srcPixel(); \n\
   405         gl_FragColor = srcPixel()*globalOpacity; \
   424     lowp vec4 compose(lowp vec4); \n\
   406     }";
   425     void main() \n\
   407 
   426     { \n\
   408 static const char* const qglslMainFragmentShader = "\
   427         gl_FragColor = compose(srcPixel()*globalOpacity); \n\
   409     lowp vec4 srcPixel(); \
   428     }\n";
   410     void main() { \
   429 
   411         gl_FragColor = srcPixel(); \
   430 static const char* const qglslMainFragmentShader_C = "\n\
   412     }";
   431     lowp vec4 srcPixel(); \n\
   413 
   432     lowp vec4 compose(lowp vec4); \n\
   414 static const char* const qglslMaskFragmentShader = "\
   433     void main() \n\
   415     varying highp   vec2      textureCoords;\
   434     { \n\
   416     uniform lowp    sampler2D maskTexture;\
   435         gl_FragColor = compose(srcPixel()); \n\
   417     lowp vec4 applyMask(lowp vec4 src) \
   436     }\n";
   418     {\
   437 
   419         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   438 static const char* const qglslMainFragmentShader_O = "\n\
   420         return src * mask.a; \
   439     uniform   lowp    float     globalOpacity; \n\
   421     }";
   440     lowp vec4 srcPixel(); \n\
       
   441     void main() \n\
       
   442     { \n\
       
   443         gl_FragColor = srcPixel()*globalOpacity; \n\
       
   444     }\n";
       
   445 
       
   446 static const char* const qglslMainFragmentShader = "\n\
       
   447     lowp vec4 srcPixel(); \n\
       
   448     void main() \n\
       
   449     { \n\
       
   450         gl_FragColor = srcPixel(); \n\
       
   451     }\n";
       
   452 
       
   453 static const char* const qglslMaskFragmentShader = "\n\
       
   454     varying   highp   vec2      textureCoords;\n\
       
   455     uniform   lowp    sampler2D maskTexture;\n\
       
   456     lowp vec4 applyMask(lowp vec4 src) \n\
       
   457     {\n\
       
   458         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
       
   459         return src * mask.a; \n\
       
   460     }\n";
   422 
   461 
   423 // For source over with subpixel antialiasing, the final color is calculated per component as follows
   462 // For source over with subpixel antialiasing, the final color is calculated per component as follows
   424 // (.a is alpha component, .c is red, green or blue component):
   463 // (.a is alpha component, .c is red, green or blue component):
   425 // alpha = src.a * mask.c * opacity
   464 // alpha = src.a * mask.c * opacity
   426 // dest.c = dest.c * (1 - alpha) + src.c * alpha
   465 // dest.c = dest.c * (1 - alpha) + src.c * alpha
   433 // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
   472 // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
   434 // alpha = src.a * mask.c * opacity
   473 // alpha = src.a * mask.c * opacity
   435 // dest.c = dest.c * (1 - mask.c) + src.c * alpha
   474 // dest.c = dest.c * (1 - mask.c) + src.c * alpha
   436 //
   475 //
   437 
   476 
   438 static const char* const qglslRgbMaskFragmentShaderPass1 = "\
   477 static const char* const qglslRgbMaskFragmentShaderPass1 = "\n\
   439     varying highp   vec2      textureCoords;\
   478     varying   highp   vec2      textureCoords;\n\
   440     uniform lowp    sampler2D maskTexture;\
   479     uniform   lowp    sampler2D maskTexture;\n\
   441     lowp vec4 applyMask(lowp vec4 src) \
   480     lowp vec4 applyMask(lowp vec4 src) \n\
   442     {\
   481     { \n\
   443         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   482         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
   444         return src.a * mask; \
   483         return src.a * mask; \n\
   445     }";
   484     }\n";
   446 
   485 
   447 static const char* const qglslRgbMaskFragmentShaderPass2 = "\
   486 static const char* const qglslRgbMaskFragmentShaderPass2 = "\n\
   448     varying highp   vec2      textureCoords;\
   487     varying   highp   vec2      textureCoords;\n\
   449     uniform lowp    sampler2D maskTexture;\
   488     uniform   lowp    sampler2D maskTexture;\n\
   450     lowp vec4 applyMask(lowp vec4 src) \
   489     lowp vec4 applyMask(lowp vec4 src) \n\
   451     {\
   490     { \n\
   452         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   491         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
   453         return src * mask; \
   492         return src * mask; \n\
   454     }";
   493     }\n";
   455 
   494 
   456 /*
   495 /*
   457     Left to implement:
   496     Left to implement:
   458         RgbMaskFragmentShader,
   497         RgbMaskFragmentShader,
   459         RgbMaskWithGammaFragmentShader,
   498         RgbMaskWithGammaFragmentShader,