Cogl.Material

Fields

None

Methods

class

ref (material)

class

unref (material)

get_ambient (ambient)

get_color ()

get_diffuse (diffuse)

get_emission (emission)

get_layer_point_sprite_coords_enabled (layer_index)

get_layer_wrap_mode_p (layer_index)

get_layer_wrap_mode_s (layer_index)

get_layer_wrap_mode_t (layer_index)

get_layers ()

get_n_layers ()

get_point_size ()

get_shininess ()

get_specular (specular)

get_user_program ()

remove_layer (layer_index)

set_alpha_test_function (alpha_func, alpha_reference)

set_ambient (ambient)

set_ambient_and_diffuse (color)

set_blend (blend_string)

set_blend_constant (constant_color)

set_color (color)

set_color4f (red, green, blue, alpha)

set_color4ub (red, green, blue, alpha)

set_diffuse (diffuse)

set_emission (emission)

set_layer (layer_index, texture)

set_layer_combine (layer_index, blend_string)

set_layer_combine_constant (layer_index, constant)

set_layer_filters (layer_index, min_filter, mag_filter)

set_layer_matrix (layer_index, matrix)

set_layer_point_sprite_coords_enabled (layer_index, enable)

set_layer_wrap_mode (layer_index, mode)

set_layer_wrap_mode_p (layer_index, mode)

set_layer_wrap_mode_s (layer_index, mode)

set_layer_wrap_mode_t (layer_index, mode)

set_point_size (point_size)

set_shininess (shininess)

set_specular (specular)

set_user_program (program)

Details

class Cogl.Material
classmethod ref(material)
Parameters:

material (object) – a Cogl.Material object.

Returns:

the material.

Return type:

object

Increment the reference count for a Cogl.Material.

New in version 1.0.

Deprecated since version 1.2: Use cogl_object_ref() instead

classmethod unref(material)
Parameters:

material (object) – a Cogl.Material object.

Decrement the reference count for a Cogl.Material.

New in version 1.0.

Deprecated since version 1.2: Use cogl_object_unref() instead

get_ambient(ambient)
Parameters:

ambient (Cogl.Color) – The location to store the ambient color

Retrieves the current ambient color for self

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

get_color()
Returns:

The location to store the color

Return type:

color: Cogl.Color

Retrieves the current material color.

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_get_color() instead

get_diffuse(diffuse)
Parameters:

diffuse (Cogl.Color) – The location to store the diffuse color

Retrieves the current diffuse color for self

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

get_emission(emission)
Parameters:

emission (Cogl.Color) – The location to store the emission color

Retrieves the materials current emission color.

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

get_layer_point_sprite_coords_enabled(layer_index)
Parameters:

layer_index (int) – the layer number to check.

Returns:

whether the texture coordinates will be replaced with point sprite coordinates.

Return type:

int

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

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_get_layer_point_sprite_coords_enabled() instead

get_layer_wrap_mode_p(layer_index)
Parameters:

layer_index (int) – the layer number to change.

Returns:

the wrap mode for the ‘p’ coordinate of texture lookups on this layer.

Return type:

Cogl.MaterialWrapMode

Returns the wrap mode for the ‘p’ coordinate of texture lookups on this layer.

New in version 1.6.

Deprecated since version 1.16: Use cogl_pipeline_get_layer_wrap_mode_p() instead

get_layer_wrap_mode_s(layer_index)
Parameters:

layer_index (int) – the layer number to change.

Returns:

the wrap mode for the ‘s’ coordinate of texture lookups on this layer.

Return type:

Cogl.MaterialWrapMode

Returns the wrap mode for the ‘s’ coordinate of texture lookups on this layer.

New in version 1.6.

Deprecated since version 1.16: Use cogl_pipeline_get_layer_wrap_mode_s() instead

get_layer_wrap_mode_t(layer_index)
Parameters:

layer_index (int) – the layer number to change.

Returns:

the wrap mode for the ‘t’ coordinate of texture lookups on this layer.

Return type:

Cogl.MaterialWrapMode

Returns the wrap mode for the ‘t’ coordinate of texture lookups on this layer.

New in version 1.6.

Deprecated since version 1.16: Use cogl_pipeline_get_layer_wrap_mode_t() instead

get_layers()
Returns:

A list of Cogl.MaterialLayer ‘s that can be passed to the cogl_material_layer_* functions. The list is owned by Cogl and it should not be modified or freed Deprecated: 1.16: Use cogl_pipeline_get_layers() instead

