-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ktx cubemap size calculation #64
Conversation
Change was introduced by commit bkaradzic#63 (b8a7a90)
The attached file is a zipped ktx file (128x128 cubemap with 8 mip levels) that texturev refuses to load on current master with this assert:
|
@attilaz This changes line previously added by you, and you might want to check logic. |
autoshop_01_ggx has imageSize = faceSize * 6. The texture I had the problem with was exported with PVRTexTool. @goodartistscopy What tool did You use for creating this ktx? |
I have checked autoshop_01_ggx with ktxinfo from here: https://github.com/KhronosGroup/KTX-Software/releases/tag/v4.0.0 ktxinfo autoshop_01_ggx.ktx identifier: «KTX 11»\r\n\x1A\n |
What numbers should be here to be correct cubemap? |
From https://www.khronos.org/registry/KTX/specs/1.0/ktxspec_v1.html pixelWidth, pixelHeight, pixelDepth numberOfArrayElements numberOfArrayElements specifies the number of array elements. If the texture is not an array texture, numberOfArrayElements must equal 0. |
@attilaz I used the bimg API to write this texture (bimg::imageWriteKtx() taking an ImageContainer). |
So IIUC, this test:
aims to implement this part of KTX spec:
Maybe it should be
? |
Reading ktx numLayers Line 4097 in 9e4d2b1
So I think _imageContainer.m_numLayers can't be zero. But yes, exception should only happen when numLayers was 0 in the file. |
Yes I think this is why I have m_numLayers = 1 in my code, because I suspected that saturation to 1 may not be done consistently throughout bimg. I think m_numLayers = 0 should be used to signal non arrayed textures. Same for depth = 0 probably. |
This still doesn't work for KTX files generated with toktx which show the following ktxinfo:
I did a ktxinfo on all the KTX files in bgfx/examples/runtime/textures and they are all invalid with the message:
I assume these files were created with BIMG and the issue seems to be:
I checked some of the BGFX examples that use these invalid KTX files and they are working implying the current BIMG logic only works with invalid files. If I comment out:
or change:
back to the previous version of src/image.cpp, my KTX files (generated with toktx) work just fine. Recommend undoing pull request #64 until this is sorted out. BTW: is there a way to load cubemaps in BGFX from 6 separate images instead of having to create these KTX files? |
Agreed. It would be better to have bimg only use numLayers > 0 for layered textures and depth > 0 for 3D textures.
|
@goossens Where did you get this ktxinfo tool? |
@bkaradzic its one of the tool from Khronos KTX SDK https://github.com/KhronosGroup/KTX-Software |
@bkaradzic The Khronos KTX SDK also includes the "toktx" tool that I used to create my cubemaps. @goodartistscopy Thanks for the hint on "updateTextureCube", it works like a charm even though it appears slow. I need to figure out why. |
Change was introduced by commit #63 (b8a7a90)