Skip to content

Commit

Permalink
Metal: Ignore redundant "macAPICocoaUseNSView" parameter. Allow to pa…
Browse files Browse the repository at this point in the history
…ss either NSView or NSWindow in "externalWindowHandle". For backward compatibility parse "parentWindowHandle" too.
  • Loading branch information
eugenegff committed Jan 22, 2020
1 parent 1a4b465 commit fc3460b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
39 changes: 20 additions & 19 deletions RenderSystems/Metal/src/OgreMetalWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ of this software and associated documentation files (the "Software"), to deal
destroy();

mClosed = false;
mHwGamma = true;
mHwGamma = true;
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
NSObject *externalWindowHandle; // NSView or NSWindow
#endif

if( miscParams )
{
Expand All @@ -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<void*>(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];

Expand Down
3 changes: 0 additions & 3 deletions Samples/2.0/Common/src/GraphicsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc3460b

Please sign in to comment.