re-init metal swapchain when providing a new native window handle (#2206)

This commit is contained in:
Cedric Guillemet 2020-07-22 17:47:57 +02:00 committed by GitHub
parent ff9f624b9b
commit 3d06fbe815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1049,6 +1049,7 @@ namespace bgfx { namespace mtl
Texture m_backBufferDepth;
Texture m_backBufferStencil;
uint32_t m_maxAnisotropy;
void* m_nwh;
};
struct FrameBufferMtl

View File

@ -1252,6 +1252,12 @@ namespace bgfx { namespace mtl
MTLPixelFormat prevMetalLayerPixelFormat = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat;
m_resolution = _resolution;
if (m_resolution.reset & BGFX_RESET_INTERNAL_FORCE
&& m_mainFrameBuffer.m_swapChain->m_nwh != g_platformData.nwh)
{
m_mainFrameBuffer.m_swapChain->init(g_platformData.nwh);
}
m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE;
m_mainFrameBuffer.m_swapChain->resize(m_mainFrameBuffer, _resolution.width, _resolution.height, _resolution.reset);
@ -3035,6 +3041,10 @@ namespace bgfx { namespace mtl
void SwapChainMtl::init(void* _nwh)
{
if (m_metalLayer)
{
release(m_metalLayer);
}
if (NULL != NSClassFromString(@"MTKView") )
{
MTKView *view = (MTKView *)_nwh;
@ -3131,7 +3141,7 @@ namespace bgfx { namespace mtl
m_metalLayer.device = s_renderMtl->m_device;
m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
m_metalLayer.magnificationFilter = kCAFilterNearest;
m_nwh = _nwh;
retain(m_metalLayer);
}