summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qglengineshadersource_p.h
diff options
context:
space:
mode:
authorTom Cooksey <thomas.cooksey@nokia.com>2010-01-20 09:18:32 (GMT)
committerTom Cooksey <thomas.cooksey@nokia.com>2010-01-21 12:28:58 (GMT)
commit3a8236a01f89882d91e22a336f1e7134d3a84b68 (patch)
tree0fffca58e99c76092ccedfaf36157d0a48b9f4c4 /src/opengl/gl2paintengineex/qglengineshadersource_p.h
parent1729c2baea4e39f97d71b77f4c25af131f23221c (diff)
downloadQt-3a8236a01f89882d91e22a336f1e7134d3a84b68.zip
Qt-3a8236a01f89882d91e22a336f1e7134d3a84b68.tar.gz
Qt-3a8236a01f89882d91e22a336f1e7134d3a84b68.tar.bz2
Use an attribute value for the PMV matrix rather than a uniform
This has several advantages: First, updating an attribute value seems to be cheaper than updating a uniform. Second, vertex atribute values are independent of shader program, which means they persist across changing of the shader program. This makes code simpler and reduces GL state changes. Note: Credit goes to Samuel for finding this little gem. :-) For the 25920 solid QGraphicsRectItem test case, this gives 10% improvement on desktop and 27% on the SGX. Reviewed-By: Kim
Diffstat (limited to 'src/opengl/gl2paintengineex/qglengineshadersource_p.h')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadersource_p.h34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
index 6e98b02..b471b81 100644
--- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
@@ -97,9 +97,12 @@ static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\
// shader are also perspective corrected.
static const char* const qglslPositionOnlyVertexShader = "\
attribute highp vec2 vertexCoordsArray;\
- uniform highp mat3 pmvMatrix;\
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
void setPosition(void)\
{\
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \
}";
@@ -114,12 +117,15 @@ static const char* const qglslUntransformedPositionVertexShader = "\
// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
static const char* const qglslPositionWithPatternBrushVertexShader = "\
attribute highp vec2 vertexCoordsArray; \
- uniform highp mat3 pmvMatrix; \
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
uniform mediump vec2 halfViewportSize; \
uniform highp vec2 invertedTextureSize; \
uniform highp mat3 brushTransform; \
varying highp vec2 patternTexCoords; \
void setPosition(void) { \
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position.xy = transformedPos.xy / transformedPos.z; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
@@ -144,12 +150,15 @@ static const char* const qglslPatternBrushSrcFragmentShader = "\
// Linear Gradient Brush
static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
attribute highp vec2 vertexCoordsArray; \
- uniform highp mat3 pmvMatrix; \
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
uniform mediump vec2 halfViewportSize; \
uniform highp vec3 linearData; \
uniform highp mat3 brushTransform; \
varying mediump float index; \
void setPosition() { \
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position.xy = transformedPos.xy / transformedPos.z; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
@@ -174,12 +183,15 @@ static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
// Conical Gradient Brush
static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
attribute highp vec2 vertexCoordsArray;\
- uniform highp mat3 pmvMatrix;\
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
uniform mediump vec2 halfViewportSize; \
uniform highp mat3 brushTransform; \
varying highp vec2 A; \
- void setPosition(void)\
- {\
+ void setPosition(void) \
+ { \
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position.xy = transformedPos.xy / transformedPos.z; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
@@ -210,7 +222,9 @@ static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
// Radial Gradient Brush
static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
attribute highp vec2 vertexCoordsArray;\
- uniform highp mat3 pmvMatrix;\
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
uniform mediump vec2 halfViewportSize; \
uniform highp mat3 brushTransform; \
uniform highp vec2 fmp; \
@@ -218,6 +232,7 @@ static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
varying highp vec2 A; \
void setPosition(void) \
{\
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position.xy = transformedPos.xy / transformedPos.z; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
@@ -247,12 +262,15 @@ static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
// Texture Brush
static const char* const qglslPositionWithTextureBrushVertexShader = "\
attribute highp vec2 vertexCoordsArray; \
- uniform highp mat3 pmvMatrix; \
+ attribute highp vec3 pmvMatrix1; \
+ attribute highp vec3 pmvMatrix2; \
+ attribute highp vec3 pmvMatrix3; \
uniform mediump vec2 halfViewportSize; \
uniform highp vec2 invertedTextureSize; \
uniform highp mat3 brushTransform; \
varying highp vec2 textureCoords; \
void setPosition(void) { \
+ highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \
vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
gl_Position.xy = transformedPos.xy / transformedPos.z; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \