mesa: Do something sensible when on-line compression is requested but not possible
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 21 Aug 2012 22:20:23 +0000 (15:20 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 29 Aug 2012 22:09:38 +0000 (15:09 -0700)
It is possible to force S3TC extensions to be enabled.  This is
generally done to support applications that will only supply
pre-compressed textures.  This accounts for the vast majority of
applications.

However, there is still the possibility of an application asking for
on-line compression.  In that case, generate a warning and substitute a
generic compressed format.  The driver will either pick an uncompressed
format or a compressed format that Mesa can handle on-line (e.g., FXT1).

This should only cause problems for applications that request on-line
compression and read the compressed texture back.  This is likely an
infinitesimal subset of an already infinitesimal subset.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/main/teximage.c

index c0868fabb217216c13dda2d091016d5dbd37d36c..11b1b3043a975aa50f18178f30a69655c0879a74 100644 (file)
@@ -2799,6 +2799,37 @@ _mesa_choose_texture_format(struct gl_context *ctx,
       }
    }
 
+   /* If the application requested compression to an S3TC format but we don't
+    * have the DTXn library, force a generic compressed format instead.
+    */
+   if (internalFormat != format) {
+      const GLenum before = internalFormat;
+
+      switch (internalFormat) {
+      case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+         if (!ctx->Mesa_DXTn)
+            internalFormat = GL_COMPRESSED_RGB;
+         break;
+      case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+      case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+      case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+         if (!ctx->Mesa_DXTn)
+            internalFormat = GL_COMPRESSED_RGBA;
+         break;
+      default:
+         break;
+      }
+
+      if (before != internalFormat) {
+         _mesa_warning(ctx,
+                       "DXT compression requested (%s), "
+                       "but libtxc_dxtn library not installed.  Using %s "
+                       "instead.",
+                       _mesa_lookup_enum_by_nr(before),
+                       _mesa_lookup_enum_by_nr(internalFormat));
+      }
+   }
+
    /* choose format from scratch */
    f = ctx->Driver.ChooseTextureFormat(ctx, texObj->Target, internalFormat,
                                        format, type);