macOS retina scaling fixes, M1 Vulkan vsync workaround, CMakeLists OpenMP path fix for Apple

This commit is contained in:
Stephen Saunders 2022-06-20 16:44:34 -04:00
parent 279c95422d
commit 8bc8d14cf2
10 changed files with 33 additions and 21 deletions

View file

@ -113,13 +113,14 @@ void MVKExample::fullScreen(bool fullscreen) {
_vulkanExample->settings.fullscreen = fullscreen;
}
MVKExample::MVKExample(void* view) {
MVKExample::MVKExample(void* view, double scaleUI) {
_vulkanExample = new VulkanExample();
_vulkanExample->settings.vsync = true; // SRS - this iOS/macOS example uses displayLink vsync rendering - set before calling prepare()
_vulkanExample->initVulkan();
_vulkanExample->setupWindow(view);
_vulkanExample->settings.vsync = true; // SRS - set vsync flag since this iOS/macOS example app uses displayLink vsync rendering
_vulkanExample->UIOverlay.scale = scaleUI; // SRS - set UIOverlay scale to maintain relative proportions/readability on retina displays
_vulkanExample->prepare();
_vulkanExample->renderLoop(); // SRS - this inits destWidth/destHeight/lastTimestamp/tPrevEnd, then falls through and returns
_vulkanExample->renderLoop(); // SRS - this inits destWidth/destHeight/lastTimestamp/tPrevEnd, then falls through and returns
}
MVKExample::~MVKExample() {

View file

@ -31,7 +31,7 @@ public:
void fullScreen(bool fullscreen); // SRS - expose VulkanExampleBase::settings.fullscreen to DemoView (macOS only)
MVKExample(void* view);
MVKExample(void* view, double scaleUI); // SRS - support UIOverlay scaling parameter based on device and display type
~MVKExample();
protected:

View file

@ -32,7 +32,7 @@ const std::string getAssetPath() {
self.view.contentScaleFactor = UIScreen.mainScreen.nativeScale;
_mvkExample = new MVKExample(self.view);
_mvkExample = new MVKExample(self.view, 1.0f); // SRS - Use 1x scale factor for UIOverlay on iOS
// SRS - Enable AppDelegate to call into DemoViewController for handling app lifecycle events (e.g. termination)
auto appDelegate = (AppDelegate *)UIApplication.sharedApplication.delegate;

View file

@ -27,6 +27,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
return kCVReturnSuccess;
}
CALayer* layer;
MVKExample* _mvkExample;
#pragma mark -
@ -40,9 +41,9 @@ MVKExample* _mvkExample;
-(void) viewDidLoad {
[super viewDidLoad];
self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.
self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method (called immediately on set)
_mvkExample = new MVKExample(self.view);
_mvkExample = new MVKExample(self.view, layer.contentsScale); // SRS - Use backing layer scale factor for UIOverlay on macOS
// SRS - Enable AppDelegate to call into DemoViewController for handling application lifecycle events (e.g. termination)
auto appDelegate = (AppDelegate *)NSApplication.sharedApplication.delegate;
@ -75,7 +76,7 @@ MVKExample* _mvkExample;
/** If the wantsLayer property is set to YES, this method will be invoked to return a layer instance. */
-(CALayer*) makeBackingLayer {
CALayer* layer = [self.class.layerClass layer];
layer = [self.class.layerClass layer];
CGSize viewScale = [self convertSizeToBacking: CGSizeMake(1.0, 1.0)];
layer.contentsScale = MIN(viewScale.width, viewScale.height);
return layer;
@ -108,8 +109,8 @@ MVKExample* _mvkExample;
// SRS - Handle mouse events
-(NSPoint) getMouseLocalPoint:(NSEvent*) theEvent {
NSPoint location = [theEvent locationInWindow];
NSPoint point = [self convertPoint:location fromView:nil];
point.y = self.frame.size.height - point.y;
NSPoint point = [self convertPointToBacking:location];
point.y = self.frame.size.height*self.window.backingScaleFactor - point.y;
return point;
}