diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-01-06 19:16:09 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-01-06 19:16:09 +0000 |
| commit | d6fb21415f5940ffce5a35f97a5c175f6c4c1124 (patch) | |
| tree | d622325f1b21f6ffbc1d8f6b00000a8140fb8364 /Common/NativeApp | |
| parent | Removed unused files (diff) | |
| download | DiligentEngine-d6fb21415f5940ffce5a35f97a5c175f6c4c1124.tar.gz DiligentEngine-d6fb21415f5940ffce5a35f97a5c175f6c4c1124.zip | |
Added windowWillClose handler to MetalView
Diffstat (limited to 'Common/NativeApp')
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/MetalView.m | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.m b/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.m index 0abfb06..6f8c187 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.m +++ b/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.m @@ -42,11 +42,17 @@ [self setDisplayLink:displayLink]; CVDisplayLinkSetOutputCallback(displayLink, &DisplayLinkCallback, (__bridge void*)self); CVDisplayLinkStart(displayLink); - + [self setPostsBoundsChangedNotifications:YES]; [self setPostsFrameChangedNotifications:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChange:) name:NSViewBoundsDidChangeNotification object:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChange:) name:NSViewFrameDidChangeNotification object:self]; + + // Register to be notified when the window closes so we can stop the displaylink + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(windowWillClose:) + name:NSWindowWillCloseNotification + object:[self window]]; } // Indicates that the view wants to draw using the backing @@ -117,17 +123,17 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, // Cube demo from MoltenVK ignores any window resize notifications and // recreates the swap chain if Present or AcquireNextImage fails, causing // jagged transitions. - + // According to this thread, there is no solution for flickering during // resize in Metal: // https://forums.developer.apple.com/thread/77901 - + // Calling WindowResize() causes flickering. // Even if [self render] is called ater WindowResize() // Similar results when using Metal kit view // Calling [self render] alone produces jagged transitions but no flickering. // Calling nothing causes the app to crash during resize. - + NSRect viewRectPoints = [self bounds]; NSRect viewRectPixels = [self convertRectToBacking:viewRectPoints]; auto* theApp = [self lockApp]; @@ -139,6 +145,12 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, } +- (void) windowWillClose:(NSNotification*)notification +{ + // Somehow this method is also called when exiting full screen + //[self destroyApp]; +} + -(NSString*)getAppName { auto* theApp = [self lockApp]; |
