This repository has been archived by the owner on May 13, 2024. It is now read-only.
Fix mip map size calculation for non-square textures #273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem description
The size of a mip map is
max{floor(width / 2 ^ level), 1} x max{floor(height / 2 ^ level), 1}
, wherewidth x height
is the size of the full-resolution image,level
is the integer mip map level and the smallest mip map has1 x 1
resolution. IfregenerateMipMapLevels
is called with custom mip map data, the mip map sizes are calculated in this function and separately inuploadTexture
.uploadTexture
calculates a size byfloor(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 to1
if it is0
.How to test
default_desert_sand.png
texture with this 2x16 pixel texture:mip_map
setting tosharp
Before the changes: Desert Sand nodes are black and in the inventory it's white.

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.
