diff --git a/scripts/bgfx.lua b/scripts/bgfx.lua index 76d6b7025..3fb031e05 100644 --- a/scripts/bgfx.lua +++ b/scripts/bgfx.lua @@ -98,6 +98,7 @@ function bgfxProject(_name, _kind, _defines) "-framework QuartzCore", "-framework OpenGL", "-weak_framework Metal", + "-weak_framework MetalKit", } configuration { "not nacl", "not linux-steamlink" } diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index 00981372c..7936d1b48 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -12,6 +12,7 @@ #import #import +#import #if BX_PLATFORM_IOS # import diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 645468268..2bd3d82e8 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -378,8 +378,16 @@ namespace bgfx { namespace mtl memset(m_uniforms, 0, sizeof(m_uniforms) ); memset(&m_resolution, 0, sizeof(m_resolution) ); + if (NULL != NSClassFromString(@"MTKView")) { + MTKView *view = (MTKView *)g_platformData.nwh; + if (NULL != view && [view isKindOfClass:NSClassFromString(@"MTKView")]) { + m_metalLayer = (CAMetalLayer *)view.layer; + } + } + if (NULL != NSClassFromString(@"CAMetalLayer") ) { + if (NULL == m_metalLayer) #if BX_PLATFORM_IOS { CAMetalLayer* metalLayer = (CAMetalLayer*)g_platformData.nwh;