Skip to content

Instantly share code, notes, and snippets.

@attilaz
Created July 31, 2019 19:01
Show Gist options
  • Save attilaz/3cabb555457949099ac611895fb7ee90 to your computer and use it in GitHub Desktop.
Save attilaz/3cabb555457949099ac611895fb7ee90 to your computer and use it in GitHub Desktop.
void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override
{
const TextureMtl& texture = m_textures[_handle.idx];
#if BX_PLATFORM_OSX
BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder();
bce.synchronizeTexture(texture.m_ptr, 0, _mip);
endEncoding();
#endif // BX_PLATFORM_OSX
m_cmd.kick(false, true);
m_commandBuffer = m_cmd.alloc();
BX_CHECK(_mip<texture.m_numMips,"Invalid mip: %d num mips:",_mip,texture.m_numMips);
uint32_t srcWidth = bx::uint32_max(1, texture.m_ptr.width() >> _mip);
uint32_t srcHeight = bx::uint32_max(1, texture.m_ptr.height() >> _mip);
const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat) );
MTLRegion region =
{
{ 0, 0, 0 },
{ srcWidth, srcHeight, 1 },
};
texture.m_ptr.getBytes(_data, srcWidth*bpp/8, 0, region, _mip, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment