From 8538bdbdeae74433ed5f50b1e6ee0db3d9a81a3e Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 5 May 2010 16:45:21 +0100 Subject: [PATCH] cogl-atlas-texture: Accept formats with different component orders When filtering on allowed formats for atlas textures, it now masks out the BGR and AFIRST bits in addition to the premult bit. That way it will accept RGB and RGBA formats in any component order. In theory it could also accept luminance and alpha-only textures but I haven't added this because presumably if the application has requested these formats then it has some reason not to use a full RGB or RGBA texture and we should respect that. --- clutter/cogl/cogl/cogl-atlas-texture.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/clutter/cogl/cogl/cogl-atlas-texture.c b/clutter/cogl/cogl/cogl-atlas-texture.c index 6459eb135..5d60476f4 100644 --- a/clutter/cogl/cogl/cogl-atlas-texture.c +++ b/clutter/cogl/cogl/cogl-atlas-texture.c @@ -903,6 +903,20 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex, return ret; } +static gboolean +_cogl_atlas_texture_can_use_format (CoglPixelFormat format) +{ + /* We don't care about the ordering or the premult status and we can + accept RGBA or RGB textures. Although we could also accept + luminance and alpha only textures or 16-bit formats it seems that + if the application is explicitly using these formats then they've + got a reason to want the lower memory requirements so putting + them in the atlas might not be a good idea */ + format &= ~(COGL_PREMULT_BIT | COGL_BGR_BIT | COGL_AFIRST_BIT); + return (format == COGL_PIXEL_FORMAT_RGB_888 || + format == COGL_PIXEL_FORMAT_RGBA_8888); +} + CoglHandle _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, CoglTextureFlags flags, @@ -954,9 +968,8 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, internal_format = _cogl_texture_determine_internal_format (bmp_format, internal_format); - /* If the texture is in a strange format then we can't use it */ - if (internal_format != COGL_PIXEL_FORMAT_RGB_888 && - (internal_format & ~COGL_PREMULT_BIT) != COGL_PIXEL_FORMAT_RGBA_8888) + /* If the texture is in a strange format then we won't use it */ + if (!_cogl_atlas_texture_can_use_format (internal_format)) { COGL_NOTE (ATLAS, "Texture can not be added because the " "format is unsupported");