KTX alignment in TexTool

I’m trying to load up a KTX file I encoded from a PNG in PVRTexTool in my application, but the file won’t load. The original image is a roughness map and I encoded it as GL_RED8 with mipmap generation.

I traced into the code it appears to be an issue with the image sizes. When I get down to the 2x2 mip, the file reports an image size of 4 bytes. However, the KTX specification says

[blockquote]Uncompressed texture data matches a GL_UNPACK_ALIGNMENT of 4.[/blockquote]

meaning that each row of the image data must be 4 byte aligned. So the image size should be 8, not 4 (2 rows of 4 bytes each, the first two of which are the pixel data, and the remaining two as padding).

Is my reading of the KTX spec incorrect?

Hi Brad,

Yes, your reading is correct and this is a bug in PVRTexTool. PVRTexTool writes out the correct amount of padding per row but we don’t seem to be taking row alignment when calculating the texture size. So that even though the data for a 2x2 8bpp mipmap is written out correctly as 8 bytes, we only write the value of 4 for the mipmap size instead of this 8.
We have fixed this problem in our MAIN branch and it will be available in our next release.

Thanks!

Carlos.