moltenvk/Demos/Cube/iOS/DemoViewController.m
Bill Hollings df8e0900fe Upgrade Cube demo to support Volk, as required by demo.
- Add Volk repo to fetchDependencies script and
  ExternalRevisions/Volk_repo_revision file.
- Cube.xcodeproj modify header paths, use of Volk,
  and remove old and unused files.
- Update Demos/README.md to explain that Volk requires MoltenVK
  be built with build setting MVK_HIDE_VULKAN_SYMBOLS enabled.
- MVKInstance support aliasing function name in one extension to a
  function in another extension, to allow MVK_HIDE_VULKAN_SYMBOLS to
  work with extensions promoted to another extension, but not to core,
  and remove additional duplicate functions that were promoted to 1.3,
  but were breaking use of MVK_HIDE_VULKAN_SYMBOLS.
2024-01-06 20:09:20 -05:00

85 lines
2.2 KiB
Objective-C

/*
* DemoViewController.m
*
* Copyright (c) 2015-2024 The Brenwill Workshop Ltd. (http://www.brenwill.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "DemoViewController.h"
#include <MoltenVK/mvk_vulkan.h>
#include "cube.c"
#pragma mark -
#pragma mark DemoViewController
@implementation DemoViewController {
CADisplayLink* _displayLink;
struct demo demo;
}
/** Since this is a single-view app, initialize Vulkan as view is appearing. */
-(void) viewWillAppear: (BOOL) animated {
[super viewWillAppear: animated];
self.view.contentScaleFactor = UIScreen.mainScreen.nativeScale;
#if TARGET_OS_SIMULATOR
// Avoid linear host-coherent texture loading on simulator
const char* argv[] = { "cube", "--use_staging" };
#else
const char* argv[] = { "cube" };
#endif
int argc = sizeof(argv)/sizeof(char*);
demo_main(&demo, self.view.layer, argc, argv);
demo_draw(&demo);
uint32_t fps = 60;
_displayLink = [CADisplayLink displayLinkWithTarget: self selector: @selector(renderLoop)];
[_displayLink setFrameInterval: 60 / fps];
[_displayLink addToRunLoop: NSRunLoop.currentRunLoop forMode: NSDefaultRunLoopMode];
}
-(void) renderLoop {
demo_draw(&demo);
}
// Allow device rotation to resize the swapchain
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
demo_resize(&demo);
}
-(void) viewDidDisappear: (BOOL) animated {
[_displayLink invalidate];
[_displayLink release];
demo_cleanup(&demo);
[super viewDidDisappear: animated];
}
@end
#pragma mark -
#pragma mark DemoView
@implementation DemoView
/** Returns a Metal-compatible layer. */
+(Class) layerClass { return [CAMetalLayer class]; }
@end