util: fix DXT1 RGBA texture compression if the source color is (0, 0, 0, 0)
authorMarek Olšák <maraeo@gmail.com>
Wed, 16 Feb 2011 03:18:42 +0000 (04:18 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 16 Feb 2011 06:04:14 +0000 (16:04 +1000)
This is a workaround for a bug in libtxc_dxtn.

Fixes:
- piglit/GL_EXT_texture_compression_s3tc/fbo-generatemipmap-formats

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/auxiliary/util/u_format_s3tc.c

index bb989c29d81869c6ea4fdff7205d5c7c97ed6e14..31288e3f0ce1c91ee64ad5e86dae295ae732718d 100644 (file)
@@ -416,8 +416,20 @@ util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
          uint8_t tmp[4][4][4];  /* [bh][bw][comps] */
          for(j = 0; j < bh; ++j) {
             for(i = 0; i < bw; ++i) {
-               for(k = 0; k < comps; ++k) {
-                  tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k];
+               const uint8_t *srcp = &src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps];
+               /* Workaround for a bug in libtxc_dxtn.
+                * If the color is (0,0,0,0), it is compressed as (0,0,0,1),
+                * which is incorrect. Any other (x,y,z,0) color is compressed
+                * correctly as (0,0,0,0), so let's use (1,0,0,0). */
+               if (srcp[0] == 0 && srcp[1] == 0 && srcp[2] == 0 && srcp[3] == 0) {
+                  tmp[j][i][0] = 255;
+                  tmp[j][i][1] = 0;
+                  tmp[j][i][2] = 0;
+                  tmp[j][i][3] = 0;
+               } else {
+                  for(k = 0; k < comps; ++k) {
+                     tmp[j][i][k] = srcp[k];
+                  }
                }
             }
          }