gl: use GLMemory for accessing textures everywhere

This simplifies and consolidates a lot of duplicated code creating
and modifying textures.
This commit is contained in:
Matthew Waters 2016-07-12 00:30:22 +10:00 committed by Tim-Philipp Müller
parent c7dd43f21a
commit 7f10822de4
23 changed files with 207 additions and 172 deletions

View file

@ -258,8 +258,8 @@ gst_gl_color_balance_callback (gint width, gint height, guint tex_id,
} }
static gboolean static gboolean
gst_gl_color_balance_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_color_balance_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
gst_gl_filter_render_to_target (filter, TRUE, in_tex, out_tex, gst_gl_filter_render_to_target (filter, TRUE, in_tex, out_tex,
(GLCB) gst_gl_color_balance_callback, filter); (GLCB) gst_gl_color_balance_callback, filter);

View file

@ -74,7 +74,7 @@ static gboolean gst_gl_colorscale_gl_start (GstGLBaseFilter * base_filter);
static void gst_gl_colorscale_gl_stop (GstGLBaseFilter * base_filter); static void gst_gl_colorscale_gl_stop (GstGLBaseFilter * base_filter);
static gboolean gst_gl_colorscale_filter_texture (GstGLFilter * filter, static gboolean gst_gl_colorscale_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static void static void
gst_gl_colorscale_class_init (GstGLColorscaleClass * klass) gst_gl_colorscale_class_init (GstGLColorscaleClass * klass)
@ -175,8 +175,8 @@ gst_gl_colorscale_gl_stop (GstGLBaseFilter * base_filter)
} }
static gboolean static gboolean
gst_gl_colorscale_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_colorscale_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLColorscale *colorscale = GST_GL_COLORSCALE (filter); GstGLColorscale *colorscale = GST_GL_COLORSCALE (filter);

View file

@ -64,7 +64,7 @@ static gboolean gst_gl_deinterlace_init_fbo (GstGLFilter * filter);
static gboolean gst_gl_deinterlace_filter (GstGLFilter * filter, static gboolean gst_gl_deinterlace_filter (GstGLFilter * filter,
GstBuffer * inbuf, GstBuffer * outbuf); GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_deinterlace_filter_texture (GstGLFilter * filter, static gboolean gst_gl_deinterlace_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static void gst_gl_deinterlace_vfir_callback (gint width, gint height, static void gst_gl_deinterlace_vfir_callback (gint width, gint height,
guint texture, gpointer stuff); guint texture, gpointer stuff);
static void gst_gl_deinterlace_greedyh_callback (gint width, gint height, static void gst_gl_deinterlace_greedyh_callback (gint width, gint height,
@ -364,8 +364,8 @@ gst_gl_deinterlace_init_fbo (GstGLFilter * filter)
} }
static gboolean static gboolean
gst_gl_deinterlace_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_deinterlace_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter); GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter);

View file

@ -62,7 +62,7 @@ static void gst_gl_differencematte_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static gboolean gst_gl_differencematte_filter_texture (GstGLFilter * filter, static gboolean gst_gl_differencematte_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static gboolean gst_gl_differencematte_loader (GstGLFilter * filter); static gboolean gst_gl_differencematte_loader (GstGLFilter * filter);
@ -79,22 +79,23 @@ gst_gl_differencematte_init_gl_resources (GstGLFilter * filter)
{ {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter); GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
const GstGLFuncs *gl = context->gl_vtable; GstGLBaseMemoryAllocator *tex_alloc;
GstGLAllocationParams *params;
GError *error = NULL; GError *error = NULL;
gint i; gint i;
for (i = 0; i < 4; i++) { tex_alloc = (GstGLBaseMemoryAllocator *)
gl->GenTextures (1, &differencematte->midtexture[i]); gst_gl_memory_allocator_get_default (context);
gl->BindTexture (GL_TEXTURE_2D, differencematte->midtexture[i]); params =
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, (GstGLAllocationParams *) gst_gl_video_allocation_params_new (context,
GST_VIDEO_INFO_WIDTH (&filter->out_info), NULL, &filter->out_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D,
GST_VIDEO_INFO_HEIGHT (&filter->out_info), GST_VIDEO_GL_TEXTURE_TYPE_RGBA);
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); for (i = 0; i < 4; i++)
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); differencematte->midtexture[i] =
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); (GstGLMemory *) gst_gl_base_memory_alloc (tex_alloc, params);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gst_gl_allocation_params_free (params);
} gst_object_unref (tex_alloc);
if (!(differencematte->identity_shader = if (!(differencematte->identity_shader =
gst_gl_shader_new_default (context, &error))) { gst_gl_shader_new_default (context, &error))) {
@ -165,11 +166,18 @@ static void
gst_gl_differencematte_reset_gl_resources (GstGLFilter * filter) gst_gl_differencematte_reset_gl_resources (GstGLFilter * filter)
{ {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter); GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
gint i; gint i;
gl->DeleteTextures (1, &differencematte->savedbgtexture); if (differencematte->savedbgtexture) {
gl->DeleteTextures (1, &differencematte->newbgtexture); gst_memory_unref (GST_MEMORY_CAST (differencematte->savedbgtexture));
differencematte->savedbgtexture = NULL;
}
if (differencematte->newbgtexture) {
gst_memory_unref (GST_MEMORY_CAST (differencematte->newbgtexture));
differencematte->newbgtexture = NULL;
}
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (differencematte->identity_shader) { if (differencematte->identity_shader) {
gst_object_unref (differencematte->identity_shader); gst_object_unref (differencematte->identity_shader);
@ -180,15 +188,14 @@ gst_gl_differencematte_reset_gl_resources (GstGLFilter * filter)
gst_object_unref (differencematte->shader[i]); gst_object_unref (differencematte->shader[i]);
differencematte->shader[i] = NULL; differencematte->shader[i] = NULL;
} }
if (differencematte->midtexture[i]) { if (differencematte->midtexture[i]) {
gl->DeleteTextures (1, &differencematte->midtexture[i]); gst_memory_unref (GST_MEMORY_CAST (differencematte->midtexture[i]));
differencematte->midtexture[i] = 0; differencematte->midtexture[i] = NULL;
} }
} }
differencematte->location = NULL; differencematte->location = NULL;
differencematte->pixbuf = NULL; differencematte->pixbuf = NULL;
differencematte->savedbgtexture = 0;
differencematte->newbgtexture = 0;
differencematte->bg_has_changed = FALSE; differencematte->bg_has_changed = FALSE;
} }
@ -277,38 +284,39 @@ gst_gl_differencematte_get_property (GObject * object, guint prop_id,
} }
static void static void
init_pixbuf_texture (GstGLContext * context, gpointer data) init_pixbuf_texture (GstGLDifferenceMatte * differencematte)
{ {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (data); GstGLContext *context = GST_GL_BASE_FILTER (differencematte)->context;
GstGLFilter *filter = GST_GL_FILTER (data); GstGLFilter *filter = GST_GL_FILTER (differencematte);
const GstGLFuncs *gl = context->gl_vtable; GstGLBaseMemoryAllocator *tex_alloc;
guint internal_format = GstGLAllocationParams *params;
gst_gl_sized_gl_format_from_gl_format_type (context, GL_RGBA, GstVideoInfo v_info;
GL_UNSIGNED_BYTE);
gl->DeleteTextures (1, &differencematte->newbgtexture); tex_alloc = (GstGLBaseMemoryAllocator *)
gl->GenTextures (1, &differencematte->newbgtexture); gst_gl_memory_allocator_get_default (context);
gl->BindTexture (GL_TEXTURE_2D, differencematte->newbgtexture); gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA,
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format, differencematte->pbuf_width, differencematte->pbuf_height);
(gint) differencematte->pbuf_width, (gint) differencematte->pbuf_height, params =
0, GL_RGBA, GL_UNSIGNED_BYTE, differencematte->pixbuf); (GstGLAllocationParams *) gst_gl_video_allocation_params_new (context,
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); NULL, &v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D,
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); GST_VIDEO_GL_TEXTURE_TYPE_RGBA);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (differencematte->savedbgtexture == 0) { differencematte->newbgtexture =
gl->GenTextures (1, &differencematte->savedbgtexture); (GstGLMemory *) gst_gl_base_memory_alloc (tex_alloc, params);
gl->BindTexture (GL_TEXTURE_2D, differencematte->savedbgtexture); gst_gl_allocation_params_free (params);
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format,
GST_VIDEO_INFO_WIDTH (&filter->out_info), if (differencematte->savedbgtexture == NULL) {
GST_VIDEO_INFO_HEIGHT (&filter->out_info), params =
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); (GstGLAllocationParams *) gst_gl_video_allocation_params_new (context,
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); NULL, &filter->out_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D,
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); GST_VIDEO_GL_TEXTURE_TYPE_RGBA);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); differencematte->savedbgtexture =
(GstGLMemory *) gst_gl_base_memory_alloc (tex_alloc, params);
gst_gl_allocation_params_free (params);
} }
gst_object_unref (tex_alloc);
} }
static void static void
@ -327,7 +335,7 @@ gst_gl_differencematte_diff (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (differencematte->shader[0], "current", 0); gst_gl_shader_set_uniform_1i (differencematte->shader[0], "current", 0);
gl->ActiveTexture (GL_TEXTURE1); gl->ActiveTexture (GL_TEXTURE1);
gl->BindTexture (GL_TEXTURE_2D, differencematte->savedbgtexture); gl->BindTexture (GL_TEXTURE_2D, differencematte->savedbgtexture->tex_id);
gst_gl_shader_set_uniform_1i (differencematte->shader[0], "saved", 1); gst_gl_shader_set_uniform_1i (differencematte->shader[0], "saved", 1);
@ -396,12 +404,12 @@ gst_gl_differencematte_interp (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (differencematte->shader[3], "blend", 0); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "blend", 0);
gl->ActiveTexture (GL_TEXTURE1); gl->ActiveTexture (GL_TEXTURE1);
gl->BindTexture (GL_TEXTURE_2D, differencematte->newbgtexture); gl->BindTexture (GL_TEXTURE_2D, differencematte->newbgtexture->tex_id);
gst_gl_shader_set_uniform_1i (differencematte->shader[3], "base", 1); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "base", 1);
gl->ActiveTexture (GL_TEXTURE2); gl->ActiveTexture (GL_TEXTURE2);
gl->BindTexture (GL_TEXTURE_2D, differencematte->midtexture[2]); gl->BindTexture (GL_TEXTURE_2D, differencematte->midtexture[2]->tex_id);
gst_gl_shader_set_uniform_1i (differencematte->shader[3], "alpha", 2); gst_gl_shader_set_uniform_1i (differencematte->shader[3], "alpha", 2);
@ -427,8 +435,8 @@ gst_gl_differencematte_identity (gint width, gint height, guint texture,
} }
static gboolean static gboolean
gst_gl_differencematte_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_differencematte_filter_texture (GstGLFilter * filter,
guint out_tex) GstGLMemory * in_tex, GstGLMemory * out_tex)
{ {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter); GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
@ -439,9 +447,7 @@ gst_gl_differencematte_filter_texture (GstGLFilter * filter, guint in_tex,
if (!gst_gl_differencematte_loader (filter)) if (!gst_gl_differencematte_loader (filter))
differencematte->pixbuf = NULL; differencematte->pixbuf = NULL;
/* if loader failed then context is turned off */ init_pixbuf_texture (differencematte);
gst_gl_context_thread_add (GST_GL_BASE_FILTER (filter)->context,
init_pixbuf_texture, differencematte);
/* save current frame, needed to calculate difference between /* save current frame, needed to calculate difference between
* this frame and next ones */ * this frame and next ones */
@ -457,7 +463,7 @@ gst_gl_differencematte_filter_texture (GstGLFilter * filter, guint in_tex,
differencematte->bg_has_changed = FALSE; differencematte->bg_has_changed = FALSE;
} }
if (differencematte->savedbgtexture != 0) { if (differencematte->savedbgtexture != NULL) {
gst_gl_filter_render_to_target (filter, TRUE, in_tex, gst_gl_filter_render_to_target (filter, TRUE, in_tex,
differencematte->midtexture[0], gst_gl_differencematte_diff, differencematte->midtexture[0], gst_gl_differencematte_diff,
differencematte); differencematte);

View file

@ -45,10 +45,10 @@ struct _GstGLDifferenceMatte
guchar *pixbuf; guchar *pixbuf;
gint pbuf_width, pbuf_height; gint pbuf_width, pbuf_height;
GLuint savedbgtexture; GstGLMemory *savedbgtexture;
GLuint newbgtexture; GstGLMemory *newbgtexture;
GLuint midtexture[4]; GstGLMemory *midtexture[4];
GLuint intexture; GstGLMemory *intexture;
float kernel[7]; float kernel[7];
}; };

View file

@ -71,7 +71,7 @@ static void gst_gl_effects_ghash_func_clean (gpointer key, gpointer value,
gpointer data); gpointer data);
static gboolean gst_gl_effects_filter_texture (GstGLFilter * filter, static gboolean gst_gl_effects_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static gboolean gst_gl_effects_filters_is_property_supported (const static gboolean gst_gl_effects_filters_is_property_supported (const
GstGLEffectsFilterDescriptor *, gint property); GstGLEffectsFilterDescriptor *, gint property);
@ -274,31 +274,27 @@ gst_gl_effects_init_gl_resources (GstGLFilter * filter)
{ {
GstGLEffects *effects = GST_GL_EFFECTS (filter); GstGLEffects *effects = GST_GL_EFFECTS (filter);
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable; GstGLBaseMemoryAllocator *base_alloc;
guint internal_format; GstGLAllocationParams *params;
gint i = 0; gint i;
base_alloc = (GstGLBaseMemoryAllocator *)
gst_gl_memory_allocator_get_default (context);
params =
(GstGLAllocationParams *) gst_gl_video_allocation_params_new (context,
NULL, &filter->out_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D,
GST_VIDEO_GL_TEXTURE_TYPE_RGBA);
for (i = 0; i < NEEDED_TEXTURES; i++) { for (i = 0; i < NEEDED_TEXTURES; i++) {
if (effects->midtexture[i])
gst_memory_unref (GST_MEMORY_CAST (effects->midtexture[i]));
if (effects->midtexture[i]) { effects->midtexture[i] =
gl->DeleteTextures (1, &effects->midtexture[i]); (GstGLMemory *) gst_gl_base_memory_alloc (base_alloc, params);
effects->midtexture[i] = 0;
}
gl->GenTextures (1, &effects->midtexture[i]);
gl->BindTexture (GL_TEXTURE_2D, effects->midtexture[i]);
internal_format =
gst_gl_sized_gl_format_from_gl_format_type (context, GL_RGBA,
GL_UNSIGNED_BYTE);
gl->TexImage2D (GL_TEXTURE_2D, 0, internal_format,
GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} }
gst_object_unref (base_alloc);
gst_gl_allocation_params_free (params);
} }
/* free resources that need a gl context */ /* free resources that need a gl context */
@ -310,8 +306,7 @@ gst_gl_effects_reset_gl_resources (GstGLFilter * filter)
gint i = 0; gint i = 0;
for (i = 0; i < NEEDED_TEXTURES; i++) { for (i = 0; i < NEEDED_TEXTURES; i++) {
gl->DeleteTextures (1, &effects->midtexture[i]); gst_memory_unref (GST_MEMORY_CAST (effects->midtexture[i]));
effects->midtexture[i] = 0;
} }
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) { for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
gl->DeleteTextures (1, &effects->curve[i]); gl->DeleteTextures (1, &effects->curve[i]);
@ -396,10 +391,11 @@ gst_gl_effects_filter_class_init (GstGLEffectsClass * klass,
} }
static void static void
set_horizontal_swap (GstGLContext * context, gpointer data) set_horizontal_swap (GstGLEffects * effects)
{ {
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
GstGLFuncs *gl = context->gl_vtable; GstGLContext *context = GST_GL_BASE_FILTER (effects)->context;
const GstGLFuncs *gl = context->gl_vtable;
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) { if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
const gfloat mirrormatrix[16] = { const gfloat mirrormatrix[16] = {
@ -527,8 +523,8 @@ gst_gl_effects_on_init_gl_context (GstGLFilter * filter)
} }
static gboolean static gboolean
gst_gl_effects_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_effects_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLEffects *effects = GST_GL_EFFECTS (filter); GstGLEffects *effects = GST_GL_EFFECTS (filter);
@ -536,8 +532,7 @@ gst_gl_effects_filter_texture (GstGLFilter * filter, guint in_tex,
effects->outtexture = out_tex; effects->outtexture = out_tex;
if (effects->horizontal_swap == TRUE) if (effects->horizontal_swap == TRUE)
gst_gl_context_thread_add (GST_GL_BASE_FILTER (filter)->context, set_horizontal_swap (effects);
set_horizontal_swap, effects);
effects->effect (effects); effects->effect (effects);

View file

@ -69,9 +69,9 @@ struct _GstGLEffects
GstGLEffectProcessFunc effect; GstGLEffectProcessFunc effect;
gint current_effect; gint current_effect;
GLuint intexture; GstGLMemory *intexture;
GLuint midtexture[NEEDED_TEXTURES]; GstGLMemory *midtexture[NEEDED_TEXTURES];
GLuint outtexture; GstGLMemory *outtexture;
GLuint curve[GST_GL_EFFECTS_N_CURVES]; GLuint curve[GST_GL_EFFECTS_N_CURVES];

View file

@ -69,7 +69,7 @@ static void gst_gl_filter_app_get_property (GObject * object, guint prop_id,
static gboolean gst_gl_filter_app_set_caps (GstGLFilter * filter, static gboolean gst_gl_filter_app_set_caps (GstGLFilter * filter,
GstCaps * incaps, GstCaps * outcaps); GstCaps * incaps, GstCaps * outcaps);
static gboolean gst_gl_filter_app_filter_texture (GstGLFilter * filter, static gboolean gst_gl_filter_app_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static gboolean gst_gl_filter_app_gl_start (GstGLBaseFilter * base_filter); static gboolean gst_gl_filter_app_gl_start (GstGLBaseFilter * base_filter);
static void gst_gl_filter_app_gl_stop (GstGLBaseFilter * base_filter); static void gst_gl_filter_app_gl_stop (GstGLBaseFilter * base_filter);
@ -200,9 +200,8 @@ struct glcb2
{ {
GLCB func; GLCB func;
gpointer data; gpointer data;
guint texture; GstGLMemory *in_tex;
guint width; GstGLMemory *out_tex;
guint height;
}; };
/* convenience functions to simplify filter development */ /* convenience functions to simplify filter development */
@ -211,27 +210,28 @@ _glcb2 (gpointer data)
{ {
struct glcb2 *cb = data; struct glcb2 *cb = data;
cb->func (cb->width, cb->height, cb->texture, cb->data); cb->func (gst_gl_memory_get_texture_width (cb->in_tex),
gst_gl_memory_get_texture_height (cb->in_tex), cb->in_tex->tex_id,
cb->data);
} }
static gboolean static gboolean
gst_gl_filter_app_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_filter_app_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLFilterApp *app_filter = GST_GL_FILTER_APP (filter); GstGLFilterApp *app_filter = GST_GL_FILTER_APP (filter);
struct glcb2 cb; struct glcb2 cb;
cb.func = (GLCB) _emit_draw_signal; cb.func = (GLCB) _emit_draw_signal;
cb.data = filter; cb.data = filter;
cb.texture = in_tex; cb.in_tex = in_tex;
cb.width = GST_VIDEO_INFO_WIDTH (&filter->in_info); cb.out_tex = out_tex;
cb.height = GST_VIDEO_INFO_HEIGHT (&filter->in_info);
//blocking call, use a FBO //blocking call, use a FBO
gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context, gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context,
GST_VIDEO_INFO_WIDTH (&filter->out_info), GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), GST_VIDEO_INFO_HEIGHT (&filter->out_info),
filter->fbo, filter->depthbuffer, out_tex, _glcb2, &cb); filter->fbo, filter->depthbuffer, out_tex->tex_id, _glcb2, &cb);
if (app_filter->default_draw) { if (app_filter->default_draw) {
gst_gl_filter_render_to_target_with_shader (filter, TRUE, in_tex, out_tex, gst_gl_filter_render_to_target_with_shader (filter, TRUE, in_tex, out_tex,

View file

@ -81,7 +81,7 @@ static void gst_gl_filter_cube_reset_gl (GstGLFilter * filter);
static gboolean gst_gl_filter_cube_init_shader (GstGLFilter * filter); static gboolean gst_gl_filter_cube_init_shader (GstGLFilter * filter);
static void _callback (gpointer stuff); static void _callback (gpointer stuff);
static gboolean gst_gl_filter_cube_filter_texture (GstGLFilter * filter, static gboolean gst_gl_filter_cube_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
/* vertex source */ /* vertex source */
static const gchar *cube_v_src = static const gchar *cube_v_src =
@ -335,8 +335,8 @@ gst_gl_filter_cube_init_shader (GstGLFilter * filter)
} }
static gboolean static gboolean
gst_gl_filter_cube_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_filter_cube_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter); GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
@ -346,7 +346,7 @@ gst_gl_filter_cube_filter_texture (GstGLFilter * filter, guint in_tex,
gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context, gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context,
GST_VIDEO_INFO_WIDTH (&filter->out_info), GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), filter->fbo, GST_VIDEO_INFO_HEIGHT (&filter->out_info), filter->fbo,
filter->depthbuffer, out_tex, _callback, (gpointer) cube_filter); filter->depthbuffer, out_tex->tex_id, _callback, (gpointer) cube_filter);
return TRUE; return TRUE;
} }
@ -466,7 +466,7 @@ _callback (gpointer stuff)
gst_gl_shader_use (cube_filter->shader); gst_gl_shader_use (cube_filter->shader);
gl->ActiveTexture (GL_TEXTURE0); gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, cube_filter->in_tex); gl->BindTexture (GL_TEXTURE_2D, cube_filter->in_tex->tex_id);
gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0); gst_gl_shader_set_uniform_1i (cube_filter->shader, "s_texture", 0);
gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot); gst_gl_shader_set_uniform_1f (cube_filter->shader, "xrot_degree", xrot);
gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot); gst_gl_shader_set_uniform_1f (cube_filter->shader, "yrot_degree", yrot);

View file

@ -40,6 +40,7 @@ struct _GstGLFilterCube
GstGLFilter filter; GstGLFilter filter;
GstGLShader *shader; GstGLShader *shader;
GstGLMemory *in_tex;
/* background color */ /* background color */
gfloat red; gfloat red;
@ -52,7 +53,6 @@ struct _GstGLFilterCube
gdouble znear; gdouble znear;
gdouble zfar; gdouble zfar;
guint in_tex;
GLuint vao; GLuint vao;
GLuint vbo_indices; GLuint vbo_indices;
GLuint vertex_buffer; GLuint vertex_buffer;

View file

@ -66,7 +66,7 @@ static gboolean gst_gl_filter_glass_reset (GstBaseTransform * trans);
static gboolean gst_gl_filter_glass_init_shader (GstGLFilter * filter); static gboolean gst_gl_filter_glass_init_shader (GstGLFilter * filter);
static gboolean gst_gl_filter_glass_filter_texture (GstGLFilter * filter, static gboolean gst_gl_filter_glass_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static void gst_gl_filter_glass_draw_background_gradient (); static void gst_gl_filter_glass_draw_background_gradient ();
static void gst_gl_filter_glass_draw_video_plane (GstGLFilter * filter, static void gst_gl_filter_glass_draw_video_plane (GstGLFilter * filter,
@ -238,17 +238,18 @@ gst_gl_filter_glass_init_shader (GstGLFilter * filter)
} }
static gboolean static gboolean
gst_gl_filter_glass_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_filter_glass_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter); GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter);
glass_filter->in_tex = in_tex; glass_filter->in_tex = in_tex;
//blocking call, use a FBO //blocking call, use a FBO
gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context, gst_gl_context_use_fbo_v2 (GST_GL_BASE_FILTER (filter)->context,
GST_VIDEO_INFO_WIDTH (&filter->out_info), GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), GST_VIDEO_INFO_HEIGHT (&filter->out_info),
filter->fbo, filter->depthbuffer, out_tex, filter->fbo, filter->depthbuffer, out_tex->tex_id,
gst_gl_filter_glass_callback, (gpointer) glass_filter); gst_gl_filter_glass_callback, (gpointer) glass_filter);
return TRUE; return TRUE;
@ -365,7 +366,7 @@ gst_gl_filter_glass_callback (gpointer stuff)
gint width = GST_VIDEO_INFO_WIDTH (&filter->out_info); gint width = GST_VIDEO_INFO_WIDTH (&filter->out_info);
gint height = GST_VIDEO_INFO_HEIGHT (&filter->out_info); gint height = GST_VIDEO_INFO_HEIGHT (&filter->out_info);
guint texture = glass_filter->in_tex; guint texture = glass_filter->in_tex->tex_id;
if (start_time == 0) if (start_time == 0)
start_time = get_time (); start_time = get_time ();

