From 1e6569e678eeb808ff3cb5b008083f718f83e7cf Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 31 Dec 2021 22:59:01 +0100 Subject: [PATCH] dxgsg9: Fix issues with luminance textures and ATI1 compression Fixes #1198 --- panda/src/dxgsg9/dxTextureContext9.cxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/panda/src/dxgsg9/dxTextureContext9.cxx b/panda/src/dxgsg9/dxTextureContext9.cxx index 70c9db7803..5e2fc2d94b 100644 --- a/panda/src/dxgsg9/dxTextureContext9.cxx +++ b/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);