mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 15:18:21 +00:00
gloverlaycompositor: Create own shader object
Make gloverlaycompositor independent of the shader used in the sink. https://bugzilla.gnome.org/show_bug.cgi?id=745107
This commit is contained in:
parent
1fae4b199a
commit
8abd2bbe35
3 changed files with 47 additions and 18 deletions
|
@ -1287,8 +1287,7 @@ prepare_next_buffer (GstGLImageSink * glimage_sink)
|
|||
}
|
||||
|
||||
gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
|
||||
next_buffer, glimage_sink->attr_position, glimage_sink->attr_texture,
|
||||
glimage_sink->window_width, glimage_sink->window_height);
|
||||
next_buffer, glimage_sink->window_width, glimage_sink->window_height);
|
||||
|
||||
/* in_buffer invalid now */
|
||||
if (!gst_video_frame_map (&gl_frame, info, next_buffer,
|
||||
|
@ -1880,8 +1879,7 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
|
|||
|
||||
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
gst_gl_overlay_compositor_draw_overlays (gl_sink->overlay_compositor,
|
||||
gl_sink->redisplay_shader);
|
||||
gst_gl_overlay_compositor_draw_overlays (gl_sink->overlay_compositor);
|
||||
|
||||
gst_gl_context_clear_shader (gl_sink->context);
|
||||
|
||||
|
|
|
@ -54,6 +54,20 @@ gst_gl_overlay_compositor_init (GstGLOverlayCompositor * compositor)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_overlay_compositor_init_gl (GstGLContext * context,
|
||||
gpointer compositor_pointer)
|
||||
{
|
||||
GstGLOverlayCompositor *compositor =
|
||||
(GstGLOverlayCompositor *) compositor_pointer;
|
||||
|
||||
if (!gst_gl_shader_compile_with_default_vf_and_check
|
||||
(compositor->shader, &compositor->position_attrib,
|
||||
&compositor->texcoord_attrib)) {
|
||||
GST_ERROR ("could not initialize shader.");
|
||||
}
|
||||
}
|
||||
|
||||
GstGLOverlayCompositor *
|
||||
gst_gl_overlay_compositor_new (GstGLContext * context)
|
||||
{
|
||||
|
@ -62,6 +76,11 @@ gst_gl_overlay_compositor_new (GstGLContext * context)
|
|||
|
||||
compositor->context = gst_object_ref (context);
|
||||
|
||||
compositor->shader = gst_gl_shader_new (compositor->context);
|
||||
|
||||
gst_gl_context_thread_add (compositor->context,
|
||||
gst_gl_overlay_compositor_init_gl, compositor);
|
||||
|
||||
GST_DEBUG_OBJECT (compositor, "Created new GstGLOverlayCompositor");
|
||||
|
||||
return compositor;
|
||||
|
@ -79,6 +98,11 @@ gst_gl_overlay_compositor_finalize (GObject * object)
|
|||
if (compositor->context)
|
||||
gst_object_unref (compositor->context);
|
||||
|
||||
if (compositor->shader) {
|
||||
gst_object_unref (compositor->shader);
|
||||
compositor->shader = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gst_gl_overlay_compositor_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -129,8 +153,7 @@ gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor)
|
|||
|
||||
void
|
||||
gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
||||
GstBuffer * buf, GLint position_attrib, GLint texcoord_attrib,
|
||||
guint window_width, guint window_height)
|
||||
GstBuffer * buf, guint window_width, guint window_height)
|
||||
{
|
||||
GstVideoOverlayCompositionMeta *composition_meta;
|
||||
|
||||
|
@ -161,10 +184,11 @@ gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
|||
if (!_is_rectangle_in_overlays (compositor->overlays, rectangle)) {
|
||||
GstGLCompositionOverlay *overlay =
|
||||
gst_gl_composition_overlay_new (compositor->context, rectangle,
|
||||
position_attrib, texcoord_attrib);
|
||||
compositor->position_attrib, compositor->texcoord_attrib);
|
||||
|
||||
gst_gl_composition_overlay_upload (overlay, buf, window_width,
|
||||
window_height);
|
||||
|
||||
gst_gl_composition_overlay_upload (overlay, buf,
|
||||
window_width, window_height);
|
||||
compositor->overlays = g_list_append (compositor->overlays, overlay);
|
||||
}
|
||||
}
|
||||
|
@ -185,19 +209,24 @@ gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
|||
}
|
||||
|
||||
void
|
||||
gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor,
|
||||
GstGLShader * shader)
|
||||
gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor)
|
||||
{
|
||||
const GstGLFuncs *gl = compositor->context->gl_vtable;
|
||||
if (compositor->overlays != NULL) {
|
||||
GList *l;
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl->Enable (GL_BLEND);
|
||||
gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
gst_gl_shader_use (compositor->shader);
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gst_gl_shader_set_uniform_1i (compositor->shader, "tex", 0);
|
||||
|
||||
for (l = compositor->overlays; l != NULL; l = l->next) {
|
||||
GstGLCompositionOverlay *overlay = (GstGLCompositionOverlay *) l->data;
|
||||
gst_gl_composition_overlay_draw (overlay, shader);
|
||||
gst_gl_composition_overlay_draw (overlay, compositor->shader);
|
||||
}
|
||||
|
||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ struct _GstGLOverlayCompositor
|
|||
guint last_window_height;
|
||||
|
||||
GList * overlays;
|
||||
|
||||
GstGLShader *shader;
|
||||
GLint position_attrib;
|
||||
GLint texcoord_attrib;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -65,11 +69,9 @@ GstGLOverlayCompositor *gst_gl_overlay_compositor_new (GstGLContext * context);
|
|||
void gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor);
|
||||
|
||||
void gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
||||
GstBuffer * buf, GLint position_attrib, GLint texcoord_attrib,
|
||||
guint window_width, guint window_height);
|
||||
GstBuffer * buf, guint window_width, guint window_height);
|
||||
|
||||
void gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor,
|
||||
GstGLShader *shader);
|
||||
void gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor);
|
||||
|
||||
GstCaps * gst_gl_overlay_compositor_add_caps(GstCaps * caps);
|
||||
|
||||
|
|
Loading…
Reference in a new issue