View file

@ -41,7 +41,8 @@ struct _GstGLFilterGlass
GstGLShader *passthrough_shader; GstGLShader *passthrough_shader;
GstGLShader *shader; GstGLShader *shader;
gint64 timestamp; gint64 timestamp;
guint in_tex; GstGLMemory *in_tex;
GstGLMemory *out_tex;
}; };
struct _GstGLFilterGlassClass struct _GstGLFilterGlassClass

View file

@ -82,7 +82,7 @@ static void gst_gl_filtershader_gl_stop (GstGLBaseFilter * base);
static gboolean gst_gl_filtershader_filter (GstGLFilter * filter, static gboolean gst_gl_filtershader_filter (GstGLFilter * filter,
GstBuffer * inbuf, GstBuffer * outbuf); GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_filtershader_filter_texture (GstGLFilter * filter, static gboolean gst_gl_filtershader_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static void gst_gl_filtershader_hcallback (gint width, gint height, static void gst_gl_filtershader_hcallback (gint width, gint height,
guint texture, gpointer stuff); guint texture, gpointer stuff);
@ -313,8 +313,8 @@ gst_gl_filtershader_filter (GstGLFilter * filter, GstBuffer * inbuf,
} }
static gboolean static gboolean
gst_gl_filtershader_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_filtershader_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLFilterShader *filtershader = GST_GL_FILTERSHADER (filter); GstGLFilterShader *filtershader = GST_GL_FILTERSHADER (filter);

View file

@ -631,7 +631,7 @@ _upload_frames (GstAggregator * agg, GstAggregatorPad * agg_pad,
gboolean gboolean
gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf) gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
{ {
guint out_tex; GstGLMemory *out_tex;
gboolean res = TRUE; gboolean res = TRUE;
GstVideoFrame out_frame; GstVideoFrame out_frame;
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix); GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix);
@ -645,7 +645,7 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
return FALSE; return FALSE;
} }
out_tex = *(guint *) out_frame.data[0]; out_tex = (GstGLMemory *) out_frame.map[0].memory;
if (!gst_aggregator_iterate_sinkpads (GST_AGGREGATOR (mix), if (!gst_aggregator_iterate_sinkpads (GST_AGGREGATOR (mix),
(GstAggregatorPadForeachFunc) _upload_frames, NULL)) (GstAggregatorPadForeachFunc) _upload_frames, NULL))

