[169/906] import remaining distortion effects from cvs branch (fisheye, twirl, bulge...
authorFilippo Argiolas <filippo.argiolas@gmail.com>
Thu, 14 Aug 2008 12:08:23 +0000 (14:08 +0200)
committerMatthew Waters <ystreet00@gmail.com>
Sat, 15 Mar 2014 17:36:25 +0000 (18:36 +0100)
gst/gl/Makefile.am
gst/gl/effects/gstgleffectbulge.c [new file with mode: 0644]
gst/gl/effects/gstgleffectfisheye.c [new file with mode: 0644]
gst/gl/effects/gstgleffectsdistortion.c [new file with mode: 0644]
gst/gl/effects/gstgleffectsquare.c [new file with mode: 0644]
gst/gl/effects/gstgleffectssources.c
gst/gl/effects/gstgleffectssources.h
gst/gl/effects/gstgleffecttunnel.c [new file with mode: 0644]
gst/gl/effects/gstgleffecttwirl.c [new file with mode: 0644]
gst/gl/gstgleffects.c
gst/gl/gstgleffects.h

index 0cc1e2f..4a1780d 100644 (file)
@@ -34,6 +34,11 @@ libgstopengl_la_SOURCES = \
        effects/gstgleffectmirror.c \
        effects/gstgleffectsqueeze.c \
        effects/gstgleffectstretch.c \
+       effects/gstgleffecttunnel.c \
+       effects/gstgleffectfisheye.c \
+       effects/gstgleffecttwirl.c \
+       effects/gstgleffectbulge.c \
+       effects/gstgleffectsquare.c \
        effects/gstgleffectlumatocurve.c \
        effects/gstgleffectrgbtocurve.c \
        effects/gstgleffectglow.c 
diff --git a/gst/gl/effects/gstgleffectbulge.c b/gst/gl/effects/gstgleffectbulge.c
new file mode 100644 (file)
index 0000000..5af38b9
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_bulge_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "bulge0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "bulge0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, bulge_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", tex_size[0]); 
+  gst_gl_shader_set_uniform_1f (shader, "height", tex_size[1]);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_bulge (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_bulge_callback, effects);
+}
diff --git a/gst/gl/effects/gstgleffectfisheye.c b/gst/gl/effects/gstgleffectfisheye.c
new file mode 100644 (file)
index 0000000..fb4e0d8
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_fisheye_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "fisheye0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "fisheye0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, fisheye_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", tex_size[0]); 
+  gst_gl_shader_set_uniform_1f (shader, "height", tex_size[1]);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_fisheye (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_fisheye_callback, effects);
+}
diff --git a/gst/gl/effects/gstgleffectsdistortion.c b/gst/gl/effects/gstgleffectsdistortion.c
new file mode 100644 (file)
index 0000000..11f3ad8
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_mirror_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "mirror0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "mirror0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, mirror_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", tex_size[0]); 
+  gst_gl_shader_set_uniform_1f (shader, "height", tex_size[1]);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_mirror (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_mirror_callback, effects);
+}
diff --git a/gst/gl/effects/gstgleffectsquare.c b/gst/gl/effects/gstgleffectsquare.c
new file mode 100644 (file)
index 0000000..e941fc2
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_square_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "square0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "square0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, square_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", tex_size[0]); 
+  gst_gl_shader_set_uniform_1f (shader, "height", tex_size[1]);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_square (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_square_callback, effects);
+}
index 3295950..dd6ce69 100644 (file)
@@ -77,6 +77,105 @@ const gchar *stretch_fragment_source =
   "  gl_FragColor = color * gl_Color;"
   "}";
 
