Mesa (master): mesa: added _mesa_compressed_format_to_glenum()

Eric Anholt anholt at kemper.freedesktop.org
Fri Oct 23 22:21:12 UTC 2009


Module: Mesa
Branch: master
Commit: 9528dc6ed8d09eba0dc3be17dc5e9ef4add8083c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9528dc6ed8d09eba0dc3be17dc5e9ef4add8083c

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Oct 23 14:37:41 2009 -0600

mesa: added _mesa_compressed_format_to_glenum()

Maps a compressed MESA_FORMAT_x to correspding GLenum.  Needed for
querying a texture's actual format when a generic format was originally
requested.

---

 src/mesa/main/texcompress.c |   50 +++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/texcompress.h |    4 +++
 2 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index c1b8c76..2cda4dd 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -360,3 +360,53 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
 
    return addr;
 }
+
+
+/**
+ * Given a compressed MESA_FORMAT_x value, return the corresponding
+ * GLenum for that format.
+ * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
+ * which must return the specific texture format used when the user might
+ * have originally specified a generic compressed format in their
+ * glTexImage2D() call.
+ * For non-compressed textures, we always return the user-specified
+ * internal format unchanged.
+ */
+GLenum
+_mesa_compressed_format_to_glenum(GLcontext *ctx, GLuint mesaFormat)
+{
+   switch (mesaFormat) {
+#if FEATURE_texture_fxt1
+   case MESA_FORMAT_RGB_FXT1:
+      return GL_COMPRESSED_RGB_FXT1_3DFX;
+   case MESA_FORMAT_RGBA_FXT1:
+      return GL_COMPRESSED_RGBA_FXT1_3DFX;
+#endif
+#if FEATURE_texture_s3tc
+   case MESA_FORMAT_RGB_DXT1:
+      return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
+   case MESA_FORMAT_RGBA_DXT1:
+      return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+   case MESA_FORMAT_RGBA_DXT3:
+      return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+   case MESA_FORMAT_RGBA_DXT5:
+      return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+#if FEATURE_EXT_texture_sRGB
+   case MESA_FORMAT_SRGB_DXT1:
+      return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
+   case MESA_FORMAT_SRGBA_DXT1:
+      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
+   case MESA_FORMAT_SRGBA_DXT3:
+      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
+   case MESA_FORMAT_SRGBA_DXT5:
+      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
+#endif
+#endif
+   default:
+      _mesa_problem(ctx, "Unexpected mesa texture format in"
+                    " _mesa_compressed_format_to_glenum()");
+      return 0;
+   }
+}
+
+
diff --git a/src/mesa/main/texcompress.h b/src/mesa/main/texcompress.h
index 44f3338..0f1a38f 100644
--- a/src/mesa/main/texcompress.h
+++ b/src/mesa/main/texcompress.h
@@ -52,6 +52,10 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
                                GLsizei width, const GLubyte *image);
 
 
+extern GLenum
+_mesa_compressed_format_to_glenum(GLcontext *ctx, GLuint mesaFormat);
+
+
 extern void
 _mesa_init_texture_s3tc( GLcontext *ctx );
 




More information about the mesa-commit mailing list