View file

@ -78,7 +78,7 @@ typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
GstCaps* outcaps); GstCaps* outcaps);
typedef void (*GstGLMixerReset) (GstGLMixer *mixer); typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix, GstBuffer *outbuf); typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix, GstBuffer *outbuf);
typedef gboolean (*GstGLMixerProcessTextures) (GstGLMixer *mix, guint out_tex); typedef gboolean (*GstGLMixerProcessTextures) (GstGLMixer *mix, GstGLMemory *out_tex);
struct _GstGLMixer struct _GstGLMixer
{ {

View file

@ -70,7 +70,7 @@ static gboolean gst_gl_mosaic_init_shader (GstGLMixer * mixer,
GstCaps * outcaps); GstCaps * outcaps);
static gboolean gst_gl_mosaic_process_textures (GstGLMixer * mixer, static gboolean gst_gl_mosaic_process_textures (GstGLMixer * mixer,
guint out_tex); GstGLMemory * out_tex);
static void gst_gl_mosaic_callback (gpointer stuff); static void gst_gl_mosaic_callback (gpointer stuff);
//vertex source //vertex source
@ -194,7 +194,7 @@ gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
} }
static gboolean static gboolean
gst_gl_mosaic_process_textures (GstGLMixer * mix, guint out_tex) gst_gl_mosaic_process_textures (GstGLMixer * mix, GstGLMemory * out_tex)
{ {
GstGLMosaic *mosaic = GST_GL_MOSAIC (mix); GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
@ -202,7 +202,8 @@ gst_gl_mosaic_process_textures (GstGLMixer * mix, guint out_tex)
gst_gl_context_use_fbo_v2 (GST_GL_BASE_MIXER (mix)->context, gst_gl_context_use_fbo_v2 (GST_GL_BASE_MIXER (mix)->context,
GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR (mix)->info), GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR (mix)->info),
GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR (mix)->info), mix->fbo, GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR (mix)->info), mix->fbo,
mix->depthbuffer, out_tex, gst_gl_mosaic_callback, (gpointer) mosaic); mix->depthbuffer, out_tex->tex_id, gst_gl_mosaic_callback,
(gpointer) mosaic);
return TRUE; return TRUE;
} }

View file

@ -40,6 +40,7 @@ struct _GstGLMosaic
GstGLMixer mixer; GstGLMixer mixer;
GstGLShader *shader; GstGLShader *shader;
GstGLMemory *out_tex;
}; };
struct _GstGLMosaicClass struct _GstGLMosaicClass

View file

@ -72,7 +72,7 @@ static void gst_gl_overlay_get_property (GObject * object, guint prop_id,
static void gst_gl_overlay_before_transform (GstBaseTransform * trans, static void gst_gl_overlay_before_transform (GstBaseTransform * trans,
GstBuffer * outbuf); GstBuffer * outbuf);
static gboolean gst_gl_overlay_filter_texture (GstGLFilter * filter, static gboolean gst_gl_overlay_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static gboolean gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp); static gboolean gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp);
static gboolean gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp); static gboolean gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp);
@ -624,8 +624,8 @@ out:
} }
static gboolean static gboolean
gst_gl_overlay_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_overlay_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
guint out_tex) GstGLMemory * out_tex)
{ {
GstGLOverlay *overlay = GST_GL_OVERLAY (filter); GstGLOverlay *overlay = GST_GL_OVERLAY (filter);

View file

@ -107,7 +107,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans,
static gboolean gst_gl_transformation_filter (GstGLFilter * filter, static gboolean gst_gl_transformation_filter (GstGLFilter * filter,
GstBuffer * inbuf, GstBuffer * outbuf); GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_transformation_filter_texture (GstGLFilter * filter, static gboolean gst_gl_transformation_filter_texture (GstGLFilter * filter,
guint in_tex, guint out_tex); GstGLMemory * in_tex, GstGLMemory * out_tex);
static void static void
gst_gl_transformation_class_init (GstGLTransformationClass * klass) gst_gl_transformation_class_init (GstGLTransformationClass * klass)
@ -782,8 +782,8 @@ gst_gl_transformation_filter (GstGLFilter * filter,
} }
static gboolean static gboolean
gst_gl_transformation_filter_texture (GstGLFilter * filter, guint in_tex, gst_gl_transformation_filter_texture (GstGLFilter * filter,
guint out_tex) GstGLMemory * in_tex, GstGLMemory * out_tex)
{ {
GstGLTransformation *transformation = GST_GL_TRANSFORMATION (filter); GstGLTransformation *transformation = GST_GL_TRANSFORMATION (filter);
@ -794,7 +794,8 @@ gst_gl_transformation_filter_texture (GstGLFilter * filter, guint in_tex,
GST_VIDEO_INFO_WIDTH (&filter->out_info), GST_VIDEO_INFO_WIDTH (&filter->out_info),
GST_VIDEO_INFO_HEIGHT (&filter->out_info), GST_VIDEO_INFO_HEIGHT (&filter->out_info),
filter->fbo, filter->depthbuffer, filter->fbo, filter->depthbuffer,
out_tex, gst_gl_transformation_callback, (gpointer) transformation); out_tex->tex_id, gst_gl_transformation_callback,
(gpointer) transformation);
return TRUE; return TRUE;
} }
@ -874,7 +875,7 @@ gst_gl_transformation_callback (gpointer stuff)
gst_gl_shader_use (transformation->shader); gst_gl_shader_use (transformation->shader);
gl->ActiveTexture (GL_TEXTURE0); gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, transformation->in_tex); gl->BindTexture (GL_TEXTURE_2D, transformation->in_tex->tex_id);
gst_gl_shader_set_uniform_1i (transformation->shader, "texture", 0); gst_gl_shader_set_uniform_1i (transformation->shader, "texture", 0);
graphene_matrix_to_float (&transformation->mvp_matrix, temp_matrix); graphene_matrix_to_float (&transformation->mvp_matrix, temp_matrix);

View file

@ -47,7 +47,8 @@ struct _GstGLTransformation
GLint attr_position; GLint attr_position;
GLint attr_texture; GLint attr_texture;
guint in_tex; GstGLMemory *in_tex;
GstGLMemory *out_tex;
gfloat xrotation; gfloat xrotation;
gfloat yrotation; gfloat yrotation;

View file

@ -474,7 +474,7 @@ static gboolean gst_gl_video_mixer_init_shader (GstGLMixer * mixer,
GstCaps * outcaps); GstCaps * outcaps);
static gboolean gst_gl_video_mixer_process_textures (GstGLMixer * mixer, static gboolean gst_gl_video_mixer_process_textures (GstGLMixer * mixer,
guint out_tex); GstGLMemory * out_tex);
static void gst_gl_video_mixer_callback (gpointer stuff); static void gst_gl_video_mixer_callback (gpointer stuff);
/* *INDENT-OFF* */ /* *INDENT-OFF* */
@ -1156,7 +1156,7 @@ gst_gl_video_mixer_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
} }
static gboolean static gboolean
gst_gl_video_mixer_process_textures (GstGLMixer * mix, guint out_tex) gst_gl_video_mixer_process_textures (GstGLMixer * mix, GstGLMemory * out_tex)
{ {
GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mix); GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mix);
@ -1164,7 +1164,7 @@ gst_gl_video_mixer_process_textures (GstGLMixer * mix, guint out_tex)
GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR (mix)->info), GST_VIDEO_INFO_WIDTH (&GST_VIDEO_AGGREGATOR (mix)->info),
GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR (mix)->info), GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_AGGREGATOR (mix)->info),
mix->fbo, mix->depthbuffer, mix->fbo, mix->depthbuffer,
out_tex, gst_gl_video_mixer_callback, (gpointer) video_mixer); out_tex->tex_id, gst_gl_video_mixer_callback, (gpointer) video_mixer);
return TRUE; return TRUE;
} }

View file

