[Cogl] [PATCH] gles: Support the GL_EXT_texture_format_BGRA8888 extension
Neil Roberts
neil at linux.intel.com
Wed Mar 21 09:11:55 PDT 2012
This extension allows an application to upload data in BGRA format. We
can use this to avoid a conversion in Cogl whenever it is given BGRA
data. This is quite useful when uploading data generated by Cairo
because at least on little-endian architectures that ends up as BGRA.
The patch just makes the pixel_format_to_gl implementation return
GL_BGRA_EXT for the data format and internal format whenever
COGL_PIXEL_FORMAT_BGRA_8888{,_PRE} is used.
A small caveat with this patch is that once a texture is created as
GL_BGRA, when later using glTexSubImage2D to update the texture it
must always be given data as GL_BGRA. Currently this just works out
because we store the internal format of a texture as a CoglPixelFormat
and we already swizzle the data if it does not match exactly on GLES.
However if we later switch to using a different enum for internal
formats then we might lose the ability to store the component ordering
so we'll have to think of another way to do this.
---
cogl/cogl-internal.h | 3 ++-
cogl/cogl-texture.c | 9 +++++++++
cogl/driver/gles/cogl-gles.c | 3 +++
cogl/driver/gles/cogl-texture-driver-gles.c | 20 ++++++++++++++++++--
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h
index 9019859..4f53cc3 100644
--- a/cogl/cogl-internal.h
+++ b/cogl/cogl-internal.h
@@ -100,7 +100,8 @@ typedef enum
COGL_PRIVATE_FEATURE_PBOS = 1L<<5,
COGL_PRIVATE_FEATURE_VBOS = 1L<<6,
COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL = 1L<<7,
- COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL = 1L<<8
+ COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL = 1L<<8,
+ COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888 = 1L<<9
} CoglPrivateFeatureFlags;
/* Sometimes when evaluating pipelines, either during comparisons or
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 6b08ec5..1f1900e 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -166,6 +166,15 @@ _cogl_texture_determine_internal_format (CoglPixelFormat src_format,
return src_format;
}
else
+ /* XXX: It might be nice to make this match the component ordering
+ of the source format when the formats are otherwise the same
+ because on GL there is no way to specify the ordering of the
+ internal format. However when using GLES with the
+ GL_EXT_texture_format_BGRA8888 the order of the internal format
+ becomes important because it must exactly match the format of
+ the uploaded data. That means that if someone creates a texture
+ with some RGBA data and then later tries to upload BGRA data we
+ do actually have to swizzle the components */
return dst_format;
}
diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c
index 8087ae0..e0f6500 100644
--- a/cogl/driver/gles/cogl-gles.c
+++ b/cogl/driver/gles/cogl-gles.c
@@ -166,6 +166,9 @@ _cogl_gles_update_features (CoglContext *context,
if (_cogl_check_extension ("GL_OES_packed_depth_stencil", gl_extensions))
private_flags |= COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL;
+ if (_cogl_check_extension ("GL_EXT_texture_format_BGRA8888", gl_extensions))
+ private_flags |= COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888;
+
/* Cache features */
context->private_feature_flags |= private_flags;
context->feature_flags |= flags;
diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c
index 2bc596b..62a65ee 100644
--- a/cogl/driver/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gles/cogl-texture-driver-gles.c
@@ -407,6 +407,8 @@ _cogl_texture_driver_pixel_format_to_gl (CoglPixelFormat format,
GLenum glformat = 0;
GLenum gltype;
+ _COGL_GET_CONTEXT (ctx, 0);
+
required_format = format;
/* Find GL equivalents */
@@ -432,11 +434,25 @@ _cogl_texture_driver_pixel_format_to_gl (CoglPixelFormat format,
required_format = COGL_PIXEL_FORMAT_RGB_888;
break;
+ case COGL_PIXEL_FORMAT_BGRA_8888:
+ case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
+ /* There is an extension to support this format */
+ if ((ctx->private_feature_flags &
+ COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888))
+ {
+ /* For some reason the extension says you have to specify
+ BGRA for the internal format too */
+ glintformat = GL_BGRA_EXT;
+ glformat = GL_BGRA_EXT;
+ gltype = GL_UNSIGNED_BYTE;
+ required_format = format;
+ break;
+ }
+ /* flow through */
+
/* Just one 32-bit ordering supported */
case COGL_PIXEL_FORMAT_RGBA_8888:
case COGL_PIXEL_FORMAT_RGBA_8888_PRE:
- case COGL_PIXEL_FORMAT_BGRA_8888:
- case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
case COGL_PIXEL_FORMAT_ARGB_8888:
case COGL_PIXEL_FORMAT_ARGB_8888_PRE:
case COGL_PIXEL_FORMAT_ABGR_8888:
--
1.7.3.16.g9464b
More information about the Cogl
mailing list