2008-08-12 09:09:37 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-01-15 17:39:48 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-gleffects.
|
|
|
|
*
|
|
|
|
* GL Shading Language effects.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Examples</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch videotestsrc ! glupload ! gleffects effect=5 ! glimagesink
|
|
|
|
* ]|
|
|
|
|
* FBO (Frame Buffer Object) and GLSL (OpenGL Shading Language) are required.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2008-08-13 20:36:13 +00:00
|
|
|
#include <gstgleffects.h>
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
#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))
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_effects_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2008-08-12 09:09:37 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_effects_debug, "gleffects", 0, "gleffects element");
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLEffects, gst_gl_effects, GST_TYPE_GL_FILTER,
|
|
|
|
DEBUG_INIT);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
static void gst_gl_effects_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-08-12 09:09:37 +00:00
|
|
|
static void gst_gl_effects_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_effects_init_resources (GstGLFilter * filter);
|
|
|
|
static void gst_gl_effects_reset_resources (GstGLFilter * filter);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
static gboolean gst_gl_effects_on_init_gl_context (GstGLFilter * filter);
|
2008-09-14 17:56:50 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_effects_ghash_func_clean (gpointer key, gpointer value,
|
|
|
|
gpointer data);
|
2008-08-19 09:07:18 +00:00
|
|
|
|
2012-09-20 13:03:55 +00:00
|
|
|
static gboolean gst_gl_effects_filter_texture (GstGLFilter * filter,
|
|
|
|
guint in_tex, guint out_tex);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2008-08-14 06:03:49 +00:00
|
|
|
/* dont' forget to edit the following when a new effect is added */
|
2009-02-11 06:39:14 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2008-08-13 20:36:13 +00:00
|
|
|
GST_GL_EFFECT_IDENTITY,
|
|
|
|
GST_GL_EFFECT_MIRROR,
|
2008-08-13 22:07:20 +00:00
|
|
|
GST_GL_EFFECT_SQUEEZE,
|
2008-08-14 06:03:49 +00:00
|
|
|
GST_GL_EFFECT_STRETCH,
|
2008-08-14 12:08:23 +00:00
|
|
|
GST_GL_EFFECT_TUNNEL,
|
|
|
|
GST_GL_EFFECT_FISHEYE,
|
|
|
|
GST_GL_EFFECT_TWIRL,
|
|
|
|
GST_GL_EFFECT_BULGE,
|
|
|
|
GST_GL_EFFECT_SQUARE,
|
2008-08-14 09:31:09 +00:00
|
|
|
GST_GL_EFFECT_HEAT,
|
|
|
|
GST_GL_EFFECT_SEPIA,
|
2008-08-14 10:09:39 +00:00
|
|
|
GST_GL_EFFECT_XPRO,
|
2008-08-14 19:29:02 +00:00
|
|
|
GST_GL_EFFECT_LUMA_XPRO,
|
2008-10-15 14:18:22 +00:00
|
|
|
GST_GL_EFFECT_XRAY,
|
2008-08-16 07:13:39 +00:00
|
|
|
GST_GL_EFFECT_SIN,
|
2008-08-14 07:26:23 +00:00
|
|
|
GST_GL_EFFECT_GLOW,
|
2008-08-13 20:36:13 +00:00
|
|
|
GST_GL_N_EFFECTS
|
|
|
|
} GstGLEffectsEffect;
|
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
#define GST_TYPE_GL_EFFECTS_EFFECT (gst_gl_effects_effect_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_gl_effects_effect_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gl_effects_effect_type = 0;
|
2009-02-11 06:39:14 +00:00
|
|
|
static const GEnumValue effect_types[] = {
|
|
|
|
{GST_GL_EFFECT_IDENTITY, "Do nothing Effect", "identity"},
|
|
|
|
{GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror"},
|
|
|
|
{GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze"},
|
2009-11-21 20:40:14 +00:00
|
|
|
#ifndef OPENGL_ES2
|
2009-02-11 06:39:14 +00:00
|
|
|
{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"},
|
|
|
|
{GST_GL_EFFECT_LUMA_XPRO, "Luma Cross Processing Effect", "lumaxpro"},
|
|
|
|
{GST_GL_EFFECT_XRAY, "Glowing negative effect", "xray"},
|
|
|
|
{GST_GL_EFFECT_SIN, "All Grey but Red Effect", "sin"},
|
|
|
|
{GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow"},
|
2009-11-21 20:40:14 +00:00
|
|
|
#endif
|
2009-02-11 06:39:14 +00:00
|
|
|
{0, NULL, NULL}
|
2008-08-12 09:09:37 +00:00
|
|
|
};
|
2008-08-13 14:01:21 +00:00
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
if (!gl_effects_effect_type) {
|
2008-08-13 14:01:21 +00:00
|
|
|
gl_effects_effect_type =
|
2009-02-11 06:39:14 +00:00
|
|
|
g_enum_register_static ("GstGLEffectsEffect", effect_types);
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
return gl_effects_effect_type;
|
|
|
|
}
|
|
|
|
|
2008-08-14 06:03:49 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_set_effect (GstGLEffects * effects, gint effect_type)
|
|
|
|
{
|
2008-08-14 06:03:49 +00:00
|
|
|
|
|
|
|
switch (effect_type) {
|
2009-02-11 06:39:14 +00:00
|
|
|
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;
|
|
|
|
case GST_GL_EFFECT_SQUEEZE:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_squeeze;
|
|
|
|
break;
|
2009-11-21 20:40:14 +00:00
|
|
|
#ifndef OPENGL_ES2
|
2009-02-11 06:39:14 +00:00
|
|
|
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;
|
|
|
|
case GST_GL_EFFECT_SEPIA:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sepia;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_XPRO:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xpro;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_LUMA_XPRO:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_luma_xpro;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_XRAY:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xray;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_SIN:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sin;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_GLOW:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow;
|
|
|
|
break;
|
2009-11-21 20:40:14 +00:00
|
|
|
#endif
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2008-08-14 06:03:49 +00:00
|
|
|
}
|
|
|
|
effects->current_effect = effect_type;
|
|
|
|
}
|
|
|
|
|
2008-08-13 20:36:13 +00:00
|
|
|
/* init resources that need a gl context */
|
2008-08-12 09:09:37 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_init_gl_resources (GstGLFilter * filter)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
|
|
|
gint i;
|
2008-08-13 14:01:21 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
2008-08-12 09:09:37 +00:00
|
|
|
glGenTextures (1, &effects->midtexture[i]);
|
2009-02-11 06:39:14 +00:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, effects->midtexture[i]);
|
|
|
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2012-09-20 13:03:55 +00:00
|
|
|
GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&filter->out_info),
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2009-02-11 06:39:14 +00:00
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
|
|
|
GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
|
|
|
GL_CLAMP_TO_EDGE);
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 20:36:13 +00:00
|
|
|
/* free resources that need a gl context */
|
2008-08-12 09:09:37 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_reset_gl_resources (GstGLFilter * filter)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
|
|
|
gint i;
|
|
|
|
|
2010-09-08 18:38:07 +00:00
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
2008-08-12 09:09:37 +00:00
|
|
|
glDeleteTextures (1, &effects->midtexture[i]);
|
|
|
|
effects->midtexture[i] = 0;
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
|
2008-08-14 09:31:09 +00:00
|
|
|
glDeleteTextures (1, &effects->curve[i]);
|
|
|
|
effects->curve[i] = 0;
|
|
|
|
}
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_class_init (GstGLEffectsClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-30 03:46:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
gobject_class->set_property = gst_gl_effects_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_effects_get_property;
|
|
|
|
|
2012-09-20 13:03:55 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->filter_texture = gst_gl_effects_filter_texture;
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->display_init_cb =
|
|
|
|
gst_gl_effects_init_gl_resources;
|
|
|
|
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
|
|
|
|
gst_gl_effects_reset_gl_resources;
|
2008-08-14 18:02:04 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_effects_init_resources;
|
|
|
|
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_effects_reset_resources;
|
2008-09-14 17:56:50 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_effects_on_init_gl_context;
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EFFECT,
|
|
|
|
g_param_spec_enum ("effect",
|
|
|
|
"Effect",
|
|
|
|
"Select which effect apply to GL video texture",
|
|
|
|
GST_TYPE_GL_EFFECTS_EFFECT,
|
|
|
|
GST_GL_EFFECT_IDENTITY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_HSWAP,
|
|
|
|
g_param_spec_boolean ("hswap",
|
|
|
|
"Horizontal Swap",
|
|
|
|
"Switch video texture left to right, useful with webcams",
|
2010-10-19 15:00:33 +00:00
|
|
|
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-05-30 03:46:21 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"Gstreamer OpenGL Effects", "Filter/Effect",
|
|
|
|
"GL Shading Language effects",
|
|
|
|
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:58:49 +00:00
|
|
|
void
|
2012-09-25 08:06:14 +00:00
|
|
|
gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex, guint width,
|
|
|
|
guint height)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
2009-11-25 09:24:37 +00:00
|
|
|
#ifndef OPENGL_ES2
|
2008-08-12 09:09:37 +00:00
|
|
|
glActiveTexture (GL_TEXTURE0);
|
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
|
|
|
|
glTexCoord2f (0.0, 0.0);
|
|
|
|
glVertex2f (-1.0, -1.0);
|
2012-09-25 08:06:14 +00:00
|
|
|
glTexCoord2f ((gfloat) width, 0.0);
|
2008-08-12 09:09:37 +00:00
|
|
|
glVertex2f (1.0, -1.0);
|
2012-09-25 08:06:14 +00:00
|
|
|
glTexCoord2f ((gfloat) width, (gfloat) height);
|
2008-08-12 09:09:37 +00:00
|
|
|
glVertex2f (1.0, 1.0);
|
2012-09-25 08:06:14 +00:00
|
|
|
glTexCoord2f (0.0, (gfloat) height);
|
2008-08-12 09:09:37 +00:00
|
|
|
glVertex2f (-1.0, 1.0);
|
|
|
|
|
|
|
|
glEnd ();
|
2009-11-21 20:40:14 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
const GLfloat vVertices[] = { -1.0f, -1.0f, 0.0f,
|
2009-11-25 09:24:37 +00:00
|
|
|
0.0f, 0.0f,
|
|
|
|
1.0, -1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f
|
|
|
|
};
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
//glClear (GL_COLOR_BUFFER_BIT);
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
//Load the vertex position
|
|
|
|
glVertexAttribPointer (effects->draw_attr_position_loc, 3, GL_FLOAT,
|
|
|
|
GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
//Load the texture coordinate
|
|
|
|
glVertexAttribPointer (effects->draw_attr_texture_loc, 2, GL_FLOAT,
|
|
|
|
GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
glEnableVertexAttribArray (effects->draw_attr_position_loc);
|
|
|
|
glEnableVertexAttribArray (effects->draw_attr_texture_loc);
|
2009-11-21 20:40:14 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
2009-11-21 20:40:14 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-04 14:22:40 +00:00
|
|
|
glUseProgramObjectARB (0);
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 20:28:19 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
set_horizontal_swap (GstGLDisplay * display, gpointer data)
|
2008-08-14 20:28:19 +00:00
|
|
|
{
|
|
|
|
// GstGLEffects *effects = GST_GL_EFFECTS (data);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2009-11-25 09:24:37 +00:00
|
|
|
#ifndef OPENGL_ES2
|
2008-08-14 20:28:19 +00:00
|
|
|
const double mirrormatrix[16] = {
|
|
|
|
-1.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 1.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 1.0
|
|
|
|
};
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2008-08-14 20:28:19 +00:00
|
|
|
glMatrixMode (GL_MODELVIEW);
|
|
|
|
glLoadMatrixd (mirrormatrix);
|
2009-11-21 20:40:14 +00:00
|
|
|
#endif
|
2008-08-14 20:28:19 +00:00
|
|
|
}
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_effects_init (GstGLEffects * effects)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
|
|
|
effects->effect = gst_gl_effects_identity;
|
2008-08-14 20:28:19 +00:00
|
|
|
effects->horizontal_swap = FALSE;
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-19 09:07:18 +00:00
|
|
|
static void
|
|
|
|
gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data)
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLShader *shader = (GstGLShader *) value;
|
|
|
|
GstGLFilter *filter = (GstGLFilter *) data;
|
2008-08-19 09:07:18 +00:00
|
|
|
|
|
|
|
//blocking call, wait the opengl thread has destroyed the shader
|
|
|
|
gst_gl_display_del_shader (filter->display, shader);
|
|
|
|
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_reset_resources (GstGLFilter * filter)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2008-08-16 07:40:54 +00:00
|
|
|
// g_message ("reset resources");
|
|
|
|
|
2008-08-19 09:07:18 +00:00
|
|
|
//release shaders in the gl thread
|
|
|
|
g_hash_table_foreach (effects->shaderstable, gst_gl_effects_ghash_func_clean,
|
2009-02-11 06:39:14 +00:00
|
|
|
filter);
|
2008-08-19 09:07:18 +00:00
|
|
|
|
|
|
|
//clean the htable without calling values destructors
|
|
|
|
//because shaders have been released in the glthread
|
|
|
|
//through the foreach func
|
2008-08-12 09:09:37 +00:00
|
|
|
g_hash_table_unref (effects->shaderstable);
|
|
|
|
effects->shaderstable = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2008-08-19 09:07:18 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (object);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-02-11 06:39:14 +00:00
|
|
|
case PROP_EFFECT:
|
|
|
|
gst_gl_effects_set_effect (effects, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
case PROP_HSWAP:
|
|
|
|
effects->horizontal_swap = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2008-08-13 18:58:49 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (object);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-02-11 06:39:14 +00:00
|
|
|
case PROP_EFFECT:
|
|
|
|
g_value_set_enum (value, effects->current_effect);
|
|
|
|
break;
|
|
|
|
case PROP_HSWAP:
|
|
|
|
g_value_set_boolean (value, effects->horizontal_swap);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_init_resources (GstGLFilter * filter)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
2008-08-16 07:40:54 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
|
|
|
gint i;
|
|
|
|
// g_message ("init resources");
|
|
|
|
// g_message ("init hashtable");
|
2009-02-11 06:39:14 +00:00
|
|
|
effects->shaderstable = g_hash_table_new (g_str_hash, g_str_equal);
|
2008-08-16 07:40:54 +00:00
|
|
|
// g_message ("zero textures and curves");
|
2009-02-11 06:39:14 +00:00
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
2008-08-16 07:40:54 +00:00
|
|
|
effects->midtexture[i] = 0;
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
|
2008-08-16 07:40:54 +00:00
|
|
|
effects->curve[i] = 0;
|
|
|
|
}
|
2008-08-12 09:09:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_effects_on_init_gl_context (GstGLFilter * filter)
|
2008-09-14 17:56:50 +00:00
|
|
|
{
|
|
|
|
//check that your hardware supports shader
|
|
|
|
//if not the pipeline correctly shut down
|
2011-11-24 15:02:32 +00:00
|
|
|
return gst_gl_display_gen_shader (filter->display, 0, 0, NULL);
|
2008-09-14 17:56:50 +00:00
|
|
|
}
|
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
static gboolean
|
2012-09-20 13:03:55 +00:00
|
|
|
gst_gl_effects_filter_texture (GstGLFilter * filter, guint in_tex,
|
|
|
|
guint out_tex)
|
2008-08-12 09:09:37 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
2008-08-12 09:09:37 +00:00
|
|
|
|
2012-09-20 13:03:55 +00:00
|
|
|
effects->intexture = in_tex;
|
|
|
|
effects->outtexture = out_tex;
|
2008-08-13 14:01:21 +00:00
|
|
|
|
2008-08-14 20:28:19 +00:00
|
|
|
if (effects->horizontal_swap == TRUE)
|
|
|
|
gst_gl_display_thread_add (filter->display, set_horizontal_swap, effects);
|
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
effects->effect (effects);
|
2008-08-13 14:01:21 +00:00
|
|
|
|
2008-08-12 09:09:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|