## Shaders

Shaders — Programmable pipeline abstraction

## Synopsis

    enum                ClutterShaderError;
                        ClutterShader;
                        ClutterShaderClass;
    ClutterShader *     clutter_shader_new                  (void);
    void                clutter_shader_set_vertex_source    (ClutterShader *shader,
                                                             const gchar *data,
                                                             gssize length);
    const gchar *       clutter_shader_get_vertex_source    (ClutterShader *shader);
    void                clutter_shader_set_fragment_source  (ClutterShader *shader,
                                                             const gchar *data,
                                                             gssize length);
    const gchar *       clutter_shader_get_fragment_source  (ClutterShader *shader);
    gboolean            clutter_shader_compile              (ClutterShader *shader,
                                                             GError **error);
    void                clutter_shader_release              (ClutterShader *shader);
    gboolean            clutter_shader_is_compiled          (ClutterShader *shader);
    void                clutter_shader_set_is_enabled       (ClutterShader *shader,
                                                             gboolean enabled);
    gboolean            clutter_shader_get_is_enabled       (ClutterShader *shader);

    void                clutter_shader_set_uniform          (ClutterShader *shader,
                                                             const gchar *name,
                                                             const GValue *value);
    CoglHandle          clutter_shader_get_cogl_program     (ClutterShader *shader);
    CoglHandle          clutter_shader_get_cogl_fragment_shader
                                                            (ClutterShader *shader);
    CoglHandle          clutter_shader_get_cogl_vertex_shader
                                                            (ClutterShader *shader);

    #define             CLUTTER_VALUE_HOLDS_SHADER_FLOAT    (x)
    void                clutter_value_set_shader_float      (GValue *value,
                                                             gint size,
                                                             const gfloat *floats);
    const gfloat *      clutter_value_get_shader_float      (const GValue *value,
                                                             gsize *length);
    #define             CLUTTER_VALUE_HOLDS_SHADER_INT      (x)
    void                clutter_value_set_shader_int        (GValue *value,
                                                             gint size,
                                                             const gint *ints);
    const gint *        clutter_value_get_shader_int        (const GValue *value,
                                                             gsize *length);
    #define             CLUTTER_VALUE_HOLDS_SHADER_MATRIX   (x)
    void                clutter_value_set_shader_matrix     (GValue *value,
                                                             gint size,
                                                             const gfloat *matrix);
    const gfloat *      clutter_value_get_shader_matrix     (const GValue *value,
                                                             gsize *length);

## Object Hierarchy

      GObject
       +----ClutterShader

## Properties

      "compiled"                 gboolean              : Read
      "enabled"                  gboolean              : Read / Write
      "fragment-source"          gchar*                : Read / Write
      "vertex-source"            gchar*                : Read / Write

## Description

ClutterShader is an object providing an abstraction over the OpenGL programmable pipeline. By using ClutterShaders is possible to override the drawing pipeline by using small programs also known as "shaders".

ClutterShader is available since Clutter 0.6

## Details

### enum ClutterShaderError

    typedef enum {
      CLUTTER_SHADER_ERROR_NO_ASM,
      CLUTTER_SHADER_ERROR_NO_GLSL,
      CLUTTER_SHADER_ERROR_COMPILE
    } ClutterShaderError;

ClutterShader error enumeration

`CLUTTER_SHADER_ERROR_NO_ASM` | No ASM shaders support
`CLUTTER_SHADER_ERROR_NO_GLSL` | No GLSL shaders support
`CLUTTER_SHADER_ERROR_COMPILE` | Compilation error

Since 0.6

### ClutterShader

    typedef struct _ClutterShader ClutterShader;

The ClutterShader structure contains only private data and should be accessed using the provided API

Since 0.6

### ClutterShaderClass

    typedef struct {
    } ClutterShaderClass;

The ClutterShaderClass structure contains only private data

Since 0.6

### clutter_shader_new ()

    ClutterShader *     clutter_shader_new                  (void);

Create a new ClutterShader instance.

Returns : | a new ClutterShader.

Since 0.6

### clutter_shader_set_vertex_source ()

    void                clutter_shader_set_vertex_source    (ClutterShader *shader,
                                                             const gchar *data,
                                                             gssize length);

Sets the GLSL source code to be used by a ClutterShader for the vertex program.

