Use existing metal layer if present on NSWindow

If we create and assign a new metal layer to NSWindow, when another one
was already assigned, the window content stays black.
This commit is contained in:
Blaž Tomažič 2018-12-28 10:57:47 +01:00
parent 7669f8442c
commit dd4edb23ed

View File

@ -2868,9 +2868,17 @@ namespace bgfx { namespace mtl
else
{
NSWindow* nsWindow = (NSWindow*)_nwh;
[nsWindow.contentView setWantsLayer:YES];
m_metalLayer = [CAMetalLayer layer];
[nsWindow.contentView setLayer:m_metalLayer];
CALayer* layer = nsWindow.contentView.layer;
if(NULL != layer && [layer isKindOfClass:NSClassFromString(@"CAMetalLayer")])
{
m_metalLayer = (CAMetalLayer*)layer;
}
else
{
[nsWindow.contentView setWantsLayer:YES];
m_metalLayer = [CAMetalLayer layer];
[nsWindow.contentView setLayer:m_metalLayer];
}
}
}
#endif // BX_PLATFORM_*