Skip to content
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

Fixes for cubemap loading from ktx/pvr3 container #63

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/bimg/bimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ namespace bimg
bool m_cubeMap;
bool m_ktx;
bool m_ktxLE;
bool m_pvr3;
bool m_srgb;
};

Expand Down
21 changes: 15 additions & 6 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,7 @@ namespace bimg
imageContainer->m_hasAlpha = false;
imageContainer->m_cubeMap = _cubeMap;
imageContainer->m_ktx = false;
imageContainer->m_pvr3 = false;
imageContainer->m_ktxLE = false;
imageContainer->m_srgb = false;

Expand Down Expand Up @@ -3738,6 +3739,7 @@ namespace bimg
_imageContainer.m_cubeMap = cubeMap;
_imageContainer.m_ktx = false;
_imageContainer.m_ktxLE = false;
_imageContainer.m_pvr3 = false;
_imageContainer.m_srgb = srgb;

return true;
Expand Down Expand Up @@ -4093,6 +4095,7 @@ namespace bimg
_imageContainer.m_cubeMap = numFaces > 1;
_imageContainer.m_ktx = true;
_imageContainer.m_ktxLE = fromLittleEndian;
_imageContainer.m_pvr3 = false;
_imageContainer.m_srgb = srgb;

if (TextureFormat::Unknown == format)
Expand Down Expand Up @@ -4258,6 +4261,7 @@ namespace bimg
_imageContainer.m_cubeMap = numFaces > 1;
_imageContainer.m_ktx = false;
_imageContainer.m_ktxLE = false;
_imageContainer.m_pvr3 = true;
_imageContainer.m_srgb = colorSpace > 0;

return TextureFormat::Unknown != format;
Expand Down Expand Up @@ -4319,6 +4323,7 @@ namespace bimg
_imageContainer.m_cubeMap = tc.m_cubeMap;
_imageContainer.m_ktx = false;
_imageContainer.m_ktxLE = false;
_imageContainer.m_pvr3 = false;
_imageContainer.m_srgb = false;

return _err->isOk();
Expand Down Expand Up @@ -5018,7 +5023,7 @@ namespace bimg
const uint8_t* data = (const uint8_t*)_data;
const uint16_t numSides = _imageContainer.m_numLayers * (_imageContainer.m_cubeMap ? 6 : 1);

if (_imageContainer.m_ktx)
if (_imageContainer.m_ktx || _imageContainer.m_pvr3)
{
uint32_t width = _imageContainer.m_width;
uint32_t height = _imageContainer.m_height;
Expand All @@ -5031,12 +5036,16 @@ namespace bimg
depth = bx::max<uint32_t>(1, depth);

const uint32_t mipSize = width/blockWidth * height/blockHeight * depth * blockSize;
const uint32_t size = mipSize*numSides;
uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
BX_ASSERT(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize);
BX_UNUSED(size, imageSize);

offset += sizeof(uint32_t);
if (_imageContainer.m_ktx)
{
const uint32_t size = mipSize * ((_imageContainer.m_numLayers<=1 && _imageContainer.m_cubeMap) ? 1 : numSides);
uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
BX_ASSERT(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize);
BX_UNUSED(size, imageSize);

offset += sizeof(uint32_t);
}

for (uint16_t side = 0; side < numSides; ++side)
{
Expand Down