+/* Light Tunnel effect */
+const gchar *tunnel_fragment_source =
+  "#extension GL_ARB_texture_rectangle : enable\n"
+  "uniform sampler2DRect tex;"
+  "uniform float width, height;"
+  "void main () {"
+  "  vec2 tex_size = vec2 (width, height);"
+  "  vec2 texturecoord = gl_TexCoord[0].xy;"
+  "  vec2 normcoord;"
+  /* little trick with normalized coords to obtain a circle */
+  "  normcoord = texturecoord / tex_size.x - tex_size / tex_size.x;"
+  "  float r = length(normcoord);"
+  "  float phi = atan(normcoord.y, normcoord.x);"
+  "  r = clamp (r, 0.0, 0.5);" /* is there a way to do this without polars? */
+  "  normcoord.x = r * cos(phi);"
+  "  normcoord.y = r * sin(phi); "
+  "  texturecoord = (normcoord + tex_size/tex_size.x) * tex_size.x;"
+  "  vec4 color = texture2DRect (tex, texturecoord); "
+  "  gl_FragColor = color;"
+  "}";
+
+/* FishEye effect */
+const gchar *fisheye_fragment_source =
+  "#extension GL_ARB_texture_rectangle : enable\n"
+  "uniform sampler2DRect tex;"
+  "uniform float width, height;"
+  "void main () {"
+  "  vec2 tex_size = vec2 (width, height);"
+  "  vec2 texturecoord = gl_TexCoord[0].xy;"
+  "  vec2 normcoord;"
+  "  normcoord = texturecoord / tex_size - 1.0;"
+  "  float r =  length (normcoord);"
+  "  normcoord *= r/sqrt(2.0);"
+  "  texturecoord = (normcoord + 1.0) * tex_size;"
+  "  vec4 color = texture2DRect (tex, texturecoord);"
+  "  gl_FragColor = color;"
+  "}";
+
+
+/* Twirl effect */
+const gchar *twirl_fragment_source =
+  "#extension GL_ARB_texture_rectangle : enable\n"
+  "uniform sampler2DRect tex;"
+  "uniform float width, height;"
+  "void main () {"
+  "  vec2 tex_size = vec2 (width, height);"
+  "  vec2 texturecoord = gl_TexCoord[0].xy;"
+  "  vec2 normcoord;"
+  "  normcoord = texturecoord / tex_size - 1.0;"
+  "  float r =  length (normcoord);"
+  "  float phi = atan (normcoord.y, normcoord.x);"
+/* height dependent rotation coeff.. why the hell this angle has
+ * different effect with different sizes? */
+  "  phi += (1.0 - smoothstep (-0.6, 0.6, r)) * height * 2.0/100.0;" 
+  "  normcoord.x = r * cos(phi);"
+  "  normcoord.y = r * sin(phi);"
+  "  texturecoord = (normcoord + 1.0) * tex_size;"
+  "  vec4 color = texture2DRect (tex, texturecoord); "
+  "  gl_FragColor = color;"
+  "}";
+
+
+/* Bulge effect */
+const gchar *bulge_fragment_source =
+  "#extension GL_ARB_texture_rectangle : enable\n"
+  "uniform sampler2DRect tex;"
+  "uniform float width, height;"
+  "void main () {"
+  "  vec2 tex_size = vec2 (width, height);"
+  "  vec2 texturecoord = gl_TexCoord[0].xy;"
+  "  vec2 normcoord;"
+  "  normcoord = texturecoord / tex_size - 1.0;"
+  "  float r =  length (normcoord);"
+  "  normcoord *= smoothstep (-0.1, 0.5, r);"
+  "  texturecoord = (normcoord + 1.0) * tex_size;"
+  "  vec4 color = texture2DRect (tex, texturecoord);"
+  "  gl_FragColor = color;"
+  "}";
+
+
+/* Square Effect */
+const gchar *square_fragment_source =
+  "#extension GL_ARB_texture_rectangle : enable\n"
+  "uniform sampler2DRect tex;"
+  "uniform float width;"
+  "uniform float height;"
+  "void main () {"
+  "  vec2 tex_size = vec2 (width, height);"
+  "  vec2 texturecoord = gl_TexCoord[0].xy;"
+  "  vec2 normcoord;"
+  "  normcoord = texturecoord / tex_size - 1.0;"
+  "  float r = length (normcoord);"
+  "  normcoord *= 1.0 + smoothstep(0.25, 0.5, abs(normcoord));"
+  "  normcoord /= 2.0; /* zoom amount */"
+  "  texturecoord = (normcoord + 1.0) * tex_size;"
+  "  vec4 color = texture2DRect (tex, texturecoord);"
+  "  gl_FragColor = color * gl_Color;"
+  "}";
+
 
 const gchar *luma_threshold_fragment_source =
   "#extension GL_ARB_texture_rectangle : enable\n"
