From a9b011f3edc9730f60280e38bf2164f1c2dd95a9 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sat, 6 Jun 2009 21:45:05 +0100 Subject: [PATCH] [premultiplication] Be more conservative with what data gets premultiplied We don't want to force texture data to be premultipled if the user explicitly specifies a non premultiplied internal_format such as COGL_PIXEL_FORMAT_RGBA_8888. So now Cogl will only automatically premultiply data when COGL_PIXEL_FORMAT_ANY is given for the internal_format, or a premultiplied internal format such as COGL_PIXEL_FORMAT_RGBA_8888_PRE is requested but non-premultiplied source data is given. This approach is consistent with OpenVG image formats which have already influenced Cogl's pixel format semantics. --- clutter/cogl/gl/cogl-texture.c | 24 +++++++++++------------- clutter/cogl/gles/cogl-texture.c | 24 +++++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/clutter/cogl/gl/cogl-texture.c b/clutter/cogl/gl/cogl-texture.c index 2ee50617c..877107d3c 100644 --- a/clutter/cogl/gl/cogl-texture.c +++ b/clutter/cogl/gl/cogl-texture.c @@ -1085,17 +1085,9 @@ _cogl_pixel_format_to_gl (CoglPixelFormat format, GLenum glformat = 0; GLenum gltype = 0; - /* 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; + /* FIXME: check YUV support */ + + required_format = format; /* Find GL equivalents */ switch (format & COGL_UNPREMULT_MASK) @@ -1197,9 +1189,15 @@ _cogl_texture_bitmap_prepare (CoglTexture *tex, CoglPixelFormat new_data_format; gboolean success; - /* Was there any internal conversion requested? */ + /* Was there any internal conversion requested? + * By default Cogl will use a premultiplied internal format. Later we will + * add control over this. */ if (internal_format == COGL_PIXEL_FORMAT_ANY) - internal_format = tex->bitmap.format; + { + if ((tex->bitmap.format & COGL_A_BIT) && + tex->bitmap.format != COGL_PIXEL_FORMAT_A_8) + internal_format = tex->bitmap.format | COGL_PREMULT_BIT; + } /* Find closest format accepted by GL */ new_data_format = _cogl_pixel_format_to_gl (internal_format, diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c index f9b6e0b78..ab1653e07 100644 --- a/clutter/cogl/gles/cogl-texture.c +++ b/clutter/cogl/gles/cogl-texture.c @@ -1184,17 +1184,9 @@ _cogl_pixel_format_to_gl (CoglPixelFormat format, GLenum glformat = 0; GLenum gltype = 0; - /* 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; + /* FIXME: check YUV support */ + + required_format = format; /* Find GL equivalents */ switch (format & COGL_UNPREMULT_MASK) @@ -1273,9 +1265,15 @@ _cogl_texture_bitmap_prepare (CoglTexture *tex, CoglPixelFormat new_data_format; gboolean success; - /* Was there any internal conversion requested? */ + /* Was there any internal conversion requested? + * By default Cogl will use a premultiplied internal format. Later we will + * add control over this. */ if (internal_format == COGL_PIXEL_FORMAT_ANY) - internal_format = tex->bitmap.format; + { + if ((tex->bitmap.format & COGL_A_BIT) && + tex->bitmap.format != COGL_PIXEL_FORMAT_A_8) + internal_format = tex->bitmap.format | COGL_PREMULT_BIT; + } /* Find closest format accepted by GL */ new_data_format = _cogl_pixel_format_to_gl (internal_format,