From 6e590c31d0ceaf3edc717d4e79aacc9afed46f5c Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Wed, 11 Apr 2018 13:38:11 -0600 Subject: cube: Move cube directory up to top level dir Change-Id: Ie1116b0b6de742b4f85834a4c9d1927dd641e19b --- cube/macOS/cubepp/AppDelegate.h | 23 +++++ cube/macOS/cubepp/AppDelegate.mm | 39 +++++++++ cube/macOS/cubepp/DemoViewController.h | 33 +++++++ cube/macOS/cubepp/DemoViewController.mm | 117 +++++++++++++++++++++++++ cube/macOS/cubepp/Info.plist | 38 ++++++++ cube/macOS/cubepp/Resources/LunarGIcon.icns | Bin 0 -> 54120 bytes cube/macOS/cubepp/Resources/Main.storyboard | 131 ++++++++++++++++++++++++++++ cube/macOS/cubepp/cubepp.cmake | 104 ++++++++++++++++++++++ cube/macOS/cubepp/main.mm | 21 +++++ 9 files changed, 506 insertions(+) create mode 100644 cube/macOS/cubepp/AppDelegate.h create mode 100644 cube/macOS/cubepp/AppDelegate.mm create mode 100644 cube/macOS/cubepp/DemoViewController.h create mode 100644 cube/macOS/cubepp/DemoViewController.mm create mode 100644 cube/macOS/cubepp/Info.plist create mode 100644 cube/macOS/cubepp/Resources/LunarGIcon.icns create mode 100644 cube/macOS/cubepp/Resources/Main.storyboard create mode 100644 cube/macOS/cubepp/cubepp.cmake create mode 100644 cube/macOS/cubepp/main.mm (limited to 'cube/macOS/cubepp') diff --git a/cube/macOS/cubepp/AppDelegate.h b/cube/macOS/cubepp/AppDelegate.h new file mode 100644 index 00000000..0b1dfe49 --- /dev/null +++ b/cube/macOS/cubepp/AppDelegate.h @@ -0,0 +1,23 @@ +/* + * AppDelegate.h + * + * Copyright (c) 2014-2018 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 + +@interface AppDelegate : NSObject + +@end diff --git a/cube/macOS/cubepp/AppDelegate.mm b/cube/macOS/cubepp/AppDelegate.mm new file mode 100644 index 00000000..2a7bcaff --- /dev/null +++ b/cube/macOS/cubepp/AppDelegate.mm @@ -0,0 +1,39 @@ +/* + * AppDelegate.m + * + * Copyright (c) 2014-2018 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 "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + // Insert code here to tear down your application +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { + return YES; +} + +@end diff --git a/cube/macOS/cubepp/DemoViewController.h b/cube/macOS/cubepp/DemoViewController.h new file mode 100644 index 00000000..7f90cc7e --- /dev/null +++ b/cube/macOS/cubepp/DemoViewController.h @@ -0,0 +1,33 @@ +/* + * DemoViewController.h + * + * Copyright (c) 2014-2018 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 + +#pragma mark - +#pragma mark DemoViewController + +/** The main view controller for the demo storyboard. */ +@interface DemoViewController : NSViewController +@end + +#pragma mark - +#pragma mark DemoView + +/** The Metal-compatibile view for the demo Storyboard. */ +@interface DemoView : NSView +@end diff --git a/cube/macOS/cubepp/DemoViewController.mm b/cube/macOS/cubepp/DemoViewController.mm new file mode 100644 index 00000000..049ec6b6 --- /dev/null +++ b/cube/macOS/cubepp/DemoViewController.mm @@ -0,0 +1,117 @@ +/* + * DemoViewController.m + * + * Copyright (c) 2014-2018 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" +#import + +#include + +#include "cube.cpp" + +#pragma mark - +#pragma mark DemoViewController + +@implementation DemoViewController { + CVDisplayLinkRef _displayLink; + struct Demo demo; + NSTimer* _timer; +} + +- (void)dealloc { + demo.cleanup(); + CVDisplayLinkRelease(_displayLink); + [super dealloc]; +} + +/** 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. + + // Convert incoming args to "C" argc/argv strings + NSArray *args = [[NSProcessInfo processInfo] arguments]; + const char** argv = (const char**) alloca(sizeof(char*) * args.count); + for(unsigned int i = 0; i < args.count; i++) { + NSString *s = args[i]; + argv[i] = s.UTF8String; + } + + demo_main(demo, self.view, args.count, argv); + + // Monitor the rendering loop for a quit condition + _timer = [NSTimer scheduledTimerWithTimeInterval: 0.2 + target: self + selector: @selector(onTick:) + userInfo: self + repeats: YES]; + + // Start the rendering loop + CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink); + CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo); + CVDisplayLinkStart(_displayLink); +} + +// Close the window if the demo is in a Quit state +-(void)onTick:(NSTimer*)timer { + if (demo.quit) { + [[[self view] window] close]; + } +} + +#pragma mark Display loop callback function + +/** 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) { + struct Demo* demo = (struct Demo*)target; + demo->run(); + if (demo->quit) { + CVDisplayLinkStop(displayLink); + CVDisplayLinkRelease(displayLink); + } + return kCVReturnSuccess; +} + +@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; +} + +@end diff --git a/cube/macOS/cubepp/Info.plist b/cube/macOS/cubepp/Info.plist new file mode 100644 index 00000000..e8a276ce --- /dev/null +++ b/cube/macOS/cubepp/Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + CFBundleGetInfoString + Cubepp + CFBundleIconFile + LunarGIcon.icns + CFBundleIdentifier + com.lunarg.cubepp + CFBundleInfoDictionaryVersion + 6.0 + CFBundleLongVersionString + 1.0 + CFBundleName + Cubepp + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + CSResourcesFileMapped + + NSHumanReadableCopyright + Copyright (c) 2018 The Khronos Group Inc. LunarG Inc. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + \ No newline at end of file diff --git a/cube/macOS/cubepp/Resources/LunarGIcon.icns b/cube/macOS/cubepp/Resources/LunarGIcon.icns new file mode 100644 index 00000000..640b756f Binary files /dev/null and b/cube/macOS/cubepp/Resources/LunarGIcon.icns differ diff --git a/cube/macOS/cubepp/Resources/Main.storyboard b/cube/macOS/cubepp/Resources/Main.storyboard new file mode 100644 index 00000000..d21c1493 --- /dev/null +++ b/cube/macOS/cubepp/Resources/Main.storyboard @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cube/macOS/cubepp/cubepp.cmake b/cube/macOS/cubepp/cubepp.cmake new file mode 100644 index 00000000..874ed25f --- /dev/null +++ b/cube/macOS/cubepp/cubepp.cmake @@ -0,0 +1,104 @@ +# Cube Application Bundle + +set(cubepp_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/main.mm + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/AppDelegate.mm + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/DemoViewController.mm +) +set(cubepp_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/AppDelegate.h + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/DemoViewController.h +) +set(cubepp_RESOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/lunarg.ppm + ${CMAKE_CURRENT_BINARY_DIR}/staging-json/MoltenVK_icd.json + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/LunarGIcon.icns +) + +# Have Xcode handle the Storyboard +if(${CMAKE_GENERATOR} MATCHES "^Xcode.*") + set(cubepp_RESOURCES ${cubepp_RESOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/Main.storyboard + ) +endif() + +add_executable(cubepp MACOSX_BUNDLE + ${cubepp_SRCS} + ${cubepp_HDRS} + ${cubepp_RESOURCES} + cube.vert.inc cube.frag.inc +) + +# Handle the Storyboard ourselves +if(NOT ${CMAKE_GENERATOR} MATCHES "^Xcode.*") + # Compile the storyboard file with the ibtool. + add_custom_command(TARGET cubepp POST_BUILD + COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text + --compile ${CMAKE_CURRENT_BINARY_DIR}/cubepp.app/Contents/Resources/Main.storyboardc + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/Main.storyboard + COMMENT "Compiling storyboard" + ) +endif() + +add_dependencies(cubepp MoltenVK_icd-staging-json) + +# Include demo source code dir because the MacOS cubepp's Objective-C source includes +# the "original" cubepp application C++ source code. +# Also include the MoltenVK helper files. +target_include_directories(cubepp PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${MOLTENVK_DIR}/MoltenVK/include +) + +target_link_libraries(cubepp ${LIBRARIES} "-framework Cocoa -framework QuartzCore") + +set_target_properties(cubepp PROPERTIES + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Info.plist +) + +# The RESOURCE target property cannot be used in conjunction with the MACOSX_PACKAGE_LOCATION +# property. We need fine-grained control over the Resource directory, so we have to specify +# the destination of all the resource files on a per-destination-directory basis. +# If all the files went into the top-level Resource directory, then we could simply set +# the RESOURCE property to a list of all the resource files. +set_source_files_properties(${cubepp_RESOURCES} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources" +) +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/staging-json/MoltenVK_icd.json" PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/vulkan/icd.d" +) + +# Direct the MoltenVK library to the right place. +install(FILES "${MOLTENVK_DIR}/MoltenVK/MacOS/libMoltenVK.dylib" + DESTINATION "demos/cubepp.app/Contents/Frameworks" + COMPONENT Runtime +) + +# Copy the MoltenVK lib into the bundle. +if(${CMAKE_GENERATOR} MATCHES "^Xcode.*") + add_custom_command(TARGET cubepp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/MoltenVK/MacOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/$/cubepp.app/Contents/Frameworks/libMoltenVK.dylib + DEPENDS vulkan + ) +else() + add_custom_command(TARGET cubepp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/MoltenVK/MacOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/cubepp.app/Contents/Frameworks/libMoltenVK.dylib + DEPENDS vulkan + ) +endif() + +# Fix up the library search path in the executable to find (loader) libraries in the bundle. +install(CODE " + include(BundleUtilities) + fixup_bundle(${CMAKE_INSTALL_PREFIX}/demos/cubepp.app \"\" \"\") + " COMPONENT Runtime +) + +# Not sure this is needed. When activated, it makes a symlink from +# libvulkan.dylib to libvulkan.1.dylib (which in turn symlinks to libvulkan.1.0.xx.dylib.) +# install(FILES +# "${CMAKE_BINARY_DIR}/loader/libvulkan.dylib" +# DESTINATION "demos/cubepp.app/Contents/MacOS" +# COMPONENT Runtime) diff --git a/cube/macOS/cubepp/main.mm b/cube/macOS/cubepp/main.mm new file mode 100644 index 00000000..cf9e0d89 --- /dev/null +++ b/cube/macOS/cubepp/main.mm @@ -0,0 +1,21 @@ +/* + * main.m + * + * Copyright (c) 2014-2018 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 + +int main(int argc, const char* argv[]) { return NSApplicationMain(argc, argv); } -- cgit v1.2.3