![]() |
![]() |
![]() |
COGL Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
CoglHandle cogl_material_new (void
); CoglHandle cogl_material_copy (CoglHandle source
); CoglHandle cogl_material_ref (CoglHandle handle
); void cogl_material_unref (CoglHandle handle
); gboolean cogl_is_material (CoglHandle handle
); void cogl_material_set_color (CoglHandle material
,const CoglColor *color
); void cogl_material_set_color4ub (CoglHandle material
,guint8 red
,guint8 green
,guint8 blue
,guint8 alpha
); void cogl_material_set_color4f (CoglHandle material
,float red
,float green
,float blue
,float alpha
); void cogl_material_get_color (CoglHandle material
,CoglColor *color
); void cogl_material_set_ambient (CoglHandle material
,const CoglColor *ambient
); void cogl_material_get_ambient (CoglHandle material
,CoglColor *ambient
); void cogl_material_set_diffuse (CoglHandle material
,const CoglColor *diffuse
); void cogl_material_get_diffuse (CoglHandle material
,CoglColor *diffuse
); void cogl_material_set_ambient_and_diffuse (CoglHandle material
,const CoglColor *color
); void cogl_material_set_emission (CoglHandle material
,const CoglColor *emission
); void cogl_material_get_emission (CoglHandle material
,CoglColor *emission
); void cogl_material_set_specular (CoglHandle material
,const CoglColor *specular
); void cogl_material_get_specular (CoglHandle material
,CoglColor *specular
); void cogl_material_set_shininess (CoglHandle material
,float shininess
); float cogl_material_get_shininess (CoglHandle material
); enum CoglMaterialAlphaFunc; void cogl_material_set_alpha_test_function (CoglHandle material
,CoglMaterialAlphaFunc alpha_func
,float alpha_reference
); #define COGL_BLEND_STRING_ERROR enum CoglBlendStringError; gboolean cogl_material_set_blend (CoglHandle material
,const char *blend_string
,GError **error
); void cogl_material_set_blend_constant (CoglHandle material
,CoglColor *constant_color
); void cogl_material_set_layer (CoglHandle material
,int layer_index
,CoglHandle texture
); void cogl_material_remove_layer (CoglHandle material
,int layer_index
); gboolean cogl_material_set_layer_combine (CoglHandle material
,int layer_index
,const char *blend_string
,GError **error
); void cogl_material_set_layer_combine_constant (CoglHandle material
,int layer_index
,CoglColor *constant
); void cogl_material_set_layer_matrix (CoglHandle material
,int layer_index
,CoglMatrix *matrix
); const GList * cogl_material_get_layers (CoglHandle material
); int cogl_material_get_n_layers (CoglHandle material
); enum CoglMaterialFilter; void cogl_material_set_layer_filters (CoglHandle material
,int layer_index
,CoglMaterialFilter min_filter
,CoglMaterialFilter mag_filter
); enum CoglMaterialLayerType; CoglMaterialLayerType cogl_material_layer_get_type (CoglHandle layer
); CoglHandle cogl_material_layer_get_texture (CoglHandle layer
); CoglMaterialFilter cogl_material_layer_get_min_filter (CoglHandle layer
); CoglMaterialFilter cogl_material_layer_get_mag_filter (CoglHandle layer
); void cogl_material_set_layer_wrap_mode (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
); void cogl_material_set_layer_wrap_mode_s (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
); void cogl_material_set_layer_wrap_mode_t (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
); CoglMaterialWrapMode cogl_material_layer_get_wrap_mode_s (CoglHandle layer
); CoglMaterialWrapMode cogl_material_layer_get_wrap_mode_t (CoglHandle layer
);
COGL allows creating and manipulating materials used to fill in geometry. Materials may simply be lighting attributes (such as an ambient and diffuse colour) or might represent one or more textures blended together.
CoglHandle cogl_material_new (void
);
Allocates and initializes a blank white material
Returns : |
a handle to the new material |
CoglHandle cogl_material_copy (CoglHandle source
);
Creates a new material handle with the configuration copied from the source material.
We would strongly advise developers to always aim to use
cogl_material_copy()
instead of cogl_material_new()
whenever there will
be any similarity between two materials. Copying a material helps Cogl
keep track of a materials ancestry which we may use to help minimize GPU
state changes.
|
the handle for the material to copy |
Returns : |
a handle to the new material |
Since 1.2
CoglHandle cogl_material_ref (CoglHandle handle
);
cogl_material_ref
has been deprecated since version 1.2 and should not be used in newly-written code. Use cogl_handle_ref()
instead
Increment the reference count for a cogl material.
|
a CoglHandle .
|
Returns : |
the handle .
|
Since 1.0
void cogl_material_unref (CoglHandle handle
);
cogl_material_unref
has been deprecated since version 1.2 and should not be used in newly-written code. Use cogl_handle_unref()
instead
Decrement the reference count for a cogl material.
|
a CoglHandle .
|
Since 1.0
gboolean cogl_is_material (CoglHandle handle
);
Gets whether the given handle references an existing material object.
|
A CoglHandle |
Returns : |
TRUE if the handle references a CoglMaterial,
FALSE otherwise
|
void cogl_material_set_color (CoglHandle material
,const CoglColor *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)
|
A CoglMaterial object |
|
The components of the color |
Since 1.0
void cogl_material_set_color4ub (CoglHandle material
,guint8 red
,guint8 green
,guint8 blue
,guint8 alpha
);
Sets the basic color of the material, used when no lighting is enabled.
The default value is (0xff, 0xff, 0xff, 0xff)
|
A CoglMaterial object |
|
The red component |
|
The green component |
|
The blue component |
|
The alpha component |
Since 1.0
void cogl_material_set_color4f (CoglHandle material
,float red
,float green
,float blue
,float alpha
);
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)
|
A CoglMaterial object |
|
The red component |
|
The green component |
|
The blue component |
|
The alpha component |
Since 1.0
void cogl_material_get_color (CoglHandle material
,CoglColor *color
);
Retrieves the current material color.
|
A CoglMaterial object |
|
The location to store the color. [out] |
Since 1.0
void cogl_material_set_ambient (CoglHandle material
,const CoglColor *ambient
);
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)
|
A CoglMaterial object |
|
The components of the desired ambient color |
Since 1.0
void cogl_material_get_ambient (CoglHandle material
,CoglColor *ambient
);
Retrieves the current ambient color for material
|
A CoglMaterial object |
|
The location to store the ambient color |
Since 1.0
void cogl_material_set_diffuse (CoglHandle material
,const CoglColor *diffuse
);
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)
|
A CoglMaterial object |
|
The components of the desired diffuse color |
Since 1.0
void cogl_material_get_diffuse (CoglHandle material
,CoglColor *diffuse
);
Retrieves the current diffuse color for material
|
A CoglMaterial object |
|
The location to store the diffuse color |
Since 1.0
void cogl_material_set_ambient_and_diffuse (CoglHandle material
,const CoglColor *color
);
Conveniently sets the diffuse and ambient color of material
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)
|
A CoglMaterial object |
|
The components of the desired ambient and diffuse colors |
Since 1.0
void cogl_material_set_emission (CoglHandle material
,const CoglColor *emission
);
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)
|
A CoglMaterial object |
|
The components of the desired emissive color |
Since 1.0
void cogl_material_get_emission (CoglHandle material
,CoglColor *emission
);
Retrieves the materials current emission color.
|
A CoglMaterial object |
|
The location to store the emission color |
Since 1.0
void cogl_material_set_specular (CoglHandle material
,const CoglColor *specular
);
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)
|
A CoglMaterial object |
|
The components of the desired specular color |
Since 1.0
void cogl_material_get_specular (CoglHandle material
,CoglColor *specular
);
Retrieves the materials current specular color.
|
A CoglMaterial object |
|
The location to store the specular color |
Since 1.0
void cogl_material_set_shininess (CoglHandle material
,float shininess
);
Sets the materials shininess, in the standard OpenGL lighting model,
which determines how specular highlights are calculated. A higher
shininess
will produce smaller brigher highlights.
The default value is 0.0
|
A CoglMaterial object |
|
The desired shininess; range: [0.0, 1.0] |
Since 1.0
float cogl_material_get_shininess (CoglHandle material
);
Retrieves the materials current emission color.
|
A CoglMaterial object |
Returns : |
The materials current shininess value |
Since 1.0
typedef enum { COGL_MATERIAL_ALPHA_FUNC_NEVER = GL_NEVER, COGL_MATERIAL_ALPHA_FUNC_LESS = GL_LESS, COGL_MATERIAL_ALPHA_FUNC_EQUAL = GL_EQUAL, COGL_MATERIAL_ALPHA_FUNC_LEQUAL = GL_LEQUAL, COGL_MATERIAL_ALPHA_FUNC_GREATER = GL_GREATER, COGL_MATERIAL_ALPHA_FUNC_NOTEQUAL = GL_NOTEQUAL, COGL_MATERIAL_ALPHA_FUNC_GEQUAL = GL_GEQUAL, COGL_MATERIAL_ALPHA_FUNC_ALWAYS = GL_ALWAYS } CoglMaterialAlphaFunc;
Alpha testing happens before blending primitives with the framebuffer and gives an opportunity to discard fragments based on a comparison with the incoming alpha value and a reference alpha value. The CoglMaterialAlphaFunc determines how the comparison is done.
Never let the fragment through. | |
Let the fragment through if the incoming alpha value is less than the reference alpha value | |
Let the fragment through if the incoming alpha value equals the reference alpha value | |
Let the fragment through if the incoming alpha value is less than or equal to the reference alpha value | |
Let the fragment through if the incoming alpha value is greater than the reference alpha value | |
Let the fragment through if the incoming alpha value does not equal the reference alpha value | |
Let the fragment through if the incoming alpha value is greater than or equal to the reference alpha value. | |
Always let the fragment through. |
void cogl_material_set_alpha_test_function (CoglHandle material
,CoglMaterialAlphaFunc alpha_func
,float alpha_reference
);
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_MATERIAL_ALPHA_FUNC_ALWAYS
|
A CoglMaterial object |
|
A CoglMaterialAlphaFunc constant
|
|
A reference point that the chosen alpha function uses to compare incoming fragments to. |
Since 1.0
#define COGL_BLEND_STRING_ERROR (cogl_blend_string_error_quark ())
GError domain for blend string parser errors
Since 1.0
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
Generic parse error | |
Argument parse error | |
Internal parser error | |
Blend string not supported by the GPU |
Since 1.0
gboolean cogl_material_set_blend (CoglHandle material
,const char *blend_string
,GError **error
);
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_material_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:
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 material is in premultiplied form.
|
A CoglMaterial object |
|
A Cogl blend string describing the desired blend function. |
|
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 1.0
void cogl_material_set_blend_constant (CoglHandle material
,CoglColor *constant_color
);
When blending is setup to reference a CONSTANT blend factor then blending will depend on the constant set with this function.
|
A CoglMaterial object |
|
The constant color you want |
Since 1.0
void cogl_material_set_layer (CoglHandle material
,int layer_index
,CoglHandle texture
);
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.
|
A CoglHandle for a material object |
|
the index of the layer |
|
a CoglHandle for the layer object |
Since 1.0
void cogl_material_remove_layer (CoglHandle material
,int layer_index
);
This function removes a layer from your material
|
A CoglMaterial object |
|
Specifies the layer you want to remove |
gboolean cogl_material_set_layer_combine (CoglHandle material
,int layer_index
,const char *blend_string
,GError **error
);
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:
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_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()
|
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_material_set_layer_constant.
1 |
RGBA = INTERPOLATE (PREVIOUS, TEXTURE, CONSTANT[A]) |
|
A CoglMaterial object |
|
Specifies the layer you want define a combine function for |
|
A Cogl blend string describing the desired texture combine function. |
|
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 1.0
void cogl_material_set_layer_combine_constant (CoglHandle material
,int layer_index
,CoglColor *constant
);
When you are using the 'CONSTANT' color source in a layer combine description then you can use this function to define its value.
|
A CoglMaterial object |
|
Specifies the layer you want to specify a constant used for texture combining |
|
The constant color you want |
Since 1.0
void cogl_material_set_layer_matrix (CoglHandle material
,int layer_index
,CoglMatrix *matrix
);
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.
|
A CoglMaterial object |
|
the index for the layer inside material
|
|
the transformation matrix for the layer |
const GList * cogl_material_get_layers (CoglHandle material
);
This function lets you access a materials internal list of layers for iteration.
|
a CoglHandle for a material |
Returns : |
A list of CoglHandle'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. [element-type Handle][transfer none Handle] |
int cogl_material_get_n_layers (CoglHandle material
);
Retrieves the number of layers defined for the given material
|
a CoglHandle for a material |
Returns : |
the number of layers |
Since 1.0
typedef enum { COGL_MATERIAL_FILTER_NEAREST = GL_NEAREST, COGL_MATERIAL_FILTER_LINEAR = GL_LINEAR, COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, COGL_MATERIAL_FILTER_LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, COGL_MATERIAL_FILTER_NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, COGL_MATERIAL_FILTER_LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR } CoglMaterialFilter;
Texture filtering is used whenever the current pixel maps either to more than one texture element (texel) or less than one. These filter enums correspond to different strategies used to come up with a pixel color, by possibly referring to multiple neighbouring texels and taking a weighted average or simply using the nearest texel.
Measuring in manhatten distance from the, current pixel center, use the nearest texture texel | |
Use the weighted average of the 4 texels nearest the current pixel center | |
Select the mimap level whose
texel size most closely matches the current pixel, and use the
COGL_MATERIAL_FILTER_NEAREST criterion
|
|
Select the mimap level whose
texel size most closely matches the current pixel, and use the
COGL_MATERIAL_FILTER_LINEAR criterion
|
|
Select the two mimap levels
whose texel size most closely matches the current pixel, use
the COGL_MATERIAL_FILTER_NEAREST criterion on each one and take
their weighted average
|
|
Select the two mimap levels
whose texel size most closely matches the current pixel, use
the COGL_MATERIAL_FILTER_LINEAR criterion on each one and take
their weighted average
|
void cogl_material_set_layer_filters (CoglHandle material
,int layer_index
,CoglMaterialFilter min_filter
,CoglMaterialFilter mag_filter
);
Changes the decimation and interpolation filters used when a texture is drawn at other scales than 100%.
|
a CoglHandle to a material. |
|
the layer number to change. |
|
the filter used when scaling a texture down. |
|
the filter used when magnifying a texture. |
typedef enum { COGL_MATERIAL_LAYER_TYPE_TEXTURE } CoglMaterialLayerType;
Available types of layers for a CoglMaterial. This enumeration might be expanded in later versions.
The layer represents a texture |
Since 1.0
CoglMaterialLayerType cogl_material_layer_get_type (CoglHandle layer
);
Retrieves the type of the layer
Currently there is only one type of layer defined:
COGL_MATERIAL_LAYER_TYPE_TEXTURE
, but considering we may add purely GLSL
based layers in the future, you should write code that checks the type
first.
|
A CoglHandle for a material layer |
Returns : |
the type of the layer |
CoglHandle cogl_material_layer_get_texture (CoglHandle layer
);
Extracts a texture handle for a specific layer.
COGL_INVALID_HANDLE
if you
try to get the texture handle from them. Considering this scenario, you
should call cogl_material_layer_get_type()
first in order check it is of
type COGL_MATERIAL_LAYER_TYPE_TEXTURE
before calling this function.
|
A CoglHandle for a material layer |
Returns : |
a CoglHandle for the texture inside the layer |
CoglMaterialFilter cogl_material_layer_get_min_filter (CoglHandle layer
);
Queries the currently set downscaling filter for a material layer
|
a CoglHandle for a material layer |
Returns : |
the current downscaling filter |
CoglMaterialFilter cogl_material_layer_get_mag_filter (CoglHandle layer
);
Queries the currently set downscaling filter for a material later
|
a CoglHandle for a material layer |
Returns : |
the current downscaling filter |
void cogl_material_set_layer_wrap_mode (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
);
Sets the wrap mode for both coordinates of texture lookups on this
layer. This is equivalent to calling
cogl_material_set_layer_wrap_mode_s()
and
cogl_material_set_layer_wrap_mode_t()
separately.
|
a CoglHandle to a material. |
|
the layer number to change. |
|
the new wrap mode |
Since 1.4
void cogl_material_set_layer_wrap_mode_s (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
);
Sets the wrap mode for the 's' coordinate of texture lookups on this layer.
|
a CoglHandle to a material. |
|
the layer number to change. |
|
the new wrap mode |
Since 1.4
void cogl_material_set_layer_wrap_mode_t (CoglHandle material
,int layer_index
,CoglMaterialWrapMode mode
);
Sets the wrap mode for the 't' coordinate of texture lookups on this layer.
|
a CoglHandle to a material. |
|
the layer number to change. |
|
the new wrap mode |
Since 1.4
CoglMaterialWrapMode cogl_material_layer_get_wrap_mode_s
(CoglHandle layer
);
Gets the wrap mode for the 's' coordinate of texture lookups on this layer.
|
a CoglHandle to a material mayer. |
Since 1.4
CoglMaterialWrapMode cogl_material_layer_get_wrap_mode_t
(CoglHandle layer
);
Gets the wrap mode for the 't' coordinate of texture lookups on this layer.
|
a CoglHandle to a material mayer. |
Since 1.4