From: Filippo Argiolas Date: Wed, 13 Aug 2008 18:58:49 +0000 (+0200) Subject: [158/906] still working on mergin gstgleffects, add mirror effect. reorganize source... X-Git-Tag: 1.19.3~507^2~12374 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7bbdcce721ae65c86e15ae7e388e7a182987061a;p=platform%2Fupstream%2Fgstreamer.git [158/906] still working on mergin gstgleffects, add mirror effect. reorganize source tree. --- diff --git a/gst/gl/Makefile.am b/gst/gl/Makefile.am index 5315f66..5b49503 100644 --- a/gst/gl/Makefile.am +++ b/gst/gl/Makefile.am @@ -12,7 +12,6 @@ libgstopengl_la_SOURCES = \ gstglupload.h \ gstgldownload.c \ gstgldownload.h \ - gstgleffects.c \ gstglfilterblur.c \ gstglfiltercube.c \ gstglfiltercube.h \ @@ -25,7 +24,12 @@ libgstopengl_la_SOURCES = \ gltestsrc.c \ gltestsrc.h \ gstgltestsrc.c \ - gstgltestsrc.h + gstgltestsrc.h \ + gstgleffects.c \ + effects/gstgleffects.h \ + effects/gstgleffectsources.h \ + effects/gstgleffectmirror.c + # check order of CFLAGS and LIBS, shouldn't the order be the other way around # (like in AM_CFLAGS)? diff --git a/gst/gl/effects/gstgleffectmirror.c b/gst/gl/effects/gstgleffectmirror.c new file mode 100644 index 0000000..5f6e110 --- /dev/null +++ b/gst/gl/effects/gstgleffectmirror.c @@ -0,0 +1,73 @@ +/* + * GStreamer + * Copyright (C) 2008 Filippo Argiolas + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstgleffects.h" +#include "gstgleffectssources.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/gstgleffects.h b/gst/gl/effects/gstgleffects.h new file mode 100644 index 0000000..77ed462 --- /dev/null +++ b/gst/gl/effects/gstgleffects.h @@ -0,0 +1,73 @@ +/* + * GStreamer + * Copyright (C) 2008 Filippo Argiolas + * + * 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. + */ + +#ifndef __GST_GL_EFFECTS_H__ +#define __GST_GL_EFFECTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_GL_EFFECTS (gst_gl_effects_get_type()) +#define GST_GL_EFFECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_GL_EFFECTS,GstGLEffects)) +#define GST_IS_GL_EFFECTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_GL_EFFECTS)) +#define GST_GL_EFFECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) , GST_TYPE_GL_EFFECTS,GstGLEffectsClass)) +#define GST_IS_GL_EFFECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) , GST_TYPE_GL_EFFECTS)) +#define GST_GL_EFFECTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) , GST_TYPE_GL_EFFECTS,GstGLEffectsClass)) + +typedef struct _GstGLEffects GstGLEffects; +typedef struct _GstGLEffectsClass GstGLEffectsClass; + +typedef void (* GstGLEffectProcessFunc) (GstGLEffects *effects); + +#define NEEDED_TEXTURES 10 + +struct _GstGLEffects +{ + GstGLFilter filter; + + GstGLEffectProcessFunc effect; + gint current_effect; + + GLuint intexture; + GLuint midtexture[NEEDED_TEXTURES]; + GLuint outtexture; + + GHashTable *shaderstable; +}; + +struct _GstGLEffectsClass +{ + GstGLFilterClass filter_class; +}; + +GType gst_gl_effects_get_type (void); + +void gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex); + +void gst_gl_effects_mirror (GstGLEffects *effects); + +G_END_DECLS + +#endif /*__GST_GL_EFFECTS_H__ */ diff --git a/gst/gl/effects/gstgleffectssources.h b/gst/gl/effects/gstgleffectssources.h new file mode 100644 index 0000000..78097e7 --- /dev/null +++ b/gst/gl/effects/gstgleffectssources.h @@ -0,0 +1,40 @@ +/* + * GStreamer + * Copyright (C) 2008 Filippo Argiolas + * + * 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. + */ + +#ifndef __GST_GL_EFFECTS_SOURCES_H__ +#define __GST_GL_EFFECTS_SOURCES_H__ + +/* Mirror effect */ +static const gchar *mirror_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;" + " normcoord.x *= sign (normcoord.x);" + " texturecoord = (normcoord + 1.0) * tex_size;" + " vec4 color = texture2DRect (tex, texturecoord); " + " gl_FragColor = color * gl_Color;" + "}"; + +#endif /* __GST_GL_EFFECTS_SOURCES_H__ */ diff --git a/gst/gl/gstgleffects.c b/gst/gl/gstgleffects.c index 0ec55c7..f85f063 100644 --- a/gst/gl/gstgleffects.c +++ b/gst/gl/gstgleffects.c @@ -18,13 +18,7 @@ * Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -//#include "effects/shadersources.h" -//#include "effects/textures.h" +#include "effects/gstgleffects.h" #define GST_TYPE_GL_EFFECTS (gst_gl_effects_get_type()) #define GST_GL_EFFECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_GL_EFFECTS,GstGLEffects)) @@ -33,53 +27,12 @@ #define GST_IS_GL_EFFECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) , GST_TYPE_GL_EFFECTS)) #define GST_GL_EFFECTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) , GST_TYPE_GL_EFFECTS,GstGLEffectsClass)) -typedef struct _GstGLEffects GstGLEffects; -typedef struct _GstGLEffectsClass GstGLEffectsClass; - typedef enum { GST_GL_EFFECT_IDENTITY, - 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_MIRROR, - GST_GL_EFFECT_HEAT, - GST_GL_EFFECT_SEPIA, - GST_GL_EFFECT_CROSS, - GST_GL_EFFECT_GLOW, - GST_GL_EFFECT_EMBOSS, - GST_GL_EFFECT_BACKGROUND, - GST_GL_EFFECT_TEST, GST_GL_N_EFFECTS } GstGLEffectsEffect; -#define NEEDED_TEXTURES 10 - -typedef void (* GstGLEffectProcessFunc) (GstGLEffects *effects); - -struct _GstGLEffects -{ - GstGLFilter filter; - - GstGLEffectProcessFunc effect; - - GLuint intexture; - GLuint midtexture[NEEDED_TEXTURES]; - GLuint outtexture; - - GHashTable *shaderstable; -}; - -struct _GstGLEffectsClass -{ - GstGLFilterClass filter_class; -}; - -GType gst_gl_effects_get_type (void); - #define GST_CAT_DEFAULT gst_gl_effects_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); @@ -93,7 +46,6 @@ static void gst_gl_effects_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_gl_effects_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static void gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex); static void gst_gl_effects_init_resources (GstGLFilter* filter); static void gst_gl_effects_reset_resources (GstGLFilter* filter); @@ -108,21 +60,7 @@ gst_gl_effects_effect_get_type (void) static GType gl_effects_effect_type = 0; static const GEnumValue effect_types [] = { { GST_GL_EFFECT_IDENTITY, "Do nothing Effect", "identity" }, - { 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_MIRROR, "Mirror Effect", "mirror" }, - { GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat" }, - { GST_GL_EFFECT_SEPIA, "Sepia Tone Effect", "sepia" }, - { GST_GL_EFFECT_CROSS, "Cross Processing Effect", "cross" }, - { GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow" }, - { GST_GL_EFFECT_EMBOSS, "Emboss Convolution Effect", "emboss" }, - { GST_GL_EFFECT_BACKGROUND, "Difference Matte Effect", "background" }, - { GST_GL_EFFECT_TEST, "Test Effect", "test" }, { 0, NULL, NULL } }; @@ -209,7 +147,7 @@ gst_gl_effects_class_init (GstGLEffectsClass * klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } -static void +void gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex) { GstGLFilter *filter = GST_GL_FILTER (effects); @@ -288,15 +226,34 @@ gst_gl_effects_reset_resources (GstGLFilter* filter) } static void +gst_gl_effects_set_effect (GstGLEffects *effects, gint effect_type) { + + switch (effect_type) { + case GST_GL_EFFECT_IDENTITY: + effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_identity; + break; + case GST_GL_EFFECT_MIRROR: + effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_mirror; + break; + default: + g_assert_not_reached (); + } + effects->current_effect = effect_type; +} + +static void gst_gl_effects_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - /* GstGLEffects *effects = GST_GL_EFFECTS (object); */ + GstGLEffects *effects = GST_GL_EFFECTS (object); switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + case PROP_EFFECT: + gst_gl_effects_set_effect (effects, g_value_get_enum (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -304,11 +261,11 @@ static void gst_gl_effects_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - //GstGLEffects *effects = GST_GL_EFFECTS (object); + GstGLEffects *effects = GST_GL_EFFECTS (object); switch (prop_id) { case PROP_EFFECT: - //gst_gl_effects_set_effect (effects, g_value_get_enum (value)); + g_value_set_enum (value, effects->current_effect); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);