Skip to content

Instantly share code, notes, and snippets.

@attilaz
Created February 6, 2020 18:26
Show Gist options
  • Save attilaz/97b383e0de2bb0111c8562e3c63e6e29 to your computer and use it in GitHub Desktop.
Save attilaz/97b383e0de2bb0111c8562e3c63e6e29 to your computer and use it in GitHub Desktop.
texture update
TextureDescriptor desc = s_renderMtl->m_textureDescriptor;
desc.textureType = _depth > 1 ? MTLTextureType3D : MTLTextureType2D;
desc.pixelFormat = m_ptr.pixelFormat();
desc.width = _rect.m_width;
desc.height = _rect.m_height;
desc.depth = _depth;
desc.mipmapLevelCount = 1;
desc.sampleCount = 1;
desc.arrayLength = 1;
if (s_renderMtl->m_iOS9Runtime
|| s_renderMtl->m_macOS11Runtime)
{
desc.cpuCacheMode = MTLCPUCacheModeDefaultCache;
desc.storageMode = BX_ENABLED(BX_PLATFORM_IOS)
? (MTLStorageMode)0 // MTLStorageModeShared
: (MTLStorageMode)1 // MTLStorageModeManaged
;
desc.usage = 0;
}
Texture tempTexture = s_renderMtl->m_device.newTextureWithDescriptor(desc);
MTLRegion region =
{
{ 0, 0, 0 },
{ _rect.m_width, _rect.m_height, _depth },
};
tempTexture.replaceRegion(region, 0, 0, data, srcpitch, srcpitch * _rect.m_height);
bce.copyFromTexture(tempTexture, 0, 0, MTLOriginMake(0,0,0), MTLSizeMake(_rect.m_width, _rect.m_height, _depth),
m_ptr, slice, _mip, MTLOriginMake(_rect.m_x, _rect.m_y, zz));
release(tempTexture);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment