[387/906] glmixer: add a glmixer base element

glmixer can be seen as a glfilter except it handles N requested
sink pads.
Each sink pad and the src pad are video/x-raw-gl.
glmixer is responsible for managing different framerates from inputs.
It uses OpenGL context sharing. It means that each input is in its
own OpenGL context shared together and shared with the OpenGL context
of the ouput gl chain.
Also add a glmosaic which is an example of implementation of glmixer.
For now glmosaic is a cube but it will be fixed in the next commits.
For now the glmixer has some weird behaviours in some configurations
but it will be improved in the next commits.
The autotools builds is temporarly broken since those changes
have been made on win32.
This commit is contained in:
Julien Isorce 2009-10-23 01:11:27 +02:00 committed by Tim-Philipp Müller
parent 8c33ba0ba6
commit b85ffef956
12 changed files with 1721 additions and 49 deletions

View file

@ -70,6 +70,7 @@ void gst_gl_display_thread_init_download (GstGLDisplay * display);
void gst_gl_display_thread_do_download (GstGLDisplay * display); void gst_gl_display_thread_do_download (GstGLDisplay * display);
void gst_gl_display_thread_gen_fbo (GstGLDisplay * display); void gst_gl_display_thread_gen_fbo (GstGLDisplay * display);
void gst_gl_display_thread_use_fbo (GstGLDisplay * display); void gst_gl_display_thread_use_fbo (GstGLDisplay * display);
void gst_gl_display_thread_use_fbo_v2 (GstGLDisplay * display);
void gst_gl_display_thread_del_fbo (GstGLDisplay * display); void gst_gl_display_thread_del_fbo (GstGLDisplay * display);
void gst_gl_display_thread_gen_shader (GstGLDisplay * display); void gst_gl_display_thread_gen_shader (GstGLDisplay * display);
void gst_gl_display_thread_del_shader (GstGLDisplay * display); void gst_gl_display_thread_del_shader (GstGLDisplay * display);
@ -123,7 +124,6 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
//gl context //gl context
display->gl_thread = NULL; display->gl_thread = NULL;
display->gl_window = NULL; display->gl_window = NULL;
display->visible = FALSE;
display->isAlive = TRUE; display->isAlive = TRUE;
display->texture_pool = g_hash_table_new (g_direct_hash, g_direct_equal); display->texture_pool = g_hash_table_new (g_direct_hash, g_direct_equal);
@ -182,6 +182,7 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
display->use_fbo_width = 0; display->use_fbo_width = 0;
display->use_fbo_height = 0; display->use_fbo_height = 0;
display->use_fbo_scene_cb = NULL; display->use_fbo_scene_cb = NULL;
display->use_fbo_scene_cb_v2 = NULL;
display->use_fbo_proj_param1 = 0; display->use_fbo_proj_param1 = 0;
display->use_fbo_proj_param2 = 0; display->use_fbo_proj_param2 = 0;
display->use_fbo_proj_param3 = 0; display->use_fbo_proj_param3 = 0;
@ -522,6 +523,8 @@ gst_gl_display_finalize (GObject * object)
display->clientDrawCallback = NULL; display->clientDrawCallback = NULL;
if (display->use_fbo_scene_cb) if (display->use_fbo_scene_cb)
display->use_fbo_scene_cb = NULL; display->use_fbo_scene_cb = NULL;
if (display->use_fbo_scene_cb_v2)
display->use_fbo_scene_cb_v2 = NULL;
if (display->use_fbo_stuff) if (display->use_fbo_stuff)
display->use_fbo_stuff = NULL; display->use_fbo_stuff = NULL;
} }
@ -538,9 +541,7 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
GLenum err = 0; GLenum err = 0;
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->gl_window = display->gl_window = gst_gl_window_new (display->external_gl_context);
gst_gl_window_new (display->upload_width, display->upload_height,
display->external_gl_context);
if (!display->gl_window) { if (!display->gl_window) {
display->isAlive = FALSE; display->isAlive = FALSE;
@ -1654,6 +1655,47 @@ gst_gl_display_thread_use_fbo (GstGLDisplay * display)
} }
/* Called in a gl thread
* Need full shader support */
void
gst_gl_display_thread_use_fbo_v2 (GstGLDisplay * display)
{
GLint viewport_dim[4];
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->use_fbo);
//setup a texture to render to
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture);
//attach the texture to the FBO to renderer to
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture, 0);
glGetIntegerv (GL_VIEWPORT, viewport_dim);
glViewport (0, 0, display->use_fbo_width, display->use_fbo_height);
#ifndef OPENGL_ES2
glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
#endif
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//the opengl scene
display->use_fbo_scene_cb_v2 (display->use_fbo_stuff);
#ifndef OPENGL_ES2
glDrawBuffer (GL_NONE);
#endif
glViewport (viewport_dim[0], viewport_dim[1],
viewport_dim[2], viewport_dim[3]);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
}
/* Called in the gl thread */ /* Called in the gl thread */
void void
gst_gl_display_thread_del_fbo (GstGLDisplay * display) gst_gl_display_thread_del_fbo (GstGLDisplay * display)
@ -1807,7 +1849,8 @@ gst_gl_display_on_draw (GstGLDisplay * display)
display->redisplay_texture_width, display->redisplay_texture_height); display->redisplay_texture_width, display->redisplay_texture_height);
if (doRedisplay && display->gl_window) if (doRedisplay && display->gl_window)
gst_gl_window_draw_unlocked (display->gl_window); gst_gl_window_draw_unlocked (display->gl_window,
display->redisplay_texture_width, display->redisplay_texture_height);
} }
//default opengl scene //default opengl scene
else { else {
@ -2064,16 +2107,13 @@ gst_gl_display_new (void)
} }
/* Create an opengl context (one context for one GstGLDisplay) /* Create an opengl context (one context for one GstGLDisplay) */
* Called by the first gl element of a video/x-raw-gl flow */
void void
gst_gl_display_create_context (GstGLDisplay * display, gst_gl_display_create_context (GstGLDisplay * display, gulong external_gl_context)
GLint width, GLint height, gulong external_gl_context)
{ {
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->upload_width = width; if (!display->gl_window) {
display->upload_height = height;
display->external_gl_context = external_gl_context; display->external_gl_context = external_gl_context;
display->gl_thread = g_thread_create ( display->gl_thread = g_thread_create (
@ -2082,6 +2122,7 @@ gst_gl_display_create_context (GstGLDisplay * display,
g_cond_wait (display->cond_create_context, display->mutex); g_cond_wait (display->cond_create_context, display->mutex);
GST_INFO ("gl thread created"); GST_INFO ("gl thread created");
}
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
} }
@ -2112,7 +2153,7 @@ gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
} }
display->keep_aspect_ratio = keep_aspect_ratio; display->keep_aspect_ratio = keep_aspect_ratio;
if (display->gl_window) if (display->gl_window)
gst_gl_window_draw (display->gl_window); gst_gl_window_draw (display->gl_window, width, height);
} }
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
@ -2327,6 +2368,30 @@ gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
return isAlive; return isAlive;
} }
gboolean
gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
if (isAlive) {
display->use_fbo = fbo;
display->use_depth_buffer = depth_buffer;
display->use_fbo_texture = texture_fbo;
display->use_fbo_width = texture_fbo_width;
display->use_fbo_height = texture_fbo_height;
display->use_fbo_scene_cb_v2 = cb;
display->use_fbo_stuff = stuff;
gst_gl_window_send_message (display->gl_window,
GST_GL_WINDOW_CB (gst_gl_display_thread_use_fbo_v2), display);
}
gst_gl_display_unlock (display);
return isAlive;
}
/* Called by gltestsrc and glfilter */ /* Called by gltestsrc and glfilter */
void void
@ -2402,6 +2467,27 @@ gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb)
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
} }
gulong
gst_gl_display_get_internal_gl_context (GstGLDisplay * display)
{
gulong external_gl_context = 0;
gst_gl_display_lock (display);
external_gl_context =
gst_gl_window_get_internal_gl_context (display->gl_window);
gst_gl_display_unlock (display);
return external_gl_context;
}
void
gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate)
{
if (!activate)
gst_gl_display_lock (display);
gst_gl_window_activate_gl_context (display->gl_window, activate);
if (activate)
gst_gl_display_unlock (display);
}
//------------------------------------------------------------ //------------------------------------------------------------
//------------------------ END PUBLIC ------------------------ //------------------------ END PUBLIC ------------------------

