summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippo Argiolas <filippo.argiolas@gmail.com>2010-04-29 09:02:12 +0200
committerFilippo Argiolas <filippo.argiolas@gmail.com>2010-04-29 09:39:35 +0200
commitf185b07e4e26e6c226498b870477f40d60e96cdf (patch)
tree5a301ecf51c45d106dff5d641022fbb63513d91c
parent6184670652af5f378eec42fae84971b0754855cd (diff)
laplacian: precalculate coordinates
Precalculate coordinates to avoid unneeded texture indirections. Now laplacian works on i915.
-rw-r--r--gst/gl/gstglfilterlaplacian.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/gst/gl/gstglfilterlaplacian.c b/gst/gl/gstglfilterlaplacian.c
index c6ebe0f..79de5bb 100644
--- a/gst/gl/gstglfilterlaplacian.c
+++ b/gst/gl/gstglfilterlaplacian.c
@@ -1,6 +1,6 @@
/*
* GStreamer
- * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
+ * Copyright (C) 2008-2010 Filippo Argiolas <filippo.argiolas@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -65,30 +65,35 @@ static void gst_gl_filter_laplacian_callback (gint width, gint height,
guint texture, gpointer stuff);
/* *INDENT-OFF* */
+
+/* This filter is meant as a demo of gst-plugins-gl + glsl
+ capabilities. So I'm keeping this shader readable enough. If and
+ when this shader will be used in production be careful to hard code
+ kernel into the shader and remove unneeded zero multiplications in
+ the convolution */
static const gchar *convolution_fragment_source =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect tex;"
- "uniform float kernel[9];"
- "void main () {"
- " vec2 offset[9];"
- " offset[0] = vec2(-1.0,-1.0);"
- " offset[1] = vec2( 0.0,-1.0);"
- " offset[2] = vec2( 1.0,-1.0);"
- " offset[3] = vec2(-1.0, 0.0);"
- " offset[4] = vec2( 0.0, 0.0);"
- " offset[5] = vec2( 1.0, 0.0);"
- " offset[6] = vec2(-1.0, 1.0);"
- " offset[7] = vec2( 0.0, 1.0);"
- " offset[8] = vec2( 1.0, 1.0);"
- " vec2 texturecoord = gl_TexCoord[0].st;"
- " int i;"
- " vec4 sum = vec4 (0.0);"
- " for (i = 0; i < 9; i++) { "
- " vec4 neighbor = texture2DRect(tex, texturecoord + vec2(offset[i]));"
- " sum += neighbor * kernel[i];"
- " }"
- " gl_FragColor = sum;"
- "}";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect tex;"
+ "uniform float kernel[9];"
+ "void main () {"
+ " vec2 texturecoord[9];"
+ " texturecoord[4] = gl_TexCoord[0].st;" /* 0 0 */
+ " texturecoord[5] = texturecoord[4] + vec2(1.0, 0.0);" /* 1 0 */
+ " texturecoord[2] = texturecoord[5] - vec2(0.0, 1.0);" /* 1 -1 */
+ " texturecoord[1] = texturecoord[2] - vec2(1.0, 0.0);" /* 0 -1 */
+ " texturecoord[0] = texturecoord[1] - vec2(1.0, 0.0);" /* -1 -1 */
+ " texturecoord[3] = texturecoord[0] + vec2(0.0, 1.0);" /* -1 0 */
+ " texturecoord[6] = texturecoord[3] + vec2(0.0, 1.0);" /* -1 1 */
+ " texturecoord[7] = texturecoord[6] + vec2(1.0, 0.0);" /* 0 1 */
+ " texturecoord[8] = texturecoord[7] + vec2(1.0, 0.0);" /* 1 1 */
+ " int i;"
+ " vec4 sum = vec4 (0.0);"
+ " for (i = 0; i < 9; i++) { "
+ " vec4 neighbor = texture2DRect(tex, texturecoord[i]);"
+ " sum += neighbor * kernel[i];"
+ " }"
+ " gl_FragColor = sum;"
+ "}";
/* *INDENT-ON* */
static void