diff options
| author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-03-31 01:30:36 +0200 |
|---|---|---|
| committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-03-31 01:30:36 +0200 |
| commit | 8e2ff15dbd3fe70fe2b52397b1eaba3fe2d7a5e8 (patch) | |
| tree | 925fa596210d1a1f01e00e0743a643f4552e7a7a /tools/Vulkan-Tools/cube/macOS | |
| parent | 1f17b4df127bd280e50d93a46ae93df704adc2b0 (diff) | |
| parent | 90bf5bc4fd8bea0d300f6564af256a51a34124b8 (diff) | |
| download | usermoji-8e2ff15dbd3fe70fe2b52397b1eaba3fe2d7a5e8.tar.xz | |
add tools/Vulkan-Tools
Diffstat (limited to 'tools/Vulkan-Tools/cube/macOS')
18 files changed, 1015 insertions, 0 deletions
diff --git a/tools/Vulkan-Tools/cube/macOS/cube/AppDelegate.h b/tools/Vulkan-Tools/cube/macOS/cube/AppDelegate.h new file mode 100644 index 00000000..0b1dfe49 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/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 <Cocoa/Cocoa.h> + +@interface AppDelegate : NSObject<NSApplicationDelegate> + +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cube/AppDelegate.m b/tools/Vulkan-Tools/cube/macOS/cube/AppDelegate.m new file mode 100644 index 00000000..c1ee96b4 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/AppDelegate.m @@ -0,0 +1,48 @@ +/* + * 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" +#import "DemoViewController.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + NSApplication *app = aNotification.object; + NSArray<NSWindow *> *windows = app.windows; + for (NSUInteger i = 0; i < windows.count; ++i) { + NSViewController *viewController = windows[i].contentViewController; + if ([viewController isKindOfClass:[DemoViewController class]]) { + [(DemoViewController *)viewController quit]; + break; + } + } +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { + return YES; +} + +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cube/CMakeLists.txt b/tools/Vulkan-Tools/cube/macOS/cube/CMakeLists.txt new file mode 100644 index 00000000..d0721a89 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/CMakeLists.txt @@ -0,0 +1,93 @@ +# ~~~ +# Copyright (c) 2018-2024 Valve Corporation +# Copyright (c) 2018-2024 LunarG, Inc. +# +# 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. +# ~~~ + +# VkCube Application Bundle + +set(cube_RESOURCES ${CMAKE_CURRENT_LIST_DIR}/Resources/VulkanIcon.icns) +if(NOT APPLE_USE_SYSTEM_ICD) + list(APPEND cube_RESOURCES ${PROJECT_BINARY_DIR}/staging-json/MoltenVK_icd.json) +endif() + +# Have Xcode handle the Storyboard +if(XCODE) + set(cube_RESOURCES ${cube_RESOURCES} ${CMAKE_CURRENT_LIST_DIR}/Resources/Main.storyboard) +endif() + +add_executable(vkcube MACOSX_BUNDLE) + +target_sources(vkcube PRIVATE + main.m + AppDelegate.m + AppDelegate.h + DemoViewController.m + DemoViewController.h + ${cube_RESOURCES} + ../../cube.vert.inc + ../../cube.frag.inc +) + +# Handle the Storyboard ourselves +if(NOT XCODE) + # Compile the storyboard file with the ibtool. + add_custom_command(TARGET vkcube POST_BUILD + COMMAND ${IBTOOL} + --errors + --warnings + --notices + --output-format human-readable-text + --compile ${CMAKE_CURRENT_BINARY_DIR}/vkcube.app/Contents/Resources/Main.storyboardc + ${CMAKE_CURRENT_LIST_DIR}/Resources/Main.storyboard + COMMENT "Compiling storyboard") +endif() + +if(NOT APPLE_USE_SYSTEM_ICD) + add_dependencies(vkcube MoltenVK_icd-staging-json) +endif() + +# Include demo source code dir because the MacOS cube's Objective-C source includes the "original" cube application C source code. +target_include_directories(vkcube PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + +# We do this so vkcube is linked to an individual library and NOT a framework. +target_link_libraries(vkcube Vulkan::Loader "-framework Cocoa -framework QuartzCore") + +# Disable warnings about sprintf +target_compile_options(vkcube PRIVATE -Wno-deprecated-declarations) + +set_target_properties(vkcube PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_LIST_DIR}/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(${cube_RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") +if(NOT APPLE_USE_SYSTEM_ICD) + set_source_files_properties("${PROJECT_BINARY_DIR}/staging-json/MoltenVK_icd.json" + PROPERTIES + MACOSX_PACKAGE_LOCATION + "Resources/vulkan/icd.d") + + # Copy the MoltenVK lib into the bundle. + if(XCODE) + add_custom_command(TARGET vkcube POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/Package/Release/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/vkcube.app/Contents/Frameworks/libMoltenVK.dylib) + else() + add_custom_command(TARGET vkcube POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/Package/Release/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/vkcube.app/Contents/Frameworks/libMoltenVK.dylib) + endif() +endif() diff --git a/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.h b/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.h new file mode 100644 index 00000000..6d7ca215 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.h @@ -0,0 +1,36 @@ +/* + * 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 <AppKit/AppKit.h> + +#pragma mark - +#pragma mark DemoViewController + +/** The main view controller for the demo storyboard. */ +@interface DemoViewController : NSViewController + +- (void)quit; + +@end + +#pragma mark - +#pragma mark DemoView + +/** The Metal-compatibile view for the demo Storyboard. */ +@interface DemoView : NSView +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.m b/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.m new file mode 100644 index 00000000..d2158521 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/DemoViewController.m @@ -0,0 +1,119 @@ +/* + * 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 <QuartzCore/CAMetalLayer.h> + +#include "cube.c" + +#pragma mark - +#pragma mark DemoViewController + +@implementation DemoViewController { + CVDisplayLinkRef _displayLink; + struct demo demo; + NSTimer* _timer; +} + +- (void)dealloc { + [self quit]; + [super dealloc]; +} + +- (void)quit { + CVDisplayLinkRelease(_displayLink); + demo_cleanup(&demo); +} + +/** 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.layer, 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(demo); + if (demo->quit) { + CVDisplayLinkStop(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/tools/Vulkan-Tools/cube/macOS/cube/Info.plist b/tools/Vulkan-Tools/cube/macOS/cube/Info.plist new file mode 100644 index 00000000..55145d32 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/Info.plist @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> + <key>CFBundleGetInfoString</key> + <string>VkCube</string> + <key>CFBundleIconFile</key> + <string>VulkanIcon.icns</string> + <key>CFBundleIdentifier</key> + <string>com.lunarg.vkcube</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleLongVersionString</key> + <string>1.0</string> + <key>CFBundleName</key> + <string>VkCube</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>CSResourcesFileMapped</key> + <true/> + <key>NSHumanReadableCopyright</key> + <string>Copyright (c) 2018 The Khronos Group Inc. LunarG Inc. All rights reserved.</string> + <key>NSMainStoryboardFile</key> + <string>Main</string> + <key>NSPrincipalClass</key> + <string>NSApplication</string> +</dict> +</plist> diff --git a/tools/Vulkan-Tools/cube/macOS/cube/Resources/Main.storyboard b/tools/Vulkan-Tools/cube/macOS/cube/Resources/Main.storyboard new file mode 100644 index 00000000..edc63148 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/Resources/Main.storyboard @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G26a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> + <dependencies> + <deployment identifier="macosx"/> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/> + </dependencies> + <scenes> + <!--Application--> + <scene sceneID="JPo-4y-FX3"> + <objects> + <application id="hnw-xV-0zn" sceneMemberID="viewController"> + <menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6"> + <items> + <menuItem title="VkCube" id="1Xt-HY-uBw"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="VkCube" systemMenu="apple" id="uQy-DD-JDr"> + <items> + <menuItem title="About Demo" id="5kV-Vb-QxS"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> + <menuItem title="Hide Demo" keyEquivalent="h" id="Olw-nP-bQN"> + <connections> + <action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/> + </connections> + </menuItem> + <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO"> + <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> + <connections> + <action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/> + </connections> + </menuItem> + <menuItem title="Show All" id="Kd2-mp-pUS"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/> + <menuItem title="Quit Demo" keyEquivalent="q" id="4sb-4s-VLi"> + <connections> + <action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + <menuItem title="Window" id="aUF-d1-5bR"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo"> + <items> + <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV"> + <connections> + <action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/> + </connections> + </menuItem> + <menuItem title="Zoom" id="R4o-n2-Eq4"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/> + <menuItem title="Bring All to Front" id="LE2-aR-0XJ"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + <menuItem title="Help" id="wpr-3q-Mcd"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ"> + <items> + <menuItem title="VkCube Help" keyEquivalent="?" id="FKE-Sm-Kum"> + <connections> + <action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + </items> + </menu> + <connections> + <outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/> + </connections> + </application> + <customObject id="Voe-Tx-rLC" customClass="AppDelegate"/> + <customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83.5" y="-47"/> + </scene> + <!--Window Controller--> + <scene sceneID="R2V-B0-nI4"> + <objects> + <windowController id="B8D-0N-5wS" sceneMemberID="viewController"> + <window key="window" title="VkCube" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA"> + <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> + <rect key="contentRect" x="1051" y="656" width="300" height="200"/> + <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> + <value key="minSize" type="size" width="300" height="200"/> + </window> + <connections> + <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/> + </connections> + </windowController> + <customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83" y="146"/> + </scene> + <!--Demo View Controller--> + <scene sceneID="hIz-AP-VOD"> + <objects> + <viewController id="XfG-lQ-9wD" customClass="DemoViewController" sceneMemberID="viewController"> + <view key="view" id="m2S-Jp-Qdl" customClass="DemoView"> + <rect key="frame" x="0.0" y="0.0" width="400" height="300"/> + <autoresizingMask key="autoresizingMask"/> + </view> + </viewController> + <customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83" y="564"/> + </scene> + </scenes> +</document> diff --git a/tools/Vulkan-Tools/cube/macOS/cube/Resources/VulkanIcon.icns b/tools/Vulkan-Tools/cube/macOS/cube/Resources/VulkanIcon.icns Binary files differnew file mode 100644 index 00000000..fb82fb7d --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/Resources/VulkanIcon.icns diff --git a/tools/Vulkan-Tools/cube/macOS/cube/main.m b/tools/Vulkan-Tools/cube/macOS/cube/main.m new file mode 100644 index 00000000..cf9e0d89 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cube/main.m @@ -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 <Cocoa/Cocoa.h> + +int main(int argc, const char* argv[]) { return NSApplicationMain(argc, argv); } diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/AppDelegate.h b/tools/Vulkan-Tools/cube/macOS/cubepp/AppDelegate.h new file mode 100644 index 00000000..0b1dfe49 --- /dev/null +++ b/tools/Vulkan-Tools/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 <Cocoa/Cocoa.h> + +@interface AppDelegate : NSObject<NSApplicationDelegate> + +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/AppDelegate.mm b/tools/Vulkan-Tools/cube/macOS/cubepp/AppDelegate.mm new file mode 100644 index 00000000..c1ee96b4 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/AppDelegate.mm @@ -0,0 +1,48 @@ +/* + * 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" +#import "DemoViewController.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + NSApplication *app = aNotification.object; + NSArray<NSWindow *> *windows = app.windows; + for (NSUInteger i = 0; i < windows.count; ++i) { + NSViewController *viewController = windows[i].contentViewController; + if ([viewController isKindOfClass:[DemoViewController class]]) { + [(DemoViewController *)viewController quit]; + break; + } + } +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { + return YES; +} + +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/CMakeLists.txt b/tools/Vulkan-Tools/cube/macOS/cubepp/CMakeLists.txt new file mode 100644 index 00000000..6390db0b --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/CMakeLists.txt @@ -0,0 +1,91 @@ +# ~~~ +# Copyright (c) 2018-2024 Valve Corporation +# Copyright (c) 2018-2024 LunarG, Inc. +# +# 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. +# ~~~ + +# VkCube Application Bundle + +set(cubepp_RESOURCES ${CMAKE_CURRENT_LIST_DIR}/Resources/VulkanIcon.icns) +if(NOT APPLE_USE_SYSTEM_ICD) + list(APPEND cubepp_RESOURCES ${PROJECT_BINARY_DIR}/staging-json/MoltenVK_icd.json) +endif() + +# Have Xcode handle the Storyboard +if(XCODE) + set(cubepp_RESOURCES ${cubepp_RESOURCES} ${CMAKE_CURRENT_LIST_DIR}/Resources/Main.storyboard) +endif() + +add_executable(vkcubepp MACOSX_BUNDLE) + +target_sources(vkcubepp PRIVATE + main.mm + AppDelegate.mm + AppDelegate.h + DemoViewController.h + DemoViewController.mm + ${cubepp_RESOURCES} + ../../cube.vert.inc + ../../cube.frag.inc +) + +# Handle the Storyboard ourselves +if(NOT XCODE) + # Compile the storyboard file with the ibtool. + add_custom_command(TARGET vkcubepp POST_BUILD + COMMAND ${IBTOOL} + --errors + --warnings + --notices + --output-format human-readable-text + --compile ${CMAKE_CURRENT_BINARY_DIR}/vkcubepp.app/Contents/Resources/Main.storyboardc + ${CMAKE_CURRENT_LIST_DIR}/Resources/Main.storyboard + COMMENT "Compiling storyboard") +endif() + +if(NOT APPLE_USE_SYSTEM_ICD) + add_dependencies(vkcubepp MoltenVK_icd-staging-json) +endif() + +# Include demo source code dir because the MacOS vkcubepp's Objective-C source includes the "original" vkcubepp application C++ source +# code. +target_include_directories(vkcubepp PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + +# We do this so vkcubepp is linked to an individual library and NOT a framework. +target_link_libraries(vkcubepp Vulkan::Loader "-framework Cocoa -framework QuartzCore") + +set_target_properties(vkcubepp PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_LIST_DIR}/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") +if(NOT APPLE_USE_SYSTEM_ICD) + set_source_files_properties("${PROJECT_BINARY_DIR}/staging-json/MoltenVK_icd.json" + PROPERTIES + MACOSX_PACKAGE_LOCATION + "Resources/vulkan/icd.d") + + # Copy the MoltenVK lib into the bundle. + if(XCODE) + add_custom_command(TARGET vkcubepp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/Package/Release/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/vkcubepp.app/Contents/Frameworks/libMoltenVK.dylib) + else() + add_custom_command(TARGET vkcubepp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/Package/Release/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" + ${CMAKE_CURRENT_BINARY_DIR}/vkcubepp.app/Contents/Frameworks/libMoltenVK.dylib) + endif() +endif() diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.h b/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.h new file mode 100644 index 00000000..6d7ca215 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.h @@ -0,0 +1,36 @@ +/* + * 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 <AppKit/AppKit.h> + +#pragma mark - +#pragma mark DemoViewController + +/** The main view controller for the demo storyboard. */ +@interface DemoViewController : NSViewController + +- (void)quit; + +@end + +#pragma mark - +#pragma mark DemoView + +/** The Metal-compatibile view for the demo Storyboard. */ +@interface DemoView : NSView +@end diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.mm b/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.mm new file mode 100644 index 00000000..fbb17797 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/DemoViewController.mm @@ -0,0 +1,118 @@ +/* + * 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 <QuartzCore/CAMetalLayer.h> + +#include "cube.cpp" + +#pragma mark - +#pragma mark DemoViewController + +@implementation DemoViewController { + CVDisplayLinkRef _displayLink; + struct Demo demo; + NSTimer* _timer; +} + +- (void)dealloc { + [self quit]; + [super dealloc]; +} + +- (void)quit { + CVDisplayLinkRelease(_displayLink); + demo.cleanup(); +} + +/** 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.layer, 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<WsiPlatform::metal>(); + if (demo->quit) { + CVDisplayLinkStop(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/tools/Vulkan-Tools/cube/macOS/cubepp/Info.plist b/tools/Vulkan-Tools/cube/macOS/cubepp/Info.plist new file mode 100644 index 00000000..d0b74e01 --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/Info.plist @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> + <key>CFBundleGetInfoString</key> + <string>VkCubepp</string> + <key>CFBundleIconFile</key> + <string>VulkanIcon.icns</string> + <key>CFBundleIdentifier</key> + <string>com.lunarg.cubepp</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleLongVersionString</key> + <string>1.0</string> + <key>CFBundleName</key> + <string>VkCubepp</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>CSResourcesFileMapped</key> + <true/> + <key>NSHumanReadableCopyright</key> + <string>Copyright (c) 2018 The Khronos Group Inc. LunarG Inc. All rights reserved.</string> + <key>NSMainStoryboardFile</key> + <string>Main</string> + <key>NSPrincipalClass</key> + <string>NSApplication</string> +</dict> +</plist> diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/Main.storyboard b/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/Main.storyboard new file mode 100644 index 00000000..abae39be --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/Main.storyboard @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G26a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> + <dependencies> + <deployment identifier="macosx"/> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/> + </dependencies> + <scenes> + <!--Application--> + <scene sceneID="JPo-4y-FX3"> + <objects> + <application id="hnw-xV-0zn" sceneMemberID="viewController"> + <menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6"> + <items> + <menuItem title="VkCubepp" id="1Xt-HY-uBw"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="VkCubepp" systemMenu="apple" id="uQy-DD-JDr"> + <items> + <menuItem title="About Demo" id="5kV-Vb-QxS"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> + <menuItem title="Hide Demo" keyEquivalent="h" id="Olw-nP-bQN"> + <connections> + <action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/> + </connections> + </menuItem> + <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO"> + <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> + <connections> + <action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/> + </connections> + </menuItem> + <menuItem title="Show All" id="Kd2-mp-pUS"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/> + <menuItem title="Quit Demo" keyEquivalent="q" id="4sb-4s-VLi"> + <connections> + <action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + <menuItem title="Window" id="aUF-d1-5bR"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo"> + <items> + <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV"> + <connections> + <action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/> + </connections> + </menuItem> + <menuItem title="Zoom" id="R4o-n2-Eq4"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/> + </connections> + </menuItem> + <menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/> + <menuItem title="Bring All to Front" id="LE2-aR-0XJ"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + <menuItem title="Help" id="wpr-3q-Mcd"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ"> + <items> + <menuItem title="VkCubepp Help" keyEquivalent="?" id="FKE-Sm-Kum"> + <connections> + <action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/> + </connections> + </menuItem> + </items> + </menu> + </menuItem> + </items> + </menu> + <connections> + <outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/> + </connections> + </application> + <customObject id="Voe-Tx-rLC" customClass="AppDelegate"/> + <customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83.5" y="-47"/> + </scene> + <!--Window Controller--> + <scene sceneID="R2V-B0-nI4"> + <objects> + <windowController id="B8D-0N-5wS" sceneMemberID="viewController"> + <window key="window" title="VkCubepp" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA"> + <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> + <rect key="contentRect" x="1051" y="656" width="300" height="200"/> + <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> + <value key="minSize" type="size" width="300" height="200"/> + </window> + <connections> + <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/> + </connections> + </windowController> + <customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83" y="146"/> + </scene> + <!--Demo View Controller--> + <scene sceneID="hIz-AP-VOD"> + <objects> + <viewController id="XfG-lQ-9wD" customClass="DemoViewController" sceneMemberID="viewController"> + <view key="view" id="m2S-Jp-Qdl" customClass="DemoView"> + <rect key="frame" x="0.0" y="0.0" width="400" height="300"/> + <autoresizingMask key="autoresizingMask"/> + </view> + </viewController> + <customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="83" y="564"/> + </scene> + </scenes> +</document> diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/VulkanIcon.icns b/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/VulkanIcon.icns Binary files differnew file mode 100644 index 00000000..fb82fb7d --- /dev/null +++ b/tools/Vulkan-Tools/cube/macOS/cubepp/Resources/VulkanIcon.icns diff --git a/tools/Vulkan-Tools/cube/macOS/cubepp/main.mm b/tools/Vulkan-Tools/cube/macOS/cubepp/main.mm new file mode 100644 index 00000000..cf9e0d89 --- /dev/null +++ b/tools/Vulkan-Tools/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 <Cocoa/Cocoa.h> + +int main(int argc, const char* argv[]) { return NSApplicationMain(argc, argv); } |