View file

@ -73,6 +73,7 @@ typedef void (*GstGLDisplayThreadFunc) (GstGLDisplay * display, gpointer data);
//opengl scene callback //opengl scene callback
typedef void (*GLCB) (gint, gint, guint, gpointer stuff); typedef void (*GLCB) (gint, gint, guint, gpointer stuff);
typedef void (*GLCB_V2) (gpointer stuff);
struct _GstGLDisplay struct _GstGLDisplay
{ {
@ -84,7 +85,6 @@ struct _GstGLDisplay
//gl context //gl context
GThread *gl_thread; GThread *gl_thread;
GstGLWindow *gl_window; GstGLWindow *gl_window;
gboolean visible;
gboolean isAlive; gboolean isAlive;
GHashTable *texture_pool; GHashTable *texture_pool;
@ -149,6 +149,7 @@ struct _GstGLDisplay
GLuint use_fbo_width; GLuint use_fbo_width;
GLuint use_fbo_height; GLuint use_fbo_height;
GLCB use_fbo_scene_cb; GLCB use_fbo_scene_cb;
GLCB_V2 use_fbo_scene_cb_v2;
gdouble use_fbo_proj_param1; gdouble use_fbo_proj_param1;
gdouble use_fbo_proj_param2; gdouble use_fbo_proj_param2;
gdouble use_fbo_proj_param3; gdouble use_fbo_proj_param3;
@ -237,7 +238,7 @@ GType gst_gl_display_get_type (void);
GstGLDisplay *gst_gl_display_new (void); GstGLDisplay *gst_gl_display_new (void);
void gst_gl_display_create_context (GstGLDisplay * display, void gst_gl_display_create_context (GstGLDisplay * display,
GLint width, GLint height, gulong external_gl_context); gulong external_gl_context);
gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture,
gint width, gint height, gboolean keep_aspect_ratio); gint width, gint height, gboolean keep_aspect_ratio);
@ -267,6 +268,9 @@ gboolean gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
gint input_texture_height, GLuint input_texture, gdouble proj_param1, gint input_texture_height, GLuint input_texture, gdouble proj_param1,
gdouble proj_param2, gdouble proj_param3, gdouble proj_param4, gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
GstGLDisplayProjection projection, gpointer * stuff); GstGLDisplayProjection projection, gpointer * stuff);
gboolean gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff);
void gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo, void gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo,
GLuint depth_buffer); GLuint depth_buffer);
@ -280,4 +284,7 @@ void gst_gl_display_set_client_reshape_callback (GstGLDisplay * display,
CRCB cb); CRCB cb);
void gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb); void gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb);
gulong gst_gl_display_get_internal_gl_context (GstGLDisplay * display);
void gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate);
#endif #endif

View file

@ -95,6 +95,7 @@
#define glUniformMatrix4fvARB glUniformMatrix4fv #define glUniformMatrix4fvARB glUniformMatrix4fv
#define glGetUniformLocationARB glGetUniformLocation #define glGetUniformLocationARB glGetUniformLocation
#define glGetAttribLocationARB glGetAttribLocation #define glGetAttribLocationARB glGetAttribLocation
#define glBindAttribLocationARB glBindAttribLocation
/* UNSUPPORTED */ /* UNSUPPORTED */

View file

@ -169,7 +169,7 @@ gst_gl_filter_src_query (GstPad * pad, GstQuery * query)
/* this gl filter is a sink in terms of the gl chain */ /* this gl filter is a sink in terms of the gl chain */
gst_structure_set (structure, "gstgldisplay", G_TYPE_POINTER, filter->display, NULL); gst_structure_set (structure, "gstgldisplay", G_TYPE_POINTER, filter->display, NULL);
} else { } else {
/* at least one gl element is before in our gl chain */ /* at least one gl element is after in our gl chain */
res = g_strcmp0 (gst_element_get_name (parent), gst_structure_get_name (structure)) == 0; res = g_strcmp0 (gst_element_get_name (parent), gst_structure_get_name (structure)) == 0;
} }
if (!res) if (!res)
@ -222,11 +222,13 @@ gst_gl_filter_start (GstBaseTransform * bt)
if (isPerformed) { if (isPerformed) {
const GValue *id_value = gst_structure_get_value (structure, "gstgldisplay"); const GValue *id_value = gst_structure_get_value (structure, "gstgldisplay");
if (G_VALUE_HOLDS_POINTER (id_value)) if (G_VALUE_HOLDS_POINTER (id_value))
/* at least one gl element is before in our gl chain */ /* at least one gl element is after in our gl chain */
filter->display = g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value))); filter->display = g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
else else {
/* this gl filter is a sink in terms of the gl chain */ /* this gl filter is a sink in terms of the gl chain */
filter->display = gst_gl_display_new (); filter->display = gst_gl_display_new ();
gst_gl_display_create_context (filter->display, 0);
}
} }
gst_query_unref (query); gst_query_unref (query);

1294
gst-libs/gst/gl/gstglmixer.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,107 @@
/*
* GStreamer
* Copyright (C) 2009 Julien Isorce <julien.isorce@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.
*/
#ifndef __GST_GL_MIXER_H__
#define __GST_GL_MIXER_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstglmixerpad.h"
G_BEGIN_DECLS
#define GST_TYPE_GL_MIXER (gst_gl_mixer_get_type())
#define GST_GL_MIXER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_MIXER, GstGLMixer))
#define GST_GL_MIXER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_MIXER, GstGLMixerClass))
#define GST_IS_GL_MIXER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_MIXER))
#define GST_IS_GL_MIXER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_MIXER))
#define GST_GL_MIXER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_GL_MIXER,GstGLMixerClass))
typedef struct _GstGLMixer GstGLMixer;
typedef struct _GstGLMixerClass GstGLMixerClass;
typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
GstCaps* outcaps);
typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
GArray *buffers, GstBuffer *outbuf);
struct _GstGLMixer
{
GstElement element;
/* pad */
GstPad *srcpad;
/* Lock to prevent the state to change while blending */
GMutex *state_lock;
/* Sink pads using Collect Pads from core's base library */
GstCollectPads *collect;
/* sinkpads, a GSList of GstGLMixerPads */
GSList *sinkpads;
GArray *array_buffers;
gint numpads;
GstClockTime last_ts;
/* the master pad */
GstGLMixerPad *master;
gint width;
gint height;
gboolean setcaps;
gboolean sendseg;
gint fps_n;
gint fps_d;
/* Next available sinkpad index */
gint next_sinkpad;
/* sink event handling */
GstPadEventFunction collect_event;
guint64 segment_position;
gdouble segment_rate;
GstGLDisplay *display;
GLuint fbo;
GLuint depthbuffer;
};
struct _GstGLMixerClass
{
GstElementClass parent_class;
GstGLMixerSetCaps set_caps;
GstGLMixerReset reset;
GstGLMixerProcessFunc process_buffers;
};
GType gst_gl_mixer_get_type(void);
G_END_DECLS
#endif /* __GST_GL_MIXER_H__ */

View file

@ -0,0 +1,77 @@
/*
* GStreamer
* Copyright (C) 2009 Julien Isorce <julien.isorce@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.
*/
#ifndef __GST_GL_MIXER_PAD_H__
#define __GST_GL_MIXER_PAD_H__
#include <gst/gst.h>
#include <gst/base/gstcollectpads.h>
#include "gstglbuffer.h"
G_BEGIN_DECLS
#define GST_TYPE_GL_MIXER_PAD (gst_gl_mixer_pad_get_type())
#define GST_GL_MIXER_PAD(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_MIXER_PAD, GstGLMixerPad))
#define GST_GL_MIXER_PAD_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_MIXER_PAD, GstGLMixerPadiClass))
#define GST_IS_GL_MIXER_PAD(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_MIXER_PAD))
#define GST_IS_GL_MIXER_PAD_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_MIXER_PAD))
typedef struct _GstGLMixerPad GstGLMixerPad;
typedef struct _GstGLMixerPadClass GstGLMixerPadClass;
typedef struct _GstGLMixerCollect GstGLMixerCollect;
struct _GstGLMixerCollect
{
GstCollectData collect; /* we extend the CollectData */
GstBuffer *buffer; /* the queued buffer for this pad */
GstGLMixerPad *mixpad;
};
/* all information needed for one video stream */
struct _GstGLMixerPad
{
GstPad parent; /* subclass the pad */
gint64 queued;
gint width;
gint height;
gint fps_n;
gint fps_d;
GstGLDisplay *display;
GstGLMixerCollect *mixcol;
};
struct _GstGLMixerPadClass
{
GstPadClass parent_class;
};
G_END_DECLS
#endif /* __GST_GL_MIXER_PAD_H__ */

