256 attribute highp vec4 vertexCoordsArray; \ |
256 attribute highp vec4 vertexCoordsArray; \ |
257 uniform highp mat4 pmvMatrix; \ |
257 uniform highp mat4 pmvMatrix; \ |
258 uniform mediump vec2 halfViewportSize; \ |
258 uniform mediump vec2 halfViewportSize; \ |
259 uniform highp vec2 invertedTextureSize; \ |
259 uniform highp vec2 invertedTextureSize; \ |
260 uniform highp mat3 brushTransform; \ |
260 uniform highp mat3 brushTransform; \ |
261 varying highp vec2 brushTextureCoords; \ |
261 varying highp vec2 textureCoords; \ |
262 void setPosition(void) { \ |
262 void setPosition(void) { \ |
263 gl_Position = pmvMatrix * vertexCoordsArray;\ |
263 gl_Position = pmvMatrix * vertexCoordsArray;\ |
264 gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
264 gl_Position.xy = gl_Position.xy / gl_Position.w; \ |
265 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
265 mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \ |
266 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
266 mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \ |
267 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
267 mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \ |
268 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
268 gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \ |
269 gl_Position.w = invertedHTexCoordsZ; \ |
269 gl_Position.w = invertedHTexCoordsZ; \ |
270 brushTextureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \ |
270 textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \ |
271 }"; |
271 }"; |
272 |
272 |
273 static const char* const qglslAffinePositionWithTextureBrushVertexShader |
273 static const char* const qglslAffinePositionWithTextureBrushVertexShader |
274 = qglslPositionWithTextureBrushVertexShader; |
274 = qglslPositionWithTextureBrushVertexShader; |
275 |
275 |
276 #if defined(QT_OPENGL_ES_2) |
276 #if defined(QT_OPENGL_ES_2) |
277 // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead, |
277 // 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. |
278 // 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 |
279 // TODO: Special case POT textures which don't need this emulation |
280 static const char* const qglslTextureBrushSrcFragmentShader = "\ |
280 static const char* const qglslTextureBrushSrcFragmentShader = "\ |
281 varying highp vec2 brushTextureCoords; \ |
281 varying highp vec2 textureCoords; \ |
282 uniform lowp sampler2D brushTexture; \ |
282 uniform lowp sampler2D brushTexture; \ |
283 lowp vec4 srcPixel() { \ |
283 lowp vec4 srcPixel() { \ |
284 return texture2D(brushTexture, fract(brushTextureCoords)); \ |
284 return texture2D(brushTexture, fract(textureCoords)); \ |
285 }"; |
285 }"; |
286 #else |
286 #else |
287 static const char* const qglslTextureBrushSrcFragmentShader = "\ |
287 static const char* const qglslTextureBrushSrcFragmentShader = "\ |
288 varying highp vec2 brushTextureCoords; \ |
288 varying highp vec2 textureCoords; \ |
289 uniform lowp sampler2D brushTexture; \ |
289 uniform lowp sampler2D brushTexture; \ |
290 lowp vec4 srcPixel() { \ |
290 lowp vec4 srcPixel() { \ |
291 return texture2D(brushTexture, brushTextureCoords); \ |
291 return texture2D(brushTexture, textureCoords); \ |
292 }"; |
292 }"; |
293 #endif |
293 #endif |
294 |
294 |
295 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\ |
295 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\ |
296 varying highp vec2 brushTextureCoords; \ |
296 varying highp vec2 textureCoords; \ |
297 uniform lowp vec4 patternColor; \ |
297 uniform lowp vec4 patternColor; \ |
298 uniform lowp sampler2D brushTexture; \ |
298 uniform lowp sampler2D brushTexture; \ |
299 lowp vec4 srcPixel() { \ |
299 lowp vec4 srcPixel() { \ |
300 return patternColor * (1.0 - texture2D(brushTexture, brushTextureCoords).r); \ |
300 return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \ |
301 }"; |
301 }"; |
302 |
302 |
303 // Solid Fill Brush |
303 // Solid Fill Brush |
304 static const char* const qglslSolidBrushSrcFragmentShader = "\ |
304 static const char* const qglslSolidBrushSrcFragmentShader = "\ |
305 uniform lowp vec4 fragmentColor; \ |
305 uniform lowp vec4 fragmentColor; \ |