2008-06-19 23:38:36 +00:00
|
|
|
/*
|
2008-05-19 16:57:39 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
2008-05-19 16:57:39 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2008-08-11 07:52:16 +00:00
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2008-05-19 16:57:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-05-19 16:57:39 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 15:08:11 +00:00
|
|
|
#include <stdio.h>
|
2009-10-16 14:29:08 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
#include <gst/gst.h>
|
2009-04-19 22:52:41 +00:00
|
|
|
#include <gst/video/gstvideosink.h>
|
2012-09-16 11:23:09 +00:00
|
|
|
#include "gstgldownload.h"
|
|
|
|
#include "gstglmemory.h"
|
2013-01-09 13:30:03 +00:00
|
|
|
#include "gstglfeature.h"
|
2013-01-16 04:21:44 +00:00
|
|
|
#include "gstglapi.h"
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#include "gstgldisplay.h"
|
2009-08-03 15:52:31 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#ifndef GL_FRAMEBUFFER_UNDEFINED
|
|
|
|
#define GL_FRAMEBUFFER_UNDEFINED 0x8219
|
|
|
|
#endif
|
|
|
|
#ifndef GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
|
|
|
|
#endif
|
|
|
|
#ifndef GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
|
|
|
|
#endif
|
|
|
|
#ifndef GL_FRAMEBUFFER_UNSUPPORTED
|
|
|
|
#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
|
|
|
|
#endif
|
|
|
|
#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
|
2009-08-03 15:52:31 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
#define USING_OPENGL(display) (display->gl_api & GST_GL_API_OPENGL)
|
|
|
|
#define USING_OPENGL3(display) (display->gl_api & GST_GL_API_OPENGL3)
|
|
|
|
#define USING_GLES(display) (display->gl_api & GST_GL_API_GLES)
|
|
|
|
#define USING_GLES2(display) (display->gl_api & GST_GL_API_GLES2)
|
|
|
|
#define USING_GLES3(display) (display->gl_api & GST_GL_API_GLES3)
|
2008-09-13 01:32:04 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_display_debug
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2008-09-13 01:32:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display");
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDisplay, gst_gl_display, G_TYPE_OBJECT,
|
2009-02-11 06:39:14 +00:00
|
|
|
DEBUG_INIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
#define GST_GL_DISPLAY_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_DISPLAY, GstGLDisplayPrivate))
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_display_finalize (GObject * object);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
|
|
|
/* Called in the gl thread, protected by lock and unlock */
|
2009-02-11 06:39:14 +00:00
|
|
|
gpointer gst_gl_display_thread_create_context (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_destroy_context (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_run_generic (GstGLDisplay * display);
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2009-03-15 13:48:19 +00:00
|
|
|
void gst_gl_display_thread_init_redisplay (GstGLDisplay * display);
|
|
|
|
#endif
|
2009-02-11 06:39:14 +00:00
|
|
|
void gst_gl_display_thread_gen_fbo (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_use_fbo (GstGLDisplay * display);
|
2009-10-22 23:11:27 +00:00
|
|
|
void gst_gl_display_thread_use_fbo_v2 (GstGLDisplay * display);
|
2009-02-11 06:39:14 +00:00
|
|
|
void gst_gl_display_thread_del_fbo (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_gen_shader (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_del_shader (GstGLDisplay * display);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
|
|
|
/* private methods */
|
2009-02-11 06:39:14 +00:00
|
|
|
void gst_gl_display_lock (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_unlock (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height);
|
|
|
|
void gst_gl_display_on_draw (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_on_close (GstGLDisplay * display);
|
2012-07-06 08:51:02 +00:00
|
|
|
void gst_gl_display_del_texture_thread (GstGLDisplay * display,
|
|
|
|
GLuint * pTexture);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2012-07-06 08:51:02 +00:00
|
|
|
void gst_gl_display_gen_texture_window_cb (GstGLDisplay * display);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
void _gen_fbo (GstGLDisplay * display);
|
|
|
|
void _del_fbo (GstGLDisplay * display);
|
|
|
|
void _gen_shader (GstGLDisplay * display);
|
|
|
|
void _del_shader (GstGLDisplay * display);
|
|
|
|
void _use_fbo (GstGLDisplay * display);
|
|
|
|
void _use_fbo_v2 (GstGLDisplay * display);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const gchar *redisplay_vertex_shader_str_gles2 =
|
|
|
|
"attribute vec4 a_position; \n"
|
|
|
|
"attribute vec2 a_texCoord; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
|
|
|
" gl_Position = a_position; \n"
|
|
|
|
" v_texCoord = a_texCoord; \n"
|
|
|
|
"} \n";
|
|
|
|
|
|
|
|
static const gchar *redisplay_fragment_shader_str_gles2 =
|
|
|
|
"precision mediump float; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
|
|
|
"uniform sampler2D s_texture; \n"
|
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
|
|
|
" gl_FragColor = texture2D( s_texture, v_texCoord );\n"
|
|
|
|
"} \n";
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
#endif
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
struct _GstGLDisplayPrivate
|
|
|
|
{
|
2013-01-09 14:44:54 +00:00
|
|
|
/* conditions */
|
2013-02-18 10:40:34 +00:00
|
|
|
GCond cond_create_context;
|
|
|
|
GCond cond_destroy_context;
|
2013-01-09 14:44:54 +00:00
|
|
|
|
|
|
|
/* generic gl code */
|
|
|
|
GstGLDisplayThreadFunc generic_callback;
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
/* action redisplay */
|
|
|
|
GLuint redisplay_texture;
|
|
|
|
GLuint redisplay_texture_width;
|
|
|
|
GLuint redisplay_texture_height;
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
GstGLShader *redisplay_shader;
|
|
|
|
gchar *redisplay_vertex_shader_str_gles2;
|
|
|
|
gchar *redisplay_fragment_shader_str_gles2;
|
|
|
|
GLint redisplay_attr_position_loc;
|
|
|
|
GLint redisplay_attr_texture_loc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* action gen and del texture */
|
|
|
|
GLuint gen_texture;
|
|
|
|
GLuint gen_texture_width;
|
|
|
|
GLuint gen_texture_height;
|
|
|
|
GstVideoFormat gen_texture_video_format;
|
|
|
|
|
|
|
|
/* client callbacks */
|
|
|
|
CRCB clientReshapeCallback;
|
|
|
|
CDCB clientDrawCallback;
|
|
|
|
gpointer client_data;
|
|
|
|
|
|
|
|
/* filter gen fbo */
|
|
|
|
GLuint gen_fbo_width;
|
|
|
|
GLuint gen_fbo_height;
|
|
|
|
GLuint generated_fbo;
|
|
|
|
GLuint generated_depth_buffer;
|
|
|
|
|
|
|
|
/* filter use fbo */
|
|
|
|
GLuint use_fbo;
|
|
|
|
GLuint use_depth_buffer;
|
|
|
|
GLuint use_fbo_texture;
|
|
|
|
GLuint use_fbo_width;
|
|
|
|
GLuint use_fbo_height;
|
|
|
|
GLCB use_fbo_scene_cb;
|
|
|
|
GLCB_V2 use_fbo_scene_cb_v2;
|
|
|
|
gdouble use_fbo_proj_param1;
|
|
|
|
gdouble use_fbo_proj_param2;
|
|
|
|
gdouble use_fbo_proj_param3;
|
|
|
|
gdouble use_fbo_proj_param4;
|
|
|
|
GstGLDisplayProjection use_fbo_projection;
|
|
|
|
gpointer *use_fbo_stuff;
|
|
|
|
GLuint input_texture_width;
|
|
|
|
GLuint input_texture_height;
|
|
|
|
GLuint input_texture;
|
|
|
|
|
|
|
|
/* filter del fbo */
|
|
|
|
GLuint del_fbo;
|
|
|
|
GLuint del_depth_buffer;
|
|
|
|
|
|
|
|
/* action gen and del shader */
|
|
|
|
const gchar *gen_shader_fragment_source;
|
|
|
|
const gchar *gen_shader_vertex_source;
|
|
|
|
GstGLShader *gen_shader;
|
|
|
|
GstGLShader *del_shader;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
|
|
--------------------- For klass GstGLDisplay ---------------
|
|
|
|
----------------------------------------------------------*/
|
2008-05-18 11:12:46 +00:00
|
|
|
static void
|
|
|
|
gst_gl_display_class_init (GstGLDisplayClass * klass)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLDisplayPrivate));
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_display_init (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
display->priv = GST_GL_DISPLAY_GET_PRIVATE (display);
|
|
|
|
|
|
|
|
/* thread safe */
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_init (&display->mutex);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_init (&display->priv->cond_create_context);
|
|
|
|
g_cond_init (&display->priv->cond_destroy_context);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
display->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
display->gl_window = gst_gl_window_new ();
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_memory_init ();
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_finalize (GObject * object)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLDisplay *display = GST_GL_DISPLAY (object);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
if (display->gl_window) {
|
2008-11-21 00:31:19 +00:00
|
|
|
gst_gl_display_lock (display);
|
|
|
|
|
|
|
|
gst_gl_window_set_resize_callback (display->gl_window, NULL, NULL);
|
|
|
|
gst_gl_window_set_draw_callback (display->gl_window, NULL, NULL);
|
|
|
|
gst_gl_window_set_close_callback (display->gl_window, NULL, NULL);
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
if (display->context_created) {
|
|
|
|
GST_INFO ("send quit gl window loop");
|
|
|
|
gst_gl_window_quit (display->gl_window,
|
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
|
2008-11-21 00:31:19 +00:00
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
GST_INFO ("quit sent to gl window loop");
|
2008-11-21 00:31:19 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_wait (&display->priv->cond_destroy_context, &display->mutex);
|
2013-02-12 12:48:36 +00:00
|
|
|
GST_INFO ("quit received from gl window");
|
|
|
|
}
|
2008-11-21 00:31:19 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (display->gl_thread) {
|
2008-10-25 00:03:16 +00:00
|
|
|
gpointer ret = g_thread_join (display->gl_thread);
|
2008-10-23 23:39:00 +00:00
|
|
|
GST_INFO ("gl thread joined");
|
2008-11-21 18:11:11 +00:00
|
|
|
if (ret != NULL)
|
|
|
|
GST_ERROR ("gl thread returned a not null pointer");
|
2008-10-23 23:39:00 +00:00
|
|
|
display->gl_thread = NULL;
|
|
|
|
}
|
2013-02-18 10:40:34 +00:00
|
|
|
|
|
|
|
g_mutex_clear (&display->mutex);
|
|
|
|
|
|
|
|
g_cond_clear (&display->priv->cond_destroy_context);
|
|
|
|
g_cond_clear (&display->priv->cond_create_context);
|
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->clientReshapeCallback)
|
|
|
|
display->priv->clientReshapeCallback = NULL;
|
|
|
|
if (display->priv->clientDrawCallback)
|
|
|
|
display->priv->clientDrawCallback = NULL;
|
|
|
|
if (display->priv->client_data)
|
|
|
|
display->priv->client_data = NULL;
|
|
|
|
if (display->priv->use_fbo_scene_cb)
|
|
|
|
display->priv->use_fbo_scene_cb = NULL;
|
|
|
|
if (display->priv->use_fbo_scene_cb_v2)
|
|
|
|
display->priv->use_fbo_scene_cb_v2 = NULL;
|
|
|
|
if (display->priv->use_fbo_stuff)
|
|
|
|
display->priv->use_fbo_stuff = NULL;
|
2011-11-24 15:02:32 +00:00
|
|
|
|
|
|
|
if (display->error_message) {
|
|
|
|
g_free (display->error_message);
|
|
|
|
display->error_message = NULL;
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
if (display->uploads) {
|
2012-09-25 05:20:21 +00:00
|
|
|
g_slist_free_full (display->uploads, g_object_unref);
|
2012-09-16 11:23:09 +00:00
|
|
|
display->uploads = NULL;
|
|
|
|
}
|
|
|
|
if (display->downloads) {
|
2012-09-25 05:20:21 +00:00
|
|
|
g_slist_free_full (display->downloads, g_object_unref);
|
2012-09-16 11:23:09 +00:00
|
|
|
display->downloads = NULL;
|
|
|
|
}
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
if (display->gl_vtable) {
|
|
|
|
g_slice_free (GstGLFuncs, display->gl_vtable);
|
|
|
|
display->gl_vtable = NULL;
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
//------------------------------------------------------------
|
2008-10-27 23:22:27 +00:00
|
|
|
//------------------ BEGIN GL THREAD PROCS -------------------
|
2008-06-29 17:27:43 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
/* Called in the gl thread */
|
2011-11-24 15:02:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_set_error (GstGLDisplay * display, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (display->error_message)
|
|
|
|
g_free (display->error_message);
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
display->error_message = g_strdup_vprintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
2013-04-24 02:18:14 +00:00
|
|
|
GST_WARNING ("%s", display->error_message);
|
2012-07-09 06:12:53 +00:00
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
display->isAlive = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
static gboolean
|
|
|
|
_create_context_gles2 (GstGLDisplay * display, gint * gl_major, gint * gl_minor)
|
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl;
|
2012-12-06 07:40:26 +00:00
|
|
|
GLenum gl_err = GL_NO_ERROR;
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl = display->gl_vtable;
|
|
|
|
|
|
|
|
GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
|
2013-01-09 13:30:03 +00:00
|
|
|
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GetString (GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
GST_INFO ("GL_VENDOR: %s", gl->GetString (GL_VENDOR));
|
|
|
|
GST_INFO ("GL_RENDERER: %s", gl->GetString (GL_RENDERER));
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl_err = gl->GetError ();
|
2012-12-06 07:40:26 +00:00
|
|
|
if (gl_err != GL_NO_ERROR) {
|
|
|
|
gst_gl_display_set_error (display, "glGetString error: 0x%x", gl_err);
|
2013-01-16 04:21:44 +00:00
|
|
|
return FALSE;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2013-01-16 04:21:44 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (!GL_ES_VERSION_2_0) {
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_display_set_error (display, "OpenGL|ES >= 2.0 is required");
|
2013-01-16 04:21:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 13:30:03 +00:00
|
|
|
_gst_gl_feature_check_ext_functions (display, 0, 0,
|
2013-01-16 04:21:44 +00:00
|
|
|
(const gchar *) gl->GetString (GL_EXTENSIONS));
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 13:30:03 +00:00
|
|
|
if (gl_major)
|
|
|
|
*gl_major = 2;
|
|
|
|
if (gl_minor)
|
|
|
|
*gl_minor = 0;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2013-01-09 14:44:54 +00:00
|
|
|
_create_context_opengl (GstGLDisplay * display, gint * gl_major,
|
|
|
|
gint * gl_minor)
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl;
|
2013-01-09 13:30:03 +00:00
|
|
|
guint maj, min;
|
2012-12-06 07:40:26 +00:00
|
|
|
GLenum gl_err = GL_NO_ERROR;
|
|
|
|
GString *opengl_version = NULL;
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl = display->gl_vtable;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
|
2013-01-09 13:30:03 +00:00
|
|
|
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GetString (GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
GST_INFO ("GL_VENDOR: %s", gl->GetString (GL_VENDOR));
|
|
|
|
GST_INFO ("GL_RENDERER: %s", gl->GetString (GL_RENDERER));
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl_err = gl->GetError ();
|
2012-12-06 07:40:26 +00:00
|
|
|
if (gl_err != GL_NO_ERROR) {
|
|
|
|
gst_gl_display_set_error (display, "glGetString error: 0x%x", gl_err);
|
2013-01-16 04:21:44 +00:00
|
|
|
return FALSE;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2013-01-09 13:30:03 +00:00
|
|
|
opengl_version =
|
2013-01-16 04:21:44 +00:00
|
|
|
g_string_truncate (g_string_new ((gchar *) gl->GetString (GL_VERSION)),
|
|
|
|
3);
|
2013-01-09 13:30:03 +00:00
|
|
|
|
|
|
|
sscanf (opengl_version->str, "%d.%d", &maj, &min);
|
|
|
|
|
|
|
|
g_string_free (opengl_version, TRUE);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
/* OpenGL > 1.2.0 */
|
2013-01-09 13:30:03 +00:00
|
|
|
if ((maj < 1) || (maj < 2 && maj >= 1 && min < 2)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_set_error (display, "OpenGL >= 1.2.0 required, found %u.%u",
|
|
|
|
maj, min);
|
2013-01-09 13:30:03 +00:00
|
|
|
return FALSE;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 13:30:03 +00:00
|
|
|
_gst_gl_feature_check_ext_functions (display, maj, min,
|
2013-01-16 04:21:44 +00:00
|
|
|
(const gchar *) gl->GetString (GL_EXTENSIONS));
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 13:30:03 +00:00
|
|
|
if (gl_major)
|
|
|
|
*gl_major = maj;
|
|
|
|
if (gl_minor)
|
|
|
|
*gl_minor = min;
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-12-08 22:32:48 +00:00
|
|
|
GstGLAPI
|
|
|
|
_compiled_api (void)
|
|
|
|
{
|
|
|
|
GstGLAPI ret = GST_GL_API_NONE;
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2012-12-08 22:32:48 +00:00
|
|
|
ret |= GST_GL_API_OPENGL;
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2012-12-08 22:32:48 +00:00
|
|
|
ret |= GST_GL_API_GLES2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
gpointer
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_thread_create_context (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2013-01-09 13:30:03 +00:00
|
|
|
gint gl_major = 0;
|
2012-12-06 07:40:26 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-12-08 22:32:48 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GstGLAPI compiled_api;
|
|
|
|
gchar *api_string;
|
|
|
|
gchar *compiled_api_s;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-07-13 11:53:17 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-08 22:32:48 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl = display->gl_vtable;
|
2012-12-08 22:32:48 +00:00
|
|
|
compiled_api = _compiled_api ();
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
if (!display->gl_window) {
|
|
|
|
gst_gl_display_set_error (display, "Failed to create opengl window");
|
|
|
|
goto failure;
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
if (!gst_gl_window_create_context (display->gl_window, compiled_api,
|
|
|
|
display->external_gl_context, &error)) {
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_display_set_error (display,
|
|
|
|
error ? error->message : "Failed to create gl window");
|
2012-12-19 03:32:20 +00:00
|
|
|
goto failure;
|
2008-10-25 00:03:16 +00:00
|
|
|
}
|
2013-02-12 12:48:36 +00:00
|
|
|
GST_INFO ("window created context");
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
display->gl_api = gst_gl_window_get_gl_api (display->gl_window);
|
2013-01-09 14:44:54 +00:00
|
|
|
g_assert (display->gl_api != GST_GL_API_NONE
|
|
|
|
&& display->gl_api != GST_GL_API_ANY);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2012-12-08 22:32:48 +00:00
|
|
|
api_string = gst_gl_api_string (display->gl_api);
|
|
|
|
GST_INFO ("available GL APIs: %s", api_string);
|
|
|
|
|
|
|
|
compiled_api_s = gst_gl_api_string (compiled_api);
|
|
|
|
GST_INFO ("compiled api support: %s", compiled_api_s);
|
|
|
|
|
2012-12-19 03:32:20 +00:00
|
|
|
if ((compiled_api & display->gl_api) == GST_GL_API_NONE) {
|
2012-12-08 22:32:48 +00:00
|
|
|
gst_gl_display_set_error (display, "failed to create_context, window "
|
|
|
|
"could not provide correct api. compiled api supports:%s, window "
|
|
|
|
"supports:%s", compiled_api_s, api_string);
|
2012-12-19 03:32:20 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2012-12-08 22:32:48 +00:00
|
|
|
|
|
|
|
g_free (api_string);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GetError =
|
|
|
|
gst_gl_window_get_proc_address (display->gl_window, "glGetError");
|
|
|
|
gl->GetString =
|
|
|
|
gst_gl_window_get_proc_address (display->gl_window, "glGetString");
|
|
|
|
|
|
|
|
if (!gl->GetError || !gl->GetString) {
|
|
|
|
gst_gl_display_set_error (display,
|
|
|
|
"could not GetProcAddress core opengl functions");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* gl api specific code */
|
2013-01-09 14:44:54 +00:00
|
|
|
if (!ret && USING_OPENGL (display))
|
2013-01-09 13:30:03 +00:00
|
|
|
ret = _create_context_opengl (display, &gl_major, NULL);
|
2013-01-09 14:44:54 +00:00
|
|
|
if (!ret && USING_GLES2 (display))
|
2013-01-09 13:30:03 +00:00
|
|
|
ret = _create_context_gles2 (display, &gl_major, NULL);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2012-12-19 03:32:20 +00:00
|
|
|
if (!ret || !gl_major) {
|
2013-02-12 12:48:36 +00:00
|
|
|
GST_WARNING ("GL api specific initialization failed");
|
2012-12-19 03:32:20 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
/* setup callbacks */
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_window_set_resize_callback (display->gl_window,
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_GL_WINDOW_RESIZE_CB (gst_gl_display_on_resize), display);
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_window_set_draw_callback (display->gl_window,
|
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_on_draw), display);
|
|
|
|
gst_gl_window_set_close_callback (display->gl_window,
|
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_on_close), display);
|
2008-06-28 15:38:41 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_signal (&display->priv->cond_create_context);
|
2008-06-28 15:38:41 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
display->isAlive = TRUE;
|
2009-07-13 11:53:17 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_run (display->gl_window);
|
2008-06-28 15:38:41 +00:00
|
|
|
|
2008-10-25 14:18:23 +00:00
|
|
|
GST_INFO ("loop exited\n");
|
|
|
|
|
2008-11-13 01:05:33 +00:00
|
|
|
gst_gl_display_lock (display);
|
|
|
|
|
2008-10-25 14:18:23 +00:00
|
|
|
display->isAlive = FALSE;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (display->gl_window));
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
display->gl_window = NULL;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_signal (&display->priv->cond_destroy_context);
|
2008-11-21 00:31:19 +00:00
|
|
|
|
2008-11-13 01:05:33 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
2008-10-22 23:40:52 +00:00
|
|
|
return NULL;
|
2012-12-19 03:32:20 +00:00
|
|
|
|
|
|
|
failure:
|
|
|
|
{
|
|
|
|
if (display->gl_window) {
|
|
|
|
g_object_unref (display->gl_window);
|
|
|
|
display->gl_window = NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_signal (&display->priv->cond_create_context);
|
2012-12-19 03:32:20 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Called in the gl thread */
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_thread_destroy_context (GstGLDisplay * display)
|
2008-06-29 17:27:43 +00:00
|
|
|
{
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-01-10 02:32:16 +00:00
|
|
|
if (display->priv->redisplay_shader) {
|
|
|
|
g_object_unref (G_OBJECT (display->priv->redisplay_shader));
|
|
|
|
display->priv->redisplay_shader = NULL;
|
2009-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-22 23:40:52 +00:00
|
|
|
GST_INFO ("Context destroyed");
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_thread_run_generic (GstGLDisplay * display)
|
2008-08-11 07:00:40 +00:00
|
|
|
{
|
2012-07-12 08:22:01 +00:00
|
|
|
GST_TRACE ("running function:%p data:%p",
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->generic_callback, display->priv->data);
|
2012-07-09 06:12:53 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->generic_callback (display, display->priv->data);
|
2008-08-11 07:00:40 +00:00
|
|
|
}
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2009-03-15 13:48:19 +00:00
|
|
|
/* Called in the gl thread */
|
|
|
|
void
|
|
|
|
gst_gl_display_thread_init_redisplay (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_shader = gst_gl_shader_new (display);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_shader_set_vertex_source (display->priv->redisplay_shader,
|
|
|
|
redisplay_vertex_shader_str_gles2);
|
|
|
|
gst_gl_shader_set_fragment_source (display->priv->redisplay_shader,
|
|
|
|
redisplay_fragment_shader_str_gles2);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_shader_compile (display->priv->redisplay_shader, &error);
|
2009-03-15 13:48:19 +00:00
|
|
|
if (error) {
|
2011-11-24 15:02:32 +00:00
|
|
|
gst_gl_display_set_error (display, "%s", error->message);
|
2009-03-15 13:48:19 +00:00
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_clear_shader (display);
|
2009-03-15 13:48:19 +00:00
|
|
|
} else {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (display->priv->redisplay_shader,
|
2009-04-10 18:42:59 +00:00
|
|
|
"a_position");
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (display->priv->redisplay_shader,
|
2009-04-10 18:42:59 +00:00
|
|
|
"a_texCoord");
|
2009-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_gen_fbo (GstGLDisplay * display)
|
2008-06-28 15:38:41 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
/* a texture must be attached to the FBO */
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2012-09-16 11:23:09 +00:00
|
|
|
GLuint fake_texture = 0;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
GST_TRACE ("creating FBO dimensions:%ux%u", display->priv->gen_fbo_width,
|
|
|
|
display->priv->gen_fbo_height);
|
2008-08-24 13:39:14 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* -- generate frame buffer object */
|
2008-09-16 00:10:31 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
if (!gl->GenFramebuffers) {
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_display_set_error (display,
|
2012-09-16 11:23:09 +00:00
|
|
|
"Context, EXT_framebuffer_object not supported");
|
|
|
|
return;
|
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
/* setup FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenFramebuffers (1, &display->priv->generated_fbo);
|
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, display->priv->generated_fbo);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* setup the render buffer for depth */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenRenderbuffers (1, &display->priv->generated_depth_buffer);
|
|
|
|
gl->BindRenderbuffer (GL_RENDERBUFFER, display->priv->generated_depth_buffer);
|
|
|
|
|
|
|
|
if (USING_OPENGL (display)) {
|
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
|
|
|
|
display->priv->gen_fbo_width, display->priv->gen_fbo_height);
|
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
|
|
|
|
display->priv->gen_fbo_width, display->priv->gen_fbo_height);
|
|
|
|
}
|
|
|
|
if (USING_GLES2 (display)) {
|
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
|
|
|
|
display->priv->gen_fbo_width, display->priv->gen_fbo_height);
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* setup a texture to render to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenTextures (1, &fake_texture);
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, fake_texture);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_fbo_width, display->priv->gen_fbo_height, 0, GL_RGBA,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_UNSIGNED_BYTE, NULL);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_CLAMP_TO_EDGE);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_CLAMP_TO_EDGE);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* attach the texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_TEXTURE_RECTANGLE_ARB, fake_texture, 0);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* attach the depth render buffer to the FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, display->priv->generated_depth_buffer);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
if (USING_OPENGL (display)) {
|
|
|
|
gl->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, display->priv->generated_depth_buffer);
|
|
|
|
}
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
if (gl->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_display_set_error (display, "GL framebuffer status incomplete");
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* unbind the FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DeleteTextures (1, &fake_texture);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_use_fbo (GstGLDisplay * display)
|
2008-06-29 17:27:43 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
GLint viewport_dim[4];
|
2012-09-16 11:23:09 +00:00
|
|
|
#endif
|
2012-07-06 08:51:02 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
GST_TRACE ("Binding v1 FBO %u dimensions:%ux%u with texture:%u "
|
2013-01-09 14:44:54 +00:00
|
|
|
"dimensions:%ux%u", display->priv->use_fbo, display->priv->use_fbo_width,
|
|
|
|
display->priv->use_fbo_height, display->priv->use_fbo_texture,
|
|
|
|
display->priv->input_texture_width, display->priv->input_texture_height);
|
2008-08-24 01:12:12 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, display->priv->use_fbo);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
/*setup a texture to render to */
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, display->priv->use_fbo_texture);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* attach the texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
2013-01-09 14:44:54 +00:00
|
|
|
GL_TEXTURE_RECTANGLE_ARB, display->priv->use_fbo_texture, 0);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_clear_shader (display);
|
2008-08-11 15:21:30 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (display)) {
|
|
|
|
gl->PushAttrib (GL_VIEWPORT_BIT);
|
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->PushMatrix ();
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
|
|
|
|
switch (display->priv->use_fbo_projection) {
|
|
|
|
case GST_GL_DISPLAY_PROJECTION_ORTHO2D:
|
|
|
|
gluOrtho2D (display->priv->use_fbo_proj_param1,
|
|
|
|
display->priv->use_fbo_proj_param2,
|
|
|
|
display->priv->use_fbo_proj_param3,
|
|
|
|
display->priv->use_fbo_proj_param4);
|
|
|
|
break;
|
|
|
|
case GST_GL_DISPLAY_PROJECTION_PERSPECTIVE:
|
|
|
|
gluPerspective (display->priv->use_fbo_proj_param1,
|
|
|
|
display->priv->use_fbo_proj_param2,
|
|
|
|
display->priv->use_fbo_proj_param3,
|
|
|
|
display->priv->use_fbo_proj_param4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gst_gl_display_set_error (display, "Unknow fbo projection %d",
|
|
|
|
display->priv->use_fbo_projection);
|
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->PushMatrix ();
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (USING_GLES2 (display))
|
|
|
|
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
|
|
|
|
#endif
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, display->priv->use_fbo_width,
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo_height);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (display)) {
|
|
|
|
const GLenum rt[] = { GL_COLOR_ATTACHMENT0 };
|
|
|
|
gl->DrawBuffers (1, rt);
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo_scene_cb (display->priv->input_texture_width,
|
|
|
|
display->priv->input_texture_height, display->priv->input_texture,
|
|
|
|
display->priv->use_fbo_stuff);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (display)) {
|
|
|
|
const GLenum rt[] = { GL_NONE };
|
|
|
|
gl->DrawBuffers (1, rt);
|
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->PopMatrix ();
|
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->PopMatrix ();
|
|
|
|
gl->PopAttrib ();
|
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-01-16 04:21:44 +00:00
|
|
|
if (USING_GLES2 (display)) {
|
|
|
|
gl->Viewport (viewport_dim[0], viewport_dim[1], viewport_dim[2],
|
|
|
|
viewport_dim[3]);
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-19 23:38:36 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2008-06-07 15:27:12 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
/* Called in a gl thread
|
|
|
|
* Need full shader support */
|
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_use_fbo_v2 (GstGLDisplay * display)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2009-10-22 23:11:27 +00:00
|
|
|
GLint viewport_dim[4];
|
|
|
|
|
2012-07-09 06:12:53 +00:00
|
|
|
GST_TRACE ("Binding v2 FBO %u dimensions:%ux%u with texture:%u ",
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo, display->priv->use_fbo_width,
|
|
|
|
display->priv->use_fbo_height, display->priv->use_fbo_texture);
|
2012-07-09 06:12:53 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, display->priv->use_fbo);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* setup a texture to render to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, display->priv->use_fbo_texture);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* attach the texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
2013-01-09 14:44:54 +00:00
|
|
|
GL_TEXTURE_RECTANGLE_ARB, display->priv->use_fbo_texture, 0);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, display->priv->use_fbo_width,
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo_height);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawBuffer (GL_COLOR_ATTACHMENT0);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* the opengl scene */
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo_scene_cb_v2 (display->priv->use_fbo_stuff);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawBuffer (GL_NONE);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (viewport_dim[0], viewport_dim[1],
|
2009-10-27 16:02:23 +00:00
|
|
|
viewport_dim[2], viewport_dim[3]);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called in the gl thread */
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_del_fbo (GstGLDisplay * display)
|
2008-06-07 15:27:12 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
GST_TRACE ("Deleting FBO %u", display->priv->del_fbo);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->del_fbo) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DeleteFramebuffers (1, &display->priv->del_fbo);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->del_fbo = 0;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2013-01-10 02:32:16 +00:00
|
|
|
if (display->priv->del_depth_buffer) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DeleteRenderbuffers (1, &display->priv->del_depth_buffer);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->del_depth_buffer = 0;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called in the gl thread */
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_gen_shader (GstGLDisplay * display)
|
2008-06-13 00:01:26 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2008-09-06 22:45:34 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
GST_TRACE ("Generating shader %" GST_PTR_FORMAT, display->priv->gen_shader);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
if (gl->CreateProgramObject || gl->CreateProgram) {
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->gen_shader_vertex_source ||
|
|
|
|
display->priv->gen_shader_fragment_source) {
|
2012-12-06 07:40:26 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_shader = gst_gl_shader_new (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->gen_shader_vertex_source)
|
|
|
|
gst_gl_shader_set_vertex_source (display->priv->gen_shader,
|
|
|
|
display->priv->gen_shader_vertex_source);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->gen_shader_fragment_source)
|
|
|
|
gst_gl_shader_set_fragment_source (display->priv->gen_shader,
|
|
|
|
display->priv->gen_shader_fragment_source);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_shader_compile (display->priv->gen_shader, &error);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (error) {
|
|
|
|
gst_gl_display_set_error (display, "%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_clear_shader (display);
|
2013-01-09 14:44:54 +00:00
|
|
|
g_object_unref (G_OBJECT (display->priv->gen_shader));
|
|
|
|
display->priv->gen_shader = NULL;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst_gl_display_set_error (display,
|
|
|
|
"One of the filter required ARB_fragment_shader");
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_shader = NULL;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-13 00:01:26 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called in the gl thread */
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-01-16 04:21:44 +00:00
|
|
|
_del_shader (GstGLDisplay * display)
|
2008-06-13 00:01:26 +00:00
|
|
|
{
|
2013-01-09 14:44:54 +00:00
|
|
|
GST_TRACE ("Deleting shader %" GST_PTR_FORMAT, display->priv->del_shader);
|
2012-07-09 06:12:53 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->del_shader) {
|
|
|
|
g_object_unref (G_OBJECT (display->priv->del_shader));
|
|
|
|
display->priv->del_shader = NULL;
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2008-06-13 00:01:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//------------------ BEGIN GL THREAD ACTIONS -----------------
|
|
|
|
//------------------------------------------------------------
|
2008-06-13 00:01:26 +00:00
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//---------------------- BEGIN PRIVATE -----------------------
|
|
|
|
//------------------------------------------------------------
|
2008-05-18 11:12:46 +00:00
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height)
|
2008-06-10 19:07:43 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-07-09 06:12:53 +00:00
|
|
|
GST_TRACE ("GL Window resized to %ux%u", width, height);
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
//check if a client reshape callback is registered
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->clientReshapeCallback)
|
|
|
|
display->priv->clientReshapeCallback (width, height,
|
|
|
|
display->priv->client_data);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
//default reshape
|
2009-02-11 06:39:14 +00:00
|
|
|
else {
|
2009-04-19 22:52:41 +00:00
|
|
|
if (display->keep_aspect_ratio) {
|
|
|
|
GstVideoRectangle src, dst, result;
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
src.y = 0;
|
2013-01-09 14:44:54 +00:00
|
|
|
src.w = display->priv->redisplay_texture_width;
|
|
|
|
src.h = display->priv->redisplay_texture_height;
|
2009-04-19 22:52:41 +00:00
|
|
|
|
|
|
|
dst.x = 0;
|
|
|
|
dst.y = 0;
|
|
|
|
dst.w = width;
|
|
|
|
dst.h = height;
|
|
|
|
|
|
|
|
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (result.x, result.y, result.w, result.h);
|
2009-04-19 22:52:41 +00:00
|
|
|
} else {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, width, height);
|
2009-04-19 22:52:41 +00:00
|
|
|
}
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-01-09 14:44:54 +00:00
|
|
|
if (USING_OPENGL (display)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2012-12-06 07:40:26 +00:00
|
|
|
gluOrtho2D (0, width, 0, height);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2009-03-15 13:48:19 +00:00
|
|
|
#endif
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
void
|
|
|
|
gst_gl_display_on_draw (GstGLDisplay * display)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* check if texture is ready for being drawn */
|
2013-01-09 14:44:54 +00:00
|
|
|
if (!display->priv->redisplay_texture)
|
2008-08-01 09:00:49 +00:00
|
|
|
return;
|
2012-12-06 07:40:26 +00:00
|
|
|
/* opengl scene */
|
2013-01-16 04:21:44 +00:00
|
|
|
GST_TRACE ("drawing texture:%u", display->priv->redisplay_texture);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* make sure that the environnement is clean */
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_clear_shader (display);
|
2012-04-18 13:44:05 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-01-09 14:44:54 +00:00
|
|
|
if (USING_OPENGL (display))
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Disable (GL_TEXTURE_RECTANGLE_ARB);
|
2012-04-18 13:44:05 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* check if a client draw callback is registered */
|
2013-01-09 14:44:54 +00:00
|
|
|
if (display->priv->clientDrawCallback) {
|
2008-08-01 09:00:49 +00:00
|
|
|
gboolean doRedisplay =
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->clientDrawCallback (display->priv->redisplay_texture,
|
|
|
|
display->priv->redisplay_texture_width,
|
|
|
|
display->priv->redisplay_texture_height,
|
|
|
|
display->priv->client_data);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2008-11-23 15:04:27 +00:00
|
|
|
if (doRedisplay && display->gl_window)
|
2009-10-22 23:11:27 +00:00
|
|
|
gst_gl_window_draw_unlocked (display->gl_window,
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_texture_width,
|
|
|
|
display->priv->redisplay_texture_height);
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
/* default opengl scene */
|
2009-02-11 06:39:14 +00:00
|
|
|
else {
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-01-09 14:44:54 +00:00
|
|
|
if (USING_OPENGL (display)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gfloat verts[8] = { 1.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f,
|
|
|
|
-1.0f, -1.0f,
|
|
|
|
1.0f, -1.0f
|
|
|
|
};
|
|
|
|
gint texcoords[8] = { display->priv->redisplay_texture_width, 0,
|
|
|
|
0, 0,
|
|
|
|
0, display->priv->redisplay_texture_height,
|
|
|
|
display->priv->redisplay_texture_width,
|
|
|
|
display->priv->redisplay_texture_height
|
|
|
|
};
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Enable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB,
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_texture);
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
|
|
|
gl->TexCoordPointer (2, GL_INT, 0, &texcoords);
|
|
|
|
|
|
|
|
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
|
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
gl->Disable (GL_TEXTURE_RECTANGLE_ARB);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-01-09 14:44:54 +00:00
|
|
|
if (USING_GLES2 (display)) {
|
2012-12-06 07:40:26 +00:00
|
|
|
const GLfloat vVertices[] = { 1.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
-1.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
-1.0f, -1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, -1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f
|
|
|
|
};
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_shader_use (display->priv->redisplay_shader);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* Load the vertex position */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (display->priv->redisplay_attr_position_loc, 3,
|
2013-01-09 14:44:54 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/* Load the texture coordinate */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (display->priv->redisplay_attr_texture_loc, 2,
|
2013-01-09 14:44:54 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->EnableVertexAttribArray (display->priv->redisplay_attr_position_loc);
|
|
|
|
gl->EnableVertexAttribArray (display->priv->redisplay_attr_texture_loc);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, display->priv->redisplay_texture);
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (display->priv->redisplay_shader,
|
|
|
|
"s_texture", 0);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2009-03-15 13:48:19 +00:00
|
|
|
#endif
|
2012-12-06 07:40:26 +00:00
|
|
|
} /* end default opengl scene */
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
void
|
|
|
|
gst_gl_display_on_close (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2011-11-24 15:02:32 +00:00
|
|
|
gst_gl_display_set_error (display, "Output window was closed");
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 08:51:02 +00:00
|
|
|
void
|
|
|
|
gst_gl_display_gen_texture_window_cb (GstGLDisplay * display)
|
|
|
|
{
|
2013-01-09 14:44:54 +00:00
|
|
|
gst_gl_display_gen_texture_thread (display, &display->priv->gen_texture,
|
|
|
|
display->priv->gen_texture_video_format, display->priv->gen_texture_width,
|
|
|
|
display->priv->gen_texture_height);
|
2012-07-06 08:51:02 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Generate a texture if no one is available in the pool
|
|
|
|
* Called in the gl thread */
|
|
|
|
void
|
2012-07-06 08:51:02 +00:00
|
|
|
gst_gl_display_gen_texture_thread (GstGLDisplay * display, GLuint * pTexture,
|
|
|
|
GstVideoFormat v_format, GLint width, GLint height)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2013-03-09 11:05:28 +00:00
|
|
|
const GstGLFuncs *gl = display->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-07-09 06:12:53 +00:00
|
|
|
GST_TRACE ("Generating texture format:%u dimensions:%ux%u", v_format,
|
|
|
|
width, height);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenTextures (1, pTexture);
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
|
2008-08-13 15:16:17 +00:00
|
|
|
|
2012-07-06 08:51:02 +00:00
|
|
|
switch (v_format) {
|
2009-09-19 12:16:25 +00:00
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
2013-03-09 11:05:28 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2009-09-19 12:16:25 +00:00
|
|
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
break;
|
2013-03-09 11:05:28 +00:00
|
|
|
}
|
2009-09-19 12:16:25 +00:00
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
2013-03-09 11:05:28 +00:00
|
|
|
{
|
2012-09-16 11:23:09 +00:00
|
|
|
switch (display->colorspace_conversion) {
|
2009-09-19 12:16:25 +00:00
|
|
|
case GST_GL_DISPLAY_CONVERSION_GLSL:
|
|
|
|
case GST_GL_DISPLAY_CONVERSION_MATRIX:
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2009-02-11 06:39:14 +00:00
|
|
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2008-09-16 00:10:31 +00:00
|
|
|
break;
|
2012-12-06 07:40:26 +00:00
|
|
|
#if 0
|
|
|
|
case GST_GL_DISPLAY_CONVERSION_MESA:
|
2009-09-19 12:16:25 +00:00
|
|
|
if (display->upload_width != display->upload_data_width ||
|
|
|
|
display->upload_height != display->upload_data_height)
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2009-09-19 12:16:25 +00:00
|
|
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
else
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
|
2009-09-19 12:16:25 +00:00
|
|
|
height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
|
2012-12-06 07:40:26 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2008-09-16 00:10:31 +00:00
|
|
|
default:
|
2012-04-11 08:44:23 +00:00
|
|
|
gst_gl_display_set_error (display, "Unknow colorspace conversion %d",
|
2012-09-16 11:23:09 +00:00
|
|
|
display->colorspace_conversion);
|
2008-09-16 00:10:31 +00:00
|
|
|
}
|
2009-09-19 12:16:25 +00:00
|
|
|
break;
|
2013-03-09 11:05:28 +00:00
|
|
|
}
|
2009-09-19 12:16:25 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
2013-03-09 11:05:28 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
2009-09-19 12:16:25 +00:00
|
|
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
break;
|
2013-03-09 11:05:28 +00:00
|
|
|
}
|
2009-09-19 12:16:25 +00:00
|
|
|
default:
|
2013-03-09 11:05:28 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_display_set_error (display, "Unsupported upload video format %d",
|
|
|
|
v_format);
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
2013-03-09 11:05:28 +00:00
|
|
|
}
|
2009-09-19 12:16:25 +00:00
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
2009-09-19 12:16:25 +00:00
|
|
|
GL_CLAMP_TO_EDGE);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
2009-09-19 12:16:25 +00:00
|
|
|
GL_CLAMP_TO_EDGE);
|
2008-08-11 17:01:33 +00:00
|
|
|
|
2009-09-19 12:16:25 +00:00
|
|
|
GST_LOG ("generated texture id:%d", *pTexture);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
void
|
2012-07-06 08:51:02 +00:00
|
|
|
gst_gl_display_del_texture_thread (GstGLDisplay * display, GLuint * pTexture)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2012-11-08 11:53:56 +00:00
|
|
|
//glDeleteTextures (1, pTexture);
|
2008-08-11 17:01:33 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/*------------------------------------------------------------
|
|
|
|
--------------------- END PRIVATE -------------------------
|
|
|
|
----------------------------------------------------------*/
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/*------------------------------------------------------------
|
|
|
|
--------------------- BEGIN PUBLIC -------------------------
|
|
|
|
----------------------------------------------------------*/
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_lock (GstGLDisplay * display)
|
|
|
|
{
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_lock (&display->mutex);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_unlock (GstGLDisplay * display)
|
|
|
|
{
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_unlock (&display->mutex);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* called in the gl thread */
|
2013-01-16 04:21:44 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_display_check_framebuffer_status (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GLenum status = 0;
|
|
|
|
status = display->gl_vtable->CheckFramebufferStatus (GL_FRAMEBUFFER);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (status) {
|
2013-01-16 04:21:44 +00:00
|
|
|
case GL_FRAMEBUFFER_COMPLETE:
|
|
|
|
return TRUE;
|
2009-02-11 06:39:14 +00:00
|
|
|
break;
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED:
|
2009-04-10 18:42:59 +00:00
|
|
|
GST_ERROR ("GL_FRAMEBUFFER_UNSUPPORTED");
|
|
|
|
break;
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
2009-04-10 18:42:59 +00:00
|
|
|
GST_ERROR ("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
|
|
|
break;
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
2009-04-10 18:42:59 +00:00
|
|
|
GST_ERROR ("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
|
|
|
|
break;
|
2013-01-16 04:21:44 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
2009-04-10 18:42:59 +00:00
|
|
|
GST_ERROR ("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
|
2009-02-11 06:39:14 +00:00
|
|
|
break;
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2012-04-20 10:33:38 +00:00
|
|
|
case GL_FRAMEBUFFER_UNDEFINED:
|
|
|
|
GST_ERROR ("GL_FRAMEBUFFER_UNDEFINED");
|
|
|
|
break;
|
2012-08-27 14:07:31 +00:00
|
|
|
#endif
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
GST_ERROR ("General FBO error");
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the first gl element of a video/x-raw-gl flow */
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLDisplay *
|
2008-05-18 11:12:46 +00:00
|
|
|
gst_gl_display_new (void)
|
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
return g_object_new (GST_GL_TYPE_DISPLAY, NULL);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
/* Create an opengl context (one context for one GstGLDisplay) */
|
2011-11-24 15:02:32 +00:00
|
|
|
gboolean
|
2009-10-27 16:02:23 +00:00
|
|
|
gst_gl_display_create_context (GstGLDisplay * display,
|
|
|
|
gulong external_gl_context)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2011-11-24 15:02:32 +00:00
|
|
|
gboolean isAlive = FALSE;
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
if (!display->context_created) {
|
2009-10-22 23:11:27 +00:00
|
|
|
display->external_gl_context = external_gl_context;
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
display->gl_thread = g_thread_new ("gstglcontext",
|
|
|
|
(GThreadFunc) gst_gl_display_thread_create_context, display);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_cond_wait (&display->priv->cond_create_context, &display->mutex);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-04-24 04:25:21 +00:00
|
|
|
display->context_created = TRUE;
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
GST_INFO ("gl thread created");
|
|
|
|
}
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
isAlive = display->isAlive;
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2011-11-24 15:02:32 +00:00
|
|
|
|
|
|
|
return isAlive;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the glimagesink element */
|
|
|
|
gboolean
|
2010-05-04 09:37:38 +00:00
|
|
|
gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture,
|
|
|
|
gint gl_width, gint gl_height, gint window_width, gint window_height,
|
|
|
|
gboolean keep_aspect_ratio)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
gboolean isAlive;
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-01-09 14:44:54 +00:00
|
|
|
if (USING_GLES2 (display)) {
|
|
|
|
if (!display->priv->redisplay_shader) {
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window,
|
2013-01-09 14:44:54 +00:00
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_thread_init_redisplay), display);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2009-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (texture) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->redisplay_texture = texture;
|
|
|
|
display->priv->redisplay_texture_width = gl_width;
|
|
|
|
display->priv->redisplay_texture_height = gl_height;
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
2009-04-19 22:52:41 +00:00
|
|
|
display->keep_aspect_ratio = keep_aspect_ratio;
|
2008-10-27 23:22:27 +00:00
|
|
|
if (display->gl_window)
|
2010-05-04 09:37:38 +00:00
|
|
|
gst_gl_window_draw (display->gl_window, window_width, window_height);
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
isAlive = display->isAlive;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
return isAlive;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 17:01:33 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_thread_add (GstGLDisplay * display,
|
|
|
|
GstGLDisplayThreadFunc func, gpointer data)
|
2008-08-11 07:00:40 +00:00
|
|
|
{
|
|
|
|
gst_gl_display_lock (display);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->data = data;
|
|
|
|
display->priv->generic_callback = func;
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window,
|
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_thread_run_generic), display);
|
2008-08-11 07:00:40 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by gst_gl_buffer_new */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
|
2012-07-06 08:51:02 +00:00
|
|
|
GstVideoFormat v_format, GLint width, GLint height)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2009-09-19 12:16:25 +00:00
|
|
|
|
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_texture_width = width;
|
|
|
|
display->priv->gen_texture_height = height;
|
|
|
|
display->priv->gen_texture_video_format = v_format;
|
2012-07-06 08:51:02 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window,
|
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_gen_texture_window_cb), display);
|
2013-01-09 14:44:54 +00:00
|
|
|
*pTexture = display->priv->gen_texture;
|
2009-09-19 12:16:25 +00:00
|
|
|
} else
|
|
|
|
*pTexture = 0;
|
2009-10-15 13:40:11 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by gst_gl_buffer_finalize */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2012-07-06 08:51:02 +00:00
|
|
|
gst_gl_display_del_texture (GstGLDisplay * display, GLuint * pTexture)
|
2008-06-10 19:07:43 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-07-06 08:51:02 +00:00
|
|
|
if (*pTexture) {
|
|
|
|
gst_gl_display_del_texture_thread (display, pTexture);
|
2008-09-18 20:50:05 +00:00
|
|
|
}
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-06-10 19:07:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
/* Called by gltestsrc and glfilter */
|
2011-11-24 15:02:32 +00:00
|
|
|
gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_gen_fbo (GstGLDisplay * display, gint width, gint height,
|
|
|
|
GLuint * fbo, GLuint * depthbuffer)
|
2008-06-07 00:01:18 +00:00
|
|
|
{
|
2011-11-24 15:02:32 +00:00
|
|
|
gboolean isAlive = FALSE;
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2009-02-11 06:39:14 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_fbo_width = width;
|
|
|
|
display->priv->gen_fbo_height = height;
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_gen_fbo),
|
|
|
|
display);
|
2013-01-09 14:44:54 +00:00
|
|
|
*fbo = display->priv->generated_fbo;
|
|
|
|
*depthbuffer = display->priv->generated_depth_buffer;
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
isAlive = display->isAlive;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2011-11-24 15:02:32 +00:00
|
|
|
|
|
|
|
return isAlive;
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by glfilter */
|
2008-08-10 09:22:34 +00:00
|
|
|
/* this function really has to be simplified... do we really need to
|
|
|
|
set projection this way? Wouldn't be better a set_projection
|
|
|
|
separate call? or just make glut functions available out of
|
|
|
|
gst-libs and call it if needed on drawcallback? -- Filippo */
|
|
|
|
/* GLCB too.. I think that only needed parameters should be
|
|
|
|
* GstGLDisplay *display and gpointer data, or just gpointer data */
|
|
|
|
/* ..everything here has to be simplified! */
|
2008-07-20 14:38:48 +00:00
|
|
|
gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
|
|
|
|
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
|
|
|
|
GLuint texture_fbo, GLCB cb, gint input_texture_width,
|
|
|
|
gint input_texture_height, GLuint input_texture, gdouble proj_param1,
|
|
|
|
gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
|
|
|
|
GstGLDisplayProjection projection, gpointer * stuff)
|
2008-06-07 15:27:12 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
gboolean isAlive;
|
2008-08-04 10:13:29 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo = fbo;
|
|
|
|
display->priv->use_depth_buffer = depth_buffer;
|
|
|
|
display->priv->use_fbo_texture = texture_fbo;
|
|
|
|
display->priv->use_fbo_width = texture_fbo_width;
|
|
|
|
display->priv->use_fbo_height = texture_fbo_height;
|
|
|
|
display->priv->use_fbo_scene_cb = cb;
|
|
|
|
display->priv->use_fbo_proj_param1 = proj_param1;
|
|
|
|
display->priv->use_fbo_proj_param2 = proj_param2;
|
|
|
|
display->priv->use_fbo_proj_param3 = proj_param3;
|
|
|
|
display->priv->use_fbo_proj_param4 = proj_param4;
|
|
|
|
display->priv->use_fbo_projection = projection;
|
|
|
|
display->priv->use_fbo_stuff = stuff;
|
|
|
|
display->priv->input_texture_width = input_texture_width;
|
|
|
|
display->priv->input_texture_height = input_texture_height;
|
|
|
|
display->priv->input_texture = input_texture;
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_use_fbo),
|
|
|
|
display);
|
2008-08-01 09:00:49 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
isAlive = display->isAlive;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
|
|
|
return isAlive;
|
2008-06-07 15:27:12 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
gboolean isAlive;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->use_fbo = fbo;
|
|
|
|
display->priv->use_depth_buffer = depth_buffer;
|
|
|
|
display->priv->use_fbo_texture = texture_fbo;
|
|
|
|
display->priv->use_fbo_width = texture_fbo_width;
|
|
|
|
display->priv->use_fbo_height = texture_fbo_height;
|
|
|
|
display->priv->use_fbo_scene_cb_v2 = cb;
|
|
|
|
display->priv->use_fbo_stuff = stuff;
|
|
|
|
gst_gl_window_send_message (display->gl_window,
|
2013-01-16 04:21:44 +00:00
|
|
|
GST_GL_WINDOW_CB (_use_fbo_v2), display);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
isAlive = display->isAlive;
|
2009-10-22 23:11:27 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
|
|
|
return isAlive;
|
|
|
|
}
|
2008-06-07 15:27:12 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by gltestsrc and glfilter */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo, GLuint depth_buffer)
|
2008-06-07 15:27:12 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->del_fbo = fbo;
|
|
|
|
display->priv->del_depth_buffer = depth_buffer;
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_del_fbo),
|
|
|
|
display);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-06-08 02:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by glfilter */
|
2011-11-24 15:02:32 +00:00
|
|
|
gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_gen_shader (GstGLDisplay * display,
|
|
|
|
const gchar * shader_vertex_source,
|
|
|
|
const gchar * shader_fragment_source, GstGLShader ** shader)
|
2008-06-13 00:01:26 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
gboolean isAlive;
|
2011-11-24 15:02:32 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->gen_shader_vertex_source = shader_vertex_source;
|
|
|
|
display->priv->gen_shader_fragment_source = shader_fragment_source;
|
|
|
|
gst_gl_window_send_message (display->gl_window,
|
2013-01-16 04:21:44 +00:00
|
|
|
GST_GL_WINDOW_CB (_gen_shader), display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (shader)
|
2013-01-09 14:44:54 +00:00
|
|
|
*shader = display->priv->gen_shader;
|
|
|
|
display->priv->gen_shader = NULL;
|
|
|
|
display->priv->gen_shader_vertex_source = NULL;
|
|
|
|
display->priv->gen_shader_fragment_source = NULL;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2011-11-24 15:02:32 +00:00
|
|
|
isAlive = display->isAlive;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2011-11-24 15:02:32 +00:00
|
|
|
|
|
|
|
return isAlive;
|
2008-06-13 00:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by glfilter */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_del_shader (GstGLDisplay * display, GstGLShader * shader)
|
2008-06-13 00:01:26 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
if (display->isAlive) {
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->del_shader = shader;
|
|
|
|
gst_gl_window_send_message (display->gl_window,
|
2013-01-16 04:21:44 +00:00
|
|
|
GST_GL_WINDOW_CB (_del_shader), display);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-06-13 00:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the glimagesink */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_display_set_window_id (GstGLDisplay * display, guintptr window_id)
|
2008-06-08 02:19:43 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_set_window_handle (display->gl_window, window_id);
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the glimagesink */
|
2008-06-19 23:38:36 +00:00
|
|
|
void
|
2008-06-29 17:27:43 +00:00
|
|
|
gst_gl_display_set_client_reshape_callback (GstGLDisplay * display, CRCB cb)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->clientReshapeCallback = cb;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-06-19 23:38:36 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-19 23:38:36 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the glimagesink */
|
|
|
|
void
|
|
|
|
gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb)
|
|
|
|
{
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_lock (display);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->clientDrawCallback = cb;
|
2008-08-01 09:00:49 +00:00
|
|
|
gst_gl_display_unlock (display);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-21 12:21:54 +00:00
|
|
|
void
|
|
|
|
gst_gl_display_set_client_data (GstGLDisplay * display, gpointer data)
|
|
|
|
{
|
|
|
|
gst_gl_display_lock (display);
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->client_data = data;
|
2009-11-21 12:21:54 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
gulong
|
|
|
|
gst_gl_display_get_internal_gl_context (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
gulong external_gl_context = 0;
|
|
|
|
gst_gl_display_lock (display);
|
2012-11-13 11:12:20 +00:00
|
|
|
external_gl_context = gst_gl_window_get_gl_context (display->gl_window);
|
2009-10-22 23:11:27 +00:00
|
|
|
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);
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_activate (display->gl_window, activate);
|
2009-10-22 23:11:27 +00:00
|
|
|
if (activate)
|
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLAPI
|
|
|
|
gst_gl_display_get_gl_api_unlocked (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
return display->gl_api;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstGLAPI
|
|
|
|
gst_gl_display_get_gl_api (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstGLAPI api;
|
|
|
|
|
|
|
|
gst_gl_display_lock (display);
|
|
|
|
api = gst_gl_display_get_gl_api_unlocked (display);
|
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gpointer
|
|
|
|
gst_gl_display_get_gl_vtable (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
gpointer gl;
|
|
|
|
|
|
|
|
gst_gl_display_lock (display);
|
|
|
|
gl = display->gl_vtable;
|
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
|
|
|
return gl;
|
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//------------------------ END PUBLIC ------------------------
|
|
|
|
//------------------------------------------------------------
|