View file

@ -66,6 +66,8 @@ gst_gl_shader_finalize (GObject * object)
shader = GST_GL_SHADER (object); shader = GST_GL_SHADER (object);
priv = shader->priv; priv = shader->priv;
g_debug ("finalizing shader %ud", priv->program_handle);
g_free (priv->vertex_src); g_free (priv->vertex_src);
g_free (priv->fragment_src); g_free (priv->fragment_src);
@ -81,6 +83,8 @@ gst_gl_shader_finalize (GObject * object)
/* g_debug ("program deletion status:%s", status == GL_TRUE ? "true" : "false" ); */ /* g_debug ("program deletion status:%s", status == GL_TRUE ? "true" : "false" ); */
} }
g_debug ("shader deleted %ud", priv->program_handle);
priv->fragment_handle = 0; priv->fragment_handle = 0;
priv->vertex_handle = 0; priv->vertex_handle = 0;
priv->program_handle = 0; priv->program_handle = 0;
@ -538,6 +542,18 @@ gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar * name)
return glGetAttribLocationARB (priv->program_handle, name); return glGetAttribLocationARB (priv->program_handle, name);
} }
void
gst_gl_shader_bind_attribute_location (GstGLShader * shader, GLuint index, const gchar * name)
{
GstGLShaderPrivate *priv;
priv = shader->priv;
g_return_if_fail (priv->program_handle != 0);
glBindAttribLocationARB (priv->program_handle, index, name);
}
GQuark GQuark
gst_gl_shader_error_quark (void) gst_gl_shader_error_quark (void)
{ {

View file

@ -99,6 +99,7 @@ void gst_gl_shader_set_uniform_matrix_4fv (GstGLShader * shader, const gchar * n
GLsizei count, GLboolean transpose, const GLfloat* value); GLsizei count, GLboolean transpose, const GLfloat* value);
GLint gst_gl_shader_get_attribute_location (GstGLShader *shader, const gchar *name); GLint gst_gl_shader_get_attribute_location (GstGLShader *shader, const gchar *name);
void gst_gl_shader_bind_attribute_location (GstGLShader * shader, GLuint index, const gchar * name);
G_END_DECLS G_END_DECLS

View file

@ -79,15 +79,18 @@ struct _GstGLWindowClass {
GQuark gst_gl_window_error_quark (void); GQuark gst_gl_window_error_quark (void);
GType gst_gl_window_get_type (void); GType gst_gl_window_get_type (void);
GstGLWindow * gst_gl_window_new (gint width, gint height, gulong external_gl_context); GstGLWindow * gst_gl_window_new (gulong external_gl_context);
gulong gst_gl_window_get_internal_gl_context (GstGLWindow *window);
void gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate);
void gst_gl_window_set_external_window_id (GstGLWindow *window, gulong id); void gst_gl_window_set_external_window_id (GstGLWindow *window, gulong id);
void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data); void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback, gpointer data); void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback, gpointer data);
void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data); void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_draw_unlocked (GstGLWindow *window); void gst_gl_window_draw_unlocked (GstGLWindow *window, gint width, gint height);
void gst_gl_window_draw (GstGLWindow *window); void gst_gl_window_draw (GstGLWindow *window, gint width, gint height);
void gst_gl_window_run_loop (GstGLWindow *window); void gst_gl_window_run_loop (GstGLWindow *window);
void gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data); void gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data);

View file

@ -136,7 +136,7 @@ gst_gl_window_init (GstGLWindow * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindow * GstGLWindow *
gst_gl_window_new (gint width, gint height, DWORD_PTR external_gl_context) gst_gl_window_new (DWORD_PTR external_gl_context)
{ {
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL); GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
GstGLWindowPrivate *priv = window->priv; GstGLWindowPrivate *priv = window->priv;
@ -162,15 +162,11 @@ gst_gl_window_new (gint width, gint height, DWORD_PTR external_gl_context)
priv->is_closed = FALSE; priv->is_closed = FALSE;
priv->visible = FALSE; priv->visible = FALSE;
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
height +=
2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
priv->internal_win_id = CreateWindowEx (0, priv->internal_win_id = CreateWindowEx (0,
"GSTGL", "GSTGL",
"OpenGL renderer", "OpenGL renderer",
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
x, y, width, height, (HWND) NULL, (HMENU) NULL, hinstance, window); x, y, 0, 0, (HWND) NULL, (HMENU) NULL, hinstance, window);
if (!priv->internal_win_id) { if (!priv->internal_win_id) {
g_debug ("failed to create gl window: %lud\n", (gulong) priv->internal_win_id); g_debug ("failed to create gl window: %lud\n", (gulong) priv->internal_win_id);
@ -193,6 +189,38 @@ gst_gl_window_error_quark (void)
return g_quark_from_static_string ("gst-gl-window-error"); return g_quark_from_static_string ("gst-gl-window-error");
} }
gulong
gst_gl_window_get_internal_gl_context (GstGLWindow *window)
{
GstGLWindowPrivate *priv = window->priv;
return (gulong) priv->gl_context;
}
void
callback_activate_gl_context (GstGLWindowPrivate *priv)
{
if (!wglMakeCurrent (priv->device, priv->gl_context))
g_debug ("failed to activate opengl context %lud\n", GetLastError ());
}
void
callback_inactivate_gl_context (GstGLWindowPrivate *priv)
{
if (!wglMakeCurrent (NULL, NULL))
g_debug ("failed to inactivate opengl context %lud\n", GetLastError ());
}
void
gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate)
{
GstGLWindowPrivate *priv = window->priv;
if (activate)
gst_gl_window_send_message (window, callback_activate_gl_context, priv);
else
gst_gl_window_send_message (window, callback_inactivate_gl_context, priv);
}
void void
gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id) gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id)
{ {
@ -285,19 +313,30 @@ gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
} }
void void
gst_gl_window_draw_unlocked (GstGLWindow * window) gst_gl_window_draw_unlocked (GstGLWindow * window, gint width, gint height)
{ {
gst_gl_window_draw (window); gst_gl_window_draw (window, width, height);
} }
/* Thread safe */ /* Thread safe */
void void
gst_gl_window_draw (GstGLWindow * window) gst_gl_window_draw (GstGLWindow * window, gint width, gint height)
{ {
GstGLWindowPrivate *priv = window->priv; GstGLWindowPrivate *priv = window->priv;
if (!priv->visible) { if (!priv->visible) {
HWND parent_id = GetProp (priv->internal_win_id, "gl_window_parent_id");
/* if no parent the real size has to be set now because this has not been done
* when at window creation */
if (!parent_id) {
RECT rect;
GetClientRect (priv->internal_win_id, &rect);
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
MoveWindow (priv->internal_win_id, rect.left, rect.top, width, height, FALSE);
}
ShowWindowAsync (priv->internal_win_id, SW_SHOW); ShowWindowAsync (priv->internal_win_id, SW_SHOW);
priv->visible = TRUE; priv->visible = TRUE;
} }
@ -369,11 +408,11 @@ gst_gl_window_set_pixel_format (GstGLWindow * window)
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA; pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24; pfd.cColorBits = 24;
pfd.cRedBits = 0; pfd.cRedBits = 8;
pfd.cRedShift = 0; pfd.cRedShift = 0;
pfd.cGreenBits = 0; pfd.cGreenBits = 8;
pfd.cGreenShift = 0; pfd.cGreenShift = 0;
pfd.cBlueBits = 0; pfd.cBlueBits = 8;
pfd.cBlueShift = 0; pfd.cBlueShift = 0;
pfd.cAlphaBits = 0; pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0; pfd.cAlphaShift = 0;
@ -382,7 +421,7 @@ gst_gl_window_set_pixel_format (GstGLWindow * window)
pfd.cAccumGreenBits = 0; pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0; pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0; pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = 32; pfd.cDepthBits = 24;
pfd.cStencilBits = 8; pfd.cStencilBits = 8;
pfd.cAuxBuffers = 0; pfd.cAuxBuffers = 0;
pfd.iLayerType = PFD_MAIN_PLANE; pfd.iLayerType = PFD_MAIN_PLANE;
@ -455,14 +494,15 @@ window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
g_assert (priv->internal_win_id == hWnd); g_assert (priv->internal_win_id == hWnd);
g_assert (priv->gl_context == wglGetCurrentContext ()); g_assert (!wglGetCurrentContext() || priv->gl_context == wglGetCurrentContext ());
switch (uMsg) { switch (uMsg) {
case WM_SIZE: case WM_SIZE:
{ {
if (priv->resize_cb) if (priv->resize_cb) {
priv->resize_cb (priv->resize_data, LOWORD (lParam), HIWORD (lParam)); priv->resize_cb (priv->resize_data, LOWORD (lParam), HIWORD (lParam));
}
break; break;
} }

View file

@ -141,7 +141,7 @@ gst_gl_window_init (GstGLWindow * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindow * GstGLWindow *
gst_gl_window_new (gint width, gint height, gulong external_gl_context) gst_gl_window_new (gulong external_gl_context)
{ {
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL); GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
GstGLWindowPrivate *priv = window->priv; GstGLWindowPrivate *priv = window->priv;
@ -169,12 +169,8 @@ gst_gl_window_new (gint width, gint height, gulong external_gl_context)
priv->is_closed = FALSE; priv->is_closed = FALSE;
priv->visible = FALSE; priv->visible = FALSE;
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
height +=
2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
priv->internal_win_id = CreateWindow ("GSTGL", "OpenGL renderer", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, //WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION priv->internal_win_id = CreateWindow ("GSTGL", "OpenGL renderer", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, //WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION
x, y, width, height, (HWND) NULL, (HMENU) NULL, hinstance, window); x, y, 0, 0, (HWND) NULL, (HMENU) NULL, hinstance, window);
if (!priv->internal_win_id) { if (!priv->internal_win_id) {
g_debug ("failed to create gl window: %d\n", priv->internal_win_id); g_debug ("failed to create gl window: %d\n", priv->internal_win_id);
@ -200,6 +196,38 @@ gst_gl_window_error_quark (void)
return g_quark_from_static_string ("gst-gl-window-error"); return g_quark_from_static_string ("gst-gl-window-error");
} }
gulong
gst_gl_window_get_internal_gl_context (GstGLWindow *window)
{
GstGLWindowPrivate *priv = window->priv;
return (gulong) priv->gl_context;
}
void
callback_activate_gl_context (GstGLWindowPrivate *priv)
{
/*if (!wglMakeCurrent (priv->device, priv->gl_context))
g_debug ("failed to activate opengl context %lud\n", GetLastError ());*/
}
void
callback_inactivate_gl_context (GstGLWindowPrivate *priv)
{
/*if (!wglMakeCurrent (NULL, NULL))
g_debug ("failed to inactivate opengl context %lud\n", GetLastError ());*/
}
void
gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate)
{
GstGLWindowPrivate *priv = window->priv;
if (activate)
gst_gl_window_send_message (window, callback_activate_gl_context, priv);
else
gst_gl_window_send_message (window, callback_inactivate_gl_context, priv);
}
void void
gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id) gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id)
{ {
@ -292,18 +320,28 @@ gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
} }
void void
gst_gl_window_draw_unlocked (GstGLWindow * window) gst_gl_window_draw_unlocked (GstGLWindow * window, gint width, gint height)
{ {
gst_gl_window_draw (window); gst_gl_window_draw (window, width, height);
} }
/* Thread safe */ /* Thread safe */
void void
gst_gl_window_draw (GstGLWindow * window) gst_gl_window_draw (GstGLWindow * window, gint width, gint height)
{ {
GstGLWindowPrivate *priv = window->priv; GstGLWindowPrivate *priv = window->priv;
if (!priv->visible) { if (!priv->visible) {
HWND parent_id = GetProp (priv->internal_win_id, "gl_window_parent_id");
/* if no parent the real size has to be set now because this has not been done
* when at window creation */
if (!parent_id) {
RECT rect;
GetClientRect (priv->internal_win_id, &rect);
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
MoveWindow (priv->internal_win_id, rect.left, rect.top, width, height, FALSE);
}
ShowWindowAsync (priv->internal_win_id, SW_SHOW); ShowWindowAsync (priv->internal_win_id, SW_SHOW);
priv->visible = TRUE; priv->visible = TRUE;
} }