## Pipeline

Pipeline — Functions for creating and manipulating the GPU pipeline

## Synopsis

    #define             cogl_pipeline_new
    #define             cogl_pipeline_copy
    #define             cogl_is_pipeline
    #define             cogl_pipeline_set_color
    #define             cogl_pipeline_set_color4ub
    #define             cogl_pipeline_set_color4f
    #define             cogl_pipeline_get_color
    #define             cogl_pipeline_set_ambient
    #define             cogl_pipeline_get_ambient
    #define             cogl_pipeline_set_diffuse
    #define             cogl_pipeline_get_diffuse
    #define             cogl_pipeline_set_ambient_and_diffuse
    #define             cogl_pipeline_set_emission
    #define             cogl_pipeline_get_emission
    #define             cogl_pipeline_set_specular
    #define             cogl_pipeline_get_specular
    #define             cogl_pipeline_set_shininess
    #define             cogl_pipeline_get_shininess
    #define             cogl_pipeline_set_alpha_test_function
    #define             COGL_BLEND_STRING_ERROR
    enum                CoglBlendStringError;
    #define             cogl_pipeline_set_blend
    #define             cogl_pipeline_set_blend_constant
    #define             cogl_pipeline_set_point_size
    #define             cogl_pipeline_get_point_size
    #define             cogl_pipeline_get_color_mask
    #define             cogl_pipeline_set_color_mask
    #define             cogl_pipeline_set_layer_texture
    #define             cogl_pipeline_set_layer_filters
    #define             cogl_pipeline_set_layer_wrap_mode
    #define             cogl_pipeline_set_layer_wrap_mode_s
    #define             cogl_pipeline_set_layer_wrap_mode_t
    #define             cogl_pipeline_set_layer_wrap_mode_p
    #define             cogl_pipeline_set_layer_combine
    #define             cogl_pipeline_set_layer_combine_constant
    #define             cogl_pipeline_set_layer_matrix
    #define             cogl_pipeline_set_layer_point_sprite_coords_enabled
    #define             cogl_pipeline_get_layer_point_sprite_coords_enabled
    #define             cogl_pipeline_remove_layer
    #define             cogl_pipeline_get_n_layers
    #define             cogl_pipeline_foreach_layer

## Description

Cogl allows creating and manipulating objects representing the full configuration of the GPU pipeline. In simplified terms the GPU pipeline takes primitive geometry as the input, it first performs vertex processing, allowing you to deform your geometry, then rasterizes that (turning it from pure geometry into fragments) then performs fragment processing including depth testing and texture mapping. Finally it blends the result with the framebuffer.

## Details

### cogl_pipeline_new

    #define cogl_pipeline_new cogl_pipeline_new_EXP

Allocates and initializes a default simple pipeline that will color a primitive white.

Returns : | a pointer to a new CoglPipeline

Since 2.0

Stability Level: Unstable

### cogl_pipeline_copy

    #define cogl_pipeline_copy cogl_pipeline_copy_EXP

Creates a new pipeline with the configuration copied from the source pipeline.

We would strongly advise developers to always aim to use `cogl_pipeline_copy()` instead of `cogl_pipeline_new()` whenever there will be any similarity between two pipelines. Copying a pipeline helps Cogl keep track of a pipelines ancestry which we may use to help minimize GPU state changes.

`source` : | a CoglPipeline object to copy
Returns : | a pointer to the newly allocated CoglPipeline

Since 2.0

Stability Level: Unstable

### cogl_is_pipeline

    #define cogl_is_pipeline cogl_is_pipeline_EXP

Gets whether the given handle references an existing pipeline object.

`handle` : | A CoglHandle
Returns : | `TRUE` if the handle references a CoglPipeline, `FALSE` otherwise

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_color

    #define cogl_pipeline_set_color cogl_pipeline_set_color_EXP

Sets the basic color of the pipeline, used when no lighting is enabled.

Note that if you don't add any layers to the pipeline then the color will be blended unmodified with the destination; the default blend expects premultiplied colors: for example, use (0.5, 0.0, 0.0, 0.5) for semi-transparent red. See `cogl_color_premultiply()`.

The default value is (1.0, 1.0, 1.0, 1.0)

`pipeline` : | A CoglPipeline object
`color` : | The components of the color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_color4ub

    #define cogl_pipeline_set_color4ub cogl_pipeline_set_color4ub_EXP

Sets the basic color of the pipeline, used when no lighting is enabled.

The default value is (0xff, 0xff, 0xff, 0xff)