@@ -89,6 +188,7 @@ const gchar *luma_threshold_fragment_source =
   "  gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
   "}";
 
+
 /* horizontal convolution */
 const gchar *hconv9_fragment_source =
 "#extension GL_ARB_texture_rectangle : enable\n"
@@ -110,6 +210,7 @@ const gchar *hconv9_fragment_source =
 "  gl_FragColor = sum + norm_offset;"
 "}";
 
+
 /* vertical convolution */
 const gchar *vconv9_fragment_source =
 "#extension GL_ARB_texture_rectangle : enable\n"
@@ -131,6 +232,7 @@ const gchar *vconv9_fragment_source =
 "  gl_FragColor = sum + norm_offset;"
 "}";
 
+
 /* TODO: support several blend modes */
 const gchar *sum_fragment_source = 
 "#extension GL_ARB_texture_rectangle : enable\n"
@@ -144,6 +246,7 @@ const gchar *sum_fragment_source =
 "  gl_FragColor = alpha * basecolor + beta * blendcolor;"
 "}";
 
+
 /* lut operations, map luma to tex1d, see orange book (chapter 19) */
 const gchar *luma_to_curve_fragment_source =
 "#extension GL_ARB_texture_rectangle : enable\n"
@@ -158,6 +261,7 @@ const gchar *luma_to_curve_fragment_source =
 "  gl_FragColor = color;"
 "}";
 
+
 /* lut operations, map rgb to tex1d, see orange book (chapter 19) */
 const gchar *rgb_to_curve_fragment_source =
 "#extension GL_ARB_texture_rectangle : enable\n"
@@ -173,5 +277,3 @@ const gchar *rgb_to_curve_fragment_source =
 "  outcolor.a = color.a;"
 "  gl_FragColor = outcolor;"
 "}";
-
-
index c6d4cd0..e8d0e32 100644 (file)
 const gchar *mirror_fragment_source;
 const gchar *squeeze_fragment_source;
 const gchar *stretch_fragment_source;
+const gchar *tunnel_fragment_source;
+const gchar *fisheye_fragment_source;
+const gchar *twirl_fragment_source;
+const gchar *bulge_fragment_source;
+const gchar *square_fragment_source;
 const gchar *luma_threshold_fragment_source;
 const gchar *hconv9_fragment_source;
 const gchar *vconv9_fragment_source;
