[cairo-commit] src/cairo-gl-shaders.c

Eric Anholt anholt at kemper.freedesktop.org
Sun Jul 11 21:58:11 PDT 2010


 src/cairo-gl-shaders.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

New commits:
commit 06ffb7df716652baba96960cd59e1a59f4bd1ac1
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Jul 10 14:19:50 2010 -0700

    gl: Only use a mat3 for the transformation for gradients coordinates.
    
    No point in passing in a column of zeroes that we multiply by zero, or
    the row that we drop on the floor.  We could do even better by just
    passing in a 3x2, at the expense of adding a language version
    dependency (or just pass in 2 vectors).
    
    No significant performance difference.

diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index b39c500..d7773f5 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -230,14 +230,13 @@ bind_matrix_arb (cairo_gl_shader_t *shader,
 		 cairo_matrix_t* m)
 {
     GLint location = glGetUniformLocationARB (shader->program, name);
-    float gl_m[16] = {
-        m->xx, m->xy, 0,     m->x0,
-        m->yx, m->yy, 0,     m->y0,
-        0,     0,     1,     0,
-        0,     0,     0,     1
+    float gl_m[9] = {
+        m->xx, m->xy, m->x0,
+        m->yx, m->yy, m->y0,
+        0,     0,     1
     };
     assert (location != -1);
-    glUniformMatrix4fvARB (location, 1, GL_TRUE, gl_m);
+    glUniformMatrix3fvARB (location, 1, GL_TRUE, gl_m);
 }
 
 static void
@@ -387,13 +386,12 @@ bind_matrix_core_2_0 (cairo_gl_shader_t *shader, const char *name, cairo_matrix_
 {
     GLint location = glGetUniformLocation (shader->program, name);
     float gl_m[16] = {
-        m->xx, m->xy, 0,     m->x0,
-        m->yx, m->yy, 0,     m->y0,
-        0,     0,     1,     0,
-        0,     0,     0,     1
+        m->xx, m->xy, m->x0,
+        m->yx, m->yy, m->y0,
+        0,     0,     1
     };
     assert (location != -1);
-    glUniformMatrix4fv (location, 1, GL_TRUE, gl_m);
+    glUniformMatrix3fv (location, 1, GL_TRUE, gl_m);
 }
 
 static void
@@ -703,12 +701,12 @@ cairo_gl_shader_emit_color (cairo_output_stream_t *stream,
     case CAIRO_GL_OPERAND_LINEAR_GRADIENT:
         _cairo_output_stream_printf (stream, 
             "uniform sampler1D %s_sampler;\n"
-            "uniform mat4 %s_matrix;\n"
+            "uniform mat3 %s_matrix;\n"
             "uniform vec2 %s_segment;\n"
             "\n"
             "vec4 get_%s()\n"
             "{\n"
-            "    vec2 pos = (%s_matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
+            "    vec2 pos = (%s_matrix * vec3 (gl_FragCoord.xy, 1.0)).xy;\n"
             "    float t = dot (pos, %s_segment) / dot (%s_segment, %s_segment);\n"
             "    return texture1D (%s_sampler, t);\n"
             "}\n",
@@ -718,14 +716,14 @@ cairo_gl_shader_emit_color (cairo_output_stream_t *stream,
     case CAIRO_GL_OPERAND_RADIAL_GRADIENT:
         _cairo_output_stream_printf (stream, 
             "uniform sampler1D %s_sampler;\n"
-            "uniform mat4 %s_matrix;\n"
+            "uniform mat3 %s_matrix;\n"
             "uniform vec2 %s_circle_1;\n"
             "uniform float %s_radius_0;\n"
             "uniform float %s_radius_1;\n"
             "\n"
             "vec4 get_%s()\n"
             "{\n"
-            "    vec2 pos = (%s_matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
+            "    vec2 pos = (%s_matrix * vec3 (gl_FragCoord.xy, 1.0)).xy;\n"
             "    \n"
             "    float dr = %s_radius_1 - %s_radius_0;\n"
             "    float dot_circle_1 = dot (%s_circle_1, %s_circle_1);\n"


More information about the cairo-commit mailing list