`pipeline` : | A CoglPipeline object
`red` : | The red component
`green` : | The green component
`blue` : | The blue component
`alpha` : | The alpha component

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_color4f

    #define cogl_pipeline_set_color4f cogl_pipeline_set_color4f_EXP

Sets the basic color of the pipeline, used when no lighting is enabled.

The default value is (1.0, 1.0, 1.0, 1.0)

`pipeline` : | A CoglPipeline object
`red` : | The red component
`green` : | The green component
`blue` : | The blue component
`alpha` : | The alpha component

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_color

    #define cogl_pipeline_get_color cogl_pipeline_get_color_EXP

Retrieves the current pipeline color.

`pipeline` : | A CoglPipeline object
`color` : | The location to store the color. [out]

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_ambient

    #define cogl_pipeline_set_ambient cogl_pipeline_set_ambient_EXP

Sets the pipeline's ambient color, in the standard OpenGL lighting model. The ambient color affects the overall color of the object.

Since the diffuse color will be intense when the light hits the surface directly, the ambient will be most apparent where the light hits at a slant.

The default value is (0.2, 0.2, 0.2, 1.0)

`pipeline` : | A CoglPipeline object
`ambient` : | The components of the desired ambient color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_ambient

    #define cogl_pipeline_get_ambient cogl_pipeline_get_ambient_EXP

Retrieves the current ambient color for `pipeline`

`pipeline` : | A CoglPipeline object
`ambient` : | The location to store the ambient color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_diffuse

    #define cogl_pipeline_set_diffuse cogl_pipeline_set_diffuse_EXP

Sets the pipeline's diffuse color, in the standard OpenGL lighting model. The diffuse color is most intense where the light hits the surface directly - perpendicular to the surface.

The default value is (0.8, 0.8, 0.8, 1.0)

`pipeline` : | A CoglPipeline object
`diffuse` : | The components of the desired diffuse color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_diffuse

    #define cogl_pipeline_get_diffuse cogl_pipeline_get_diffuse_EXP

Retrieves the current diffuse color for `pipeline`

`pipeline` : | A CoglPipeline object
`diffuse` : | The location to store the diffuse color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_ambient_and_diffuse

    #define             cogl_pipeline_set_ambient_and_diffuse

Conveniently sets the diffuse and ambient color of `pipeline` at the same time. See `cogl_pipeline_set_ambient()` and `cogl_pipeline_set_diffuse()`.

The default ambient color is (0.2, 0.2, 0.2, 1.0)

The default diffuse color is (0.8, 0.8, 0.8, 1.0)

`pipeline` : | A CoglPipeline object
`color` : | The components of the desired ambient and diffuse colors

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_emission

    #define cogl_pipeline_set_emission cogl_pipeline_set_emission_EXP

Sets the pipeline's emissive color, in the standard OpenGL lighting model. It will look like the surface is a light source emitting this color.

The default value is (0.0, 0.0, 0.0, 1.0)

`pipeline` : | A CoglPipeline object
`emission` : | The components of the desired emissive color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_emission

    #define cogl_pipeline_get_emission cogl_pipeline_get_emission_EXP

Retrieves the pipelines current emission color.

`pipeline` : | A CoglPipeline object
`emission` : | The location to store the emission color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_specular

    #define cogl_pipeline_set_specular cogl_pipeline_set_specular_EXP

Sets the pipeline's specular color, in the standard OpenGL lighting model. The intensity of the specular color depends on the viewport position, and is brightest along the lines of reflection.

The default value is (0.0, 0.0, 0.0, 1.0)

`pipeline` : | A CoglPipeline object
`specular` : | The components of the desired specular color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_specular

    #define cogl_pipeline_get_specular cogl_pipeline_get_specular_EXP

Retrieves the pipelines current specular color.

`pipeline` : | A CoglPipeline object
`specular` : | The location to store the specular color

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_shininess

    #define cogl_pipeline_set_shininess cogl_pipeline_set_shininess_EXP

Sets the shininess of the pipeline, in the standard OpenGL lighting model, which determines the size of the specular highlights. A higher `shininess` will produce smaller highlights which makes the object appear more shiny.

The default value is 0.0

`pipeline` : | A CoglPipeline object
`shininess` : | The desired shininess; must be >= 0.0

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_shininess

    #define cogl_pipeline_get_shininess cogl_pipeline_get_shininess_EXP

Retrieves the pipelines current emission color.

`pipeline` : | A CoglPipeline object
Returns : | The pipelines current shininess value

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_alpha_test_function

    #define             cogl_pipeline_set_alpha_test_function

