Skip to content

Commit

Permalink
Fixes for cubemap loading from ktx/pvr3 container
Browse files Browse the repository at this point in the history
  • Loading branch information
attilaz committed Aug 6, 2021
1 parent 39c0a78 commit b8a7a90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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

0 comments on commit b8a7a90

Please sign in to comment.