diff options
author | Filippo Argiolas <filippo.argiolas@gmail.com> | 2010-04-26 12:45:57 +0200 |
---|---|---|
committer | Filippo Argiolas <filippo.argiolas@gmail.com> | 2010-04-26 13:09:38 +0200 |
commit | a81d386308afa5e57d08b4f5fc984a06cbdf223d (patch) | |
tree | 8f6913c17e6253c4e6f6620e3ed9a85d0dc5ac79 | |
parent | 15f8e2d17a61bf505c2c6fcd1296f776cd48dfee (diff) |
convolution: save some indirection grouping math and sampling
Thanks to Eric Anholt I've finally understood (at least I hope) how to
count texture indirections and save up some. Texture sampling dependent
on the result of some math counts as an indirection phase. Grouped
texture lookups with no math involved count as a single indirection.
Math on the coordinates count as indirection.
So the best thing is to group all the math involving coordinates and
then do all the lookups.
This saves enough indirections to make glfilterblur and glow effect
work, albeit a bit slowly, on i915.
-rw-r--r-- | gst/gl/effects/gstgleffectssources.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/gst/gl/effects/gstgleffectssources.c b/gst/gl/effects/gstgleffectssources.c index aeaeb7d..6934712 100644 --- a/gst/gl/effects/gstgleffectssources.c +++ b/gst/gl/effects/gstgleffectssources.c @@ -308,13 +308,22 @@ const gchar *hconv9_fragment_source = "uniform sampler2DRect tex;" "uniform float kernel[9];" "void main () {" - " vec2 texturecoord = gl_TexCoord[0].st;" - " texturecoord.s -= 4.0;" + " vec2 texturecoord[10];" + " float s = gl_TexCoord[0].s;" + " float t = gl_TexCoord[0].t;" + " texturecoord[0] = vec2(s-4.0, t);" + " texturecoord[1] = vec2(s-3.0, t);" + " texturecoord[2] = vec2(s-2.0, t);" + " texturecoord[3] = vec2(s-1.0, t);" + " texturecoord[4] = vec2(s, t);" + " texturecoord[5] = vec2(s+1.0, t);" + " texturecoord[6] = vec2(s+2.0, t);" + " texturecoord[7] = vec2(s+3.0, t);" + " texturecoord[8] = vec2(s+4.0, t);" " int i;" " vec4 sum = vec4 (0.0);" " for (i = 0; i < 9; i++) { " - " vec4 neighbor = texture2DRect(tex, texturecoord); " - " ++texturecoord.s;" + " vec4 neighbor = texture2DRect(tex, texturecoord[i]); " " sum += neighbor * kernel[i];" " }" " gl_FragColor = sum;" @@ -326,13 +335,22 @@ const gchar *vconv9_fragment_source = "uniform sampler2DRect tex;" "uniform float kernel[9];" "void main () {" - " vec2 texturecoord = gl_TexCoord[0].st;" - " texturecoord.t -= 4.0;" + " vec2 texturecoord[9];" + " float s = gl_TexCoord[0].s;" + " float t = gl_TexCoord[0].t;" + " texturecoord[0] = vec2(s, t-4.0);" + " texturecoord[1] = vec2(s, t-3.0);" + " texturecoord[2] = vec2(s, t-2.0);" + " texturecoord[3] = vec2(s, t-1.0);" + " texturecoord[4] = vec2(s, t);" + " texturecoord[5] = vec2(s, t+1.0);" + " texturecoord[6] = vec2(s, t+2.0);" + " texturecoord[7] = vec2(s, t+3.0);" + " texturecoord[8] = vec2(s, t+4.0);" " int i;" " vec4 sum = vec4 (0.0);" " for (i = 0; i < 9; i++) { " - " vec4 neighbor = texture2DRect(tex, texturecoord); " - " ++texturecoord.t;" + " vec4 neighbor = texture2DRect(tex, texturecoord[i]);" " sum += neighbor * kernel[i]; " " }" " gl_FragColor = sum;" |