Before a primitive is blended with the framebuffer, it goes through an alpha test stage which lets you discard fragments based on the current alpha value. This function lets you change the function used to evaluate the alpha channel, and thus determine which fragments are discarded and which continue on to the blending stage.

The default is `COGL_PIPELINE_ALPHA_FUNC_ALWAYS`

`pipeline` : | A CoglPipeline object
`alpha_func` : | A `CoglPipelineAlphaFunc` constant
`alpha_reference` : | A reference point that the chosen alpha function uses to compare incoming fragments to.

Since 2.0

Stability Level: Unstable

### COGL_BLEND_STRING_ERROR

    #define COGL_BLEND_STRING_ERROR (cogl_blend_string_error_quark ())

GError domain for blend string parser errors

Since 1.0

### enum CoglBlendStringError

    typedef enum { /*< prefix=COGL_BLEND_STRING_ERROR >*/
      COGL_BLEND_STRING_ERROR_PARSE_ERROR,
      COGL_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR,
      COGL_BLEND_STRING_ERROR_INVALID_ERROR,
      COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR
    } CoglBlendStringError;

Error enumeration for the blend strings parser

`COGL_BLEND_STRING_ERROR_PARSE_ERROR` | Generic parse error
`COGL_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR` | Argument parse error
`COGL_BLEND_STRING_ERROR_INVALID_ERROR` | Internal parser error
`COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR` | Blend string not supported by the GPU

Since 1.0

### cogl_pipeline_set_blend

    #define cogl_pipeline_set_blend cogl_pipeline_set_blend_EXP

If not already familiar; please refer here for an overview of what blend strings are, and their syntax.

Blending occurs after the alpha test function, and combines fragments with the framebuffer.

Currently the only blend function Cogl exposes is `ADD()`. So any valid blend statements will be of the form:

    1

    <channel-mask>=ADD(SRC_COLOR*(<factor>), DST_COLOR*(<factor>))

This is the list of source-names usable as blend factors:

- SRC_COLOR: The color of the in comming fragment

- DST_COLOR: The color of the framebuffer

- CONSTANT: The constant set via `cogl_pipeline_set_blend_constant()`

The source names can be used according to the color-source and factor syntax, so for example "(1-SRC_COLOR[A])" would be a valid factor, as would "(CONSTANT[RGB])"

These can also be used as factors:

- 0: (0, 0, 0, 0)
- 1: (1, 1, 1, 1)
- SRC_ALPHA_SATURATE_FACTOR: (f,f,f,1) where f = MIN(SRC_COLOR[A],1-DST_COLOR[A])

### Note

Remember; all color components are normalized to the range [0, 1] before computing the result of blending.

Example 1. Blend Strings/1

Blend a non-premultiplied source over a destination with premultiplied alpha:

    "RGB = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))"
    "A   = ADD(SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))"

Example 2. Blend Strings/2

Blend a premultiplied source over a destination with premultiplied alpha

    "RGBA = ADD(SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))"

The default blend string is:

    1

    RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))

That gives normal alpha-blending when the calculated color for the pipeline is in premultiplied form.

`pipeline` : | A CoglPipeline object
`blend_string` : | A Cogl blend string describing the desired blend function.
`error` : | return location for a GError that may report lack of driver support if you give separate blend string statements for the alpha channel and RGB channels since some drivers, or backends such as GLES 1.1, don't support this feature. May be `NULL`, in which case a warning will be printed out using GLib's logging facilities if an error is encountered.
Returns : | `TRUE` if the blend string was successfully parsed, and the described blending is supported by the underlying driver/hardware. If there was an error, `FALSE` is returned and `error` is set accordingly (if present).

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_blend_constant

    #define cogl_pipeline_set_blend_constant cogl_pipeline_set_blend_constant_EXP

When blending is setup to reference a CONSTANT blend factor then blending will depend on the constant set with this function.

`pipeline` : | A CoglPipeline object
`constant_color` : | The constant color you want

Since 2.0

Stability Level: Unstable

### cogl_pipeline_set_point_size

    #define cogl_pipeline_set_point_size cogl_pipeline_set_point_size_EXP

Changes the size of points drawn when `COGL_VERTICES_MODE_POINTS` is used with the vertex buffer API. Note that typically the GPU will only support a limited minimum and maximum range of point sizes. If the chosen point size is outside that range then the nearest value within that range will be used instead. The size of a point is in screen space so it will be the same regardless of any transformations. The default point size is 1.0.

`pipeline` : | a CoglPipeline pointer
`point_size` : | the new point size.

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_point_size

    #define cogl_pipeline_get_point_size cogl_pipeline_get_point_size_EXP

