r300g: fix RGTC1_UNORM and RGTC2_UNORM
authorMarek Olšák <maraeo@gmail.com>
Tue, 1 Mar 2011 02:21:23 +0000 (03:21 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 1 Mar 2011 02:24:55 +0000 (03:24 +0100)
Signs don't work the way I'd like...

src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_texture.c

index 7776ab5a3ff35fd5a01cbdbd9d14b2c04979bf46..7e06958972b232e7bc6376fd52efde9790acdd7b 100644 (file)
@@ -641,8 +641,22 @@ static uint32_t r300_get_border_color(enum pipe_format format,
 
     /* Compressed formats. */
     if (util_format_is_compressed(format)) {
-        util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
-        return uc.ui;
+        switch (format) {
+        case PIPE_FORMAT_RGTC1_SNORM:
+        case PIPE_FORMAT_RGTC1_UNORM:
+            /* Add 1/32 to round the border color instead of truncating. */
+            /* The Y component is used for the border color. */
+            border_swizzled[1] = border_swizzled[2] + 1.0f/32;
+            util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
+            return uc.ui;
+        case PIPE_FORMAT_RGTC2_SNORM:
+        case PIPE_FORMAT_RGTC2_UNORM:
+            util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+            return uc.ui;
+        default:
+            util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
+            return uc.ui;
+        }
     }
 
     switch (desc->channel[0].size) {
index bbd3f972a551b176eaabb6fe83bf87261aa93e77..831b06b0e587b7943d5f428b14afc11c0425f94a 100644 (file)
@@ -171,8 +171,16 @@ uint32_t r300_translate_texformat(enum pipe_format format,
             }
     }
 
-    result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view,
-                    util_format_is_compressed(format) && dxtc_swizzle);
+    if (util_format_is_compressed(format) &&
+        dxtc_swizzle &&
+        format != PIPE_FORMAT_RGTC2_UNORM &&
+        format != PIPE_FORMAT_RGTC2_SNORM) {
+        result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view,
+                                            dxtc_swizzle);
+    } else {
+        result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view,
+                                            FALSE);
+    }
 
     /* S3TC formats. */
     if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
@@ -215,17 +223,12 @@ uint32_t r300_translate_texformat(enum pipe_format format,
     if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
         switch (format) {
             case PIPE_FORMAT_RGTC1_SNORM:
-                result |= sign_bit[0];
+                result |= sign_bit[1];
             case PIPE_FORMAT_RGTC1_UNORM:
-                result &= ~(0xfff << 9); /* mask off swizzle */
-                result |= R300_TX_FORMAT_Y << R300_TX_FORMAT_R_SHIFT;
                 return R500_TX_FORMAT_ATI1N | result;
             case PIPE_FORMAT_RGTC2_SNORM:
                 result |= sign_bit[0] | sign_bit[1];
             case PIPE_FORMAT_RGTC2_UNORM:
-                result &= ~(0xfff << 9); /* mask off swizzle */
-                result |= R300_TX_FORMAT_Y << R300_TX_FORMAT_R_SHIFT |
-                          R300_TX_FORMAT_X << R300_TX_FORMAT_G_SHIFT;
                 return R400_TX_FORMAT_ATI2N | result;
             default:
                 return ~0; /* Unsupported/unknown. */