src/opengl/gl2paintengineex/qglengineshadersource_p.h
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 7 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
    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     { \
       
    96             setPosition(); \
       
    97             gl_Position.z = depth * gl_Position.w; \
       
    98             textureCoords = textureCoordArray; \
       
    99             opacity = opacityArray; \
       
   100     }";
       
   101 
    95 
   102 // NOTE: We let GL do the perspective correction so texture lookups in the fragment
    96 // NOTE: We let GL do the perspective correction so texture lookups in the fragment
   103 //       shader are also perspective corrected.
    97 //       shader are also perspective corrected.
   104 static const char* const qglslPositionOnlyVertexShader = "\
    98 static const char* const qglslPositionOnlyVertexShader = "\n\
   105     attribute highp vec2    vertexCoordsArray;\
    99     attribute highp   vec2      vertexCoordsArray; \n\
   106     uniform   highp mat3    pmvMatrix;\
   100     attribute highp   vec3      pmvMatrix1; \n\
   107     void setPosition(void)\
   101     attribute highp   vec3      pmvMatrix2; \n\
   108     {\
   102     attribute highp   vec3      pmvMatrix3; \n\
   109         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   103     void setPosition(void) \n\
   110         gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \
   104     { \n\
   111     }";
   105         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   112 
   106         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   113 static const char* const qglslUntransformedPositionVertexShader = "\
   107         gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \n\
   114     attribute highp vec4    vertexCoordsArray;\
   108     }\n";
   115     void setPosition(void)\
   109 
   116     {\
   110 static const char* const qglslUntransformedPositionVertexShader = "\n\
   117             gl_Position = vertexCoordsArray;\
   111     attribute highp   vec4      vertexCoordsArray; \n\
   118     }";
   112     void setPosition(void) \n\
       
   113     { \n\
       
   114         gl_Position = vertexCoordsArray; \n\
       
   115     }\n";
   119 
   116 
   120 // 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
   121 static const char* const qglslPositionWithPatternBrushVertexShader = "\
   118 static const char* const qglslPositionWithPatternBrushVertexShader = "\n\
   122     attribute highp   vec2  vertexCoordsArray; \
   119     attribute highp   vec2      vertexCoordsArray; \n\
   123     uniform   highp   mat3  pmvMatrix; \
   120     attribute highp   vec3      pmvMatrix1; \n\
   124     uniform   mediump vec2  halfViewportSize; \
   121     attribute highp   vec3      pmvMatrix2; \n\
   125     uniform   highp   vec2  invertedTextureSize; \
   122     attribute highp   vec3      pmvMatrix3; \n\
   126     uniform   highp   mat3  brushTransform; \
   123     uniform   mediump vec2      halfViewportSize; \n\
   127     varying   highp   vec2  patternTexCoords; \
   124     uniform   highp   vec2      invertedTextureSize; \n\
   128     void setPosition(void) { \
   125     uniform   highp   mat3      brushTransform; \n\
   129             vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   126     varying   highp   vec2      patternTexCoords; \n\
   130             gl_Position.xy = transformedPos.xy / transformedPos.z; \
   127     void setPosition(void) \n\
   131             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   128     { \n\
   132             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \
   129         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   133             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   130         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   134             gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
   131         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   135             patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
   132         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   136     }";
   133         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
       
   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";
   137 
   138 
   138 static const char* const qglslAffinePositionWithPatternBrushVertexShader
   139 static const char* const qglslAffinePositionWithPatternBrushVertexShader
   139                  = qglslPositionWithPatternBrushVertexShader;
   140                  = qglslPositionWithPatternBrushVertexShader;
   140 
   141 
   141 static const char* const qglslPatternBrushSrcFragmentShader = "\
   142 static const char* const qglslPatternBrushSrcFragmentShader = "\n\
   142     uniform lowp    sampler2D brushTexture;\
   143     uniform   lowp    sampler2D brushTexture; \n\
   143     uniform lowp    vec4      patternColor; \
   144     uniform   lowp    vec4      patternColor; \n\
   144     varying highp   vec2      patternTexCoords;\
   145     varying   highp   vec2      patternTexCoords;\n\
   145     lowp vec4 srcPixel() { \
   146     lowp vec4 srcPixel() \n\
   146         return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \
   147     { \n\
       
   148         return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \n\
   147     }\n";
   149     }\n";
   148 
   150 
   149 
   151 
   150 // Linear Gradient Brush
   152 // Linear Gradient Brush
   151 static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
   153 static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\n\
   152     attribute highp   vec2  vertexCoordsArray; \
   154     attribute highp   vec2      vertexCoordsArray; \n\
   153     uniform   highp   mat3  pmvMatrix; \
   155     attribute highp   vec3      pmvMatrix1; \n\
   154     uniform   mediump vec2  halfViewportSize; \
   156     attribute highp   vec3      pmvMatrix2; \n\
   155     uniform   highp   vec3  linearData; \
   157     attribute highp   vec3      pmvMatrix3; \n\
   156     uniform   highp   mat3  brushTransform; \
   158     uniform   mediump vec2      halfViewportSize; \n\
   157     varying   mediump float index; \
   159     uniform   highp   vec3      linearData; \n\
   158     void setPosition() { \
   160     uniform   highp   mat3      brushTransform; \n\
   159         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   161     varying   mediump float     index; \n\
   160         gl_Position.xy = transformedPos.xy / transformedPos.z; \
   162     void setPosition() \n\
   161         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   163     { \n\
   162         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   164         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   163         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   165         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   164         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
   166         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   165         index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
   167         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   166     }";
   168         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
       
   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";
   167 
   173 
   168 static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
   174 static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
   169                  = qglslPositionWithLinearGradientBrushVertexShader;
   175                  = qglslPositionWithLinearGradientBrushVertexShader;
   170 
   176 
   171 static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
   177 static const char* const qglslLinearGradientBrushSrcFragmentShader = "\n\
   172     uniform lowp    sampler2D   brushTexture; \
   178     uniform   lowp    sampler2D brushTexture; \n\
   173     varying mediump float       index; \
   179     varying   mediump float     index; \n\
   174     lowp vec4 srcPixel() { \
   180     lowp vec4 srcPixel() \n\
   175         mediump vec2 val = vec2(index, 0.5); \
   181     { \n\
   176         return texture2D(brushTexture, val); \
   182         mediump vec2 val = vec2(index, 0.5); \n\
       
   183         return texture2D(brushTexture, val); \n\
   177     }\n";
   184     }\n";
   178 
   185 
   179 
   186 
   180 // Conical Gradient Brush
   187 // Conical Gradient Brush
   181 static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
   188 static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\n\
   182     attribute highp   vec2  vertexCoordsArray;\
   189     attribute highp   vec2      vertexCoordsArray; \n\
   183     uniform   highp   mat3  pmvMatrix;\
   190     attribute highp   vec3      pmvMatrix1; \n\
   184     uniform   mediump vec2  halfViewportSize; \
   191     attribute highp   vec3      pmvMatrix2; \n\
   185     uniform   highp   mat3  brushTransform; \
   192     attribute highp   vec3      pmvMatrix3; \n\
   186     varying   highp   vec2  A; \
   193     uniform   mediump vec2      halfViewportSize; \n\
   187     void setPosition(void)\
   194     uniform   highp   mat3      brushTransform; \n\
   188     {\
   195     varying   highp   vec2      A; \n\
   189         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   196     void setPosition(void) \n\
   190         gl_Position.xy = transformedPos.xy / transformedPos.z; \
   197     { \n\
   191         mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   198         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   192         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   199         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   193         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   200         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   194         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
   201         mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   195         A = hTexCoords.xy * invertedHTexCoordsZ; \
   202         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   196     }";
   203         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
       
   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   vec2 vertexCoordsArray;\
   229     attribute highp   vec2      vertexCoordsArray;\n\
   219     uniform   highp   mat3 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         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   238     void setPosition(void) \n\
   228         gl_Position.xy = transformedPos.xy / transformedPos.z; \
   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 = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
   243         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   233         A = hTexCoords.xy * invertedHTexCoordsZ; \
   244         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
   234         b = 2.0 * dot(A, fmp); \
   245         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
   235     }";
   246         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
       
   247         A = hTexCoords.xy * invertedHTexCoordsZ; \n\
       
   248         b = 2.0 * dot(A, fmp); \n\
       
   249     }\n";
   236 
   250 
   237 static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
   251 static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
   238                  = qglslPositionWithRadialGradientBrushVertexShader;
   252                  = qglslPositionWithRadialGradientBrushVertexShader;
   239 
   253 
   240 static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
   254 static const char* const qglslRadialGradientBrushSrcFragmentShader = "\n\
   241     uniform lowp    sampler2D   brushTexture; \
   255     uniform   lowp    sampler2D brushTexture; \n\
   242     uniform highp   float       fmp2_m_radius2; \
   256     uniform   highp   float     fmp2_m_radius2; \n\
   243     uniform highp   float       inverse_2_fmp2_m_radius2; \
   257     uniform   highp   float     inverse_2_fmp2_m_radius2; \n\
   244     varying highp   float       b; \
   258     varying   highp   float     b; \n\
   245     varying highp   vec2        A; \
   259     varying   highp   vec2      A; \n\
   246     lowp vec4 srcPixel() { \
   260     lowp vec4 srcPixel() \n\
   247         highp float c = -dot(A, A); \
   261     { \n\
   248         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\
   249         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\
   250     }";
   264         return texture2D(brushTexture, val); \n\
       
   265     }\n";
   251 
   266 
   252 
   267 
   253 // Texture Brush
   268 // Texture Brush
   254 static const char* const qglslPositionWithTextureBrushVertexShader = "\
   269 static const char* const qglslPositionWithTextureBrushVertexShader = "\n\
   255     attribute highp   vec2 vertexCoordsArray; \
   270     attribute highp   vec2      vertexCoordsArray; \n\
   256     uniform   highp   mat3  pmvMatrix; \
   271     attribute highp   vec3      pmvMatrix1; \n\
   257     uniform   mediump vec2  halfViewportSize; \
   272     attribute highp   vec3      pmvMatrix2; \n\
   258     uniform   highp   vec2  invertedTextureSize; \
   273     attribute highp   vec3      pmvMatrix3; \n\
   259     uniform   highp   mat3  brushTransform; \
   274     uniform   mediump vec2      halfViewportSize; \n\
   260     varying   highp   vec2  textureCoords; \
   275     uniform   highp   vec2      invertedTextureSize; \n\
   261     void setPosition(void) { \
   276     uniform   highp   mat3      brushTransform; \n\
   262             vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
   277     varying   highp   vec2      textureCoords; \n\
   263             gl_Position.xy = transformedPos.xy / transformedPos.z; \
   278     void setPosition(void) \n\
   264             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
   279     { \n\
   265             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
   280         highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
   266             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
   281         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
   267             gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
   282         gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
   268             textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
   283         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
   269     }";
   284         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
       
   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";
   270 
   289 
   271 static const char* const qglslAffinePositionWithTextureBrushVertexShader
   290 static const char* const qglslAffinePositionWithTextureBrushVertexShader
   272                  = qglslPositionWithTextureBrushVertexShader;
   291                  = qglslPositionWithTextureBrushVertexShader;
   273 
   292 
   274 #if defined(QT_OPENGL_ES_2)
   293 #if defined(QT_OPENGL_ES_2)
   275 // 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,
   276 // 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.
   277 // TODO: Special case POT textures which don't need this emulation
   296 // TODO: Special case POT textures which don't need this emulation
   278 static const char* const qglslTextureBrushSrcFragmentShader = "\
   297 static const char* const qglslTextureBrushSrcFragmentShader = "\n\
   279     varying highp   vec2      textureCoords; \
   298     varying highp   vec2      textureCoords; \n\
   280     uniform lowp    sampler2D brushTexture; \
   299     uniform lowp    sampler2D brushTexture; \n\
   281     lowp vec4 srcPixel() { \
   300     lowp vec4 srcPixel() { \n\
   282         return texture2D(brushTexture, fract(textureCoords)); \
   301         return texture2D(brushTexture, fract(textureCoords)); \n\
   283     }";
   302     }\n";
   284 #else
   303 #else
   285 static const char* const qglslTextureBrushSrcFragmentShader = "\
   304 static const char* const qglslTextureBrushSrcFragmentShader = "\n\
   286     varying highp   vec2      textureCoords; \
   305     varying   highp   vec2      textureCoords; \n\
   287     uniform lowp    sampler2D brushTexture; \
   306     uniform   lowp    sampler2D brushTexture; \n\
   288     lowp vec4 srcPixel() { \
   307     lowp vec4 srcPixel() \n\
   289         return texture2D(brushTexture, textureCoords); \
   308     { \n\
   290     }";
   309         return texture2D(brushTexture, textureCoords); \n\
       
   310     }\n";
   291 #endif
   311 #endif
   292 
   312 
   293 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\
   313 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\n\
   294     varying highp   vec2      textureCoords; \
   314     varying   highp   vec2      textureCoords; \n\
   295     uniform lowp    vec4      patternColor; \
   315     uniform   lowp    vec4      patternColor; \n\
   296     uniform lowp    sampler2D brushTexture; \
   316     uniform   lowp    sampler2D brushTexture; \n\
   297     lowp vec4 srcPixel() { \
   317     lowp vec4 srcPixel() \n\
   298         return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \
   318     { \n\
   299     }";
   319         return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \n\
       
   320     }\n";
   300 
   321 
   301 // Solid Fill Brush
   322 // Solid Fill Brush
   302 static const char* const qglslSolidBrushSrcFragmentShader = "\
   323 static const char* const qglslSolidBrushSrcFragmentShader = "\n\
   303     uniform lowp vec4 fragmentColor; \
   324     uniform   lowp    vec4      fragmentColor; \n\
   304     lowp vec4 srcPixel() { \
   325     lowp vec4 srcPixel() \n\
   305         return fragmentColor; \
   326     { \n\
   306     }";
   327         return fragmentColor; \n\
   307 
   328     }\n";
   308 static const char* const qglslImageSrcFragmentShader = "\
   329 
   309     varying highp   vec2    textureCoords; \
   330 static const char* const qglslImageSrcFragmentShader = "\n\
   310     uniform lowp  sampler2D imageTexture; \
   331     varying   highp   vec2      textureCoords; \n\
   311     lowp vec4 srcPixel() { \
   332     uniform   lowp    sampler2D imageTexture; \n\
   312         return texture2D(imageTexture, textureCoords); \
   333     lowp vec4 srcPixel() \n\
   313     }";
   334     { \n\
   314 
   335         return texture2D(imageTexture, textureCoords); \n\
   315 static const char* const qglslCustomSrcFragmentShader = "\
   336     }\n";
   316     varying highp vec2      textureCoords; \
   337 
   317     uniform lowp  sampler2D imageTexture; \
   338 static const char* const qglslCustomSrcFragmentShader = "\n\
   318     lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \
   339     varying   highp   vec2      textureCoords; \n\
   319     lowp vec4 srcPixel() { \
   340     uniform   lowp    sampler2D imageTexture; \n\
   320         return customShader(imageTexture, textureCoords); \
   341     lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \n\
   321     }";
   342     lowp vec4 srcPixel() \n\
   322 
   343     { \n\
   323 static const char* const qglslImageSrcWithPatternFragmentShader = "\
   344         return customShader(imageTexture, textureCoords); \n\
   324     varying highp vec2      textureCoords; \
   345     }\n";
   325     uniform lowp  vec4      patternColor; \
   346 
   326     uniform lowp  sampler2D imageTexture; \
   347 static const char* const qglslImageSrcWithPatternFragmentShader = "\n\
   327     lowp vec4 srcPixel() { \
   348     varying   highp   vec2      textureCoords; \n\
   328         return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \
   349     uniform   lowp    vec4      patternColor; \n\
   329     }\n";
   350     uniform   lowp    sampler2D imageTexture; \n\
   330 
   351     lowp vec4 srcPixel() \n\
   331 static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
   352     { \n\
   332     varying highp vec2      textureCoords; \
   353         return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \n\
   333     uniform lowp  sampler2D imageTexture; \
   354     }\n";
   334     lowp vec4 srcPixel() { \
   355 
   335         lowp vec4 sample = texture2D(imageTexture, textureCoords); \
   356 static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\n\
   336         sample.rgb = sample.rgb * sample.a; \
   357     varying   highp   vec2      textureCoords; \n\
   337         return sample; \
   358     uniform   lowp    sampler2D imageTexture; \n\
   338     }";
   359     lowp vec4 srcPixel() \n\
   339 
   360     { \n\
   340 static const char* const qglslShockingPinkSrcFragmentShader = "\
   361         lowp vec4 sample = texture2D(imageTexture, textureCoords); \n\
   341     lowp vec4 srcPixel() { \
   362         sample.rgb = sample.rgb * sample.a; \n\
   342         return vec4(0.98, 0.06, 0.75, 1.0); \
   363         return sample; \n\
   343     }";
   364     }\n";
   344 
   365 
   345 static const char* const qglslMainFragmentShader_ImageArrays = "\
   366 static const char* const qglslShockingPinkSrcFragmentShader = "\n\
   346     varying lowp float opacity; \
   367     lowp vec4 srcPixel() \n\
   347     lowp vec4 srcPixel(); \
   368     { \n\
   348     void main() { \
   369         return vec4(0.98, 0.06, 0.75, 1.0); \n\
   349         gl_FragColor = srcPixel() * opacity; \
   370     }\n";
   350     }";
   371 
   351 
   372 static const char* const qglslMainFragmentShader_ImageArrays = "\n\
   352 static const char* const qglslMainFragmentShader_CMO = "\
   373     varying   lowp    float     opacity; \n\
   353     uniform lowp float globalOpacity; \
   374     lowp vec4 srcPixel(); \n\
   354     lowp vec4 srcPixel(); \
   375     void main() \n\
   355     lowp vec4 applyMask(lowp vec4); \
   376     { \n\
   356     lowp vec4 compose(lowp vec4); \
   377         gl_FragColor = srcPixel() * opacity; \n\
   357     void main() { \
   378     }\n";
   358         gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \
   379 
   359     }";
   380 static const char* const qglslMainFragmentShader_CMO = "\n\
   360 
   381     uniform   lowp    float     globalOpacity; \n\
   361 static const char* const qglslMainFragmentShader_CM = "\
   382     lowp vec4 srcPixel(); \n\
   362     lowp vec4 srcPixel(); \
   383     lowp vec4 applyMask(lowp vec4); \n\
   363     lowp vec4 applyMask(lowp vec4); \
   384     lowp vec4 compose(lowp vec4); \n\
   364     lowp vec4 compose(lowp vec4); \
   385     void main() \n\
   365     void main() { \
   386     { \n\
   366         gl_FragColor = applyMask(compose(srcPixel())); \
   387         gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
   367     }";
   388     }\n";
   368 
   389 
   369 static const char* const qglslMainFragmentShader_MO = "\
   390 static const char* const qglslMainFragmentShader_CM = "\n\
   370     uniform lowp float globalOpacity; \
   391     lowp vec4 srcPixel(); \n\
   371     lowp vec4 srcPixel(); \
   392     lowp vec4 applyMask(lowp vec4); \n\
   372     lowp vec4 applyMask(lowp vec4); \
   393     lowp vec4 compose(lowp vec4); \n\
   373     void main() { \
   394     void main() \n\
   374         gl_FragColor = applyMask(srcPixel()*globalOpacity); \
   395     { \n\
   375     }";
   396         gl_FragColor = applyMask(compose(srcPixel())); \n\
   376 
   397     }\n";
   377 static const char* const qglslMainFragmentShader_M = "\
   398 
   378     lowp vec4 srcPixel(); \
   399 static const char* const qglslMainFragmentShader_MO = "\n\
   379     lowp vec4 applyMask(lowp vec4); \
   400     uniform   lowp    float     globalOpacity; \n\
   380     void main() { \
   401     lowp vec4 srcPixel(); \n\
   381         gl_FragColor = applyMask(srcPixel()); \
   402     lowp vec4 applyMask(lowp vec4); \n\
   382     }";
   403     void main() \n\
   383 
   404     { \n\
   384 static const char* const qglslMainFragmentShader_CO = "\
   405         gl_FragColor = applyMask(srcPixel()*globalOpacity); \n\
   385     uniform lowp float globalOpacity; \
   406     }\n";
   386     lowp vec4 srcPixel(); \
   407 
   387     lowp vec4 compose(lowp vec4); \
   408 static const char* const qglslMainFragmentShader_M = "\n\
   388     void main() { \
   409     lowp vec4 srcPixel(); \n\
   389         gl_FragColor = compose(srcPixel()*globalOpacity); \
   410     lowp vec4 applyMask(lowp vec4); \n\
   390     }";
   411     void main() \n\
   391 
   412     { \n\
   392 static const char* const qglslMainFragmentShader_C = "\
   413         gl_FragColor = applyMask(srcPixel()); \n\
   393     lowp vec4 srcPixel(); \
   414     }\n";
   394     lowp vec4 compose(lowp vec4); \
   415 
   395     void main() { \
   416 static const char* const qglslMainFragmentShader_CO = "\n\
   396         gl_FragColor = compose(srcPixel()); \
   417     uniform   lowp    float     globalOpacity; \n\
   397     }";
   418     lowp vec4 srcPixel(); \n\
   398 
   419     lowp vec4 compose(lowp vec4); \n\
   399 static const char* const qglslMainFragmentShader_O = "\
   420     void main() \n\
   400     uniform lowp float globalOpacity; \
   421     { \n\
   401     lowp vec4 srcPixel(); \
   422         gl_FragColor = compose(srcPixel()*globalOpacity); \n\
   402     void main() { \
   423     }\n";
   403         gl_FragColor = srcPixel()*globalOpacity; \
   424 
   404     }";
   425 static const char* const qglslMainFragmentShader_C = "\n\
   405 
   426     lowp vec4 srcPixel(); \n\
   406 static const char* const qglslMainFragmentShader = "\
   427     lowp vec4 compose(lowp vec4); \n\
   407     lowp vec4 srcPixel(); \
   428     void main() \n\
   408     void main() { \
   429     { \n\
   409         gl_FragColor = srcPixel(); \
   430         gl_FragColor = compose(srcPixel()); \n\
   410     }";
   431     }\n";
   411 
   432 
   412 static const char* const qglslMaskFragmentShader = "\
   433 static const char* const qglslMainFragmentShader_O = "\n\
   413     varying highp   vec2      textureCoords;\
   434     uniform   lowp    float     globalOpacity; \n\
   414     uniform lowp    sampler2D maskTexture;\
   435     lowp vec4 srcPixel(); \n\
   415     lowp vec4 applyMask(lowp vec4 src) \
   436     void main() \n\
   416     {\
   437     { \n\
   417         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   438         gl_FragColor = srcPixel()*globalOpacity; \n\
   418         return src * mask.a; \
   439     }\n";
   419     }";
   440 
       
   441 static const char* const qglslMainFragmentShader = "\n\
       
   442     lowp vec4 srcPixel(); \n\
       
   443     void main() \n\
       
   444     { \n\
       
   445         gl_FragColor = srcPixel(); \n\
       
   446     }\n";
       
   447 
       
   448 static const char* const qglslMaskFragmentShader = "\n\
       
   449     varying   highp   vec2      textureCoords;\n\
       
   450     uniform   lowp    sampler2D maskTexture;\n\
       
   451     lowp vec4 applyMask(lowp vec4 src) \n\
       
   452     {\n\
       
   453         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
       
   454         return src * mask.a; \n\
       
   455     }\n";
   420 
   456 
   421 // For source over with subpixel antialiasing, the final color is calculated per component as follows
   457 // For source over with subpixel antialiasing, the final color is calculated per component as follows
   422 // (.a is alpha component, .c is red, green or blue component):
   458 // (.a is alpha component, .c is red, green or blue component):
   423 // alpha = src.a * mask.c * opacity
   459 // alpha = src.a * mask.c * opacity
   424 // dest.c = dest.c * (1 - alpha) + src.c * alpha
   460 // dest.c = dest.c * (1 - alpha) + src.c * alpha
   431 // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
   467 // For source composition with subpixel antialiasing, the final color is calculated per component as follows:
   432 // alpha = src.a * mask.c * opacity
   468 // alpha = src.a * mask.c * opacity
   433 // dest.c = dest.c * (1 - mask.c) + src.c * alpha
   469 // dest.c = dest.c * (1 - mask.c) + src.c * alpha
   434 //
   470 //
   435 
   471 
   436 static const char* const qglslRgbMaskFragmentShaderPass1 = "\
   472 static const char* const qglslRgbMaskFragmentShaderPass1 = "\n\
   437     varying highp   vec2      textureCoords;\
   473     varying   highp   vec2      textureCoords;\n\
   438     uniform lowp    sampler2D maskTexture;\
   474     uniform   lowp    sampler2D maskTexture;\n\
   439     lowp vec4 applyMask(lowp vec4 src) \
   475     lowp vec4 applyMask(lowp vec4 src) \n\
   440     {\
   476     { \n\
   441         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   477         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
   442         return src.a * mask; \
   478         return src.a * mask; \n\
   443     }";
   479     }\n";
   444 
   480 
   445 static const char* const qglslRgbMaskFragmentShaderPass2 = "\
   481 static const char* const qglslRgbMaskFragmentShaderPass2 = "\n\
   446     varying highp   vec2      textureCoords;\
   482     varying   highp   vec2      textureCoords;\n\
   447     uniform lowp    sampler2D maskTexture;\
   483     uniform   lowp    sampler2D maskTexture;\n\
   448     lowp vec4 applyMask(lowp vec4 src) \
   484     lowp vec4 applyMask(lowp vec4 src) \n\
   449     {\
   485     { \n\
   450         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
   486         lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
   451         return src * mask; \
   487         return src * mask; \n\
   452     }";
   488     }\n";
   453 
   489 
   454 /*
   490 /*
   455     Left to implement:
   491     Left to implement:
   456         RgbMaskFragmentShader,
   492         RgbMaskFragmentShader,
   457         RgbMaskWithGammaFragmentShader,
   493         RgbMaskWithGammaFragmentShader,