Default to a blend function that expects premultiplied colors

Many operations, like mixing two textures together or alpha-blending
onto a destination with alpha, are done most logically if texture data
is in premultiplied form. We also have many sources of premultiplied
texture data, like X pixmaps, FBOs, cairo surfaces. Rather than trying
to work with two different types of texture data, simplify things by
always premultiplying texture data before uploading to GL.

Because the default blend function is changed to accommodate this,
uses of pure-color CoglMaterial need to be adapted to add
premultiplication.

gl/cogl-texture.c gles/cogl-texture.c: Always premultiply
  non-premultiplied texture data before uploading to GL.

cogl-material.c cogl-material.h: Switch the default blend functions
  to ONE, ONE_MINUS_SRC_ALPHA so they work correctly with premultiplied
  data.

cogl.c: Make cogl_set_source_color() premultiply the color.

cogl.h.in color-material.h: Add some documentation about
  premultiplication and its interaction with color values.

cogl-pango-render.c clutter-texture.c tests/interactive/test-cogl-offscreen.c:
  Use premultiplied colors.

http://bugzilla.openedhand.com/show_bug.cgi?id=1406

Signed-off-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Owen W. Taylor
2009-05-09 14:39:01 -04:00
committed by Robert Bragg
parent 888a261999
commit c3448314d5
10 changed files with 67 additions and 34 deletions

View File

@ -124,16 +124,20 @@ cogl_pango_renderer_init (CoglPangoRenderer *priv)
/* 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 ();