[Mesa-dev] Patch no 2: more verbose logging

Carl-Philip Haensch Carl-Philip.Haensch at mailbox.tu-dresden.de
Sat Apr 16 09:18:32 PDT 2011


Hi,

The first patch for more verbose logging why texture compression fails  
showed me that the problem was in the internalFormat.
But i did not know which internalFormat the compression of this  
texture needed.
So i extended the code a bit to log which OpenGL extension is needed  
for each internalFormat so that I have a more exact output when sth.  
fails.

Here's the patch:

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index 28841c2..7978f92 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1025,39 +1025,48 @@ _mesa_is_integer_format(GLenum format)
   * \return GL_TRUE if compressed, GL_FALSE if uncompressed
   */
  GLboolean
-_mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
+_mesa_is_compressed_format(struct gl_context *ctx, GLenum format,
+                           char **extension)
  {
+   *extension = "";
     switch (format) {
     case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
     case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
     case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
     case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+      *extension = "EXT_texture_compression_s3tc";
        return ctx->Extensions.EXT_texture_compression_s3tc;
     case GL_RGB_S3TC:
     case GL_RGB4_S3TC:
     case GL_RGBA_S3TC:
     case GL_RGBA4_S3TC:
+      *extension = "s3tc";
        return ctx->Extensions.S3_s3tc;
     case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
     case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
     case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
     case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+      *extension = "EXT_texture_compression_s3tc with EXT_texture_sRGB";
        return ctx->Extensions.EXT_texture_sRGB
           && ctx->Extensions.EXT_texture_compression_s3tc;
     case GL_COMPRESSED_RGB_FXT1_3DFX:
     case GL_COMPRESSED_RGBA_FXT1_3DFX:
+      *extension = "TDFX_texture_compression_FXT1";
        return ctx->Extensions.TDFX_texture_compression_FXT1;
     case GL_COMPRESSED_RED_RGTC1:
     case GL_COMPRESSED_SIGNED_RED_RGTC1:
     case GL_COMPRESSED_RG_RGTC2:
     case GL_COMPRESSED_SIGNED_RG_RGTC2:
+      *extension = "ARB_texture_compression_rgtc";
        return ctx->Extensions.ARB_texture_compression_rgtc;
     case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
     case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
     case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
     case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
+      *extension = "EXT_texture_compression_latc";
        return ctx->Extensions.EXT_texture_compression_latc;
     case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+      *extension = "ATI_texture_compression_3dc";
        return ctx->Extensions.ATI_texture_compression_3dc;
     default:
        return GL_FALSE;
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index 005fbcc..54f78c1 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -85,7 +85,8 @@ extern GLboolean
  _mesa_is_integer_format(GLenum format);

  extern GLboolean
-_mesa_is_compressed_format(struct gl_context *ctx, GLenum format);
+_mesa_is_compressed_format(struct gl_context *ctx, GLenum format,
+			   char **extension);

  extern GLvoid *
  _mesa_image_address( GLuint dimensions,
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 8fb54c6..8bd48b1 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1582,7 +1582,7 @@ texture_error_check( struct gl_context *ctx,
                       GLint level, GLint internalFormat,
                       GLenum format, GLenum type,
                       GLint width, GLint height,
-                     GLint depth, GLint border )
+                     GLint depth, GLint border)
  {
     const GLenum proxyTarget = get_proxy_target(target);
     const GLboolean isProxy = target == proxyTarget;
@@ -1730,11 +1730,12 @@ texture_error_check( struct gl_context *ctx,
     }

     /* additional checks for compressed textures */
-   if (_mesa_is_compressed_format(ctx, internalFormat)) {
+   char *compression;
+   if (_mesa_is_compressed_format(ctx, internalFormat, &compression)) {
        if (!target_can_be_compressed(ctx, target, internalFormat)) {
           if (!isProxy)
              _mesa_error(ctx, GL_INVALID_ENUM,
-                        "glTexImage%dD(target)", dimensions);
+                        "glTexImage%dD(target requires %s)",  
dimensions, compression);
           return GL_TRUE;
        }
        if (border != 0) {
@@ -2008,10 +2009,11 @@ copytexture_error_check( struct gl_context  
*ctx, GLuint dimensions,
        return GL_TRUE;
     }

-   if (_mesa_is_compressed_format(ctx, internalFormat)) {
+   char *compression;
+   if (_mesa_is_compressed_format(ctx, internalFormat, &compression)) {
        if (!target_can_be_compressed(ctx, target, internalFormat)) {
           _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glCopyTexImage%dD(target)", dimensions);
+                     "glCopyTexImage%dD(target requires %s)",  
dimensions, compression);
           return GL_TRUE;
        }
        if (border != 0) {
@@ -3061,8 +3063,7 @@ compressed_texture_error_check(struct gl_context  
*ctx, GLint dimensions,
     }

     /* This will detect any invalid internalFormat value */
-   if (!_mesa_is_compressed_format(ctx, internalFormat)) {
-      *reason = "internalFormat";
+   if (!_mesa_is_compressed_format(ctx, internalFormat, reason)) {
        return GL_INVALID_ENUM;
     }

@@ -3143,6 +3144,7 @@ compressed_subtexture_error_check(struct  
gl_context *ctx, GLint dimensions,
                                    GLsizei width, GLsizei height,  
GLsizei depth,
                                    GLenum format, GLsizei imageSize)
  {
+   // ToDo: This also has to be mined with reason checking constructs
     GLint expectedSize, maxLevels = 0, maxTextureSize;
     GLuint bw, bh;
     (void) zoffset;
@@ -3181,7 +3183,8 @@ compressed_subtexture_error_check(struct  
gl_context *ctx, GLint dimensions,
     maxTextureSize = 1 << (maxLevels - 1);

     /* this will catch any invalid compressed format token */
-   if (!_mesa_is_compressed_format(ctx, format))
+   char *dummy;
+   if (!_mesa_is_compressed_format(ctx, format, &dummy))
        return GL_INVALID_ENUM;

     if (width < 1 || width > maxTextureSize)



More information about the mesa-dev mailing list