ShaderEffect


Object Hierarchy:

Object hierarchy for ShaderEffect

Description:

[ CCode ( type_id = "clutter_shader_effect_get_type ()" ) ]
[ Version ( since = "1.4" ) ]
public class ShaderEffect : OffscreenEffect

ShaderEffect is a class that implements all the plumbing for creating Effects using GLSL shaders.

ShaderEffect 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.

ShaderEffect is available since Clutter 1.4

typeof (unichar2) typeof (unichar2) Implementing a ClutterShaderEffect

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

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 ShaderEffect 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 strdup.

The paint_target should set the shader's uniforms if any. This is done by calling set_uniform_value or clutter_shader_effect_set_uniform. The sub-class should then chain up to the ShaderEffect implementation.

typeof (unichar2) typeof (unichar2) Setting uniforms on a ClutterShaderEffect

The example below shows a typical implementation of the get_static_shader_source and paint_target virtual functions for a ShaderEffect 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->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);
}


Namespace: Clutter
Package: clutter-1.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Clutter.OffscreenEffect
All known members inherited from class Clutter.Effect
All known members inherited from class Clutter.ActorMeta