Get the size of points drawn when `COGL_VERTICES_MODE_POINTS` is used with the vertex buffer API.

`pipeline` : | a CoglPipeline pointer
Returns : | the point size of the `pipeline`.

Since 2.0

Stability Level: Unstable

### cogl_pipeline_get_color_mask

    #define cogl_pipeline_get_color_mask cogl_pipeline_get_color_mask_EXP

Gets the current CoglColorMask of which channels would be written to the current framebuffer. Each bit set in the mask means that the corresponding color would be written.

`pipeline` : | a CoglPipeline object.
Returns : | A CoglColorMask

Since 1.8

Stability Level: Unstable

### cogl_pipeline_set_color_mask

    #define cogl_pipeline_set_color_mask cogl_pipeline_set_color_mask_EXP

Defines a bit mask of which color channels should be written to the current framebuffer. If a bit is set in `color_mask` that means that color will be written.

`pipeline` : | a CoglPipeline object.
`color_mask` : | A CoglColorMask of which color channels to write to the current framebuffer.

Since 1.8

Stability Level: Unstable

### cogl_pipeline_set_layer_texture

    #define cogl_pipeline_set_layer_texture cogl_pipeline_set_layer_texture_EXP

### cogl_pipeline_set_layer_filters

    #define cogl_pipeline_set_layer_filters cogl_pipeline_set_layer_filters_EXP

Changes the decimation and interpolation filters used when a texture is drawn at other scales than 100%.

`pipeline` : | A CoglPipeline object
`layer_index` : | the layer number to change.
`min_filter` : | the filter used when scaling a texture down.
`mag_filter` : | the filter used when magnifying a texture.

### cogl_pipeline_set_layer_wrap_mode

    #define             cogl_pipeline_set_layer_wrap_mode

Sets the wrap mode for all three coordinates of texture lookups on this layer. This is equivalent to calling `cogl_pipeline_set_layer_wrap_mode_s()`, `cogl_pipeline_set_layer_wrap_mode_t()` and `cogl_pipeline_set_layer_wrap_mode_p()` separately.

`pipeline` : | A CoglPipeline object
`layer_index` : | the layer number to change.
`mode` : | the new wrap mode

Since 2.0

### cogl_pipeline_set_layer_wrap_mode_s

    #define             cogl_pipeline_set_layer_wrap_mode_s

Sets the wrap mode for the 's' coordinate of texture lookups on this layer.

`pipeline` : | A CoglPipeline object
`layer_index` : | the layer number to change.
`mode` : | the new wrap mode

Since 2.0

### cogl_pipeline_set_layer_wrap_mode_t

    #define             cogl_pipeline_set_layer_wrap_mode_t

Sets the wrap mode for the 't' coordinate of texture lookups on this layer.

`pipeline` : | A CoglPipeline object
`layer_index` : | the layer number to change.
`mode` : | the new wrap mode

Since 2.0

### cogl_pipeline_set_layer_wrap_mode_p

    #define             cogl_pipeline_set_layer_wrap_mode_p

Sets the wrap mode for the 'p' coordinate of texture lookups on this layer. 'p' is the third coordinate.

`pipeline` : | A CoglPipeline object
`layer_index` : | the layer number to change.
`mode` : | the new wrap mode

Since 2.0

### cogl_pipeline_set_layer_combine

    #define cogl_pipeline_set_layer_combine cogl_pipeline_set_layer_combine_EXP

If not already familiar; you can refer here for an overview of what blend strings are and there syntax.

These are all the functions available for texture combining:

- REPLACE(arg0) = arg0
- MODULATE(arg0, arg1) = arg0 x arg1
- ADD(arg0, arg1) = arg0 + arg1
- ADD_SIGNED(arg0, arg1) = arg0 + arg1 - 0.5
- INTERPOLATE(arg0, arg1, arg2) = arg0 x arg2 + arg1 x (1 - arg2)
- SUBTRACT(arg0, arg1) = arg0 - arg1

-      DOT3_RGB(arg0, arg1) = 4 x ((arg0[R] - 0.5)) * (arg1[R] - 0.5) +
                                   (arg0[G] - 0.5)) * (arg1[G] - 0.5) +
                                   (arg0[B] - 0.5)) * (arg1[B] - 0.5))

-      DOT3_RGBA(arg0, arg1) = 4 x ((arg0[R] - 0.5)) * (arg1[R] - 0.5) +
                                    (arg0[G] - 0.5)) * (arg1[G] - 0.5) +
                                    (arg0[B] - 0.5)) * (arg1[B] - 0.5))