@ -78,7 +78,8 @@ enum
#define gst_gl_filter_parent_class parent_class #define gst_gl_filter_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLFilter, gst_gl_filter, GST_TYPE_GL_BASE_FILTER, G_DEFINE_TYPE_WITH_CODE (GstGLFilter, gst_gl_filter, GST_TYPE_GL_BASE_FILTER,
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0,
"glfilter element");); "glfilter element");
);
static void gst_gl_filter_set_property (GObject * object, guint prop_id, static void gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
@ -904,7 +905,7 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
GstBuffer * outbuf) GstBuffer * outbuf)
{ {
GstGLFilterClass *filter_class; GstGLFilterClass *filter_class;
guint in_tex, out_tex; GstMemory *in_tex, *out_tex;
GstVideoFrame gl_frame, out_frame; GstVideoFrame gl_frame, out_frame;
gboolean ret; gboolean ret;
@ -916,7 +917,12 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
goto inbuf_error; goto inbuf_error;
} }
in_tex = *(guint *) gl_frame.data[0]; in_tex = gl_frame.map[0].memory;
if (!gst_is_gl_memory (in_tex)) {
ret = FALSE;
GST_ERROR_OBJECT (filter, "Input memory must be GstGLMemory");
goto inbuf_error;
}
if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf, if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf,
GST_MAP_WRITE | GST_MAP_GL)) { GST_MAP_WRITE | GST_MAP_GL)) {
@ -924,13 +930,17 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
goto unmap_out_error; goto unmap_out_error;
} }
out_tex = *(guint *) out_frame.data[0]; out_tex = out_frame.map[0].memory;
g_return_val_if_fail (gst_is_gl_memory (out_tex), FALSE);
GST_DEBUG ("calling filter_texture with textures in:%i out:%i", in_tex, GST_DEBUG ("calling filter_texture with textures in:%i out:%i",
out_tex); GST_GL_MEMORY_CAST (in_tex)->tex_id,
GST_GL_MEMORY_CAST (out_tex)->tex_id);
g_assert (filter_class->filter_texture); g_assert (filter_class->filter_texture);
ret = filter_class->filter_texture (filter, in_tex, out_tex);
ret = filter_class->filter_texture (filter, GST_GL_MEMORY_CAST (in_tex),
GST_GL_MEMORY_CAST (out_tex));
gst_video_frame_unmap (&out_frame); gst_video_frame_unmap (&out_frame);
unmap_out_error: unmap_out_error:
@ -941,10 +951,19 @@ inbuf_error:
} }
static void static void
_debug_marker (GstGLContext * context, GstGLFilter * filter) _filter_gl (GstGLContext * context, GstGLFilter * filter)
{ {
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
gst_gl_insert_debug_marker (context, gst_gl_insert_debug_marker (context,
"processing in element %s", GST_OBJECT_NAME (filter)); "processing in element %s", GST_OBJECT_NAME (filter));
if (filter_class->filter)
filter->gl_result =
filter_class->filter (filter, filter->inbuf, filter->outbuf);
else
filter->gl_result =
gst_gl_filter_filter_texture (filter, filter->inbuf, filter->outbuf);
} }
static GstFlowReturn static GstFlowReturn
@ -967,12 +986,11 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
if (in_sync_meta) if (in_sync_meta)
gst_gl_sync_meta_wait (in_sync_meta, context); gst_gl_sync_meta_wait (in_sync_meta, context);
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _debug_marker, filter->inbuf = inbuf;
filter->outbuf = outbuf;
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _filter_gl,
filter); filter);
if (filter_class->filter) ret = filter->gl_result;
ret = filter_class->filter (filter, inbuf, outbuf);
else
ret = gst_gl_filter_filter_texture (filter, inbuf, outbuf);
out_sync_meta = gst_buffer_get_gl_sync_meta (outbuf); out_sync_meta = gst_buffer_get_gl_sync_meta (outbuf);
if (out_sync_meta) if (out_sync_meta)
@ -1014,7 +1032,7 @@ _glcb2 (gpointer data)
*/ */
void void
gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize, gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize,
GLuint input, GLuint target, GLCB func, gpointer data) GstGLMemory * input, GstGLMemory * output, GLCB func, gpointer data)
{ {
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
guint in_width, in_height, out_width, out_height; guint in_width, in_height, out_width, out_height;
@ -1030,12 +1048,12 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize,
in_height = out_height; in_height = out_height;
} }
GST_LOG ("rendering to target. in %u, %ux%u out %u, %ux%u", input, in_width, GST_LOG ("rendering to target. in %u, %ux%u out %u, %ux%u", input->tex_id,
in_height, target, out_width, out_height); in_width, in_height, output->tex_id, out_width, out_height);
cb.func = func; cb.func = func;
cb.data = data; cb.data = data;
cb.texture = input; cb.texture = input->tex_id;
cb.width = in_width; cb.width = in_width;
cb.height = in_height; cb.height = in_height;
@ -1110,13 +1128,14 @@ _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff)
* the shader, render input to a quad */ * the shader, render input to a quad */
void void
gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
gboolean resize, GLuint input, GLuint target, GstGLShader * shader) gboolean resize, GstGLMemory * input, GstGLMemory * output,
GstGLShader * shader)
{ {
if (filter->default_shader != shader) if (filter->default_shader != shader)
filter->valid_attributes = FALSE; filter->valid_attributes = FALSE;
filter->default_shader = shader; filter->default_shader = shader;
gst_gl_filter_render_to_target (filter, resize, input, target, gst_gl_filter_render_to_target (filter, resize, input, output,
_draw_with_shader_cb, filter); _draw_with_shader_cb, filter);
} }

View file

@ -66,6 +66,9 @@ struct _GstGLFilter
/* <private> */ /* <private> */
GLuint fbo; GLuint fbo;
GLuint depthbuffer; GLuint depthbuffer;
gboolean gl_result;
GstBuffer *inbuf;
GstBuffer *outbuf;
GstGLShader *default_shader; GstGLShader *default_shader;
gboolean valid_attributes; gboolean valid_attributes;
@ -99,7 +102,7 @@ struct _GstGLFilterClass
gboolean (*set_caps) (GstGLFilter* filter, GstCaps* incaps, GstCaps* outcaps); gboolean (*set_caps) (GstGLFilter* filter, GstCaps* incaps, GstCaps* outcaps);
gboolean (*filter) (GstGLFilter *filter, GstBuffer *inbuf, GstBuffer *outbuf); gboolean (*filter) (GstGLFilter *filter, GstBuffer *inbuf, GstBuffer *outbuf);
gboolean (*filter_texture) (GstGLFilter *filter, guint in_tex, guint out_tex); gboolean (*filter_texture) (GstGLFilter *filter, GstGLMemory *in_tex, GstGLMemory *out_tex);
gboolean (*init_fbo) (GstGLFilter *filter); gboolean (*init_fbo) (GstGLFilter *filter);
GstCaps *(*transform_internal_caps) (GstGLFilter *filter, GstCaps *(*transform_internal_caps) (GstGLFilter *filter,
@ -113,13 +116,19 @@ struct _GstGLFilterClass
gboolean gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf, gboolean gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
GstBuffer * outbuf); GstBuffer * outbuf);
void gst_gl_filter_render_to_target (GstGLFilter *filter, gboolean resize, GLuint input, void gst_gl_filter_render_to_target (GstGLFilter *filter,
GLuint target, GLCB func, gpointer data); gboolean resize,
GstGLMemory * input,
void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize, GstGLMemory * output,
GLuint input, GLuint target, GstGLShader *shader); GLCB func,
gpointer data);
void gst_gl_filter_draw_fullscreen_quad (GstGLFilter *filter); void gst_gl_filter_draw_fullscreen_quad (GstGLFilter *filter);
void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
gboolean resize,
GstGLMemory * input,
GstGLMemory * output,
GstGLShader *shader);
G_END_DECLS G_END_DECLS