Nominom / BCnEncoder.NET

Cross-platform texture encoding libary for .NET. With support for BC1-3/DXT, BC4-5/RGTC and BC6-7/BPTC compression. Outputs files in ktx or dds formats.
The Unlicense
108 stars 16 forks source link

`DecodeAllMipMaps2D(DdsFile)` returns empty array if `dwMipMapCount` is 0 even when there is a face with mip maps #64

Open Crauzer opened 1 year ago

Crauzer commented 1 year ago

This issue arises from the fact that mip count is handled differently in DdsFile and in DecodeInternal.

These are the relevent lines: https://github.com/Nominom/BCnEncoder.NET/blob/master/BCnEnc.Net/Decoder/BcDecoder.cs#L1161-L1164 https://github.com/Nominom/BCnEncoder.NET/blob/master/BCnEnc.Net/Shared/ImageFiles/DdsFile.cs#L57

I think the easiest way to fix this would to be assume that each file has at least 1 mipmap. Microsoft says that you shouldn't rely on the mipmap flag being set.

Crauzer commented 1 year ago

Another reference to mip count being clamped to at least 1: https://learn.microsoft.com/en-us/windows/uwp/gaming/complete-code-for-ddstextureloader

    size_t mipCount = header->mipMapCount;
    if (0 == mipCount)
    {
        mipCount = 1;
    }