Browse Source

dxgsg9: Fix issues with luminance textures and ATI1 compression

Fixes #1198
rdb 4 years ago
parent
commit
1e6569e678
1 changed files with 20 additions and 4 deletions
  1. 20 4
      panda/src/dxgsg9/dxTextureContext9.cxx

+ 20 - 4
panda/src/dxgsg9/dxTextureContext9.cxx

@@ -427,10 +427,26 @@ create_texture(DXScreenData &scrn) {
   }
 
   if (compress_texture) {
-    if (num_color_channels == 1) {
-      CHECK_FOR_FMT(ATI1);
-    } else if (num_alpha_bits == 0 && num_color_channels == 2) {
-      CHECK_FOR_FMT(ATI2);
+    // The ATI1 and ATI2 formats can't be compressed by the driver.
+    // Only choose them if we can compress them on the CPU.
+    // Also, don't choose ATI for a luminance texture, since it gets read as
+    // a texture with just a red channel.
+    if (num_alpha_bits == 0 && !needs_luminance) {
+      if (num_color_channels == 1) {
+        if (scrn._supported_tex_formats_mask & ATI1_FLAG) {
+          if (tex->compress_ram_image(Texture::CM_rgtc)) {
+            target_pixel_format = D3DFMT_ATI1;
+            goto found_matching_format;
+          }
+        }
+      } else if (num_color_channels == 2) {
+        if (scrn._supported_tex_formats_mask & ATI2_FLAG) {
+          if (tex->compress_ram_image(Texture::CM_rgtc)) {
+            target_pixel_format = D3DFMT_ATI2;
+            goto found_matching_format;
+          }
+        }
+      }
     }
     if (num_alpha_bits <= 1) {
       CHECK_FOR_FMT(DXT1);