Refer to the color-source syntax for describing the arguments. The valid source names for texture combining are:

TEXTURE | Use the color from the current texture layer
TEXTURE_0, TEXTURE_1, etc | Use the color from the specified texture layer
CONSTANT | Use the color from the constant given with `cogl_pipeline_set_layer_constant()`
PRIMARY | Use the color of the pipeline as set with `cogl_pipeline_set_color()`
PREVIOUS | Either use the texture color from the previous layer, or if this is layer 0, use the color of the pipeline as set with `cogl_pipeline_set_color()`

### Layer Combine Examples

This is effectively what the default blending is:

    1

    RGBA = MODULATE (PREVIOUS, TEXTURE)

This could be used to cross-fade between two images, using the alpha component of a constant as the interpolator. The constant color is given by calling cogl_pipeline_set_layer_constant.

    1

    RGBA = INTERPOLATE (PREVIOUS, TEXTURE, CONSTANT[A])

### Note

You can't give a multiplication factor for arguments as you can with blending.

`pipeline` : | A CoglPipeline object
`layer_index` : | Specifies the layer you want define a combine function for
`blend_string` : | A Cogl blend string describing the desired texture combine function.
`error` : | A GError that may report parse errors or lack of GPU/driver support. May be `NULL`, in which case a warning will be printed out if an error is encountered.
Returns : | `TRUE` if the blend string was successfully parsed, and the described texture combining is supported by the underlying driver and or hardware. On failure, `FALSE` is returned and `error` is set

Since 2.0

### cogl_pipeline_set_layer_combine_constant

    #define             cogl_pipeline_set_layer_combine_constant

When you are using the 'CONSTANT' color source in a layer combine description then you can use this function to define its value.

`pipeline` : | A CoglPipeline object
`layer_index` : | Specifies the layer you want to specify a constant used for texture combining
`constant` : | The constant color you want

Since 2.0

### cogl_pipeline_set_layer_matrix

    #define cogl_pipeline_set_layer_matrix cogl_pipeline_set_layer_matrix_EXP

This function lets you set a matrix that can be used to e.g. translate and rotate a single layer of a pipeline used to fill your geometry.

`pipeline` : | A CoglPipeline object
`layer_index` : | the index for the layer inside `pipeline`
`matrix` : | the transformation matrix for the layer

### cogl_pipeline_set_layer_point_sprite_coords_enabled

    #define             cogl_pipeline_set_layer_point_sprite_coords_enabled

When rendering points, if `enable` is `TRUE` then the texture coordinates for this layer will be replaced with coordinates that vary from 0.0 to 1.0 across the primitive. The top left of the point will have the coordinates 0.0,0.0 and the bottom right will have 1.0,1.0. If `enable` is `FALSE` then the coordinates will be fixed for the entire point.

This function will only work if `COGL_FEATURE_POINT_SPRITE` is available. If the feature is not available then the function will return `FALSE` and set `error`.

`pipeline` : | a CoglHandle to a pipeline.
`layer_index` : | the layer number to change.
`enable` : | whether to enable point sprite coord generation.
`error` : | A return location for a GError, or NULL to ignore errors.
Returns : | `TRUE` if the function succeeds, `FALSE` otherwise.

Since 2.0

### cogl_pipeline_get_layer_point_sprite_coords_enabled

    #define             cogl_pipeline_get_layer_point_sprite_coords_enabled

Gets whether point sprite coordinate generation is enabled for this texture layer.

`pipeline` : | a CoglHandle to a pipeline.
`layer_index` : | the layer number to check.
Returns : | whether the texture coordinates will be replaced with point sprite coordinates.

Since 2.0

### cogl_pipeline_remove_layer

    #define cogl_pipeline_remove_layer cogl_pipeline_remove_layer_EXP

This function removes a layer from your pipeline

`pipeline` : | A CoglPipeline object
`layer_index` : | Specifies the layer you want to remove

### cogl_pipeline_get_n_layers

    #define cogl_pipeline_get_n_layers cogl_pipeline_get_n_layers_EXP

Retrieves the number of layers defined for the given `pipeline`

`pipeline` : | A CoglPipeline object
Returns : | the number of layers

Since 2.0

### cogl_pipeline_foreach_layer

    #define cogl_pipeline_foreach_layer cogl_pipeline_foreach_layer_EXP

Iterates all the layer indices of the given `pipeline`.

`pipeline` : | A CoglPipeline object
`callback` : | A CoglPipelineLayerCallback to be called for each layer index
`user_data` : | Private data that will be passed to the callback

Since 2.0

Stability Level: Unstable