Fix mip calculation for compressed formats. #94
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.
The correct mipchain size is calculated un-rounded, and then rounded up per mip. Instead, bgfx::calcTextureSize rounds up per-mip, and sizes down the mip from the rounded up value, resulting in a larger value than expected.
GLI library implements this correctly, and was used as the reference here.
BC1 texture example 1920x1080:
From the above you can see even though the 60 x 33 mip matches, the 30x16 mip gets incorrectly sized up to 30x20.
ref:
https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf
section 8.14.3
A texture is mipmap complete if:
...
The dimensions of the images follow the sequence described in sec-
tion 8.14.3.
The storage per-mip is rounded up to 4x4 blocks, but the width + height sequence does not change as a result. This matches GL_TEXTURE_COMPRESSED_IMAGE_SIZE size return and also matches GLI, which implements the spec. Other APIs such as DX, vulkan and proprietary console APIs have the same storage mechanism that GL describes here.