2007-12-03 16:29:18 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2009-02-28 17:19:05 +00:00
|
|
|
* Authored By: Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Øyvind Kolås <pippin@o-hand.com>
|
|
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
2007-12-03 16:29:18 +00:00
|
|
|
*
|
2009-02-28 17:19:05 +00:00
|
|
|
* Copyright (C) 2007, 2008 OpenedHand
|
|
|
|
* Copyright (C) 2009 Intel Corp
|
2007-12-03 16:29:18 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-12-03 16:29:18 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-15 14:36:27 +00:00
|
|
|
/**
|
|
|
|
* SECTION:clutter-shader
|
|
|
|
* @short_description: Programmable pipeline abstraction
|
|
|
|
*
|
|
|
|
* #ClutterShader is an object providing an abstraction over the
|
|
|
|
* OpenGL programmable pipeline. By using #ClutterShader<!-- -->s is
|
|
|
|
* possible to override the drawing pipeline by using small programs
|
|
|
|
* also known as "shaders".
|
|
|
|
*
|
2011-05-25 15:23:08 +00:00
|
|
|
* #ClutterShader is available since Clutter 0.6.
|
|
|
|
*
|
|
|
|
* #ClutterShader is deprecated since Clutter 1.8; use #ClutterShaderEffect
|
|
|
|
* in newly written code.
|
2007-12-15 14:36:27 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2007-12-03 16:29:18 +00:00
|
|
|
#include <unistd.h>
|
2007-12-11 14:49:41 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-14 10:34:38 +00:00
|
|
|
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
#include <glib.h>
|
2009-02-28 17:19:05 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2011-05-25 15:23:08 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "clutter-shader.h"
|
2007-12-11 14:49:41 +00:00
|
|
|
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
/* global list of shaders */
|
2007-12-11 14:49:41 +00:00
|
|
|
static GList *clutter_shaders_list = NULL;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
#define CLUTTER_SHADER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_SHADER, ClutterShaderPrivate))
|
2007-12-03 16:29:18 +00:00
|
|
|
|
|
|
|
struct _ClutterShaderPrivate
|
|
|
|
{
|
2008-04-11 12:00:50 +00:00
|
|
|
guint compiled : 1; /* Shader is bound to the GL context */
|
2008-01-16 10:38:05 +00:00
|
|
|
guint is_enabled : 1;
|
|
|
|
guint vertex_is_glsl : 1;
|
|
|
|
guint fragment_is_glsl : 1;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2008-01-16 10:38:05 +00:00
|
|
|
gchar *vertex_source; /* GLSL source for vertex shader */
|
|
|
|
gchar *fragment_source; /* GLSL source for fragment shader */
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2008-04-29 16:10:37 +00:00
|
|
|
CoglHandle program;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2008-04-29 16:10:37 +00:00
|
|
|
CoglHandle vertex_shader;
|
|
|
|
CoglHandle fragment_shader;
|
2007-12-03 16:29:18 +00:00
|
|
|
};
|
|
|
|
|
2009-05-12 13:15:18 +00:00
|
|
|
enum
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
|
|
|
PROP_0,
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
PROP_VERTEX_SOURCE,
|
2007-12-11 14:49:41 +00:00
|
|
|
PROP_FRAGMENT_SOURCE,
|
2008-04-11 12:00:50 +00:00
|
|
|
PROP_COMPILED,
|
2010-06-21 09:20:32 +00:00
|
|
|
PROP_ENABLED,
|
|
|
|
|
|
|
|
PROP_LAST
|
2007-12-03 16:29:18 +00:00
|
|
|
};
|
|
|
|
|
2010-06-21 09:20:32 +00:00
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
G_DEFINE_TYPE (ClutterShader, clutter_shader, G_TYPE_OBJECT);
|
|
|
|
|
2011-01-11 10:23:59 +00:00
|
|
|
static inline void
|
|
|
|
clutter_shader_release_internal (ClutterShader *shader)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv = shader->priv;
|
|
|
|
|
|
|
|
if (!priv->compiled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_assert (priv->program != COGL_INVALID_HANDLE);
|
|
|
|
|
|
|
|
if (priv->vertex_is_glsl && priv->vertex_shader != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (priv->vertex_shader);
|
|
|
|
|
|
|
|
if (priv->fragment_is_glsl && priv->fragment_shader != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (priv->fragment_shader);
|
|
|
|
|
|
|
|
if (priv->program != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (priv->program);
|
|
|
|
|
|
|
|
priv->vertex_shader = COGL_INVALID_HANDLE;
|
|
|
|
priv->fragment_shader = COGL_INVALID_HANDLE;
|
|
|
|
priv->program = COGL_INVALID_HANDLE;
|
|
|
|
priv->compiled = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
static void
|
|
|
|
clutter_shader_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterShader *shader;
|
|
|
|
ClutterShaderPrivate *priv;
|
|
|
|
|
|
|
|
shader = CLUTTER_SHADER (object);
|
|
|
|
priv = shader->priv;
|
|
|
|
|
|
|
|
clutter_shaders_list = g_list_remove (clutter_shaders_list, object);
|
|
|
|
|
|
|
|
g_free (priv->fragment_source);
|
|
|
|
g_free (priv->vertex_source);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_shader_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-01-11 10:23:59 +00:00
|
|
|
static void
|
|
|
|
clutter_shader_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterShader *shader = CLUTTER_SHADER (object);
|
|
|
|
|
|
|
|
clutter_shader_release_internal (shader);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_shader_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
static void
|
|
|
|
clutter_shader_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterShader *shader = CLUTTER_SHADER(object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_VERTEX_SOURCE:
|
2009-05-12 13:15:18 +00:00
|
|
|
clutter_shader_set_vertex_source (shader,
|
2008-02-03 01:53:10 +00:00
|
|
|
g_value_get_string (value), -1);
|
2007-12-11 14:49:41 +00:00
|
|
|
break;
|
|
|
|
case PROP_FRAGMENT_SOURCE:
|
2009-05-12 13:15:18 +00:00
|
|
|
clutter_shader_set_fragment_source (shader,
|
2008-02-03 01:53:10 +00:00
|
|
|
g_value_get_string (value), -1);
|
2007-12-11 14:49:41 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENABLED:
|
|
|
|
clutter_shader_set_is_enabled (shader, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_shader_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterShader *shader;
|
|
|
|
ClutterShaderPrivate *priv;
|
|
|
|
|
|
|
|
shader = CLUTTER_SHADER(object);
|
|
|
|
priv = shader->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_VERTEX_SOURCE:
|
|
|
|
g_value_set_string (value, priv->vertex_source);
|
|
|
|
break;
|
|
|
|
case PROP_FRAGMENT_SOURCE:
|
|
|
|
g_value_set_string (value, priv->fragment_source);
|
|
|
|
break;
|
2008-04-11 12:00:50 +00:00
|
|
|
case PROP_COMPILED:
|
|
|
|
g_value_set_boolean (value, priv->compiled);
|
2007-12-11 14:49:41 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENABLED:
|
|
|
|
g_value_set_boolean (value, priv->is_enabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
clutter_shader_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
2008-02-04 22:38:27 +00:00
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *object;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2008-02-04 22:38:27 +00:00
|
|
|
parent_class = G_OBJECT_CLASS (clutter_shader_parent_class);
|
|
|
|
object = parent_class->constructor (type, n_params, params);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
|
|
|
/* add this instance to the global list of shaders */
|
|
|
|
clutter_shaders_list = g_list_prepend (clutter_shaders_list, object);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
static void
|
|
|
|
clutter_shader_class_init (ClutterShaderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2009-02-28 17:19:05 +00:00
|
|
|
GParamSpec *pspec = NULL;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
|
|
|
object_class->finalize = clutter_shader_finalize;
|
2011-01-11 10:23:59 +00:00
|
|
|
object_class->dispose = clutter_shader_dispose;
|
2007-12-03 16:29:18 +00:00
|
|
|
object_class->set_property = clutter_shader_set_property;
|
|
|
|
object_class->get_property = clutter_shader_get_property;
|
|
|
|
object_class->constructor = clutter_shader_constructor;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (ClutterShaderPrivate));
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* ClutterShader:vertex-source:
|
|
|
|
*
|
2009-02-28 17:19:05 +00:00
|
|
|
* GLSL source code for the vertex shader part of the shader
|
|
|
|
* program, if any
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2009-02-28 17:19:05 +00:00
|
|
|
pspec = g_param_spec_string ("vertex-source",
|
2010-06-03 11:57:50 +00:00
|
|
|
P_("Vertex Source"),
|
|
|
|
P_("Source of vertex shader"),
|
2009-02-28 17:19:05 +00:00
|
|
|
NULL,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
2010-06-21 09:20:32 +00:00
|
|
|
obj_props[PROP_VERTEX_SOURCE] = pspec;
|
2009-02-28 17:19:05 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_VERTEX_SOURCE, pspec);
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* ClutterShader:fragment-source:
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* GLSL source code for the fragment shader part of the shader program.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2009-02-28 17:19:05 +00:00
|
|
|
pspec = g_param_spec_string ("fragment-source",
|
2010-06-03 11:57:50 +00:00
|
|
|
P_("Fragment Source"),
|
|
|
|
P_("Source of fragment shader"),
|
2009-02-28 17:19:05 +00:00
|
|
|
NULL,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
2010-06-21 09:20:32 +00:00
|
|
|
obj_props[PROP_FRAGMENT_SOURCE] = pspec;
|
2009-02-28 17:19:05 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_FRAGMENT_SOURCE, pspec);
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
2008-04-11 12:00:50 +00:00
|
|
|
* ClutterShader:compiled:
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Whether the shader is compiled and linked, ready for use
|
|
|
|
* in the GL context.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Since: 0.8
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2009-02-28 17:19:05 +00:00
|
|
|
pspec = g_param_spec_boolean ("compiled",
|
2010-06-03 11:57:50 +00:00
|
|
|
P_("Compiled"),
|
|
|
|
P_("Whether the shader is compiled and linked"),
|
2009-02-28 17:19:05 +00:00
|
|
|
FALSE,
|
|
|
|
CLUTTER_PARAM_READABLE);
|
2010-06-21 09:20:32 +00:00
|
|
|
obj_props[PROP_COMPILED] = pspec;
|
2009-02-28 17:19:05 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_COMPILED, pspec);
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* ClutterShader:enabled:
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Whether the shader is currently used in the GL rendering pipeline.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2009-02-28 17:19:05 +00:00
|
|
|
pspec = g_param_spec_boolean ("enabled",
|
2010-06-03 11:57:50 +00:00
|
|
|
P_("Enabled"),
|
|
|
|
P_("Whether the shader is enabled"),
|
2009-02-28 17:19:05 +00:00
|
|
|
FALSE,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
2010-06-21 09:20:32 +00:00
|
|
|
obj_props[PROP_ENABLED] = pspec;
|
2009-02-28 17:19:05 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_ENABLED, pspec);
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_shader_init (ClutterShader *self)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv = CLUTTER_SHADER_GET_PRIVATE (self);
|
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
priv->compiled = FALSE;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
|
|
|
priv->vertex_source = NULL;
|
|
|
|
priv->fragment_source = NULL;
|
|
|
|
|
2008-04-29 16:10:37 +00:00
|
|
|
priv->program = COGL_INVALID_HANDLE;
|
|
|
|
priv->vertex_shader = COGL_INVALID_HANDLE;
|
|
|
|
priv->fragment_shader = COGL_INVALID_HANDLE;
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_new:
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Create a new #ClutterShader instance.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Return value: a new #ClutterShader.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
ClutterShader *
|
|
|
|
clutter_shader_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CLUTTER_TYPE_SHADER, NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
static inline void
|
|
|
|
clutter_shader_set_source (ClutterShader *shader,
|
|
|
|
ClutterShaderType shader_type,
|
|
|
|
const gchar *data,
|
|
|
|
gssize length)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv = shader->priv;
|
|
|
|
gboolean is_glsl = FALSE;
|
|
|
|
|
|
|
|
if (length < 0)
|
|
|
|
length = strlen (data);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (shader));
|
|
|
|
|
|
|
|
/* release shader if bound when changing the source, the shader will
|
|
|
|
* automatically be rebound on the next use.
|
|
|
|
*/
|
|
|
|
if (clutter_shader_is_compiled (shader))
|
|
|
|
clutter_shader_release (shader);
|
|
|
|
|
|
|
|
is_glsl = !g_str_has_prefix (data, "!!ARBfp");
|
|
|
|
|
|
|
|
CLUTTER_NOTE (SHADER,
|
|
|
|
"setting %s shader (GLSL:%s, len:%" G_GSSIZE_FORMAT ")",
|
|
|
|
shader_type == CLUTTER_VERTEX_SHADER ? "vertex" : "fragment",
|
|
|
|
is_glsl ? "yes" : "no",
|
|
|
|
length);
|
|
|
|
|
|
|
|
switch (shader_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_FRAGMENT_SHADER:
|
|
|
|
g_free (priv->fragment_source);
|
|
|
|
|
|
|
|
priv->fragment_source = g_strndup (data, length);
|
|
|
|
priv->fragment_is_glsl = is_glsl;
|
2011-03-03 11:35:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (shader), obj_props[PROP_FRAGMENT_SOURCE]);
|
2009-02-28 17:19:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_VERTEX_SHADER:
|
|
|
|
g_free (priv->vertex_source);
|
|
|
|
|
|
|
|
priv->vertex_source = g_strndup (data, length);
|
|
|
|
priv->vertex_is_glsl = is_glsl;
|
2011-03-03 11:35:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (shader), obj_props[PROP_VERTEX_SOURCE]);
|
2009-02-28 17:19:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (shader));
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_shader_set_fragment_source:
|
|
|
|
* @shader: a #ClutterShader
|
2008-01-25 17:20:33 +00:00
|
|
|
* @data: GLSL source code.
|
|
|
|
* @length: length of source buffer (currently ignored)
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Sets the GLSL source code to be used by a #ClutterShader for the fragment
|
|
|
|
* program.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_shader_set_fragment_source (ClutterShader *shader,
|
|
|
|
const gchar *data,
|
|
|
|
gssize length)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_IS_SHADER (shader));
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
clutter_shader_set_source (shader, CLUTTER_FRAGMENT_SHADER, data, length);
|
2007-12-11 14:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_shader_set_vertex_source:
|
|
|
|
* @shader: a #ClutterShader
|
2008-01-25 17:20:33 +00:00
|
|
|
* @data: GLSL source code.
|
|
|
|
* @length: length of source buffer (currently ignored)
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Sets the GLSL source code to be used by a #ClutterShader for the vertex
|
|
|
|
* program.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_shader_set_vertex_source (ClutterShader *shader,
|
|
|
|
const gchar *data,
|
|
|
|
gssize length)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_IS_SHADER (shader));
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
clutter_shader_set_source (shader, CLUTTER_VERTEX_SHADER, data, length);
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
static const gchar *
|
|
|
|
clutter_shader_get_source (ClutterShader *shader,
|
|
|
|
ClutterShaderType shader_type)
|
|
|
|
{
|
|
|
|
switch (shader_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_FRAGMENT_SHADER:
|
|
|
|
return shader->priv->fragment_source;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
case CLUTTER_VERTEX_SHADER:
|
|
|
|
return shader->priv->vertex_source;
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
static CoglHandle
|
|
|
|
clutter_shader_get_cogl_shader (ClutterShader *shader,
|
|
|
|
ClutterShaderType shader_type)
|
|
|
|
{
|
|
|
|
switch (shader_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_FRAGMENT_SHADER:
|
|
|
|
return shader->priv->fragment_shader;
|
|
|
|
|
|
|
|
case CLUTTER_VERTEX_SHADER:
|
|
|
|
return shader->priv->vertex_shader;
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
return COGL_INVALID_HANDLE;
|
2007-12-11 14:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-28 17:19:05 +00:00
|
|
|
clutter_shader_glsl_bind (ClutterShader *self,
|
|
|
|
ClutterShaderType shader_type,
|
|
|
|
GError **error)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2009-02-28 17:19:05 +00:00
|
|
|
ClutterShaderPrivate *priv = self->priv;
|
|
|
|
CoglHandle shader = COGL_INVALID_HANDLE;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
switch (shader_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_VERTEX_SHADER:
|
2009-05-12 13:15:18 +00:00
|
|
|
shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX);
|
2009-02-28 17:19:05 +00:00
|
|
|
cogl_shader_source (shader, priv->vertex_source);
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
priv->vertex_shader = shader;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_FRAGMENT_SHADER:
|
2009-05-12 13:15:18 +00:00
|
|
|
shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT);
|
2009-02-28 17:19:05 +00:00
|
|
|
cogl_shader_source (shader, priv->fragment_source);
|
|
|
|
|
|
|
|
priv->fragment_shader = shader;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (shader != COGL_INVALID_HANDLE);
|
|
|
|
|
|
|
|
cogl_shader_compile (shader);
|
2009-05-12 13:15:18 +00:00
|
|
|
if (!cogl_shader_is_compiled (shader))
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2009-06-01 15:31:32 +00:00
|
|
|
gchar *log_buf;
|
2008-06-26 13:54:13 +00:00
|
|
|
|
2009-06-01 15:31:32 +00:00
|
|
|
log_buf = cogl_shader_get_info_log (shader);
|
2008-06-26 13:54:13 +00:00
|
|
|
|
2009-06-01 15:31:32 +00:00
|
|
|
/* translators: the first %s is the type of the shader, either
|
|
|
|
* Vertex shader or Fragment shader; the second %s is the actual
|
|
|
|
* error as reported by COGL
|
|
|
|
*/
|
2009-02-28 17:19:05 +00:00
|
|
|
g_set_error (error, CLUTTER_SHADER_ERROR,
|
|
|
|
CLUTTER_SHADER_ERROR_COMPILE,
|
|
|
|
_("%s compilation failed: %s"),
|
|
|
|
shader_type == CLUTTER_VERTEX_SHADER ? _("Vertex shader")
|
|
|
|
: _("Fragment shader"),
|
2009-06-01 15:31:32 +00:00
|
|
|
log_buf);
|
|
|
|
|
|
|
|
g_free (log_buf);
|
2008-06-26 13:54:13 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_program_attach_shader (priv->program, shader);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
bind_glsl_shader (ClutterShader *self,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv = self->priv;
|
|
|
|
GError *bind_error = NULL;
|
|
|
|
gboolean res;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
priv->program = cogl_create_program ();
|
2008-06-26 13:54:13 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
if (priv->vertex_is_glsl && priv->vertex_source != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
res = clutter_shader_glsl_bind (self,
|
|
|
|
CLUTTER_VERTEX_SHADER,
|
|
|
|
&bind_error);
|
2008-06-26 13:54:13 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, bind_error);
|
2008-06-26 13:54:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2008-04-29 16:10:37 +00:00
|
|
|
if (priv->fragment_is_glsl && priv->fragment_source != COGL_INVALID_HANDLE)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2009-02-28 17:19:05 +00:00
|
|
|
res = clutter_shader_glsl_bind (self,
|
|
|
|
CLUTTER_FRAGMENT_SHADER,
|
|
|
|
&bind_error);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2009-02-28 17:19:05 +00:00
|
|
|
if (!res)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2009-02-28 17:19:05 +00:00
|
|
|
g_propagate_error (error, bind_error);
|
2007-12-03 16:29:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
cogl_program_link (priv->program);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2007-12-03 16:29:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
2008-04-11 12:00:50 +00:00
|
|
|
* clutter_shader_compile:
|
2007-12-11 14:49:41 +00:00
|
|
|
* @shader: a #ClutterShader
|
2007-12-15 14:36:27 +00:00
|
|
|
* @error: return location for a #GError, or %NULL
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Compiles and links GLSL sources set for vertex and fragment shaders for
|
2008-01-25 17:20:33 +00:00
|
|
|
* a #ClutterShader. If the compilation fails and a #GError return location is
|
|
|
|
* provided the error will contain the errors from the compiler, if any.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Return value: returns TRUE if the shader was succesfully compiled.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Since: 0.8
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2007-12-03 16:29:18 +00:00
|
|
|
gboolean
|
2008-04-11 12:00:50 +00:00
|
|
|
clutter_shader_compile (ClutterShader *shader,
|
|
|
|
GError **error)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv;
|
2007-12-11 14:49:41 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), FALSE);
|
|
|
|
|
|
|
|
priv = shader->priv;
|
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
if (priv->compiled)
|
|
|
|
return priv->compiled;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2008-04-29 16:10:37 +00:00
|
|
|
if ((priv->vertex_source != COGL_INVALID_HANDLE && !priv->vertex_is_glsl) ||
|
|
|
|
(priv->fragment_source != COGL_INVALID_HANDLE && !priv->fragment_is_glsl))
|
2007-12-11 14:49:41 +00:00
|
|
|
{
|
2008-01-25 17:20:33 +00:00
|
|
|
/* XXX: Could remove this check, since we only advertise support for GLSL
|
|
|
|
* shaders anyways. */
|
2007-12-11 14:49:41 +00:00
|
|
|
g_set_error (error, CLUTTER_SHADER_ERROR,
|
|
|
|
CLUTTER_SHADER_ERROR_NO_ASM,
|
|
|
|
"ASM shaders not supported");
|
2008-04-11 12:00:50 +00:00
|
|
|
priv->compiled = FALSE;
|
|
|
|
return priv->compiled;
|
2007-12-11 14:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL))
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_set_error (error, CLUTTER_SHADER_ERROR,
|
|
|
|
CLUTTER_SHADER_ERROR_NO_GLSL,
|
|
|
|
"GLSL shaders not supported");
|
2008-04-11 12:00:50 +00:00
|
|
|
priv->compiled = FALSE;
|
|
|
|
return priv->compiled;
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
priv->compiled = bind_glsl_shader (shader, error);
|
2011-03-03 11:35:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (shader), obj_props[PROP_COMPILED]);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
return priv->compiled;
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_release:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Frees up any GL context resources held by the shader.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
2007-12-03 16:29:18 +00:00
|
|
|
void
|
2007-12-11 14:49:41 +00:00
|
|
|
clutter_shader_release (ClutterShader *shader)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_SHADER (shader));
|
|
|
|
|
2011-01-11 10:23:59 +00:00
|
|
|
clutter_shader_release_internal (shader);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2011-03-03 11:35:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (shader), obj_props[PROP_COMPILED]);
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
2008-04-11 12:00:50 +00:00
|
|
|
* clutter_shader_is_compiled:
|
2007-12-11 14:49:41 +00:00
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
2008-02-03 01:53:10 +00:00
|
|
|
* Checks whether @shader is is currently compiled, linked and bound
|
|
|
|
* to the GL context.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Return value: %TRUE if the shader is compiled, linked and ready for use.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Since: 0.8
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2008-04-11 12:00:50 +00:00
|
|
|
clutter_shader_is_compiled (ClutterShader *shader)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), FALSE);
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
return shader->priv->compiled;
|
2007-12-11 14:49:41 +00:00
|
|
|
}
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_set_is_enabled:
|
|
|
|
* @shader: a #ClutterShader
|
2008-01-25 17:20:33 +00:00
|
|
|
* @enabled: The new state of the shader.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-04-11 12:00:50 +00:00
|
|
|
* Enables a shader. This function will attempt to compile and link
|
|
|
|
* the shader, if it isn't already.
|
|
|
|
*
|
|
|
|
* When @enabled is %FALSE the default state of the GL pipeline will be
|
|
|
|
* used instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_shader_set_is_enabled (ClutterShader *shader,
|
|
|
|
gboolean enabled)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_SHADER (shader));
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
priv = shader->priv;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
if (priv->is_enabled != enabled)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean res;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2008-04-11 12:00:50 +00:00
|
|
|
res = clutter_shader_compile (shader, &error);
|
2007-12-11 14:49:41 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
g_warning ("Unable to bind the shader: %s",
|
|
|
|
error ? error->message : "unknown error");
|
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
priv->is_enabled = enabled;
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
if (priv->is_enabled)
|
|
|
|
cogl_program_use (priv->program);
|
|
|
|
else
|
2008-04-29 16:10:37 +00:00
|
|
|
cogl_program_use (COGL_INVALID_HANDLE);
|
2007-12-11 14:49:41 +00:00
|
|
|
|
2011-03-03 11:35:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (shader), obj_props[PROP_ENABLED]);
|
2007-12-11 14:49:41 +00:00
|
|
|
}
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_get_is_enabled:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Checks whether @shader is enabled.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Return value: %TRUE if the shader is enabled.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_shader_get_is_enabled (ClutterShader *shader)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), FALSE);
|
|
|
|
|
|
|
|
return shader->priv->is_enabled;
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 15:08:40 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_set_uniform:
|
|
|
|
* @shader: a #ClutterShader.
|
|
|
|
* @name: name of uniform in GLSL shader program to set.
|
|
|
|
* @value: a #ClutterShaderFloat, #ClutterShaderInt or #ClutterShaderMatrix
|
|
|
|
* #GValue.
|
|
|
|
*
|
|
|
|
* Sets a user configurable variable in the GLSL shader programs attached to
|
|
|
|
* a #ClutterShader.
|
|
|
|
*
|
|
|
|
* Since: 1.0
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2008-11-18 15:08:40 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_shader_set_uniform (ClutterShader *shader,
|
|
|
|
const gchar *name,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
|
|
|
ClutterShaderPrivate *priv;
|
|
|
|
GLint location = 0;
|
|
|
|
gsize size;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_SHADER (shader));
|
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value) ||
|
|
|
|
CLUTTER_VALUE_HOLDS_SHADER_INT (value) ||
|
|
|
|
CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value) ||
|
|
|
|
G_VALUE_HOLDS_FLOAT (value) ||
|
|
|
|
G_VALUE_HOLDS_INT (value));
|
|
|
|
|
|
|
|
priv = shader->priv;
|
|
|
|
g_return_if_fail (priv->program != COGL_INVALID_HANDLE);
|
|
|
|
|
|
|
|
location = cogl_program_get_uniform_location (priv->program, name);
|
|
|
|
|
|
|
|
if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value))
|
|
|
|
{
|
|
|
|
const GLfloat *floats;
|
|
|
|
|
|
|
|
floats = clutter_value_get_shader_float (value, &size);
|
2010-08-11 18:32:09 +00:00
|
|
|
cogl_program_set_uniform_float (priv->program,
|
|
|
|
location, size, 1, floats);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
else if (CLUTTER_VALUE_HOLDS_SHADER_INT (value))
|
|
|
|
{
|
2009-05-12 13:15:18 +00:00
|
|
|
const int *ints;
|
2008-11-18 15:08:40 +00:00
|
|
|
|
|
|
|
ints = clutter_value_get_shader_int (value, &size);
|
2010-08-11 18:32:09 +00:00
|
|
|
cogl_program_set_uniform_int (priv->program,
|
|
|
|
location, size, 1, ints);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value))
|
|
|
|
{
|
|
|
|
const GLfloat *matrix;
|
|
|
|
|
|
|
|
matrix = clutter_value_get_shader_matrix (value, &size);
|
2010-08-11 18:32:09 +00:00
|
|
|
cogl_program_set_uniform_matrix (priv->program,
|
|
|
|
location, size, 1, FALSE, matrix);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_FLOAT (value))
|
|
|
|
{
|
|
|
|
GLfloat float_val = g_value_get_float (value);
|
|
|
|
|
2010-08-11 18:32:09 +00:00
|
|
|
cogl_program_set_uniform_float (priv->program,
|
|
|
|
location, 1, 1, &float_val);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_INT (value))
|
|
|
|
{
|
2009-05-12 13:15:18 +00:00
|
|
|
int int_val = g_value_get_int (value);
|
2008-11-18 15:08:40 +00:00
|
|
|
|
2010-08-11 18:32:09 +00:00
|
|
|
cogl_program_set_uniform_int (priv->program,
|
|
|
|
location, 1, 1, &int_val);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2007-12-03 16:29:18 +00:00
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_get_fragment_source:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Query the current GLSL fragment source set on @shader.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-02-03 01:53:10 +00:00
|
|
|
* Return value: the source of the fragment shader for this
|
|
|
|
* ClutterShader object or %NULL. The returned string is owned by the
|
|
|
|
* shader object and should never be modified or freed
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
Eliminate G_CONST_RETURN
The G_CONST_RETURN define in GLib is, and has always been, a bit fuzzy.
We always used it to conform to the platform, at least for public-facing
API.
At first I assumed it has something to do with brain-damaged compilers
or with weird platforms where const was not really supported; sadly,
it's something much, much worse: it's a define that can be toggled at
compile-time to remove const from the signature of public API. This is a
truly terrifying feature that I assume was added in the past century,
and whose inception clearly had something to do with massive doses of
absynthe and opium — because any other explanation would make the
existence of such a feature even worse than assuming drugs had anything
to do with it.
Anyway, and pleasing the gods, this dubious feature is being
removed/deprecated in GLib; see bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
Before deprecation, though, we should just remove its usage from the
whole API. We should especially remove its usage from Cally's internals,
since there it never made sense in the first place.
2011-06-07 14:49:20 +00:00
|
|
|
const gchar *
|
2007-12-11 14:49:41 +00:00
|
|
|
clutter_shader_get_fragment_source (ClutterShader *shader)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), NULL);
|
2009-02-28 17:19:05 +00:00
|
|
|
|
|
|
|
return clutter_shader_get_source (shader, CLUTTER_FRAGMENT_SHADER);
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_get_vertex_source:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
2008-01-25 17:20:33 +00:00
|
|
|
* Query the current GLSL vertex source set on @shader.
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
2008-02-03 01:53:10 +00:00
|
|
|
* Return value: the source of the vertex shader for this
|
|
|
|
* ClutterShader object or %NULL. The returned string is owned by the
|
|
|
|
* shader object and should never be modified or freed
|
2007-12-11 14:49:41 +00:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2007-12-11 14:49:41 +00:00
|
|
|
*/
|
Eliminate G_CONST_RETURN
The G_CONST_RETURN define in GLib is, and has always been, a bit fuzzy.
We always used it to conform to the platform, at least for public-facing
API.
At first I assumed it has something to do with brain-damaged compilers
or with weird platforms where const was not really supported; sadly,
it's something much, much worse: it's a define that can be toggled at
compile-time to remove const from the signature of public API. This is a
truly terrifying feature that I assume was added in the past century,
and whose inception clearly had something to do with massive doses of
absynthe and opium — because any other explanation would make the
existence of such a feature even worse than assuming drugs had anything
to do with it.
Anyway, and pleasing the gods, this dubious feature is being
removed/deprecated in GLib; see bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
Before deprecation, though, we should just remove its usage from the
whole API. We should especially remove its usage from Cally's internals,
since there it never made sense in the first place.
2011-06-07 14:49:20 +00:00
|
|
|
const gchar *
|
2007-12-11 14:49:41 +00:00
|
|
|
clutter_shader_get_vertex_source (ClutterShader *shader)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), NULL);
|
2009-02-28 17:19:05 +00:00
|
|
|
|
|
|
|
return clutter_shader_get_source (shader, CLUTTER_VERTEX_SHADER);
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 15:08:40 +00:00
|
|
|
/**
|
|
|
|
* clutter_shader_get_cogl_program:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
|
|
|
* Retrieves the underlying #CoglHandle for the shader program.
|
|
|
|
*
|
2010-09-03 11:14:50 +00:00
|
|
|
* Return value: (transfer none): A #CoglHandle for the shader program,
|
|
|
|
* or %NULL. The handle is owned by the #ClutterShader and it should
|
|
|
|
* not be unreferenced
|
2008-11-18 15:08:40 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2008-11-18 15:08:40 +00:00
|
|
|
*/
|
|
|
|
CoglHandle
|
|
|
|
clutter_shader_get_cogl_program (ClutterShader *shader)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), NULL);
|
2009-02-28 17:19:05 +00:00
|
|
|
|
2008-11-18 15:08:40 +00:00
|
|
|
return shader->priv->program;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_shader_get_cogl_fragment_shader:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
|
|
|
* Retrieves the underlying #CoglHandle for the fragment shader.
|
|
|
|
*
|
2010-09-03 11:14:50 +00:00
|
|
|
* Return value: (transfer none): A #CoglHandle for the fragment
|
|
|
|
* shader, or %NULL. The handle is owned by the #ClutterShader
|
|
|
|
* and it should not be unreferenced
|
2008-11-18 15:08:40 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2008-11-18 15:08:40 +00:00
|
|
|
*/
|
|
|
|
CoglHandle
|
|
|
|
clutter_shader_get_cogl_fragment_shader (ClutterShader *shader)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), NULL);
|
2009-02-28 17:19:05 +00:00
|
|
|
|
|
|
|
return clutter_shader_get_cogl_shader (shader, CLUTTER_FRAGMENT_SHADER);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_shader_get_cogl_vertex_shader:
|
|
|
|
* @shader: a #ClutterShader
|
|
|
|
*
|
|
|
|
* Retrieves the underlying #CoglHandle for the vertex shader.
|
|
|
|
*
|
2010-09-03 11:14:50 +00:00
|
|
|
* Return value: (transfer none): A #CoglHandle for the vertex
|
|
|
|
* shader, or %NULL. The handle is owned by the #ClutterShader
|
|
|
|
* and it should not be unreferenced
|
2008-11-18 15:08:40 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
2011-05-25 15:23:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.8: Use #ClutterShaderEffect instead.
|
2008-11-18 15:08:40 +00:00
|
|
|
*/
|
|
|
|
CoglHandle
|
|
|
|
clutter_shader_get_cogl_vertex_shader (ClutterShader *shader)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SHADER (shader), NULL);
|
2009-02-28 17:19:05 +00:00
|
|
|
|
|
|
|
return clutter_shader_get_cogl_shader (shader, CLUTTER_VERTEX_SHADER);
|
2008-11-18 15:08:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 14:49:41 +00:00
|
|
|
GQuark
|
|
|
|
clutter_shader_error_quark (void)
|
2007-12-03 16:29:18 +00:00
|
|
|
{
|
2007-12-11 14:49:41 +00:00
|
|
|
return g_quark_from_static_string ("clutter-shader-error");
|
2007-12-03 16:29:18 +00:00
|
|
|
}
|