clutter_actor_get_name (self) ? clutter_actor_get_name (self)
: "unknown");
- cogl_material_set_color4ub (priv->material, 0xff, 0xff, 0xff, paint_opacity);
+ cogl_material_set_color4ub (priv->material,
+ paint_opacity, paint_opacity, paint_opacity, paint_opacity);
clutter_actor_get_allocation_box (self, &box);
*
* This is 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)
*
* Since 1.0
* </programlisting>
* </section>
*
+ * 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.
+ *
* 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, it returns FALSE.
* cogl_set_source_color:
* @color: a #CoglColor
*
- * Sets the source color using normalized values for each component.
- * This color will be used for any subsequent drawing operation.
+ * This is a convenience function for creating a solid fill source material
+ * from the given color. This color will be used for any subsequent drawing
+ * operation.
+ *
+ * The color will be premultiplied by Cogl, so the color should be
+ * non-premultiplied. For example: use (1.0, 0.0, 0.0, 0.5) for
+ * semi-transparent red.
*
* See also cogl_set_source_color4ub() and cogl_set_source_color4f()
* if you already have the color components.
material->blend_constant[2] = 0;
material->blend_constant[3] = 0;
#endif
- material->blend_src_factor_rgb = GL_SRC_ALPHA;
+ material->blend_src_factor_rgb = GL_ONE;
material->blend_dst_factor_rgb = GL_ONE_MINUS_SRC_ALPHA;
material->flags |= COGL_MATERIAL_FLAG_DEFAULT_BLEND_FUNC;
void
cogl_set_source_color (const CoglColor *color)
{
+ CoglColor premultiplied;
+
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* In case cogl_set_source_texture was previously used... */
cogl_material_remove_layer (ctx->default_material, 0);
- cogl_material_set_color (ctx->default_material, color);
+ premultiplied = *color;
+ cogl_color_premultiply (&premultiplied);
+ cogl_material_set_color (ctx->default_material, &premultiplied);
+
cogl_set_source (ctx->default_material);
}
GLenum glformat = 0;
GLenum gltype = 0;
- /* No premultiplied formats accepted by GL
- * (FIXME: latest hardware?) */
-
- if (format & COGL_PREMULT_BIT)
- format = (format & COGL_UNPREMULT_MASK);
-
- /* Everything else accepted
- * (FIXME: check YUV support) */
- required_format = format;
+ /* If PREMULT_BIT isn't specified, that means that we premultiply
+ * textures with alpha before uploading to GL; once we are in GL land,
+ * everything is premultiplied.
+ *
+ * Everything else accepted (FIXME: check YUV support)
+ */
+ if ((format & COGL_A_BIT) != 0 &&
+ format != COGL_PIXEL_FORMAT_A_8)
+ required_format = format | COGL_PREMULT_BIT;
+ else
+ required_format = format;
/* Find GL equivalents */
- switch (format)
+ switch (format & COGL_UNPREMULT_MASK)
{
case COGL_PIXEL_FORMAT_A_8:
glintformat = GL_ALPHA;
GLenum glformat = 0;
GLenum gltype = 0;
- /* No premultiplied formats accepted by GL
- * (FIXME: latest hardware?) */
-
- if (format & COGL_PREMULT_BIT)
- format = (format & COGL_UNPREMULT_MASK);
-
- /* Everything else accepted
- * (FIXME: check YUV support) */
- required_format = format;
+ /* If PREMULT_BIT isn't specified, that means that we premultiply
+ * textures with alpha before uploading to GL; once we are in GL land,
+ * everything is premultiplied.
+ *
+ * Everything else accepted (FIXME: check YUV support)
+ */
+ if ((format & COGL_A_BIT) != 0 &&
+ format != COGL_PIXEL_FORMAT_A_8)
+ required_format = format | COGL_PREMULT_BIT;
+ else
+ required_format = format;
/* Find GL equivalents */
- switch (format)
+ switch (format & COGL_UNPREMULT_MASK)
{
case COGL_PIXEL_FORMAT_A_8:
glintformat = GL_ALPHA;
glformat = GL_RGBA;
gltype = GL_UNSIGNED_BYTE;
required_format = COGL_PIXEL_FORMAT_RGBA_8888;
+ required_format |= (format & COGL_PREMULT_BIT);
break;
/* The following three types of channel ordering
const CoglColor *color,
CoglPangoDisplayListNode *node)
{
+ CoglColor premult_color = *color;
cogl_material_set_layer (material, 0, node->d.texture.texture);
- cogl_material_set_color (material, color);
+ cogl_color_premultiply (&premult_color);
+ cogl_material_set_color (material, &premult_color);
cogl_set_source (material);
if (node->d.texture.vertex_buffer == COGL_INVALID_HANDLE)
cogl_color_get_alpha_byte (color));
else
draw_color = *color;
+ cogl_color_premultiply (&draw_color);
switch (node->type)
{
/* The default combine mode of materials is to modulate (A x B) the texture
* RGBA channels with the RGBA channels of the previous layer (which in our
- * case is just the solid font color)
+ * case is just the font color)
*
- * Since our glyph cache textures are component alpha textures, and so the
- * RGB channels are defined as (0, 0, 0) we don't want to modulate the RGB
- * channels, instead we want to simply replace them with our solid font
- * color...
+ * Since the RGB for an alpha texture is defined as 0, this gives us:
+ *
+ * result.rgb = color.rgb * 0
+ * result.a = color.a * texture.a
+ *
+ * What we want is premultiplied rgba values:
+ *
+ * result.rgba = color.rgb * texture.a
+ * result.a = color.a * texture.a
*/
cogl_material_set_layer_combine (priv->glyph_material, 0, /* layer */
- "RGB = REPLACE (PREVIOUS)"
- "A = MODULATE (PREVIOUS, TEXTURE)",
+ "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
NULL);
priv->solid_material = cogl_material_new ();
cogl_set_draw_buffer (COGL_WINDOW_BUFFER, 0);
material = cogl_material_new ();
- cogl_material_set_color4ub (material, 0xff, 0xff, 0xff, 0x88);
+ cogl_material_set_color4ub (material, 0x88, 0x88, 0x88, 0x88);
cogl_material_set_layer (material, 0, priv->texture_id);
cogl_set_source (material);
cogl_rectangle_with_texture_coords (100, 100,