minetest / irrlicht

Minetest's fork of Irrlicht
Other
115 stars 87 forks source link

Fix mip map size calculation for non-square textures #273

Closed HybridDog closed 10 months ago

HybridDog commented 10 months ago

Problem description

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).

Proposed changes

To support non-square textures, after this change, uploadTexture sets the mip map width or height to 1 if it is 0.

How to test

Before the changes: Desert Sand nodes are black and in the inventory it's white. before

After the changes: Desert Sand looks like the other nodes, i.e. the full resolution and inventory image show the texture and only the mip maps are cyan, which is supposed to happen with the code in my mipmap_custom_simple_fill branch. after