`shader` : | a ClutterShader
`data` : | GLSL source code.
`length` : | length of source buffer (currently ignored)

Since 0.6

### clutter_shader_get_vertex_source ()

    const gchar *       clutter_shader_get_vertex_source    (ClutterShader *shader);

Query the current GLSL vertex source set on `shader`.

`shader` : | a ClutterShader
Returns : | 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

Since 0.6

### clutter_shader_set_fragment_source ()

    void                clutter_shader_set_fragment_source  (ClutterShader *shader,
                                                             const gchar *data,
                                                             gssize length);

Sets the GLSL source code to be used by a ClutterShader for the fragment program.

`shader` : | a ClutterShader
`data` : | GLSL source code.
`length` : | length of source buffer (currently ignored)

Since 0.6

### clutter_shader_get_fragment_source ()

    const gchar *       clutter_shader_get_fragment_source  (ClutterShader *shader);

Query the current GLSL fragment source set on `shader`.

`shader` : | a ClutterShader
Returns : | 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

Since 0.6

### clutter_shader_compile ()

    gboolean            clutter_shader_compile              (ClutterShader *shader,
                                                             GError **error);

Compiles and links GLSL sources set for vertex and fragment shaders for a ClutterShader. If the compilation fails and a GError return location is provided the error will contain the errors from the compiler, if any.

`shader` : | a ClutterShader
`error` : | return location for a GError, or `NULL`
Returns : | returns TRUE if the shader was succesfully compiled.

Since 0.8

### clutter_shader_release ()

    void                clutter_shader_release              (ClutterShader *shader);

Frees up any GL context resources held by the shader.

`shader` : | a ClutterShader

Since 0.6

### clutter_shader_is_compiled ()

    gboolean            clutter_shader_is_compiled          (ClutterShader *shader);

Checks whether `shader` is is currently compiled, linked and bound to the GL context.

`shader` : | a ClutterShader
Returns : | `TRUE` if the shader is compiled, linked and ready for use.

Since 0.8

### clutter_shader_set_is_enabled ()

    void                clutter_shader_set_is_enabled       (ClutterShader *shader,
                                                             gboolean enabled);

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.

`shader` : | a ClutterShader
`enabled` : | The new state of the shader.

Since 0.6

### clutter_shader_get_is_enabled ()

    gboolean            clutter_shader_get_is_enabled       (ClutterShader *shader);

Checks whether `shader` is enabled.

`shader` : | a ClutterShader
Returns : | `TRUE` if the shader is enabled.

Since 0.6

### clutter_shader_set_uniform ()

    void                clutter_shader_set_uniform          (ClutterShader *shader,
                                                             const gchar *name,
                                                             const GValue *value);

Sets a user configurable variable in the GLSL shader programs attached to a ClutterShader.

`shader` : | a ClutterShader.
`name` : | name of uniform in GLSL shader program to set.
`value` : | a ClutterShaderFloat, ClutterShaderInt or ClutterShaderMatrix GValue.

Since 1.0

### clutter_shader_get_cogl_program ()

    CoglHandle          clutter_shader_get_cogl_program     (ClutterShader *shader);

Retrieves the underlying CoglHandle for the shader program.

`shader` : | a ClutterShader
Returns : | A CoglHandle for the shader program, or `NULL`

Since 1.0

### clutter_shader_get_cogl_fragment_shader ()

    CoglHandle          clutter_shader_get_cogl_fragment_shader
                                                            (ClutterShader *shader);

Retrieves the underlying CoglHandle for the fragment shader.

`shader` : | a ClutterShader
Returns : | A CoglHandle for the fragment shader, or `NULL`

Since 1.0

### clutter_shader_get_cogl_vertex_shader ()

    CoglHandle          clutter_shader_get_cogl_vertex_shader
                                                            (ClutterShader *shader);

Retrieves the underlying CoglHandle for the vertex shader.

`shader` : | a ClutterShader
Returns : | A CoglHandle for the vertex shader, or `NULL`

Since 1.0

### CLUTTER_VALUE_HOLDS_SHADER_FLOAT()

    #define CLUTTER_VALUE_HOLDS_SHADER_FLOAT(x) (G_VALUE_HOLDS ((x), CLUTTER_TYPE_SHADER_FLOAT))

Evaluates to `TRUE` if `x` holds a ClutterShaderFloat.

