gl/utils: move gen_shader() to the plugin and remove del_shader()

gst_gl_context_del_shader() can be replaced by a g_object_unref().
gst_gl_context_gen_shader() should be replaced by using GstGLSLStage.
This commit is contained in:
Matthew Waters 2016-11-10 19:14:24 +11:00 committed by Tim-Philipp Müller
parent e483b092f1
commit 8a1d31f6ab
13 changed files with 20 additions and 113 deletions

View file

@ -43,7 +43,8 @@ libgstopengl_la_SOURCES = \
gstgldeinterlace.c \
gstglstereomix.c \
gltestsrc.c \
gstgltestsrc.c
gstgltestsrc.c \
gstglutils.c
noinst_HEADERS = \
gstglbasemixer.h \
@ -69,7 +70,8 @@ noinst_HEADERS = \
gstgldeinterlace.h \
gstglviewconvert.h \
gltestsrc.h \
gstgltestsrc.h
gstgltestsrc.h \
gstglutils.h
# full opengl required
if USE_OPENGL

View file

@ -294,10 +294,8 @@ gst_gl_deinterlace_ghash_func_clean (gpointer key, gpointer value,
gpointer data)
{
GstGLShader *shader = (GstGLShader *) value;
GstGLFilter *filter = (GstGLFilter *) data;
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context, shader);
gst_object_unref (shader);
value = NULL;
}

View file

@ -436,10 +436,8 @@ static void
gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data)
{
GstGLShader *shader = (GstGLShader *) value;
GstGLFilter *filter = (GstGLFilter *) data;
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context, shader);
gst_object_unref (shader);
value = NULL;
}

View file

@ -46,6 +46,7 @@
#include <gst/gl/gstglapi.h>
#include "gstglfiltercube.h"
#include "gstglutils.h"
#define GST_CAT_DEFAULT gst_gl_filter_cube_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);

View file

@ -42,6 +42,7 @@
#include <math.h>
#include "gstglfilterglass.h"
#include "gstglutils.h"
#define GST_CAT_DEFAULT gst_gl_filter_glass_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -181,12 +182,10 @@ gst_gl_filter_glass_reset (GstBaseTransform * trans)
//blocking call, wait the opengl thread has destroyed the shader
if (glass_filter->shader)
gst_gl_context_del_shader (GST_GL_BASE_FILTER (trans)->context,
glass_filter->shader);
gst_object_unref (glass_filter->shader);
glass_filter->shader = NULL;
if (glass_filter->passthrough_shader)
gst_gl_context_del_shader (GST_GL_BASE_FILTER (trans)->context,
glass_filter->passthrough_shader);
gst_object_unref (glass_filter->passthrough_shader);
glass_filter->passthrough_shader = NULL;
return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (trans);

View file

@ -45,6 +45,7 @@
#endif
#include "gstglmosaic.h"
#include "gstglutils.h"
#define GST_CAT_DEFAULT gst_gl_mosaic_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -177,8 +178,7 @@ gst_gl_mosaic_reset (GstGLMixer * mixer)
//blocking call, wait the opengl thread has destroyed the shader
if (mosaic->shader)
gst_gl_context_del_shader (GST_GL_BASE_MIXER (mixer)->context,
mosaic->shader);
gst_object_unref (mosaic->shader);
mosaic->shader = NULL;
}

View file

@ -41,6 +41,7 @@
#include "gstgloverlay.h"
#include "effects/gstgleffectssources.h"
#include "gstglutils.h"
#include <stdio.h>
#include <stdlib.h>

View file

@ -49,6 +49,7 @@
#include <gst/gl/gstglapi.h>
#include <graphene-gobject.h>
#include "gstglutils.h"
#define GST_CAT_DEFAULT gst_gl_transformation_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);

View file

@ -47,6 +47,7 @@
#include "gstglvideomixer.h"
#include "gstglmixerbin.h"
#include "gstglutils.h"
#define GST_CAT_DEFAULT gst_gl_video_mixer_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -1129,11 +1130,11 @@ gst_gl_video_mixer_reset (GstGLMixer * mixer)
GST_DEBUG_OBJECT (mixer, "context:%p", context);
if (video_mixer->shader)
gst_gl_context_del_shader (context, video_mixer->shader);
gst_object_unref (video_mixer->shader);
video_mixer->shader = NULL;
if (video_mixer->checker)
gst_gl_context_del_shader (context, video_mixer->checker);
gst_object_unref (video_mixer->checker);
video_mixer->checker = NULL;
if (GST_GL_BASE_MIXER (mixer)->context)
@ -1147,8 +1148,7 @@ gst_gl_video_mixer_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mixer);
if (video_mixer->shader)
gst_gl_context_del_shader (GST_GL_BASE_MIXER (mixer)->context,
video_mixer->shader);
gst_object_unref (video_mixer->shader);
return gst_gl_context_gen_shader (GST_GL_BASE_MIXER (mixer)->context,
gst_gl_shader_string_vertex_mat4_vertex_transform,

View file

@ -42,6 +42,7 @@ opengl_sources = [
'gstglstereomix.c',
'gltestsrc.c',
'gstgltestsrc.c',
'gstglutils.c'
]
if build_gstgl and gstgl_dep.found()

View file

@ -49,93 +49,6 @@
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
struct _compile_shader
{
GstGLShader **shader;
const gchar *vertex_src;
const gchar *fragment_src;
};
static void
_compile_shader (GstGLContext * context, struct _compile_shader *data)
{
GstGLShader *shader;
GstGLSLStage *vert, *frag;
GError *error = NULL;
shader = gst_gl_shader_new (context);
if (data->vertex_src) {
vert = gst_glsl_stage_new_with_string (context, GL_VERTEX_SHADER,
GST_GLSL_VERSION_NONE,
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, data->vertex_src);
if (!gst_glsl_stage_compile (vert, &error)) {
GST_ERROR_OBJECT (vert, "%s", error->message);
gst_object_unref (vert);
gst_object_unref (shader);
return;
}
if (!gst_gl_shader_attach (shader, vert)) {
gst_object_unref (shader);
return;
}
}
if (data->fragment_src) {
frag = gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER,
GST_GLSL_VERSION_NONE,
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY,
data->fragment_src);
if (!gst_glsl_stage_compile (frag, &error)) {
GST_ERROR_OBJECT (frag, "%s", error->message);
gst_object_unref (frag);
gst_object_unref (shader);
return;
}
if (!gst_gl_shader_attach (shader, frag)) {
gst_object_unref (shader);
return;
}
}
if (!gst_gl_shader_link (shader, &error)) {
GST_ERROR_OBJECT (shader, "%s", error->message);
g_error_free (error);
error = NULL;
gst_gl_context_clear_shader (context);
gst_object_unref (shader);
return;
}
*data->shader = shader;
}
/* Called by glfilter */
gboolean
gst_gl_context_gen_shader (GstGLContext * context, const gchar * vert_src,
const gchar * frag_src, GstGLShader ** shader)
{
struct _compile_shader data;
g_return_val_if_fail (frag_src != NULL || vert_src != NULL, FALSE);
g_return_val_if_fail (shader != NULL, FALSE);
data.shader = shader;
data.vertex_src = vert_src;
data.fragment_src = frag_src;
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _compile_shader,
&data);
return *shader != NULL;
}
/* Called by glfilter */
void
gst_gl_context_del_shader (GstGLContext * context, GstGLShader * shader)
{
gst_object_unref (shader);
}
static gboolean
gst_gl_display_found (GstElement * element, GstGLDisplay * display)

View file

@ -28,13 +28,6 @@
G_BEGIN_DECLS
GST_EXPORT
gboolean gst_gl_context_gen_shader (GstGLContext * context,
const gchar * shader_vertex_source,
const gchar * shader_fragment_source, GstGLShader ** shader);
GST_EXPORT
void gst_gl_context_del_shader (GstGLContext * context, GstGLShader * shader);
GST_EXPORT
gboolean gst_gl_ensure_element_data (gpointer element,
GstGLDisplay **display_ptr, GstGLContext ** other_context_ptr);

View file

@ -1357,7 +1357,7 @@ gst_gl_view_convert_reset (GstGLViewConvert * viewconvert)
{
g_return_if_fail (GST_IS_GL_VIEW_CONVERT (viewconvert));
if (viewconvert->shader)
gst_gl_context_del_shader (viewconvert->context, viewconvert->shader);
gst_object_unref (viewconvert->shader);
viewconvert->shader = NULL;
if (viewconvert->fbo)