summaryrefslogtreecommitdiff
path: root/cogl/cogl-bitmap-conversion.c
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2014-01-14 15:52:45 +0000
committerNeil Roberts <neil@linux.intel.com>2014-01-20 14:28:43 +0000
commit568677ab3bcb62ababad1623be0d6b9b117d0a26 (patch)
tree5feec3374d3409985d1f7b0db8a215db4431bb28 /cogl/cogl-bitmap-conversion.c
parent2f12c4329c519fa14b927b2dcd708dddcc903c32 (diff)
downloadcogl-568677ab3bcb62ababad1623be0d6b9b117d0a26.tar.gz
Add support for RG textures
This adds COGL_PIXEL_FORMAT_RG_88 and COGL_TEXTURE_COMPONENTS_RG in order to support two-component textures. The RG components for a texture is only supported if COGL_FEATURE_ID_TEXTURE_RG is advertised. This is only available on GL 3, GL 2 with the GL_ARB_texture_rg extension or GLES with the GL_EXT_texture_rg extension. The RG pixel format is always supported for images because Cogl can easily do the conversion if an application uses this format to upload to a texture with a different format. If an application tries to create an RG texture when the feature isn't supported then it will raise an error when the texture is allocated. https://bugzilla.gnome.org/show_bug.cgi?id=712830 Reviewed-by: Robert Bragg <robert@linux.intel.com>
Diffstat (limited to 'cogl/cogl-bitmap-conversion.c')
-rw-r--r--cogl/cogl-bitmap-conversion.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/cogl/cogl-bitmap-conversion.c b/cogl/cogl-bitmap-conversion.c
index 6a2e8507..b6d9b149 100644
--- a/cogl/cogl-bitmap-conversion.c
+++ b/cogl/cogl-bitmap-conversion.c
@@ -325,6 +325,7 @@ _cogl_bitmap_needs_short_temp_buffer (CoglPixelFormat format)
g_assert_not_reached ();
case COGL_PIXEL_FORMAT_A_8:
+ case COGL_PIXEL_FORMAT_RG_88:
case COGL_PIXEL_FORMAT_RGB_565:
case COGL_PIXEL_FORMAT_RGBA_4444:
case COGL_PIXEL_FORMAT_RGBA_5551:
@@ -512,6 +513,35 @@ _cogl_bitmap_convert (CoglBitmap *src_bmp,
return dst_bmp;
}
+static CoglBool
+driver_can_convert (CoglContext *ctx,
+ CoglPixelFormat src_format,
+ CoglPixelFormat internal_format)
+{
+ if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_FORMAT_CONVERSION))
+ return FALSE;
+
+ if (src_format == internal_format)
+ return TRUE;
+
+ /* If the driver doesn't natively support alpha textures then it
+ * won't work correctly to convert to/from component-alpha
+ * textures */
+ if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEXTURES) &&
+ (src_format == COGL_PIXEL_FORMAT_A_8 ||
+ internal_format == COGL_PIXEL_FORMAT_A_8))
+ return FALSE;
+
+ /* Same for red-green textures. If red-green textures aren't
+ * supported then the internal format should never be RG_88 but we
+ * should still be able to convert from an RG source image */
+ if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_RG) &&
+ src_format == COGL_PIXEL_FORMAT_RG_88)
+ return FALSE;
+
+ return TRUE;
+}
+
CoglBitmap *
_cogl_bitmap_convert_for_upload (CoglBitmap *src_bmp,
CoglPixelFormat internal_format,
@@ -532,15 +562,7 @@ _cogl_bitmap_convert_for_upload (CoglBitmap *src_bmp,
limited number of formats so we must convert using the Cogl
bitmap code instead */
- /* If the driver doesn't natively support alpha textures then it
- * won't work correctly to convert to/from component-alpha
- * textures */
-
- if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_FORMAT_CONVERSION) &&
- (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEXTURES) ||
- (src_format != COGL_PIXEL_FORMAT_A_8 &&
- internal_format != COGL_PIXEL_FORMAT_A_8) ||
- src_format == internal_format))
+ if (driver_can_convert (ctx, src_format, internal_format))
{
/* If the source format does not have the same premult flag as the
internal_format then we need to copy and convert it */