mesa: clean-up, simplify compressed texture size checking
authorBrian Paul <brianp@vmware.com>
Sun, 25 Oct 2009 22:59:08 +0000 (16:59 -0600)
committerBrian Paul <brianp@vmware.com>
Sun, 25 Oct 2009 22:59:08 +0000 (16:59 -0600)
src/mesa/main/texcompress.c
src/mesa/main/texcompress.h
src/mesa/main/teximage.c

index ad10993307e0dbe6a8ed478129531d6fad9e96f8..423ad2490c0ce5909b36957f9d62d545ef55d9ff 100644 (file)
@@ -114,67 +114,42 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
 
 
 /**
- * As above, but format is specified by a GLenum (GL_COMPRESSED_*) token.
- *
- * Note: This function CAN NOT return a padded hardware texture size.
- * That's why we don't call the ctx->Driver.CompressedTextureSize() function.
- *
- * We use this function to validate the <imageSize> parameter
- * of glCompressedTex[Sub]Image1/2/3D(), which must be an exact match.
+ * Convert a compressed MESA_FORMAT_x to a GLenum.
  */
-GLuint
-_mesa_compressed_texture_size_glenum(GLcontext *ctx,
-                                     GLsizei width, GLsizei height,
-                                     GLsizei depth, GLenum glformat)
+gl_format
+_mesa_glenum_to_compressed_format(GLenum format)
 {
-   gl_format mesaFormat;
-
-   switch (glformat) {
-#if FEATURE_texture_fxt1
+   switch (format) {
    case GL_COMPRESSED_RGB_FXT1_3DFX:
-      mesaFormat = MESA_FORMAT_RGB_FXT1;
-      break;
+      return MESA_FORMAT_RGB_FXT1;
    case GL_COMPRESSED_RGBA_FXT1_3DFX:
-      mesaFormat = MESA_FORMAT_RGBA_FXT1;
-      break;
-#endif
-#if FEATURE_texture_s3tc
+      return MESA_FORMAT_RGBA_FXT1;
+
    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
    case GL_RGB_S3TC:
-      mesaFormat = MESA_FORMAT_RGB_DXT1;
-      break;
+      return MESA_FORMAT_RGB_DXT1;
    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
    case GL_RGB4_S3TC:
-      mesaFormat = MESA_FORMAT_RGBA_DXT1;
-      break;
+      return MESA_FORMAT_RGBA_DXT1;
    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
    case GL_RGBA_S3TC:
-      mesaFormat = MESA_FORMAT_RGBA_DXT3;
-      break;
+      return MESA_FORMAT_RGBA_DXT3;
    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
    case GL_RGBA4_S3TC:
-      mesaFormat = MESA_FORMAT_RGBA_DXT5;
-      break;
-#if FEATURE_EXT_texture_sRGB
+      return MESA_FORMAT_RGBA_DXT5;
+
    case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
-      mesaFormat = MESA_FORMAT_SRGB_DXT1;
-      break;
+      return MESA_FORMAT_SRGB_DXT1;
    case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
-      mesaFormat = MESA_FORMAT_SRGBA_DXT1;
-      break;
+      return MESA_FORMAT_SRGBA_DXT1;
    case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
-      mesaFormat = MESA_FORMAT_SRGBA_DXT3;
-      break;
+      return MESA_FORMAT_SRGBA_DXT3;
    case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
-      mesaFormat = MESA_FORMAT_SRGBA_DXT5;
-      break;
-#endif
-#endif
+      return MESA_FORMAT_SRGBA_DXT5;
+
    default:
-      return 0;
+      return MESA_FORMAT_NONE;
    }
-
-   return _mesa_format_image_size(mesaFormat, width, height, depth);
 }
 
 
index 70247098b2ae43bb5610f33a627428bd5ddaec6c..43cd741895664f82e5780481b21c89ee7102ce07 100644 (file)
 extern GLuint
 _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all);
 
-extern GLuint
-_mesa_compressed_texture_size_glenum(GLcontext *ctx,
-                                     GLsizei width, GLsizei height,
-                                     GLsizei depth, GLenum glformat);
+extern gl_format
+_mesa_glenum_to_compressed_format(GLenum format);
 
 extern GLint
 _mesa_compressed_row_stride(gl_format mesaFormat, GLsizei width);
index 52d2886d0aea6e5d5e930c7b68cfa450d6c81ab2..4fbfeb8582680176bdbefb741ba317890e1ddc4e 100644 (file)
@@ -3034,6 +3034,20 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
 /**********************************************************************/
 
 
+/**
+ * Return expected size of a compressed texture.
+ */
+static GLuint
+compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
+                    GLenum glformat)
+{
+   gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
+   return _mesa_format_image_size(mesaFormat, width, height, depth);
+}
+
+
+
+
 /**
  * Error checking for glCompressedTexImage[123]D().
  * \return error code or GL_NO_ERROR.
@@ -3116,8 +3130,7 @@ compressed_texture_error_check(GLcontext *ctx, GLint dimensions,
    if (level < 0 || level >= maxLevels)
       return GL_INVALID_VALUE;
 
-   expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height,
-                                                       depth, internalFormat);
+   expectedSize = compressed_tex_size(width, height, depth, internalFormat);
    if (expectedSize != imageSize)
       return GL_INVALID_VALUE;
 
@@ -3211,8 +3224,7 @@ compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions,
    if ((height & 3) != 0 && height != 2 && height != 1)
       return GL_INVALID_VALUE;
 
-   expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height,
-                                                       depth, format);
+   expectedSize = compressed_tex_size(width, height, depth, format);
    if (expectedSize != imageSize)
       return GL_INVALID_VALUE;