diff --git a/gst/gl/effects/gstgleffecttunnel.c b/gst/gl/effects/gstgleffecttunnel.c
new file mode 100644 (file)
index 0000000..cc0245e
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_tunnel_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "tunnel0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "tunnel0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, tunnel_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", tex_size[0]); 
+  gst_gl_shader_set_uniform_1f (shader, "height", tex_size[1]);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_tunnel (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_tunnel_callback, effects);
+}
diff --git a/gst/gl/effects/gstgleffecttwirl.c b/gst/gl/effects/gstgleffecttwirl.c
new file mode 100644 (file)
index 0000000..5fbb932
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * GStreamer
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gstgleffects.h>
+
+static void
+gst_gl_effects_twirl_callback (gint width, gint height, guint texture, gpointer data)
+{
+  GstGLEffects* effects = GST_GL_EFFECTS (data);
+
+  GstGLShader *shader;
+  gfloat tex_size[2];
+          
+  shader = g_hash_table_lookup (effects->shaderstable, "twirl0");
+  
+  if (!shader) {
+    shader = gst_gl_shader_new ();
+    g_hash_table_insert (effects->shaderstable, "twirl0", shader);
+  }
+  
+  g_return_if_fail (
+    gst_gl_shader_compile_and_check (shader, twirl_fragment_source,
+                                    GST_GL_SHADER_FRAGMENT_SOURCE));
+
+  glMatrixMode (GL_PROJECTION);
+  glLoadIdentity ();
+  
+  gst_gl_shader_use (shader);
+
+  glActiveTexture (GL_TEXTURE0);
+  glEnable (GL_TEXTURE_RECTANGLE_ARB);
+  glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
+     
+  gst_gl_shader_set_uniform_1i (shader, "tex", 0);
+  
+  tex_size[0] = GST_GL_FILTER(effects)->width / 2.0;
+  tex_size[1] = GST_GL_FILTER(effects)->height / 2.0;
+
+  gst_gl_shader_set_uniform_1f (shader, "width", width / 2.0); 
+  gst_gl_shader_set_uniform_1f (shader, "height", height / 2.0);
+  
+  gst_gl_effects_draw_texture (effects, texture);
+}
+
+void
+gst_gl_effects_twirl (GstGLEffects *effects) {
+  GstGLFilter *filter = GST_GL_FILTER (effects);
+
+  gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
+                                 gst_gl_effects_twirl_callback, effects);
+}
index 867f821..f46fa4b 100644 (file)
@@ -59,6 +59,11 @@ typedef enum {
   GST_GL_EFFECT_MIRROR,
   GST_GL_EFFECT_SQUEEZE,
   GST_GL_EFFECT_STRETCH,
+  GST_GL_EFFECT_TUNNEL,
+  GST_GL_EFFECT_FISHEYE,
+  GST_GL_EFFECT_TWIRL,
+  GST_GL_EFFECT_BULGE,
+  GST_GL_EFFECT_SQUARE,
   GST_GL_EFFECT_HEAT,
   GST_GL_EFFECT_SEPIA,
   GST_GL_EFFECT_XPRO,
@@ -76,6 +81,11 @@ gst_gl_effects_effect_get_type (void)
     { GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror" },
     { GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze" },
     { GST_GL_EFFECT_STRETCH, "Stretch Effect", "stretch" },
+    { GST_GL_EFFECT_FISHEYE, "FishEye Effect", "fisheye" },
+    { GST_GL_EFFECT_TWIRL, "Twirl Effect", "twirl" },
+    { GST_GL_EFFECT_BULGE, "Bulge Effect", "bulge" },
+    { GST_GL_EFFECT_TUNNEL, "Light Tunnel Effect", "tunnel" },
+    { GST_GL_EFFECT_SQUARE, "Square Effect", "square" },
     { GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat" },
     { GST_GL_EFFECT_SEPIA, "Sepia Toning Effect", "sepia" },
     { GST_GL_EFFECT_XPRO, "Cross Processing Effect", "xpro" },
@@ -106,6 +116,21 @@ gst_gl_effects_set_effect (GstGLEffects *effects, gint effect_type) {
   case GST_GL_EFFECT_STRETCH:
     effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_stretch;
     break;
+  case GST_GL_EFFECT_TUNNEL:
+    effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_tunnel;
+    break;
+  case GST_GL_EFFECT_FISHEYE:
+    effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_fisheye;
+    break;
+  case GST_GL_EFFECT_TWIRL:
+    effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_twirl;
+    break;
+  case GST_GL_EFFECT_BULGE:
+    effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_bulge;
+    break;
+  case GST_GL_EFFECT_SQUARE:
+    effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_square;
+    break;
   case GST_GL_EFFECT_HEAT:
     effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_heat;
     break;
index 5440f65..24c114d 100644 (file)
@@ -88,6 +88,11 @@ void gst_gl_effects_identity (GstGLEffects *effects);
 void gst_gl_effects_mirror (GstGLEffects *effects);
 void gst_gl_effects_squeeze (GstGLEffects *effects);
 void gst_gl_effects_stretch (GstGLEffects *effects);
+void gst_gl_effects_tunnel (GstGLEffects *effects);
+void gst_gl_effects_fisheye (GstGLEffects *effects);
+void gst_gl_effects_twirl (GstGLEffects *effects);
+void gst_gl_effects_bulge (GstGLEffects *effects);
+void gst_gl_effects_square (GstGLEffects *effects);
 void gst_gl_effects_heat (GstGLEffects *effects);
 void gst_gl_effects_sepia (GstGLEffects *effects);
 void gst_gl_effects_xpro (GstGLEffects *effects);