Use getAssetPath() instead of ASSET_PATH to support broader range of platforms. Multisampling example determines sample rate from device at runtime. Move example wrapper code from DemoViewController.mm to dedicated MVKExample.cpp file. Remove AssImp libraries for iOS and macOS from repo, and add instructions for generating them from AssImp source files. Update general README.md file to mention support for iOS and macOS platforms. Add Apple logo for README.md. Update Vulkan logo to current registered TM logo. Update copyright notice of MoltenVK example files to MIT license. Examples use +/- on main keyboard, instead of numpad.
86 lines
2.4 KiB
Text
86 lines
2.4 KiB
Text
/*
|
|
* DemoViewController.mm
|
|
*
|
|
* Copyright (c) 2016-2017 The Brenwill Workshop Ltd.
|
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
*/
|
|
|
|
#import "DemoViewController.h"
|
|
#import <QuartzCore/CAMetalLayer.h>
|
|
|
|
#include "MVKExample.h"
|
|
|
|
|
|
const std::string VulkanExampleBase::getAssetPath() {
|
|
return [NSBundle.mainBundle.resourcePath stringByAppendingString: @"/data/"].UTF8String;
|
|
}
|
|
|
|
/** Rendering loop callback function for use with a CVDisplayLink. */
|
|
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
|
|
const CVTimeStamp* now,
|
|
const CVTimeStamp* outputTime,
|
|
CVOptionFlags flagsIn,
|
|
CVOptionFlags* flagsOut,
|
|
void* target) {
|
|
((MVKExample*)target)->renderFrame();
|
|
return kCVReturnSuccess;
|
|
}
|
|
|
|
|
|
#pragma mark -
|
|
#pragma mark DemoViewController
|
|
|
|
@implementation DemoViewController {
|
|
MVKExample* _mvkExample;
|
|
CVDisplayLinkRef _displayLink;
|
|
}
|
|
|
|
/** Since this is a single-view app, initialize Vulkan during view loading. */
|
|
-(void) viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.
|
|
|
|
_mvkExample = new MVKExample(self.view);
|
|
|
|
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
|
|
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, _mvkExample);
|
|
CVDisplayLinkStart(_displayLink);
|
|
}
|
|
|
|
-(void) dealloc {
|
|
CVDisplayLinkRelease(_displayLink);
|
|
delete _mvkExample;
|
|
[super dealloc];
|
|
}
|
|
|
|
// Handle keyboard input
|
|
-(void) keyDown:(NSEvent*) theEvent {
|
|
_mvkExample->keyPressed(theEvent.keyCode);
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
#pragma mark -
|
|
#pragma mark DemoView
|
|
|
|
@implementation DemoView
|
|
|
|
/** Indicates that the view wants to draw using the backing layer instead of using drawRect:. */
|
|
-(BOOL) wantsUpdateLayer { return YES; }
|
|
|
|
/** Returns a Metal-compatible layer. */
|
|
+(Class) layerClass { return [CAMetalLayer class]; }
|
|
|
|
/** 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];
|
|
CGSize viewScale = [self convertSizeToBacking: CGSizeMake(1.0, 1.0)];
|
|
layer.contentsScale = MIN(viewScale.width, viewScale.height);
|
|
return layer;
|
|
}
|
|
|
|
-(BOOL) acceptsFirstResponder { return YES; }
|
|
|
|
@end
|