Description [src]

class Clutter.ShaderEffect : Clutter.OffscreenEffect
  /* No available fields */

Base class for shader effects

ClutterShaderEffect is a class that implements all the plumbing for creating ClutterEffects using GLSL shaders.

ClutterShaderEffect creates an offscreen buffer and then applies the GLSL shader (after checking whether the compilation and linking were successful) to the buffer before painting it on screen.

Implementing a ClutterShaderEffect

Creating a sub-class of ClutterShaderEffect requires the overriding of the Clutter.OffscreenEffectClass.paint_target virtual function from the ClutterOffscreenEffect class. It is also convenient to implement the Clutter.ShaderEffectClass.get_static_shader_source virtual function in case you are planning to create more than one instance of the effect.

The Clutter.ShaderEffectClass.get_static_shader_source function should return a copy of the shader source to use. This function is only called once per subclass of ClutterShaderEffect 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 Clutter.OffscreenEffectClass.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 ClutterShaderEffect implementation.

Setting uniforms on a ClutterShaderEffect

The example below shows a typical implementation of the Clutter.ShaderEffectClass.get_static_shader_source and Clutter.OffscreenEffectClass.paint_target virtual functions for a ClutterShaderEffect subclass.

 static gchar *
 my_effect_get_static_shader_source (ClutterShaderEffect *effect)
   // shader_source is set elsewhere
   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->   / 255.0f;
   component_g = self-> / 255.0f;
   component_b = self->  / 255.0f;
   clutter_shader_effect_set_uniform (shader, "component",
                                      G_TYPE_FLOAT, 3,

   // chain up to the parent's implementation
   parent_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (my_effect_parent_class);
   return parent_class->paint_target (effect);


hierarchy this ClutterShaderEffect ancestor_0 ClutterOffscreenEffect ancestor_0--this ancestor_1 ClutterEffect ancestor_1--ancestor_0 ancestor_2 ClutterActorMeta ancestor_2--ancestor_1 ancestor_3 GInitiallyUnowned ancestor_3--ancestor_2 ancestor_4 GObject ancestor_4--ancestor_3



Creates a new ClutterShaderEffect, to be applied to an actor using clutter_actor_add_effect().

Instance methods


Retrieves a pointer to the program’s handle.


Retrieves a pointer to the shader’s handle.


Sets the source of the GLSL shader used by effect.


Sets a list of values as the payload for the uniform name inside the shader effect.


Sets value as the payload for the uniform name inside the shader effect.

Methods inherited from ClutterOffscreenEffect (5)

Calls the Clutter.OffscreenEffectClass.create_texture virtual function of the effect.


Retrieves the pipeline used as a render target for the offscreen buffer created by effect.


Retrieves the size of the offscreen buffer used by effect to paint the actor to which it has been applied.


Retrieves the texture used as a render target for the offscreen buffer created by effect.


Calls the Clutter.OffscreenEffectClass.paint_target virtual function of the effect.

Methods inherited from ClutterEffect (1)

Queues a repaint of the effect. The effect can detect when the ‘paint’ method is called as a result of this function because it will not have the CLUTTER_EFFECT_PAINT_ACTOR_DIRTY flag set. In that case the effect is free to assume that the actor has not changed its appearance since the last time it was painted so it doesn’t need to call clutter_actor_continue_paint() if it can draw a cached image. This is mostly intended for effects that are using a %CoglOffscreen to redirect the actor (such as %ClutterOffscreenEffect). In that case the effect can save a bit of rendering time by painting the cached texture without causing the entire actor to be painted.

Methods inherited from ClutterActorMeta (5)

Retrieves a pointer to the ClutterActor that owns meta.


Retrieves whether meta is enabled.


Retrieves the name set using clutter_actor_meta_set_name()


Sets whether meta should be enabled or not.


Sets the name of meta.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.



The type of shader that is used by the effect. This property should be set by the constructor of ClutterShaderEffect sub-classes.

Properties inherited from ClutterActorMeta (3)

The ClutterActor attached to the ClutterActorMeta instance.


Whether or not the ClutterActorMeta is enabled.


The unique name to access the ClutterActorMeta.


Signals inherited from GObject (1)

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct ClutterShaderEffectClass {
  gchar* (* get_static_shader_source) (
    ClutterShaderEffect* effect

The ClutterShaderEffectClass structure contains only private data.

Class members
get_static_shader_source: gchar* (* get_static_shader_source) ( ClutterShaderEffect* effect )

No description available.

Virtual methods