diff options
author | Juan Linietsky <reduzio@gmail.com> | 2021-06-11 12:35:00 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 12:35:00 -0300 |
commit | fbb5a541ef30f41bb7814687e9cd9f11e991faa7 (patch) | |
tree | 310dcd962e26a598c594c0502a5cb964f729fa71 /core/io/image.cpp | |
parent | 8d4046929c05a865247caa5bb6958a75c45cf293 (diff) | |
parent | 81ed9fa31bc63823235f64c88d441a8e530ab039 (diff) |
Merge pull request #49421 from floppyhammer/fix-vram-compressed-mipmaps
Fix mipmaps of VRAM compressed textures
Diffstat (limited to 'core/io/image.cpp')
-rw-r--r-- | core/io/image.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index c36fa6e45f..bac439dd33 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -1428,16 +1428,23 @@ void Image::flip_x() { } } +/// Get mipmap size and offset. int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) { + // Data offset in mipmaps (including the original texture). int size = 0; + int w = p_width; int h = p_height; + + // Current mipmap index in the loop below. p_mipmaps is the target mipmap index. + // In this function, mipmap 0 represents the first mipmap instead of the original texture. int mm = 0; int pixsize = get_format_pixel_size(p_format); int pixshift = get_format_pixel_rshift(p_format); int block = get_format_block_size(p_format); - //technically, you can still compress up to 1 px no matter the format, so commenting this + + // Technically, you can still compress up to 1 px no matter the format, so commenting this. //int minw, minh; //get_format_min_pixel_size(p_format, minw, minh); int minw = 1, minh = 1; @@ -1453,17 +1460,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & size += s; - if (r_mm_width) { - *r_mm_width = bw; - } - if (r_mm_height) { - *r_mm_height = bh; - } - - if (p_mipmaps >= 0 && mm == p_mipmaps) { - break; - } - if (p_mipmaps >= 0) { w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); @@ -1474,6 +1470,21 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); } + + // Set mipmap size. + // It might be necessary to put this after the minimum mipmap size check because of the possible occurrence of "1 >> 1". + if (r_mm_width) { + *r_mm_width = bw >> 1; + } + if (r_mm_height) { + *r_mm_height = bh >> 1; + } + + // Reach target mipmap. + if (p_mipmaps >= 0 && mm == p_mipmaps) { + break; + } + mm++; } |