mesa: document sRGBDecode field
[mesa.git] / src / mesa / main / texcompress.c
index 262e8236eddd8152370149a798fd0bf676531438..7a0b522a2d8ea0873c40187e6961e7cb0628887d 100644 (file)
 #include "glheader.h"
 #include "imports.h"
 #include "colormac.h"
-#include "context.h"
 #include "formats.h"
-#include "image.h"
-#include "mipmap.h"
+#include "mfeatures.h"
+#include "mtypes.h"
 #include "texcompress.h"
-#include "texstore.h"
 
 
 /**
@@ -54,7 +52,7 @@
  * \return number of formats.
  */
 GLuint
-_mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
+_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats, GLboolean all)
 {
    GLuint n = 0;
    if (ctx->Extensions.TDFX_texture_compression_FXT1) {
@@ -110,6 +108,24 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
    }
 #endif /* FEATURE_EXT_texture_sRGB */
    return n;
+
+#if FEATURE_ES1 || FEATURE_ES2
+   if (formats) {
+      formats[n++] = GL_PALETTE4_RGB8_OES;
+      formats[n++] = GL_PALETTE4_RGBA8_OES;
+      formats[n++] = GL_PALETTE4_R5_G6_B5_OES;
+      formats[n++] = GL_PALETTE4_RGBA4_OES;
+      formats[n++] = GL_PALETTE4_RGB5_A1_OES;
+      formats[n++] = GL_PALETTE8_RGB8_OES;
+      formats[n++] = GL_PALETTE8_RGBA8_OES;
+      formats[n++] = GL_PALETTE8_R5_G6_B5_OES;
+      formats[n++] = GL_PALETTE8_RGBA4_OES;
+      formats[n++] = GL_PALETTE8_RGB5_A1_OES;
+   }
+   else {
+      n += 10;
+   }
+#endif
 }
 
 
@@ -153,6 +169,54 @@ _mesa_glenum_to_compressed_format(GLenum format)
 }
 
 
+/**
+ * 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(struct gl_context *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;
+   }
+}
+
+
 /*
  * Return the address of the pixel at (col, row, img) in a
  * compressed texture image.