From fb4ee6ac930c16a63127427a817593d81e218349 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Fri, 5 Jan 2024 12:07:30 +0100 Subject: [PATCH] Fix mip map size calculation for non-square textures The size of a mip map is `max{floor(width / 2 ^ level), 1} x max{floor(height / 2 ^ level), 1}`, where `width x height` is the size of the full-resolution image, `level` is the integer mip map level and the smallest mip map has `1 x 1` resolution. If `regenerateMipMapLevels` is called with custom mip map data, the mip map sizes are calculated in this function and separately in `uploadTexture`. `uploadTexture` calculates a size by `floor(width / 2 ^ level) x floor(height / 2 ^ level)`. To support non-square textures, after this change, `uploadTexture` sets the mip map width or height to `1` if it is `0`. --- source/Irrlicht/COpenGLCoreTexture.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index d4133fdd..8d9e66ce 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -561,6 +561,10 @@ protected: u32 width = Size.Width >> level; u32 height = Size.Height >> level; + if (width < 1) + width = 1; + if (height < 1) + height = 1; GLenum tmpTextureType = TextureType;