`x` : | a GValue

Since 1.0

### clutter_value_set_shader_float ()

    void                clutter_value_set_shader_float      (GValue *value,
                                                             gint size,
                                                             const gfloat *floats);

Sets `floats` as the contents of `value`. The passed GValue must have been initialized using `CLUTTER_TYPE_SHADER_FLOAT`.

`value` : | a GValue
`size` : | number of floating point values in `floats`
`floats` : | an array of floating point values

Since 0.8

### clutter_value_get_shader_float ()

    const gfloat *      clutter_value_get_shader_float      (const GValue *value,
                                                             gsize *length);

Retrieves the list of floating point values stored inside the passed GValue. `value` must have been initialized with `CLUTTER_TYPE_SHADER_FLOAT`.

`value` : | a GValue
`length` : | return location for the number of returned floating point values, or `NULL`
Returns : | the pointer to a list of floating point values. The returned value is owned by the GValue and should never be modified or freed.

Since 0.8

### CLUTTER_VALUE_HOLDS_SHADER_INT()

    #define CLUTTER_VALUE_HOLDS_SHADER_INT(x) (G_VALUE_HOLDS ((x), CLUTTER_TYPE_SHADER_INT))

Evaluates to `TRUE` if `x` holds a ClutterShaderInt.

`x` : | a GValue

Since 1.0

### clutter_value_set_shader_int ()

    void                clutter_value_set_shader_int        (GValue *value,
                                                             gint size,
                                                             const gint *ints);

Sets `ints` as the contents of `value`. The passed GValue must have been initialized using `CLUTTER_TYPE_SHADER_INT`.

`value` : | a GValue
`size` : | number of integer values in `ints`
`ints` : | an array of integer values

Since 0.8

### clutter_value_get_shader_int ()

    const gint *        clutter_value_get_shader_int        (const GValue *value,
                                                             gsize *length);

Retrieves the list of integer values stored inside the passed GValue. `value` must have been initialized with `CLUTTER_TYPE_SHADER_INT`.

`value` : | a GValue
`length` : | return location for the number of returned integer values, or `NULL`
Returns : | the pointer to a list of integer values. The returned value is owned by the GValue and should never be modified or freed.

Since 0.8

### CLUTTER_VALUE_HOLDS_SHADER_MATRIX()

    #define CLUTTER_VALUE_HOLDS_SHADER_MATRIX(x) (G_VALUE_HOLDS ((x), CLUTTER_TYPE_SHADER_MATRIX))

Evaluates to `TRUE` if `x` holds a ClutterShaderMatrix.

`x` : | a GValue

Since 1.0

### clutter_value_set_shader_matrix ()

    void                clutter_value_set_shader_matrix     (GValue *value,
                                                             gint size,
                                                             const gfloat *matrix);

Sets `matrix` as the contents of `value`. The passed GValue must have been initialized using `CLUTTER_TYPE_SHADER_MATRIX`.

`value` : | a GValue
`size` : | number of floating point values in `floats`
`matrix` : | a matrix of floating point values

Since 0.8

### clutter_value_get_shader_matrix ()

    const gfloat *      clutter_value_get_shader_matrix     (const GValue *value,
                                                             gsize *length);

Retrieves a matrix of floating point values stored inside the passed GValue. `value` must have been initialized with `CLUTTER_TYPE_SHADER_MATRIX`.

`value` : | a GValue
`length` : | return location for the number of returned floating point values, or `NULL`. out.
Returns : | the pointer to a matrix of floating point values. The returned value is owned by the GValue and should never be modified or freed. . array length=length. transfer none length=length.

Since 0.8

## Property Details

### The `"compiled"` property

      "compiled"                 gboolean              : Read

Whether the shader is compiled and linked, ready for use in the GL context.

Default value: FALSE

Since 0.8

### The `"enabled"` property

      "enabled"                  gboolean              : Read / Write

Whether the shader is currently used in the GL rendering pipeline.

Default value: FALSE

Since 0.6

### The `"fragment-source"` property

      "fragment-source"          gchar*                : Read / Write

GLSL source code for the fragment shader part of the shader program.

Default value: NULL

Since 0.6

### The `"vertex-source"` property

      "vertex-source"            gchar*                : Read / Write

GLSL source code for the vertex shader part of the shader program, if any

Default value: NULL

Since 0.6