From 463083eef77b6ff4a9429424153be7ca561f2661 Mon Sep 17 00:00:00 2001 From: Eugene Golushkov Date: Wed, 22 Jan 2020 11:45:41 +0200 Subject: [PATCH] Metal: Ignore redundant "macAPICocoaUseNSView" parameter. Allow to pass either NSView or NSWindow in "externalWindowHandle". For backward compatibility parse "parentWindowHandle" too. --- RenderSystems/Metal/src/OgreMetalWindow.mm | 37 +++++++++++----------- Samples/2.0/Common/src/GraphicsSystem.cpp | 3 -- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/RenderSystems/Metal/src/OgreMetalWindow.mm b/RenderSystems/Metal/src/OgreMetalWindow.mm index 6899327c0d7..08dddf6a52d 100644 --- a/RenderSystems/Metal/src/OgreMetalWindow.mm +++ b/RenderSystems/Metal/src/OgreMetalWindow.mm @@ -206,6 +206,9 @@ of this software and associated documentation files (the "Software"), to deal mClosed = false; mHwGamma = true; +#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS + NSObject *externalWindowHandle; // NSView or NSWindow +#endif if( miscParams ) { @@ -221,33 +224,31 @@ of this software and associated documentation files (the "Software"), to deal mHwGamma = StringConverter::parseBool( opt->second ); #if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS - opt = miscParams->find("macAPICocoaUseNSView"); + opt = miscParams->find("externalWindowHandle"); if( opt != end ) + externalWindowHandle = (__bridge NSObject*)(void*)StringConverter::parseSizeT(opt->second); + + if( !externalWindowHandle ) { - LogManager::getSingleton().logMessage("Mac Cocoa Window: Rendering on an external plain NSView*"); opt = miscParams->find("parentWindowHandle"); - NSView *nsview = (__bridge NSView*)reinterpret_cast(StringConverter::parseSizeT(opt->second)); - assert( nsview && - "Unable to get a pointer to the parent NSView." - "Was the 'parentWindowHandle' parameter set correctly in the call to createRenderWindow()?"); - mWindow = [nsview window]; + if( opt != end ) + externalWindowHandle = (__bridge NSObject*)(void*)StringConverter::parseSizeT(opt->second); } -#endif - } -#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS - CGRect frame; -#else - NSRect frame; + if( [externalWindowHandle isKindOfClass:[NSWindow class]] ) + mWindow = (NSWindow*)externalWindowHandle; + else if( [externalWindowHandle isKindOfClass:[NSView class]] ) + mWindow = [(NSView*)externalWindowHandle window]; + else + assert( false && "Unable to get a pointer to the external NSView or NSWindow." + "Was the 'externalWindowHandle' parameter set correctly in the call to createRenderWindow()?"); #endif + } #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS - frame.origin.x = 0; - frame.origin.y = 0; - frame.size.width = mRequestedWidth; - frame.size.height = mRequestedHeight; + CGRect frame = CGRectMake(0.0, 0.0, mRequestedWidth, mRequestedHeight); #else - frame = [mWindow.contentView bounds]; + NSRect frame = [mWindow.contentView bounds]; #endif mMetalView = [[OgreMetalView alloc] initWithFrame:frame]; diff --git a/Samples/2.0/Common/src/GraphicsSystem.cpp b/Samples/2.0/Common/src/GraphicsSystem.cpp index 6917fd5ef86..d3fb4aba7f5 100644 --- a/Samples/2.0/Common/src/GraphicsSystem.cpp +++ b/Samples/2.0/Common/src/GraphicsSystem.cpp @@ -251,9 +251,6 @@ namespace Demo #endif #if defined(SDL_VIDEO_DRIVER_COCOA) case SDL_SYSWM_COCOA: - //required to make OGRE play nice with our window - params.insert( std::make_pair("macAPICocoaUseNSView", "true") ); - winHandle = Ogre::StringConverter::toString(WindowContentViewHandle(wmInfo)); break; #endif