Fix updateTexture2D pitch handling for compressed textures. Fixed #3705. (#3722)

This commit is contained in:
Branimir Karadžić
2026-06-01 21:22:46 -07:00
committed by GitHub
parent 0d4141d03a
commit 7b8927049a
3 changed files with 61 additions and 15 deletions

View File

@@ -185,6 +185,15 @@ bgfx::TextureHandle loadTextureWithUpdate(const char* _filePath, uint64_t _flags
width = bx::max(blockWidth, width);
height = bx::max(blockHeight, height);
// Compute source row pitch and pass it to updateTexture2D to
// exercise the explicit-pitch upload path.
const uint32_t numBlocksX = (width + blockWidth - 1) / blockWidth;
const uint32_t srcPitch = bimg::isCompressed(imageContainer->m_format)
? numBlocksX * blockInfo.blockSize
: width * blockInfo.bitsPerPixel / 8
;
bimg::ImageMip mip;
if (bimg::imageGetRawData(*imageContainer, 0, lod, imageContainer->m_data, imageContainer->m_size, mip))
@@ -201,6 +210,7 @@ bgfx::TextureHandle loadTextureWithUpdate(const char* _filePath, uint64_t _flags
, uint16_t(width)
, uint16_t(height)
, bgfx::copy(mipData, mipDataSize)
, uint16_t(srcPitch)
);
}