Base class for shader effects
<clutter-shader-effect> is a class that implements all the
plumbing for creating <clutter-effect>s using GLSL shaders.
<clutter-shader-effect> creates an offscreen buffer and then
applies the GLSL shader (after checking whether the compilation and
linking were successfull) to the buffer before painting it on screen.
Creating a sub-class of <clutter-shader-effect> requires the
overriding of the paint-target virtual function from the
<clutter-offscreen-effect> class as well as the
get-static-shader-source virtual from the
<clutter-shader-effect> class.
The get-static-shader-source function should return a copy
of the shader source to use. This function is only called once per
subclass of <clutter-shader-effect> regardless of how many
instances of the effect are created. The source for the shader is
typically stored in a static const string which is returned from this
function via g-strdup.
The paint-target should set the shader's uniforms if any.
This is done by calling clutter-shader-effect-set-uniform-value
or clutter-shader-effect-set-uniform. The sub-class should then
chain up to the <clutter-shader-effect> implementation.
The example below shows a typical implementation of the
get-static-shader-source and paint-target
phases of a <clutter-shader-effect> sub-class.
static gchar *
my_effect_get_static_shader_source (ClutterShaderEffect *effect)
{
return g_strdup (shader_source);
}
static gboolean
my_effect_paint_target (ClutterOffscreenEffect *effect)
{
MyEffect *self = MY_EFFECT (effect);
ClutterShaderEffect *shader = CLUTTER_SHADER_EFFECT (effect);
ClutterEffectClass *parent_class;
gfloat component_r, component_g, component_b;
/* the "tex" uniform is declared in the shader as:
*
* uniform int tex;
*
* and it is passed a constant value of 0
*/
clutter_shader_effect_set_uniform (shader, "tex", G_TYPE_INT, 1, 0);
/* the "component" uniform is declared in the shader as:
*
* uniform vec3 component;
*
* and it's defined to contain the normalized components
* of a ClutterColor
*/
component_r = self->color.red / 255.0f;
component_g = self->color.green / 255.0f;
component_b = self->color.blue / 255.0f;
clutter_shader_effect_set_uniform (shader, "component",
G_TYPE_FLOAT, 3,
component_r,
component_g,
component_b);
/* chain up to the parent's implementation */
parent_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (my_effect_parent_class);
return parent_class->paint_target (effect);
}
<clutter-shader-effect> is available since Clutter 1.4
<clutter-shader-type>) ⇒ (ret <clutter-effect>)Creates a new
<clutter-shader-effect>, to be applied to an actor usingclutter-actor-add-effect.The effect will be empty until
clutter-shader-effect-set-shader-sourceis called.
- shader-type
- the type of the shader, either ‘CLUTTER_FRAGMENT_SHADER’, or ‘CLUTTER_VERTEX_SHADER’
- ret
- the newly created
<clutter-shader-effect>. Useg-object-unrefwhen done.Since 1.8