mesa: add generic compressed -> uncompressed format helper
authorBrian Paul <brianp@vmware.com>
Fri, 24 Aug 2012 14:43:42 +0000 (08:43 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 24 Aug 2012 20:09:03 +0000 (14:09 -0600)
_mesa_generic_compressed_format_to_uncompressed_format() probably wins the
prize for longest function name in Mesa.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/mesa/main/glformats.c
src/mesa/main/glformats.h

index b6f9e94f5f544391bc9dc8f70887468685957d8e..2d06cb7151b9e58247af4aea5f4db279a2e3917b 100644 (file)
@@ -970,6 +970,45 @@ _mesa_base_format_has_channel(GLenum base_format, GLenum pname)
 }
 
 
+/**
+ * If format is a generic compressed format, return the corresponding
+ * non-compressed format.  For other formats, return the format as-is.
+ */
+GLenum
+_mesa_generic_compressed_format_to_uncompressed_format(GLenum format)
+{
+   switch (format) {
+   case GL_COMPRESSED_RED:
+      return GL_RED;
+   case GL_COMPRESSED_RG:
+      return GL_RG;
+   case GL_COMPRESSED_RGB:
+      return GL_RGB;
+   case GL_COMPRESSED_RGBA:
+      return GL_RGBA;
+   case GL_COMPRESSED_ALPHA:
+      return GL_ALPHA;
+   case GL_COMPRESSED_LUMINANCE:
+      return GL_LUMINANCE;
+   case GL_COMPRESSED_LUMINANCE_ALPHA:
+      return GL_LUMINANCE_ALPHA;
+   case GL_COMPRESSED_INTENSITY:
+      return GL_INTENSITY;
+   /* sRGB formats */
+   case GL_COMPRESSED_SRGB:
+      return GL_SRGB;
+   case GL_COMPRESSED_SRGB_ALPHA:
+      return GL_SRGB_ALPHA;
+   case GL_COMPRESSED_SLUMINANCE:
+      return GL_SLUMINANCE;
+   case GL_COMPRESSED_SLUMINANCE_ALPHA:
+      return GL_SLUMINANCE_ALPHA;
+   default:
+      return format;
+   }
+}
+
+
 /**
  * Do error checking of format/type combinations for glReadPixels,
  * glDrawPixels and glTex[Sub]Image.  Note that depending on the format
index d553eae0a0ada2926c0b900a2dd77122eb45396d..24fbda9913738496e2c5d7dd963b65b78ef2cb5b 100644 (file)
@@ -91,6 +91,9 @@ _mesa_base_format_to_integer_format(GLenum format);
 extern GLboolean
 _mesa_base_format_has_channel(GLenum base_format, GLenum pname);
 
+extern GLenum
+_mesa_generic_compressed_format_to_uncompressed_format(GLenum format);
+
 extern GLenum
 _mesa_error_check_format_and_type(const struct gl_context *ctx,
                                   GLenum format, GLenum type);