From e297506365559f2b13534b9dd5f3250db06975a5 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 23 Nov 2024 15:28:58 -0500 Subject: [PATCH] Round DDS width/height to next divisor multiple for block compression --- modules/dds/texture_loader_dds.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 601d0e0c244..667de70d130 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -289,6 +289,15 @@ static Ref _dds_load_layer(Ref p_file, DDSFormat p_dds_format if (info.compressed) { // BC compressed. + w += w % info.divisor; + h += h % info.divisor; + if (w != p_width) { + WARN_PRINT(vformat("%s: DDS width '%d' is not divisible by %d. This is not allowed as per the DDS specification, attempting to load anyway.", p_file->get_path(), p_width, info.divisor)); + } + if (h != p_height) { + WARN_PRINT(vformat("%s: DDS height '%d' is not divisible by %d. This is not allowed as per the DDS specification, attempting to load anyway.", p_file->get_path(), p_height, info.divisor)); + } + uint32_t size = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size; if (p_flags & DDSD_LINEARSIZE) {