shader-effect: Allow instantiating ShaderEffect
ClutterShaderEffect doesn't require to be sub-classed in order to be useful. It is possible to just create an instance, set the source and the uniforms, and attach it to an actor. This should effectively replace ClutterShader for good.
This commit is contained in:
parent
9ed5f2842a
commit
53483896a8
@ -27,11 +27,11 @@
|
|||||||
* @short_description: Base class for shader effects
|
* @short_description: Base class for shader effects
|
||||||
* @See_Also: #ClutterEffect, #ClutterOffscreenEffect
|
* @See_Also: #ClutterEffect, #ClutterOffscreenEffect
|
||||||
*
|
*
|
||||||
* #ClutterShaderEffect is an abstract class that implements all the
|
* #ClutterShaderEffect is a class that implements all the plumbing for
|
||||||
* plumbing for creating #ClutterEffect<!-- -->s using GLSL shaders.
|
* creating #ClutterEffect<!-- -->s using GLSL shaders.
|
||||||
*
|
*
|
||||||
* #ClutterShaderEffect creates an offscreen buffer and then applies the GLSL
|
* #ClutterShaderEffect creates an offscreen buffer and then applies the
|
||||||
* shader (after checking whether the compilation and linking were
|
* GLSL shader (after checking whether the compilation and linking were
|
||||||
* successfull) to the buffer before painting it on screen.
|
* successfull) to the buffer before painting it on screen.
|
||||||
*
|
*
|
||||||
* <refsect2 id="ClutterShaderEffect-implementing">
|
* <refsect2 id="ClutterShaderEffect-implementing">
|
||||||
@ -150,9 +150,9 @@ enum
|
|||||||
|
|
||||||
static GParamSpec *obj_props[PROP_LAST];
|
static GParamSpec *obj_props[PROP_LAST];
|
||||||
|
|
||||||
G_DEFINE_ABSTRACT_TYPE (ClutterShaderEffect,
|
G_DEFINE_TYPE (ClutterShaderEffect,
|
||||||
clutter_shader_effect,
|
clutter_shader_effect,
|
||||||
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
clutter_shader_effect_clear (ClutterShaderEffect *self,
|
clutter_shader_effect_clear (ClutterShaderEffect *self,
|
||||||
@ -437,6 +437,30 @@ clutter_shader_effect_init (ClutterShaderEffect *effect)
|
|||||||
ClutterShaderEffectPrivate);
|
ClutterShaderEffectPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clutter_shader_effect_new:
|
||||||
|
* @shader_type: the type of the shader, either %CLUTTER_FRAGMENT_SHADER,
|
||||||
|
* or %CLUTTER_VERTEX_SHADER
|
||||||
|
*
|
||||||
|
* Creates a new #ClutterShaderEffect, to be applied to an actor using
|
||||||
|
* clutter_actor_add_effect().
|
||||||
|
*
|
||||||
|
* The effect will be empty until clutter_shader_effect_set_shader_source()
|
||||||
|
* is called.
|
||||||
|
*
|
||||||
|
* Return value: (transfer full): the newly created #ClutterShaderEffect.
|
||||||
|
* Use g_object_unref() when done.
|
||||||
|
*
|
||||||
|
* Since: 1.8
|
||||||
|
*/
|
||||||
|
ClutterEffect *
|
||||||
|
clutter_shader_effect_new (ClutterShaderType shader_type)
|
||||||
|
{
|
||||||
|
return g_object_new (CLUTTER_TYPE_SHADER_EFFECT,
|
||||||
|
"shader-type", shader_type,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_shader_effect_get_shader:
|
* clutter_shader_effect_get_shader:
|
||||||
* @effect: a #ClutterShaderEffect
|
* @effect: a #ClutterShaderEffect
|
||||||
@ -547,6 +571,9 @@ clutter_shader_effect_add_uniform (ClutterShaderEffect *effect,
|
|||||||
uniform->location =
|
uniform->location =
|
||||||
cogl_program_get_uniform_location (priv->program, uniform->name);
|
cogl_program_get_uniform_location (priv->program, uniform->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (priv->actor != NULL && !CLUTTER_ACTOR_IN_PAINT (priv->actor))
|
||||||
|
clutter_actor_queue_redraw (priv->actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,20 +84,22 @@ struct _ClutterShaderEffectClass
|
|||||||
|
|
||||||
GType clutter_shader_effect_get_type (void) G_GNUC_CONST;
|
GType clutter_shader_effect_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
gboolean clutter_shader_effect_set_shader_source (ClutterShaderEffect *effect,
|
ClutterEffect * clutter_shader_effect_new (ClutterShaderType shader_type);
|
||||||
const gchar *source);
|
|
||||||
|
|
||||||
void clutter_shader_effect_set_uniform (ClutterShaderEffect *effect,
|
gboolean clutter_shader_effect_set_shader_source (ClutterShaderEffect *effect,
|
||||||
const gchar *name,
|
const gchar *source);
|
||||||
GType gtype,
|
|
||||||
gsize n_values,
|
|
||||||
...);
|
|
||||||
void clutter_shader_effect_set_uniform_value (ClutterShaderEffect *effect,
|
|
||||||
const gchar *name,
|
|
||||||
const GValue *value);
|
|
||||||
|
|
||||||
CoglHandle clutter_shader_effect_get_shader (ClutterShaderEffect *effect);
|
void clutter_shader_effect_set_uniform (ClutterShaderEffect *effect,
|
||||||
CoglHandle clutter_shader_effect_get_program (ClutterShaderEffect *effect);
|
const gchar *name,
|
||||||
|
GType gtype,
|
||||||
|
gsize n_values,
|
||||||
|
...);
|
||||||
|
void clutter_shader_effect_set_uniform_value (ClutterShaderEffect *effect,
|
||||||
|
const gchar *name,
|
||||||
|
const GValue *value);
|
||||||
|
|
||||||
|
CoglHandle clutter_shader_effect_get_shader (ClutterShaderEffect *effect);
|
||||||
|
CoglHandle clutter_shader_effect_get_program (ClutterShaderEffect *effect);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user