diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_ios.mm')
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_ios.mm | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_ios.mm b/3rdparty/bgfx/examples/common/entry/entry_ios.mm index 569e99f51bd..8592a33c43e 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_ios.mm +++ b/3rdparty/bgfx/examples/common/entry/entry_ios.mm @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "entry_p.h" @@ -14,7 +14,7 @@ #if __IPHONE_8_0 && !TARGET_IPHONE_SIMULATOR // check if sdk/target supports metal # import <Metal/Metal.h> # import <QuartzCore/CAMetalLayer.h> -//# define HAS_METAL_SDK +# define HAS_METAL_SDK #endif #include <bgfx/platform.h> @@ -38,8 +38,8 @@ namespace entry { Context(uint32_t _width, uint32_t _height) { - const char* const argv[1] = { "ios" }; - m_mte.m_argc = 1; + static const char* const argv[] = { "ios" }; + m_mte.m_argc = BX_COUNTOF(argv); m_mte.m_argv = argv; m_eventQueue.postSizeEvent(s_defaultWindow, _width, _height); @@ -57,6 +57,7 @@ namespace entry MainThreadEntry m_mte; bx::Thread m_thread; + void* m_window; EventQueue m_eventQueue; }; @@ -145,16 +146,31 @@ namespace entry BX_UNUSED(_handle, _lock); } + void* getNativeWindowHandle(WindowHandle _handle) + { + if (kDefaultWindowHandle.idx == _handle.idx) + { + return s_ctx.m_window; + } + + return NULL; + } + + void* getNativeDisplayHandle() + { + return NULL; + } + + bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType(WindowHandle _handle) + { + BX_UNUSED(_handle); + return bgfx::NativeWindowHandleType::Default; + } + } // namespace entry using namespace entry; -#ifdef HAS_METAL_SDK -static id<MTLDevice> m_device = NULL; -#else -static void* m_device = NULL; -#endif - @interface ViewController : UIViewController @end @implementation ViewController @@ -177,13 +193,14 @@ static void* m_device = NULL; + (Class)layerClass { #ifdef HAS_METAL_SDK + static id<MTLDevice> device = NULL; Class metalClass = NSClassFromString(@"CAMetalLayer"); //is metal runtime sdk available if ( metalClass != nil) { - m_device = MTLCreateSystemDefaultDevice(); // is metal supported on this device (is there a better way to do this - without creating device ?) - if (m_device) + device = MTLCreateSystemDefaultDevice(); // is metal supported on this device (is there a better way to do this - without creating device ?) + if (NULL != device) { - [m_device retain]; + [device retain]; return metalClass; } } @@ -201,13 +218,7 @@ static void* m_device = NULL; return nil; } - bgfx::PlatformData pd; - pd.ndt = NULL; - pd.nwh = self.layer; - pd.context = m_device; - pd.backBuffer = NULL; - pd.backBufferDS = NULL; - bgfx::setPlatformData(pd); + s_ctx->m_window = self.layer; return self; } @@ -226,7 +237,7 @@ static void* m_device = NULL; m_displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(renderFrame)]; //[m_displayLink setFrameInterval:1]; //[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; - // [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]]; + //[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]]; [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; } } |