2008-11-05 01:06:33 +00:00
|
|
|
/*
|
2008-07-18 08:49:34 +00:00
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2014-04-30 14:20:23 +00:00
|
|
|
* Copyright (C) 2014 Julien Isorce <julien.isorce@collabora.co.uk>
|
2008-07-18 08:49:34 +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-07-18 08:49:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-10 15:03:04 +00:00
|
|
|
#include "gl.h"
|
2008-07-18 08:49:34 +00:00
|
|
|
#include "gstglshader.h"
|
2015-09-04 06:02:32 +00:00
|
|
|
#include "gstglsl_private.h"
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2016-03-06 08:35:38 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglshader
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: GstGLShader
|
2016-03-06 08:35:38 +00:00
|
|
|
* @short_description: object representing an OpenGL shader program
|
|
|
|
* @see_also: #GstGLSLStage
|
|
|
|
*/
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#ifndef GLhandleARB
|
|
|
|
#define GLhandleARB GLuint
|
|
|
|
#endif
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
#define GST_GL_SHADER_GET_PRIVATE(o) \
|
2016-10-05 01:19:12 +00:00
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_TYPE_GL_SHADER, GstGLShaderPrivate))
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2014-05-30 00:27:14 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
|
|
|
|
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
typedef struct _GstGLShaderVTable
|
|
|
|
{
|
2017-05-25 10:06:03 +00:00
|
|
|
GLuint (GSTGLAPI * CreateProgram) (void);
|
|
|
|
void (GSTGLAPI * DeleteProgram) (GLuint program);
|
|
|
|
void (GSTGLAPI * UseProgram) (GLuint program);
|
|
|
|
void (GSTGLAPI * GetAttachedShaders) (GLuint program, GLsizei maxcount,
|
2013-06-02 07:52:30 +00:00
|
|
|
GLsizei * count, GLuint * shaders);
|
|
|
|
|
2017-05-25 10:06:03 +00:00
|
|
|
GLuint (GSTGLAPI * CreateShader) (GLenum shaderType);
|
|
|
|
void (GSTGLAPI * DeleteShader) (GLuint shader);
|
|
|
|
void (GSTGLAPI * AttachShader) (GLuint program, GLuint shader);
|
|
|
|
void (GSTGLAPI * DetachShader) (GLuint program, GLuint shader);
|
2013-06-02 07:52:30 +00:00
|
|
|
|
2017-05-25 10:06:03 +00:00
|
|
|
void (GSTGLAPI * GetShaderiv) (GLuint program, GLenum pname, GLint * params);
|
|
|
|
void (GSTGLAPI * GetProgramiv) (GLuint program, GLenum pname, GLint * params);
|
|
|
|
void (GSTGLAPI * GetShaderInfoLog) (GLuint shader, GLsizei maxLength,
|
2013-06-02 07:52:30 +00:00
|
|
|
GLsizei * length, char *log);
|
2017-05-25 10:06:03 +00:00
|
|
|
void (GSTGLAPI * GetProgramInfoLog) (GLuint shader, GLsizei maxLength,
|
2013-06-02 07:52:30 +00:00
|
|
|
GLsizei * length, char *log);
|
2013-01-16 04:21:44 +00:00
|
|
|
} GstGLShaderVTable;
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2015-09-04 06:02:32 +00:00
|
|
|
PROP_LINKED,
|
2008-07-18 08:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstGLShaderPrivate
|
|
|
|
{
|
|
|
|
GLhandleARB program_handle;
|
2015-09-04 06:02:32 +00:00
|
|
|
GList *stages;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
gboolean linked;
|
2016-02-10 05:37:22 +00:00
|
|
|
GHashTable *uniform_locations;
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GstGLSLFuncs vtable;
|
2008-07-18 08:49:34 +00:00
|
|
|
};
|
|
|
|
|
2012-12-02 03:58:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_shader_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_shader_debug
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2012-12-02 03:58:14 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_shader_debug, "glshader", 0, "shader");
|
2014-05-08 05:30:49 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLShader, gst_gl_shader, GST_TYPE_OBJECT,
|
|
|
|
DEBUG_INIT);
|
2008-09-20 12:12:49 +00:00
|
|
|
|
2013-06-13 04:36:41 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_cleanup_shader (GstGLContext * context, GstGLShader * shader)
|
2013-06-13 04:36:41 +00:00
|
|
|
{
|
2013-06-27 14:34:48 +00:00
|
|
|
GstGLShaderPrivate *priv = shader->priv;
|
2013-06-13 04:36:41 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
|
2013-06-27 14:34:48 +00:00
|
|
|
/* release shader objects */
|
2015-09-04 06:02:32 +00:00
|
|
|
gst_gl_shader_release_unlocked (shader);
|
2013-06-13 04:36:41 +00:00
|
|
|
|
2013-06-27 14:34:48 +00:00
|
|
|
/* delete program */
|
|
|
|
if (priv->program_handle) {
|
|
|
|
GST_TRACE ("finalizing program shader %u", priv->program_handle);
|
|
|
|
|
|
|
|
priv->vtable.DeleteProgram (priv->program_handle);
|
2013-06-13 04:36:41 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 14:34:48 +00:00
|
|
|
GST_DEBUG ("shader deleted %u", priv->program_handle);
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2013-06-13 04:36:41 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
static void
|
|
|
|
gst_gl_shader_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLShader *shader;
|
|
|
|
GstGLShaderPrivate *priv;
|
|
|
|
|
|
|
|
shader = GST_GL_SHADER (object);
|
|
|
|
priv = shader->priv;
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_TRACE_OBJECT (shader, "finalizing shader %u", priv->program_handle);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_thread_add (shader->context,
|
|
|
|
(GstGLContextThreadFunc) _cleanup_shader, shader);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
priv->program_handle = 0;
|
2016-02-10 05:37:22 +00:00
|
|
|
g_hash_table_destroy (priv->uniform_locations);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (shader->context) {
|
|
|
|
gst_object_unref (shader->context);
|
|
|
|
shader->context = NULL;
|
2013-06-27 14:34:48 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_shader_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_shader_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_shader_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGLShader *shader = GST_GL_SHADER (object);
|
|
|
|
GstGLShaderPrivate *priv = shader->priv;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-09-04 06:02:32 +00:00
|
|
|
case PROP_LINKED:
|
|
|
|
g_value_set_boolean (value, priv->linked);
|
2008-07-18 08:49:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-07 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
static void
|
|
|
|
gst_gl_shader_class_init (GstGLShaderClass * klass)
|
|
|
|
{
|
|
|
|
/* bind class methods .. */
|
|
|
|
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GstGLShaderPrivate));
|
|
|
|
|
|
|
|
obj_class->finalize = gst_gl_shader_finalize;
|
|
|
|
obj_class->set_property = gst_gl_shader_set_property;
|
|
|
|
obj_class->get_property = gst_gl_shader_get_property;
|
|
|
|
|
|
|
|
/* .. and install properties */
|
|
|
|
g_object_class_install_property (obj_class,
|
2015-09-04 06:02:32 +00:00
|
|
|
PROP_LINKED,
|
|
|
|
g_param_spec_boolean ("linked",
|
|
|
|
"Linked",
|
|
|
|
"Shader link status", FALSE,
|
2010-10-19 15:00:33 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
static void
|
|
|
|
gst_gl_shader_init (GstGLShader * self)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
/* initialize sources and create program object */
|
2008-07-18 08:49:34 +00:00
|
|
|
GstGLShaderPrivate *priv;
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
priv = self->priv = GST_GL_SHADER_GET_PRIVATE (self);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
priv->linked = FALSE;
|
2016-02-10 05:37:22 +00:00
|
|
|
priv->uniform_locations =
|
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_get_uniform_location (GstGLShader * shader, const gchar * name)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv = shader->priv;
|
|
|
|
int location;
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (priv->linked, 0);
|
|
|
|
|
|
|
|
if (!g_hash_table_lookup_extended (priv->uniform_locations, name, NULL,
|
|
|
|
&value)) {
|
|
|
|
const GstGLFuncs *gl = shader->context->gl_vtable;
|
|
|
|
location = gl->GetUniformLocation (priv->program_handle, name);
|
|
|
|
g_hash_table_insert (priv->uniform_locations, g_strdup (name),
|
|
|
|
GINT_TO_POINTER (location));
|
|
|
|
} else {
|
|
|
|
location = GPOINTER_TO_INT (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return location;
|
2015-09-04 06:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLShader *
|
|
|
|
_new_with_stages_va_list (GstGLContext * context, GError ** error,
|
|
|
|
va_list varargs)
|
|
|
|
{
|
|
|
|
GstGLShader *shader;
|
|
|
|
GstGLSLStage *stage;
|
2015-11-11 01:23:30 +00:00
|
|
|
gboolean to_unref_and_out = FALSE;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2016-10-05 01:19:12 +00:00
|
|
|
shader = g_object_new (GST_TYPE_GL_SHADER, NULL);
|
2017-05-15 17:31:31 +00:00
|
|
|
gst_object_ref_sink (shader);
|
2015-09-04 06:02:32 +00:00
|
|
|
shader->context = gst_object_ref (context);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
while ((stage = va_arg (varargs, GstGLSLStage *))) {
|
2015-11-11 01:23:30 +00:00
|
|
|
if (to_unref_and_out) {
|
|
|
|
gst_object_unref (stage);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!gst_glsl_stage_compile (stage, error)) {
|
2015-11-11 01:23:30 +00:00
|
|
|
gst_object_unref (stage);
|
|
|
|
to_unref_and_out = TRUE;
|
|
|
|
continue;
|
2015-09-04 06:02:32 +00:00
|
|
|
}
|
|
|
|
if (!gst_gl_shader_attach (shader, stage)) {
|
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM,
|
|
|
|
"Failed to attach stage to program");
|
2015-11-11 01:23:30 +00:00
|
|
|
to_unref_and_out = TRUE;
|
|
|
|
continue;
|
2015-09-04 06:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 01:23:30 +00:00
|
|
|
if (to_unref_and_out) {
|
|
|
|
gst_object_unref (shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
return shader;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_new_link_with_stages:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @error: a #GError
|
2016-03-06 08:35:38 +00:00
|
|
|
* @...: a NULL terminated list of #GstGLSLStage's
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Each stage will attempt to be compiled and attached to @shader. Then
|
|
|
|
* the shader will be linked. On error, %NULL will be returned and @error will
|
|
|
|
* contain the details of the error.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new @shader with the specified stages.
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
GstGLShader *
|
|
|
|
gst_gl_shader_new_link_with_stages (GstGLContext * context, GError ** error,
|
|
|
|
...)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
GstGLShader *shader;
|
|
|
|
va_list varargs;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
va_start (varargs, error);
|
|
|
|
shader = _new_with_stages_va_list (context, error, varargs);
|
|
|
|
va_end (varargs);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!shader)
|
|
|
|
return NULL;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!gst_gl_shader_link (shader, error))
|
|
|
|
return NULL;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
return shader;
|
|
|
|
}
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_new_with_stages:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @error: a #GError
|
2016-03-06 08:35:38 +00:00
|
|
|
* @...: a NULL terminated list of #GstGLSLStage's
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Each stage will attempt to be compiled and attached to @shader. On error,
|
|
|
|
* %NULL will be returned and @error will contain the details of the error.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new @shader with the specified stages.
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
GstGLShader *
|
|
|
|
gst_gl_shader_new_with_stages (GstGLContext * context, GError ** error, ...)
|
|
|
|
{
|
|
|
|
GstGLShader *shader;
|
|
|
|
va_list varargs;
|
|
|
|
|
|
|
|
va_start (varargs, error);
|
|
|
|
shader = _new_with_stages_va_list (context, error, varargs);
|
|
|
|
va_end (varargs);
|
|
|
|
|
|
|
|
return shader;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_new:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new empty @shader
|
|
|
|
*/
|
|
|
|
GstGLShader *
|
|
|
|
gst_gl_shader_new (GstGLContext * context)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
return gst_gl_shader_new_with_stages (context, NULL, NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_new_default:
|
|
|
|
* @context: a #GstGLContext
|
2016-03-06 08:35:38 +00:00
|
|
|
* @error: a #GError that is filled on failure
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
2016-03-06 08:35:38 +00:00
|
|
|
* Returns: (transfer full): a default @shader or %NULL on failure
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
GstGLShader *
|
|
|
|
gst_gl_shader_new_default (GstGLContext * context, GError ** error)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
return gst_gl_shader_new_link_with_stages (context, error,
|
|
|
|
gst_glsl_stage_new_default_vertex (context),
|
|
|
|
gst_glsl_stage_new_default_fragment (context), NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_is_linked:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: whether @shader has been successfully linked
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_shader_is_linked (GstGLShader * shader)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
gboolean ret;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_SHADER (shader), FALSE);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
ret = shader->priv->linked;
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
static gboolean
|
|
|
|
_ensure_program (GstGLShader * shader)
|
|
|
|
{
|
|
|
|
if (shader->priv->program_handle)
|
|
|
|
return TRUE;
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
shader->priv->program_handle = shader->priv->vtable.CreateProgram ();
|
|
|
|
return shader->priv->program_handle != 0;
|
2013-01-16 04:21:44 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_get_program_handle:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
*
|
|
|
|
* Returns: the GL program handle for this shader
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
gst_gl_shader_get_program_handle (GstGLShader * shader)
|
2013-01-16 04:21:44 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
int ret;
|
2012-04-13 10:38:11 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_SHADER (shader), 0);
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
ret = (int) shader->priv->program_handle;
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
|
|
|
|
return ret;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_detach_unlocked:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @stage: a #GstGLSLStage to attach
|
|
|
|
*
|
|
|
|
* Detaches @stage from @shader. @stage must have been successfully attached
|
|
|
|
* to @shader with gst_gl_shader_attach() or gst_gl_shader_attach_unlocked().
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_shader_detach_unlocked (GstGLShader * shader, GstGLSLStage * stage)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
guint stage_handle;
|
|
|
|
GList *elem;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_SHADER (shader));
|
2015-09-04 06:02:32 +00:00
|
|
|
g_return_if_fail (GST_IS_GLSL_STAGE (stage));
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!_gst_glsl_funcs_fill (&shader->priv->vtable, shader->context)) {
|
|
|
|
GST_WARNING_OBJECT (shader, "Failed to retreive required GLSL functions");
|
|
|
|
return;
|
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!shader->priv->program_handle)
|
|
|
|
return;
|
2015-02-12 14:02:31 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
elem = g_list_find (shader->priv->stages, stage);
|
|
|
|
if (!elem) {
|
|
|
|
GST_FIXME_OBJECT (shader, "Could not find stage %p in shader %p", stage,
|
|
|
|
shader);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage_handle = gst_glsl_stage_get_handle (stage);
|
|
|
|
if (!stage_handle) {
|
|
|
|
GST_FIXME_OBJECT (shader, "Stage %p doesn't have a GL handle", stage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-10 06:46:05 +00:00
|
|
|
if (shader->context->gl_vtable->IsProgram)
|
|
|
|
g_assert (shader->context->gl_vtable->IsProgram (shader->
|
|
|
|
priv->program_handle));
|
|
|
|
if (shader->context->gl_vtable->IsShader)
|
|
|
|
g_assert (shader->context->gl_vtable->IsShader (stage_handle));
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (shader, "detaching shader %i from program %i", stage_handle,
|
|
|
|
(int) shader->priv->program_handle);
|
|
|
|
shader->priv->vtable.DetachShader (shader->priv->program_handle,
|
|
|
|
stage_handle);
|
|
|
|
|
2015-11-06 12:31:09 +00:00
|
|
|
shader->priv->stages = g_list_delete_link (shader->priv->stages, elem);
|
2015-09-04 06:02:32 +00:00
|
|
|
gst_object_unref (stage);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_detach:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @stage: a #GstGLSLStage to attach
|
|
|
|
*
|
|
|
|
* Detaches @stage from @shader. @stage must have been successfully attached
|
|
|
|
* to @shader with gst_gl_shader_attach() or gst_gl_shader_attach_unlocked().
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_shader_detach (GstGLShader * shader, GstGLSLStage * stage)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_SHADER (shader));
|
2015-09-04 06:02:32 +00:00
|
|
|
g_return_if_fail (GST_IS_GLSL_STAGE (stage));
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
gst_gl_shader_detach_unlocked (shader, stage);
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_attach_unlocked:
|
|
|
|
* @shader: a #GstGLShader
|
2017-05-15 09:00:50 +00:00
|
|
|
* @stage: (transfer floating): a #GstGLSLStage to attach
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Attaches @stage to @shader. @stage must have been successfully compiled
|
|
|
|
* with gst_glsl_stage_compile().
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: whether @stage could be attached to @shader
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_shader_attach_unlocked (GstGLShader * shader, GstGLSLStage * stage)
|
2015-05-12 12:04:26 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
guint stage_handle;
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_SHADER (shader), FALSE);
|
2015-09-04 06:02:32 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GLSL_STAGE (stage), FALSE);
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!_gst_glsl_funcs_fill (&shader->priv->vtable, shader->context)) {
|
|
|
|
GST_WARNING_OBJECT (shader, "Failed to retreive required GLSL functions");
|
2017-05-15 09:00:50 +00:00
|
|
|
gst_object_ref_sink (stage);
|
|
|
|
gst_object_unref (stage);
|
2015-09-04 06:02:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2017-05-15 09:00:50 +00:00
|
|
|
if (!_ensure_program (shader)) {
|
|
|
|
gst_object_ref_sink (stage);
|
|
|
|
gst_object_unref (stage);
|
2015-09-04 06:02:32 +00:00
|
|
|
return FALSE;
|
2017-05-15 09:00:50 +00:00
|
|
|
}
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/* already attached? */
|
2017-05-15 09:00:50 +00:00
|
|
|
if (g_list_find (shader->priv->stages, stage)) {
|
|
|
|
gst_object_ref_sink (stage);
|
|
|
|
gst_object_unref (stage);
|
2015-09-04 06:02:32 +00:00
|
|
|
return TRUE;
|
2017-05-15 09:00:50 +00:00
|
|
|
}
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
stage_handle = gst_glsl_stage_get_handle (stage);
|
|
|
|
if (!stage_handle) {
|
2017-05-15 09:00:50 +00:00
|
|
|
gst_object_ref_sink (stage);
|
|
|
|
gst_object_unref (stage);
|
2015-09-04 06:02:32 +00:00
|
|
|
return FALSE;
|
2015-05-12 12:04:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 06:46:05 +00:00
|
|
|
if (shader->context->gl_vtable->IsProgram)
|
|
|
|
g_assert (shader->context->gl_vtable->IsProgram (shader->
|
|
|
|
priv->program_handle));
|
|
|
|
if (shader->context->gl_vtable->IsShader)
|
|
|
|
g_assert (shader->context->gl_vtable->IsShader (stage_handle));
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
shader->priv->stages =
|
|
|
|
g_list_prepend (shader->priv->stages, gst_object_ref_sink (stage));
|
|
|
|
GST_LOG_OBJECT (shader, "attaching shader %i to program %i", stage_handle,
|
|
|
|
(int) shader->priv->program_handle);
|
|
|
|
shader->priv->vtable.AttachShader (shader->priv->program_handle,
|
|
|
|
stage_handle);
|
|
|
|
|
|
|
|
return TRUE;
|
2015-05-12 12:04:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_attach:
|
|
|
|
* @shader: a #GstGLShader
|
2017-05-15 09:00:50 +00:00
|
|
|
* @stage: (transfer floating): a #GstGLSLStage to attach
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Attaches @stage to @shader. @stage must have been successfully compiled
|
|
|
|
* with gst_glsl_stage_compile().
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: whether @stage could be attached to @shader
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_shader_attach (GstGLShader * shader, GstGLSLStage * stage)
|
2015-05-12 12:04:26 +00:00
|
|
|
{
|
2015-09-04 06:02:32 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_SHADER (shader), FALSE);
|
2015-09-04 06:02:32 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GLSL_STAGE (stage), FALSE);
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
ret = gst_gl_shader_attach_unlocked (shader, stage);
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_shader_compile_attach_stage:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @stage: a #GstGLSLStage to attach
|
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Compiles @stage and attaches it to @shader.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: whether @stage could be compiled and attached to @shader
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_shader_compile_attach_stage (GstGLShader * shader, GstGLSLStage * stage,
|
|
|
|
GError ** error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GLSL_STAGE (stage), FALSE);
|
|
|
|
|
|
|
|
if (!gst_glsl_stage_compile (stage, error)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!gst_gl_shader_attach (shader, stage)) {
|
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_COMPILE,
|
|
|
|
"Failed to attach stage to shader");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-12 12:04:26 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
return TRUE;
|
2015-05-12 12:04:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_link:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Links the current list of #GstGLSLStage's in @shader.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
|
|
|
*
|
|
|
|
* Returns: whether @shader could be linked together.
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
2008-07-18 08:49:34 +00:00
|
|
|
gboolean
|
2015-09-04 06:02:32 +00:00
|
|
|
gst_gl_shader_link (GstGLShader * shader, GError ** error)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2015-09-04 06:02:32 +00:00
|
|
|
const GstGLFuncs *gl;
|
2008-07-18 08:49:34 +00:00
|
|
|
gchar info_buffer[2048];
|
|
|
|
GLint status = GL_FALSE;
|
2015-09-04 06:02:32 +00:00
|
|
|
gint len = 0;
|
|
|
|
gboolean ret;
|
|
|
|
GList *elem;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_SHADER (shader), FALSE);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
priv = shader->priv;
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (priv->linked) {
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!_gst_glsl_funcs_fill (&shader->priv->vtable, shader->context)) {
|
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM,
|
|
|
|
"Failed to retreive required GLSL functions");
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2013-06-16 10:41:29 +00:00
|
|
|
return FALSE;
|
2015-09-04 06:02:32 +00:00
|
|
|
}
|
2013-06-16 10:41:29 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!_ensure_program (shader)) {
|
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM,
|
|
|
|
"Failed to create GL program object");
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-16 10:41:29 +00:00
|
|
|
|
|
|
|
GST_TRACE ("shader created %u", shader->priv->program_handle);
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
for (elem = shader->priv->stages; elem; elem = elem->next) {
|
|
|
|
GstGLSLStage *stage = elem->data;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!gst_glsl_stage_compile (stage, error)) {
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
return FALSE;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
2012-04-18 13:44:05 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!gst_gl_shader_attach_unlocked (shader, stage)) {
|
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_COMPILE,
|
|
|
|
"Failed to attach shader %" GST_PTR_FORMAT "to program %"
|
|
|
|
GST_PTR_FORMAT, stage, shader);
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
return FALSE;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if nothing failed link shaders */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->LinkProgram (priv->program_handle);
|
2015-07-02 09:26:18 +00:00
|
|
|
status = GL_FALSE;
|
2013-01-16 04:21:44 +00:00
|
|
|
priv->vtable.GetProgramiv (priv->program_handle, GL_LINK_STATUS, &status);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
priv->vtable.GetProgramInfoLog (priv->program_handle,
|
2008-07-18 08:49:34 +00:00
|
|
|
sizeof (info_buffer) - 1, &len, info_buffer);
|
|
|
|
info_buffer[len] = '\0';
|
|
|
|
|
|
|
|
if (status != GL_TRUE) {
|
2013-07-15 05:39:07 +00:00
|
|
|
GST_ERROR ("Shader linking failed:\n%s", info_buffer);
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_LINK,
|
|
|
|
"Shader Linking failed:\n%s", info_buffer);
|
|
|
|
ret = priv->linked = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
return ret;
|
2008-07-18 08:49:34 +00:00
|
|
|
} else if (len > 1) {
|
2012-12-02 03:58:14 +00:00
|
|
|
GST_FIXME ("shader link log:\n%s\n", info_buffer);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
ret = priv->linked = TRUE;
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (shader), "linked");
|
|
|
|
|
|
|
|
return ret;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_release_unlocked:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
*
|
|
|
|
* Releases the shader and stages.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
2008-07-18 08:49:34 +00:00
|
|
|
void
|
2015-09-04 06:02:32 +00:00
|
|
|
gst_gl_shader_release_unlocked (GstGLShader * shader)
|
2008-07-18 08:49:34 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2015-09-04 06:02:32 +00:00
|
|
|
GList *elem;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_SHADER (shader));
|
2008-07-18 08:49:34 +00:00
|
|
|
|
|
|
|
priv = shader->priv;
|
|
|
|
|
2015-11-13 05:50:22 +00:00
|
|
|
for (elem = shader->priv->stages; elem;) {
|
2015-09-04 06:02:32 +00:00
|
|
|
GstGLSLStage *stage = elem->data;
|
2015-11-13 05:50:22 +00:00
|
|
|
GList *next = elem->next;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
gst_gl_shader_detach_unlocked (shader, stage);
|
2015-11-13 05:50:22 +00:00
|
|
|
elem = next;
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
g_list_free_full (shader->priv->stages, (GDestroyNotify) gst_object_unref);
|
|
|
|
shader->priv->stages = NULL;
|
2012-04-13 10:38:11 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
priv->linked = FALSE;
|
2016-02-10 05:37:22 +00:00
|
|
|
g_hash_table_remove_all (priv->uniform_locations);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
g_object_notify (G_OBJECT (shader), "linked");
|
|
|
|
}
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_release:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
*
|
|
|
|
* Releases the shader and stages.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.8
|
2015-09-04 06:02:32 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_shader_release (GstGLShader * shader)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_SHADER (shader));
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (shader);
|
|
|
|
gst_gl_shader_release_unlocked (shader);
|
|
|
|
GST_OBJECT_UNLOCK (shader);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_use:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
*
|
|
|
|
* Mark's @shader as being used for the next GL draw command.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread and @shader must have been linked.
|
|
|
|
*/
|
2008-07-18 08:49:34 +00:00
|
|
|
void
|
|
|
|
gst_gl_shader_use (GstGLShader * shader)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_SHADER (shader));
|
2008-07-18 08:49:34 +00:00
|
|
|
|
|
|
|
priv = shader->priv;
|
|
|
|
|
2012-04-11 08:44:23 +00:00
|
|
|
g_return_if_fail (priv->program_handle);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
priv->vtable.UseProgram (priv->program_handle);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_clear_shader:
|
2016-03-06 08:35:38 +00:00
|
|
|
* @context: a #GstGLContext
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* Clear's the currently set shader from the GL state machine.
|
|
|
|
*
|
|
|
|
* Note: must be called in the GL thread.
|
|
|
|
*/
|
2013-01-16 04:21:44 +00:00
|
|
|
void
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (GstGLContext * context)
|
2013-01-16 04:21:44 +00:00
|
|
|
{
|
|
|
|
GstGLFuncs *gl;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
if (gl->CreateProgram)
|
|
|
|
gl->UseProgram (0);
|
|
|
|
else if (gl->CreateProgramObject)
|
|
|
|
gl->UseProgramObject (0);
|
|
|
|
}
|
|
|
|
|
2008-07-18 08:49:34 +00:00
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_1f (GstGLShader * shader, const gchar * name,
|
|
|
|
gfloat value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2008-07-18 08:49:34 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
priv = shader->priv;
|
2008-07-18 08:49:34 +00:00
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform1f (location, value);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_1fv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gfloat * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2008-07-18 08:49:34 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform1fv (location, count, value);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_1i (GstGLShader * shader, const gchar * name,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2008-07-18 08:49:34 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2008-07-18 08:49:34 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform1i (location, value);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 16:36:44 +00:00
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_1iv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gint * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform1iv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_2f (GstGLShader * shader, const gchar * name,
|
|
|
|
gfloat value0, gfloat value1)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform2f (location, value0, value1);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_2fv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gfloat * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform2fv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_2i (GstGLShader * shader, const gchar * name,
|
|
|
|
gint v0, gint v1)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform2i (location, v0, v1);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_2iv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gint * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform2iv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_3f (GstGLShader * shader, const gchar * name,
|
|
|
|
gfloat v0, gfloat v1, gfloat v2)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform3f (location, v0, v1, v2);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_3fv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gfloat * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform3fv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_3i (GstGLShader * shader, const gchar * name,
|
|
|
|
gint v0, gint v1, gint v2)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform3i (location, v0, v1, v2);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_3iv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gint * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform3iv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_4f (GstGLShader * shader, const gchar * name,
|
|
|
|
gfloat v0, gfloat v1, gfloat v2, gfloat v3)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform4f (location, v0, v1, v2, v3);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_4fv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gfloat * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform4fv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_4i (GstGLShader * shader, const gchar * name,
|
|
|
|
gint v0, gint v1, gint v2, gint v3)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform4i (location, v0, v1, v2, v3);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_4iv (GstGLShader * shader, const gchar * name,
|
|
|
|
guint count, gint * value)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Uniform4iv (location, count, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_matrix_2fv (GstGLShader * shader, const gchar * name,
|
2012-12-06 07:40:26 +00:00
|
|
|
gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix2fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_3fv (GstGLShader * shader, const gchar * name,
|
|
|
|
gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix3fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_4fv (GstGLShader * shader, const gchar * name,
|
|
|
|
gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix4fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2011-11-17 16:36:44 +00:00
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_2x3fv (GstGLShader * shader,
|
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix2x3fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_2x4fv (GstGLShader * shader,
|
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix2x4fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_3x2fv (GstGLShader * shader,
|
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix3x2fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 13:48:19 +00:00
|
|
|
void
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_3x4fv (GstGLShader * shader,
|
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2009-03-15 13:48:19 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2009-03-15 13:48:19 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2009-03-15 13:48:19 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2009-03-15 13:48:19 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix3x4fv (location, count, transpose, value);
|
2009-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 16:36:44 +00:00
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_matrix_4x2fv (GstGLShader * shader,
|
2012-12-06 07:40:26 +00:00
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix4x2fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_set_uniform_matrix_4x3fv (GstGLShader * shader,
|
2012-12-06 07:40:26 +00:00
|
|
|
const gchar * name, gint count, gboolean transpose, const gfloat * value)
|
2011-11-17 16:36:44 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2011-11-17 16:36:44 +00:00
|
|
|
GLint location = -1;
|
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2011-11-17 16:36:44 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
location = _get_uniform_location (shader, name);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UniformMatrix4x3fv (location, count, transpose, value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_OPENGL */
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
GLint
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar * name)
|
2008-09-06 22:45:34 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2015-09-04 06:02:32 +00:00
|
|
|
gint ret;
|
2008-09-06 22:45:34 +00:00
|
|
|
|
2015-03-13 17:41:17 +00:00
|
|
|
g_return_val_if_fail (shader != NULL, -1);
|
2008-09-06 22:45:34 +00:00
|
|
|
priv = shader->priv;
|
2015-03-13 17:41:17 +00:00
|
|
|
g_return_val_if_fail (priv->program_handle != 0, -1);
|
2015-03-13 17:04:17 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2008-09-06 22:45:34 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
ret = gl->GetAttribLocation (priv->program_handle, name);
|
|
|
|
|
|
|
|
GST_TRACE_OBJECT (shader, "retreived program %i attribute \'%s\' location %i",
|
|
|
|
(int) priv->program_handle, name, ret);
|
|
|
|
|
|
|
|
return ret;
|
2008-09-06 22:45:34 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
void
|
2010-10-19 15:00:33 +00:00
|
|
|
gst_gl_shader_bind_attribute_location (GstGLShader * shader, GLuint index,
|
|
|
|
const gchar * name)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2009-10-22 23:11:27 +00:00
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program_handle != 0);
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = shader->context->gl_vtable;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_TRACE_OBJECT (shader, "binding program %i attribute \'%s\' location %i",
|
|
|
|
(int) priv->program_handle, name, index);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
gl->BindAttribLocation (priv->program_handle, index, name);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
2016-03-31 08:25:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_shader_bind_frag_data_location (GstGLShader * shader,
|
|
|
|
guint index, const gchar * name)
|
|
|
|
{
|
|
|
|
GstGLShaderPrivate *priv;
|
|
|
|
GstGLFuncs *gl;
|
|
|
|
|
|
|
|
g_return_if_fail (shader != NULL);
|
|
|
|
if (!_ensure_program (shader))
|
|
|
|
g_return_if_fail (shader->priv->program_handle);
|
|
|
|
priv = shader->priv;
|
|
|
|
gl = shader->context->gl_vtable;
|
|
|
|
g_return_if_fail (gl->BindFragDataLocation);
|
|
|
|
|
|
|
|
GST_TRACE_OBJECT (shader, "binding program %i frag data \'%s\' location %i",
|
|
|
|
(int) priv->program_handle, name, index);
|
|
|
|
|
|
|
|
gl->BindFragDataLocation (priv->program_handle, index, name);
|
|
|
|
}
|