diff options
author | Lyuma <xn.lyuma@gmail.com> | 2022-01-23 11:32:05 -0800 |
---|---|---|
committer | Lyuma <xn.lyuma@gmail.com> | 2022-01-23 11:32:05 -0800 |
commit | e8da21dc6b4b90d345c8bbfc8354699dd19b9bb3 (patch) | |
tree | 8ed0ae7dc0ef102238cbea338dd1e037e81965f0 /modules/etcpak | |
parent | dd6e5b3eaaaa715fd6b6c808a35fac14bdf17521 (diff) |
etcpak: Workaround multiple-of-4 requirement for 3D texture mipmaps.
Diffstat (limited to 'modules/etcpak')
-rw-r--r-- | modules/etcpak/image_compress_etcpak.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/etcpak/image_compress_etcpak.cpp b/modules/etcpak/image_compress_etcpak.cpp index 274d43d437..7d5557d197 100644 --- a/modules/etcpak/image_compress_etcpak.cpp +++ b/modules/etcpak/image_compress_etcpak.cpp @@ -152,14 +152,18 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img, float p_lossy_qua are used for a 2x2 map, and texel 'a' is used for 1x1. Note that this is similar to, but distinct from, the surface pitch, which can encompass additional padding beyond the physical surface size. */ - int next_width = (width + 3) & ~3; - int next_height = (height + 3) & ~3; + int next_width = width <= 2 ? width : (width + 3) & ~3; + int next_height = height <= 2 ? height : (height + 3) & ~3; if (next_width != width || next_height != height) { r_img->resize(next_width, next_height, Image::INTERPOLATE_LANCZOS); width = r_img->get_width(); height = r_img->get_height(); } - ERR_FAIL_COND(width % 4 != 0 || height % 4 != 0); // Should be guaranteed by above + // ERR_FAIL_COND(width % 4 != 0 || height % 4 != 0); // FIXME: No longer guaranteed. + // Multiple-of-4 should be guaranteed by above. + // However, power-of-two 3d textures will create Nx2 and Nx1 mipmap levels, + // which are individually compressed Image objects that violate the above rule. + // Hence, we allow Nx1 and Nx2 images through without forcing to multiple-of-4. const uint8_t *src_read = r_img->get_data().ptr(); |