Return type:

[Cogl.MaterialLayer]

This function lets you access a material’s internal list of layers for iteration.

You should avoid using this API if possible since it was only made public by mistake and will be deprecated when we have suitable alternative. It’s important to understand that the list returned may not remain valid if you modify the material or any of the layers in any way and so you would have to re-get the list in that situation.

get_n_layers()
Returns:

the number of layers

Return type:

int

Retrieves the number of layers defined for the given self

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_get_n_layers() instead

get_point_size()
Returns:

the point size of the material.

Return type:

float

Get the size of points drawn when Cogl.VerticesMode.POINTS is used with the vertex buffer API.

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_get_point_size() instead

get_shininess()
Returns:

The materials current shininess value

Return type:

float

Retrieves the materials current emission color.

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

get_specular(specular)
Parameters:

specular (Cogl.Color) – The location to store the specular color

Retrieves the materials current specular color.

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

get_user_program()
Returns:

The current user program or %COGL_INVALID_HANDLE.

Return type:

object

Queries what user program has been associated with the given self using Cogl.Material.set_user_program().

New in version 1.4.

Deprecated since version 1.16: Use #CoglSnippet api instead instead

remove_layer(layer_index)
Parameters:

layer_index (int) – Specifies the layer you want to remove

This function removes a layer from your material

Deprecated since version 1.16: Use cogl_pipeline_remove_layer() instead

set_alpha_test_function(alpha_func, alpha_reference)
Parameters:
  • alpha_func (Cogl.MaterialAlphaFunc) – A CoglMaterialAlphaFunc constant

  • alpha_reference (float) – A reference point that the chosen alpha function uses to compare incoming fragments to.

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.MaterialAlphaFunc.ALWAYS

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_alpha_test_function() instead

set_ambient(ambient)
Parameters:

ambient (Cogl.Color) – The components of the desired ambient color

Sets the material’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)

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_ambient_and_diffuse(color)
Parameters:

color (Cogl.Color) – The components of the desired ambient and diffuse colors

Conveniently sets the diffuse and ambient color of self at the same time. See Cogl.Material.set_ambient() and Cogl.Material.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)

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_blend(blend_string)
Parameters:

blend_string (str) – A ‘Cogl blend string [cogl-Blend-Strings]’ describing the desired blend function.

Raises:

GLib.Error

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

Return type:

int

If not already familiar; please refer ‘here [cogl-Blend-Strings]’ 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:

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

The brackets around blend factors are currently not optional! This is the list of source-names usable as blend factors:

The source names can be used according to the

‘color-source and factor syntax [cogl-Blend-String-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])

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

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]))"
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:

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

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_blend() instead

set_blend_constant(constant_color)
Parameters:

constant_color (Cogl.Color) – The constant color you want

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_blend_constant() instead

set_color(color)
Parameters:

color (Cogl.Color) – The components of the color

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

Note that if you don’t add any layers to the material 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)

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_color() instead

set_color4f(red, green, blue, alpha)
Parameters:
  • red (float) – The red component

  • green (float) – The green component

  • blue (float) – The blue component

  • alpha (float) – The alpha component

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

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_color4f() instead

set_color4ub(red, green, blue, alpha)
Parameters:
  • red (int) – The red component

  • green (int) – The green component

  • blue (int) – The blue component

  • alpha (int) – The alpha component

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

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_color4ub() instead

set_diffuse(diffuse)
Parameters:

diffuse (Cogl.Color) – The components of the desired diffuse color

Sets the material’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)

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_emission(emission)
Parameters:

emission (Cogl.Color) – The components of the desired emissive color

Sets the material’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)

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_layer(layer_index, texture)
Parameters:
  • layer_index (int) – the index of the layer

  • texture (object) – a #CoglHandle for the layer object

In addition to the standard OpenGL lighting model a Cogl material may have one or more layers comprised of textures that can be blended together in order, with a number of different texture combine modes. This function defines a new texture layer.

The index values of multiple layers do not have to be consecutive; it is only their relative order that is important.

In the future, we may define other types of material layers, such as purely GLSL based layers.

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_layer() instead

set_layer_combine(layer_index, blend_string)
Parameters:
  • layer_index (int) – Specifies the layer you want define a combine function for

  • blend_string (str) – A ‘Cogl blend string [cogl-Blend-Strings]’ describing the desired texture combine function.

Raises:

GLib.Error

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

Return type:

int

