Fixes for vulkanExample: frame timing now equals diff between frames for Win & macOS portability, support vsync off rendering on macOS, support swapchain image count change on resize, handle macOS fullscreen; Fixes for xcode example: use PanGestureRecognizer on iOS, add macOS cursor tracking, cleanup Vulkan on shutdown
This commit is contained in:
parent
a1e19ea5de
commit
cb343c329a
15 changed files with 222 additions and 87 deletions
|
|
@ -9,4 +9,6 @@
|
|||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) NSViewController *viewController;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "DemoViewController.h"
|
||||
|
||||
@interface AppDelegate ()
|
||||
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||
// Insert code here to tear down your application
|
||||
[(DemoViewController *)_viewController shutdownExample];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
/** The main view controller for the demo storyboard. */
|
||||
@interface DemoViewController : NSViewController
|
||||
-(void) shutdownExample;
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#import "DemoViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
#include "MVKExample.h"
|
||||
|
|
@ -43,25 +44,19 @@ MVKExample* _mvkExample;
|
|||
|
||||
_mvkExample = new MVKExample(self.view);
|
||||
|
||||
// SRS - Enable AppDelegate to call into DemoViewController for handling application lifecycle events (e.g. termination)
|
||||
auto appDelegate = (AppDelegate *)NSApplication.sharedApplication.delegate;
|
||||
appDelegate.viewController = self;
|
||||
|
||||
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
|
||||
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, _mvkExample);
|
||||
CVDisplayLinkStart(_displayLink);
|
||||
}
|
||||
|
||||
// SRS - Center the window and set VulkanExampleBase::refreshPeriod from the active displayLink
|
||||
-(void) viewWillAppear {
|
||||
[super viewWillAppear];
|
||||
|
||||
NSWindow* window = self.view.window;
|
||||
[window center];
|
||||
|
||||
_mvkExample->setRefreshPeriod(CVDisplayLinkGetActualOutputVideoRefreshPeriod(_displayLink));
|
||||
}
|
||||
|
||||
-(void) dealloc {
|
||||
-(void) shutdownExample {
|
||||
CVDisplayLinkStop(_displayLink);
|
||||
CVDisplayLinkRelease(_displayLink);
|
||||
delete _mvkExample;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -86,6 +81,15 @@ MVKExample* _mvkExample;
|
|||
return layer;
|
||||
}
|
||||
|
||||
// SRS - Activate mouse cursor tracking within the view, set view as window delegate, and center the window
|
||||
- (void) viewDidMoveToWindow {
|
||||
auto trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseMoved | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil];
|
||||
[self addTrackingArea: trackingArea];
|
||||
|
||||
[self.window setDelegate: self.window.contentView];
|
||||
[self.window center];
|
||||
}
|
||||
|
||||
-(BOOL) acceptsFirstResponder { return YES; }
|
||||
|
||||
// SRS - Handle keyboard events
|
||||
|
|
@ -151,9 +155,24 @@ MVKExample* _mvkExample;
|
|||
_mvkExample->mouseDragged(point.x, point.y);
|
||||
}
|
||||
|
||||
-(void) mouseMoved:(NSEvent*) theEvent {
|
||||
auto point = [self getMouseLocalPoint:theEvent];
|
||||
_mvkExample->mouseDragged(point.x, point.y);
|
||||
}
|
||||
|
||||
-(void) scrollWheel:(NSEvent*) theEvent {
|
||||
short wheelDelta = [theEvent deltaY];
|
||||
_mvkExample->scrollWheel(wheelDelta);
|
||||
}
|
||||
|
||||
- (void)windowWillEnterFullScreen:(NSNotification *)notification
|
||||
{
|
||||
_mvkExample->fullScreen(true);
|
||||
}
|
||||
|
||||
- (void)windowWillExitFullScreen:(NSNotification *)notification
|
||||
{
|
||||
_mvkExample->fullScreen(false);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue