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
|
|
|
|
|
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,
|
2018-06-23 19:33:16 +00:00
|
|
|
G_ADD_PRIVATE (GstGLShader) 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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
priv = self->priv = gst_gl_shader_get_instance_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);
|
|
|
|
}
|
|
|
|
|
2018-09-03 06:06:45 +00:00
|
|
|
GST_TRACE_OBJECT (shader, "Retrieved uniform \'%s\' location %i", name,
|
|
|
|
location);
|
|
|
|
|
2016-02-10 05:37:22 +00:00
|
|
|
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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @error: (optional): 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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @error: (optional): 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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @error: (optional): 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)) {
|
2019-08-29 17:42:39 +00:00
|
|
|
GST_WARNING_OBJECT (shader, "Failed to retrieve required GLSL functions");
|
2015-09-04 06:02:32 +00:00
|
|
|
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)
|
2018-09-03 06:06:45 +00:00
|
|
|
g_assert (shader->context->gl_vtable->IsProgram (shader->
|
|
|
|
priv->program_handle));
|
2016-03-10 06:46:05 +00:00
|
|
|
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)) {
|
2019-08-29 17:42:39 +00:00
|
|
|
GST_WARNING_OBJECT (shader, "Failed to retrieve 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)
|
2018-09-03 06:06:45 +00:00
|
|
|
g_assert (shader->context->gl_vtable->IsProgram (shader->
|
|
|
|
priv->program_handle));
|
2016-03-10 06:46:05 +00:00
|
|
|
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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @error: (optional): a #GError
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @error: (optional): a #GError
|
2015-09-04 06:02:32 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2019-08-29 17:42:39 +00:00
|
|
|
"Failed to retrieve required GLSL functions");
|
2015-09-04 06:02:32 +00:00
|
|
|
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) {
|
2019-12-11 09:07:12 +00:00
|
|
|
GST_FIXME ("shader link log:\n%s", 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);
|
|
|
|
}
|
|
|
|
|
2018-09-03 06:06:45 +00:00
|
|
|
#define set_uniform_pre_check(shader, name) \
|
|
|
|
GLint location = -1; \
|
|
|
|
g_return_if_fail (shader != NULL); \
|
|
|
|
g_return_if_fail (shader->priv->program_handle != 0); \
|
|
|
|
location = _get_uniform_location (shader, name);
|
|
|
|
|
2018-11-22 10:10:53 +00:00
|
|
|
#ifdef G_HAVE_ISO_VARARGS
|
2018-09-03 06:06:45 +00:00
|
|
|
|
|
|
|
#define set_uniform_v(gl_suffix, c_type, debug_stride, debug_str, ...) \
|
|
|
|
void \
|
|
|
|
G_PASTE(gst_gl_shader_set_uniform_,gl_suffix) (GstGLShader * shader, \
|
|
|
|
const gchar * name, guint count, const c_type * value) \
|
|
|
|
{ \
|
|
|
|
guint i; \
|
|
|
|
set_uniform_pre_check(shader, name) \
|
|
|
|
for (i = 0; i < count; i++) { \
|
|
|
|
const c_type * item = &value[i * debug_stride]; \
|
|
|
|
GST_TRACE_OBJECT (shader, "Setting uniform %s (%i) index %i to " \
|
|
|
|
debug_str, name, location, i, __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
shader->context->gl_vtable->G_PASTE(Uniform,gl_suffix) (location, count, value); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define set_uniform_func_decl(gl_suffix, ...) \
|
|
|
|
void \
|
|
|
|
G_PASTE(gst_gl_shader_set_uniform_,gl_suffix) (GstGLShader * shader, \
|
|
|
|
const gchar * name, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define set_uniform_body(gl_suffix, debug_str, ...) \
|
|
|
|
{ \
|
|
|
|
set_uniform_pre_check(shader, name) \
|
|
|
|
GST_TRACE_OBJECT (shader, "Setting uniform %s (%i) = " debug_str, \
|
|
|
|
name, location, __VA_ARGS__); \
|
|
|
|
shader->context->gl_vtable->G_PASTE(Uniform,gl_suffix) (location, __VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* G_HAVE_ISO_VARARGS */
|
|
|
|
#if G_HAVE_GNUC_VARARGS
|
|
|
|
|
|
|
|
#define set_uniform_v(gl_suffix, c_type, debug_stride, debug_str, args...) \
|
|
|
|
void \
|
|
|
|
G_PASTE(gst_gl_shader_set_uniform_,gl_suffix) (GstGLShader * shader, \
|
|
|
|
const gchar * name, guint count, const c_type * value) \
|
|
|
|
{ \
|
|
|
|
guint i; \
|
|
|
|
set_uniform_pre_check(shader, name) \
|
|
|
|
for (i = 0; i < count; i++) { \
|
|
|
|
const c_type * item = &value[i * debug_stride]; \
|
|
|
|
GST_TRACE_OBJECT (shader, "Setting uniform %s (%i) index %i to " \
|
|
|
|
debug_str, name, location, i, ##args); \
|
|
|
|
} \
|
|
|
|
shader->context->gl_vtable->G_PASTE(Uniform,gl_suffix) (location, count, value); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define set_uniform_func_decl(gl_suffix, args...) \
|
|
|
|
void \
|
|
|
|
G_PASTE(gst_gl_shader_set_uniform_,gl_suffix) (GstGLShader * shader, \
|
|
|
|
const gchar * name, ##args)
|
|
|
|
|
|
|
|
#define set_uniform_body(gl_suffix, debug_str, args...) \
|
|
|
|
{ \
|
|
|
|
set_uniform_pre_check(shader, name) \
|
|
|
|
GST_TRACE_OBJECT (shader, "Setting uniform %s (%i) = " debug_str, \
|
|
|
|
name, location, ##args); \
|
|
|
|
shader->context->gl_vtable->G_PASTE(Uniform,gl_suffix) (location, ##args); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#error "No vararg support in C macros. What kind of C compiler is this?!"
|
|
|
|
|
|
|
|
#endif /* G_HAVE_GNUC_VARARGS */
|
|
|
|
#endif /* G_HAVE_ISO_VARARGS */
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_1f:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @value: value to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform1f()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(1f, float value)
|
|
|
|
set_uniform_body(1f, "%f", value);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_1fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform1fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(1fv, float, 1, "%f", item[0]);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_1i:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @value: value to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform1i()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(1i, int value)
|
|
|
|
set_uniform_body(1i, "%i", value);
|
2008-07-18 08:49:34 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_1iv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform1iv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(1iv, int, 1, "%i", item[0]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_2f:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform2f()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(2f, float v0, float v1)
|
|
|
|
set_uniform_body(2f, "%f, %f", v0, v1);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_2fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform2fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(2fv, float, 2, "%f, %f", item[0], item[1]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_2i:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform2i()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(2i, int v0, int v1)
|
|
|
|
set_uniform_body(2i, "%i, %i", v0, v1);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_2iv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform2iv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(2iv, int, 2, "%i, %i", item[0], item[1]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_3f:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
|
|
|
* @v2: third value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform3f()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(3f, float v0, float v1, float v2)
|
|
|
|
set_uniform_body(3f, "%f, %f, %f", v0, v1, v2);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_3fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform3fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(3fv, float, 3, "%f, %f, %f", item[0], item[1], item[2]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_3i:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
|
|
|
* @v2: third value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform3i()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(3i, int v0, int v1, int v2)
|
|
|
|
set_uniform_body(3i, "%i, %i, %i", v0, v1, v2);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_3iv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform3iv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(3iv, int, 3, "%i, %i, %i", item[0], item[1], item[2]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_4f:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
|
|
|
* @v2: third value to set
|
|
|
|
* @v3: fourth value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform4f()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(4f, float v0, float v1, float v2, float v3)
|
|
|
|
set_uniform_body(4f, "%f, %f, %f, %f", v0, v1, v2, v3);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_4fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform4fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(4fv, float, 4, "%f, %f, %f, %f", item[0], item[1], item[2], item[3]);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_4i:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
2018-02-05 03:58:06 +00:00
|
|
|
* @v0: first value to set
|
|
|
|
* @v1: second value to set
|
|
|
|
* @v2: third value to set
|
|
|
|
* @v3: fourth value to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform4i()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_func_decl(4i, int v0, int v1, int v2, int v3)
|
|
|
|
set_uniform_body(4i, "%i, %i, %i, %i", v0, v1, v2, v3);
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_4iv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of values to set
|
|
|
|
* @value: (array length=count): values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniform4iv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_v(4iv, int, 4, "%i, %i, %i, %i", item[0], item[1], item[2], item[3]);
|
|
|
|
/* *INDENT-ON* */
|
2011-11-17 16:36:44 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_2fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 2x2 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
2018-02-05 03:58:06 +00:00
|
|
|
* @value: matrix to set
|
2017-07-28 15:58:38 +00:00
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix2fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix2fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_3fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 3x3 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix3fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix3fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_4fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 4x4 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix4fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix4fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_2x3fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 2x3 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix2x3fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix2x3fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_2x4fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 2x4 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix2x4fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix2x4fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_3x2fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 3x2 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix3x2fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix3x2fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_3x4fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 3x4 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix3x4fv()` for @name on @shader
|
2017-07-28 15:58:38 +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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix3x4fv (location, count, transpose,
|
|
|
|
value);
|
2009-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_4x2fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 4x2 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix4x2fv()` for @name on @shader
|
2017-07-28 15:58:38 +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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix4x2fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_set_uniform_matrix_4x3fv:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the uniform
|
|
|
|
* @count: number of 4x3 matrices to set
|
|
|
|
* @transpose: transpose the matrix
|
|
|
|
* @value: values to set
|
|
|
|
*
|
2019-05-20 01:14:27 +00:00
|
|
|
* Perform `glUniformMatrix4x3fv()` for @name on @shader
|
2017-07-28 15:58:38 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2018-09-03 06:06:45 +00:00
|
|
|
set_uniform_pre_check (shader, name);
|
|
|
|
shader->context->gl_vtable->UniformMatrix4x3fv (location, count, transpose,
|
|
|
|
value);
|
2011-11-17 16:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_get_attribute_location:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @name: name of the attribute
|
|
|
|
*
|
|
|
|
* Returns: the attribute index for @name in @shader or -1 on failure
|
|
|
|
*/
|
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
|
|
|
{
|
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);
|
2018-09-03 06:06:45 +00:00
|
|
|
g_return_val_if_fail (shader->priv->program_handle != 0, -1);
|
2008-09-06 22:45:34 +00:00
|
|
|
|
2018-09-03 06:06:45 +00:00
|
|
|
ret =
|
|
|
|
shader->context->gl_vtable->GetAttribLocation (shader->priv->
|
|
|
|
program_handle, name);
|
2015-09-04 06:02:32 +00:00
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
GST_TRACE_OBJECT (shader, "retrieved program %i attribute \'%s\' location %i",
|
2018-09-03 06:06:45 +00:00
|
|
|
(int) shader->priv->program_handle, name, ret);
|
2015-09-04 06:02:32 +00:00
|
|
|
|
|
|
|
return ret;
|
2008-09-06 22:45:34 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_bind_attribute_location:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @index: attribute index to set
|
|
|
|
* @name: name of the attribute
|
|
|
|
*
|
|
|
|
* Bind attribute @name to the specified location @index using
|
2019-05-20 01:14:27 +00:00
|
|
|
* `glBindAttributeLocation()`.
|
2017-07-28 15:58:38 +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
|
|
|
{
|
2012-12-07 02:32:28 +00:00
|
|
|
g_return_if_fail (shader != NULL);
|
2018-09-03 06:06:45 +00:00
|
|
|
g_return_if_fail (shader->priv->program_handle != 0);
|
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",
|
2018-09-03 06:06:45 +00:00
|
|
|
(int) shader->priv->program_handle, name, index);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2018-09-03 06:06:45 +00:00
|
|
|
shader->context->gl_vtable->BindAttribLocation (shader->priv->program_handle,
|
|
|
|
index, name);
|
2008-07-18 08:49:34 +00:00
|
|
|
}
|
2016-03-31 08:25:32 +00:00
|
|
|
|
2017-07-28 15:58:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_shader_bind_frag_data_location:
|
|
|
|
* @shader: a #GstGLShader
|
|
|
|
* @index: attribute index to set
|
|
|
|
* @name: name of the attribute
|
|
|
|
*
|
|
|
|
* Bind attribute @name to the specified location @index using
|
2019-05-20 01:14:27 +00:00
|
|
|
* `glBindFragDataLocation()`.
|
2017-07-28 15:58:38 +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)
|
|
|
|
{
|
|
|
|
g_return_if_fail (shader != NULL);
|
|
|
|
if (!_ensure_program (shader))
|
|
|
|
g_return_if_fail (shader->priv->program_handle);
|
2018-09-03 06:06:45 +00:00
|
|
|
g_return_if_fail (shader->context->gl_vtable->BindFragDataLocation);
|
2016-03-31 08:25:32 +00:00
|
|
|
|
|
|
|
GST_TRACE_OBJECT (shader, "binding program %i frag data \'%s\' location %i",
|
2018-09-03 06:06:45 +00:00
|
|
|
(int) shader->priv->program_handle, name, index);
|
2016-03-31 08:25:32 +00:00
|
|
|
|
2018-09-03 06:06:45 +00:00
|
|
|
shader->context->gl_vtable->BindFragDataLocation (shader->priv->
|
|
|
|
program_handle, index, name);
|
2016-03-31 08:25:32 +00:00
|
|
|
}
|