If not already familiar; you can refer

‘here [cogl-Blend-Strings]’ 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 [cogl-Blend-String-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_material_set_layer_constant()

PRIMARY

Use the color of the material as set with Cogl.Material.set_color()

PREVIOUS

Either use the texture color from the previous layer, or if this is layer 0, use the color of the material as set with Cogl.Material.set_color()

Layer Combine Examples

This is effectively what the default blending is:

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

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

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_combine() instead

set_layer_combine_constant(layer_index, constant)
Parameters:
  • layer_index (int) – Specifies the layer you want to specify a constant used for texture combining

  • constant (Cogl.Color) – The constant color you want

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

New in version 1.0.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_combine_constant() instead

set_layer_filters(layer_index, min_filter, mag_filter)
Parameters:
  • layer_index (int) – the layer number to change.

  • min_filter (Cogl.MaterialFilter) – the filter used when scaling a texture down.

  • mag_filter (Cogl.MaterialFilter) – the filter used when magnifying a texture.

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

Deprecated since version 1.16: Use cogl_pipeline_set_layer_filters() instead

set_layer_matrix(layer_index, matrix)
Parameters:
  • layer_index (int) – the index for the layer inside self

  • matrix (Cogl.Matrix) – the transformation matrix for the layer

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

Deprecated since version 1.16: Use cogl_pipeline_set_layer_matrix() instead

set_layer_point_sprite_coords_enabled(layer_index, enable)
Parameters:
  • layer_index (int) – the layer number to change.

  • enable (int) – whether to enable point sprite coord generation.

Raises:

GLib.Error

Returns:

True if the function succeeds, False otherwise.

Return type:

int

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.FeatureFlags.POINT_SPRITE is available. If the feature is not available then the function will return False and set error.

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_point_sprite_coords_enabled() instead

set_layer_wrap_mode(layer_index, mode)
Parameters:

Sets the wrap mode for all three coordinates of texture lookups on this layer. This is equivalent to calling Cogl.Material.set_layer_wrap_mode_s(), Cogl.Material.set_layer_wrap_mode_t() and Cogl.Material.set_layer_wrap_mode_p() separately.

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_wrap_mode() instead

set_layer_wrap_mode_p(layer_index, mode)
Parameters:

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

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_wrap_mode_p() instead

set_layer_wrap_mode_s(layer_index, mode)
Parameters:

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

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_wrap_mode_s() instead

set_layer_wrap_mode_t(layer_index, mode)
Parameters:

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

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_layer_wrap_mode_t() instead

set_point_size(point_size)
Parameters:

point_size (float) – the new point size.

Changes the size of points drawn when Cogl.VerticesMode.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.

New in version 1.4.

Deprecated since version 1.16: Use cogl_pipeline_set_point_size() instead

set_shininess(shininess)
Parameters:

shininess (float) – The desired shininess; must be >= 0.0

Sets the shininess of the material, 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

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_specular(specular)
Parameters:

specular (Cogl.Color) – The components of the desired specular color

Sets the material’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)

New in version 1.0.

Deprecated since version 1.16: Use the #CoglSnippet shader api for lighting

set_user_program(program)
Parameters:

program (object) – A #CoglHandle to a linked CoglProgram

Associates a linked CoglProgram with the given material so that the program can take full control of vertex and/or fragment processing.

This is an example of how it can be used to associate an ARBfp program with a Cogl.Material:

CoglHandle shader;
CoglHandle program;
CoglMaterial *material;

shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT);
cogl_shader_source (shader,
                    "!!ARBfp1.0\n"
                    "MOV result.color,fragment.color;\n"
                    "END\n");
cogl_shader_compile (shader);

program = cogl_create_program ();
cogl_program_attach_shader (program, shader);
cogl_program_link (program);

material = cogl_material_new ();
cogl_material_set_user_program (material, program);

cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_rectangle (0, 0, 100, 100);

It is possibly worth keeping in mind that this API is not part of the long term design for how we want to expose shaders to Cogl developers (We are planning on deprecating the cogl_program and cogl_shader APIs in favour of a “snippet” framework) but in the meantime we hope this will handle most practical GLSL and ARBfp requirements.

Also remember you need to check for either the Cogl.FeatureFlags.SHADERS_GLSL or Cogl.FeatureFlags.SHADERS_ARBFP before using the cogl_program or cogl_shader API.

New in version 1.4.

Deprecated since version 1.16: Use #CoglSnippet api instead instead