updated to Swift 3
This commit is contained in:
parent
18ce09ec48
commit
6efead4328
|
|
@ -9,7 +9,6 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
29400C7D1C3AEE1300345568 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29400C7C1C3AEE1300345568 /* AppDelegate.swift */; };
|
||||
29400C7F1C3AEE1300345568 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29400C7E1C3AEE1300345568 /* ViewController.swift */; };
|
||||
29400C811C3AEE1300345568 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29400C801C3AEE1300345568 /* Assets.xcassets */; };
|
||||
29400C841C3AEE1300345568 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29400C821C3AEE1300345568 /* Main.storyboard */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
|
@ -17,7 +16,6 @@
|
|||
29400C791C3AEE1300345568 /* chapter01.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter01.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29400C7C1C3AEE1300345568 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29400C7E1C3AEE1300345568 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
29400C801C3AEE1300345568 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29400C831C3AEE1300345568 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29400C851C3AEE1300345568 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
|
@ -53,7 +51,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
29400C7E1C3AEE1300345568 /* ViewController.swift */,
|
||||
29400C801C3AEE1300345568 /* Assets.xcassets */,
|
||||
29400C821C3AEE1300345568 /* Main.storyboard */,
|
||||
29400C851C3AEE1300345568 /* Info.plist */,
|
||||
29400C7C1C3AEE1300345568 /* AppDelegate.swift */,
|
||||
|
|
@ -88,11 +85,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29400C781C3AEE1300345568 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -119,7 +117,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29400C811C3AEE1300345568 /* Assets.xcassets in Resources */,
|
||||
29400C841C3AEE1300345568 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -186,7 +183,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -224,7 +221,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -233,24 +230,25 @@
|
|||
29400C891C3AEE1300345568 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter01/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter01;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29400C8A1C3AEE1300345568 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter01/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter01;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -273,6 +271,7 @@
|
|||
29400C8A1C3AEE1300345568 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -10,17 +10,4 @@ import Cocoa
|
|||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
// Insert code here to initialize your application
|
||||
}
|
||||
|
||||
func applicationWillTerminate(aNotification: NSNotification) {
|
||||
// Insert code here to tear down your application
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11163.2" systemVersion="16A254g" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11163.2"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
|
|
@ -673,8 +673,11 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Xlv-xm-iWj">
|
||||
<rect key="frame" x="18" y="110" width="444" height="50"/>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Xlv-xm-iWj">
|
||||
<rect key="frame" x="18" y="99" width="444" height="72"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="72" id="qBP-GW-cE6"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Label" id="Jzz-ex-W3x">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
|
|
@ -682,6 +685,11 @@
|
|||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="Xlv-xm-iWj" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="20" symbolic="YES" id="2EG-P4-Bft"/>
|
||||
<constraint firstItem="Xlv-xm-iWj" firstAttribute="centerY" secondItem="m2S-Jp-Qdl" secondAttribute="centerY" id="JS5-Nd-Fba"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Xlv-xm-iWj" secondAttribute="trailing" constant="20" symbolic="YES" id="zFv-gV-dhn"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="label" destination="Xlv-xm-iWj" id="j10-Xo-Jzk"/>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
// Copyright © 2016 Marius Horga. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa // contains Metal
|
||||
import Cocoa
|
||||
|
||||
class ViewController: NSViewController {
|
||||
|
||||
|
|
@ -15,10 +15,15 @@ class ViewController: NSViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if let device = MTLCreateSystemDefaultDevice() {
|
||||
label.stringValue = "Your GPU name is:\n\(device.name!)"
|
||||
} else {
|
||||
label.stringValue = "Your GPU does not support Metal!"
|
||||
/* The MTLCopyAllDevices() function is only available in macOS.
|
||||
For iOS/tvOS devices use MTLCreateSystemDefaultDevice() instead. */
|
||||
let devices = MTLCopyAllDevices()
|
||||
guard let _ = devices.first else {
|
||||
fatalError("Your GPU does not support Metal!")
|
||||
}
|
||||
label.stringValue = "Your system has the following GPU(s):\n"
|
||||
for device in devices {
|
||||
label.stringValue += "\(device.name!)\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
29E74AD11C4159D60023A39A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E74AD01C4159D60023A39A /* AppDelegate.swift */; };
|
||||
29E74AD51C4159D60023A39A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29E74AD41C4159D60023A39A /* Assets.xcassets */; };
|
||||
29E74AD81C4159D60023A39A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29E74AD61C4159D60023A39A /* Main.storyboard */; };
|
||||
29E74AE01C415A020023A39A /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E74ADF1C415A020023A39A /* MetalView.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
|
@ -16,7 +15,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
29E74ACD1C4159D60023A39A /* chapter02.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter02.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29E74AD01C4159D60023A39A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29E74AD41C4159D60023A39A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29E74AD71C4159D60023A39A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29E74AD91C4159D60023A39A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
29E74ADF1C415A020023A39A /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -54,7 +52,6 @@
|
|||
children = (
|
||||
29E74ADF1C415A020023A39A /* MetalView.swift */,
|
||||
29E74AD61C4159D60023A39A /* Main.storyboard */,
|
||||
29E74AD41C4159D60023A39A /* Assets.xcassets */,
|
||||
29E74AD91C4159D60023A39A /* Info.plist */,
|
||||
29E74AD01C4159D60023A39A /* AppDelegate.swift */,
|
||||
);
|
||||
|
|
@ -88,11 +85,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29E74ACC1C4159D60023A39A = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -119,7 +117,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29E74AD51C4159D60023A39A /* Assets.xcassets in Resources */,
|
||||
29E74AD81C4159D60023A39A /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -186,7 +183,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -224,7 +221,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -233,24 +230,25 @@
|
|||
29E74ADD1C4159D60023A39A /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter02/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter02;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29E74ADE1C4159D60023A39A /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter02/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter02;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -273,6 +271,7 @@
|
|||
29E74ADE1C4159D60023A39A /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -10,25 +10,21 @@ import MetalKit
|
|||
|
||||
class MetalView: MTKView {
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
|
||||
render()
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
}
|
||||
|
||||
func render() {
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
self.device = device
|
||||
let rpd = MTLRenderPassDescriptor()
|
||||
let bleen = MTLClearColor(red: 0, green: 0.5, blue: 0.5, alpha: 1)
|
||||
rpd.colorAttachments[0].texture = currentDrawable!.texture
|
||||
rpd.colorAttachments[0].clearColor = bleen
|
||||
rpd.colorAttachments[0].loadAction = .Clear
|
||||
let commandQueue = device.newCommandQueue()
|
||||
let commandBuffer = commandQueue.commandBuffer()
|
||||
let encoder = commandBuffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
encoder.endEncoding()
|
||||
commandBuffer.presentDrawable(currentDrawable!)
|
||||
commandBuffer.commit()
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable, let rpd = currentRenderPassDescriptor {
|
||||
rpd.colorAttachments[0].texture = currentDrawable!.texture
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0.5, blue: 0.5, alpha: 1)
|
||||
rpd.colorAttachments[0].loadAction = .clear
|
||||
let commandBuffer = device!.newCommandQueue().commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
294BD6211C4D1FD7009CF449 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294BD6201C4D1FD7009CF449 /* MetalView.swift */; };
|
||||
29CB59901C4461EA0004DB55 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29CB598F1C4461EA0004DB55 /* AppDelegate.swift */; };
|
||||
29CB59941C4461EA0004DB55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29CB59931C4461EA0004DB55 /* Assets.xcassets */; };
|
||||
29CB59971C4461EA0004DB55 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29CB59951C4461EA0004DB55 /* Main.storyboard */; };
|
||||
29CB599F1C44665B0004DB55 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 29CB599E1C44665B0004DB55 /* Shaders.metal */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
|
@ -18,7 +17,6 @@
|
|||
294BD6201C4D1FD7009CF449 /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
29CB598C1C4461EA0004DB55 /* chapter03.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter03.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29CB598F1C4461EA0004DB55 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29CB59931C4461EA0004DB55 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29CB59961C4461EA0004DB55 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29CB59981C4461EA0004DB55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
29CB599E1C44665B0004DB55 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
|
||||
|
|
@ -57,7 +55,6 @@
|
|||
294BD6201C4D1FD7009CF449 /* MetalView.swift */,
|
||||
29CB599E1C44665B0004DB55 /* Shaders.metal */,
|
||||
29CB59951C4461EA0004DB55 /* Main.storyboard */,
|
||||
29CB59931C4461EA0004DB55 /* Assets.xcassets */,
|
||||
29CB59981C4461EA0004DB55 /* Info.plist */,
|
||||
29CB598F1C4461EA0004DB55 /* AppDelegate.swift */,
|
||||
);
|
||||
|
|
@ -91,11 +88,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29CB598B1C4461E90004DB55 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -122,7 +120,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29CB59941C4461EA0004DB55 /* Assets.xcassets in Resources */,
|
||||
29CB59971C4461EA0004DB55 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -190,7 +187,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -228,7 +225,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -237,24 +234,25 @@
|
|||
29CB599C1C4461EA0004DB55 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter03/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter03;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29CB599D1C4461EA0004DB55 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter03/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter03;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -10,41 +10,49 @@ import MetalKit
|
|||
|
||||
class MetalView: MTKView {
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
var commandQueue: MTLCommandQueue?
|
||||
var rps: MTLRenderPipelineState?
|
||||
var vertexData: [Float]?
|
||||
var vertexBuffer: MTLBuffer?
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
render()
|
||||
}
|
||||
|
||||
func render() {
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
let vertex_data:[Float] = [-1.0, -1.0, 0.0, 1.0,
|
||||
1.0, -1.0, 0.0, 1.0,
|
||||
0.0, 1.0, 0.0, 1.0]
|
||||
let data_size = vertex_data.count * sizeof(Float)
|
||||
let vertex_buffer = device!.newBufferWithBytes(vertex_data, length: data_size, options: [])
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device!.newCommandQueue()
|
||||
vertexData = [-1.0, -1.0, 0.0, 1.0,
|
||||
1.0, -1.0, 0.0, 1.0,
|
||||
0.0, 1.0, 0.0, 1.0]
|
||||
let dataSize = vertexData!.count * sizeof(Float.self)
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertexData!, length: dataSize, options: [])
|
||||
let library = device!.newDefaultLibrary()!
|
||||
let vertex_func = library.newFunctionWithName("vertex_func")
|
||||
let frag_func = library.newFunctionWithName("fragment_func")
|
||||
let vertex_func = library.newFunction(withName: "vertex_func")
|
||||
let frag_func = library.newFunction(withName: "fragment_func")
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vertex_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
var rps: MTLRenderPipelineState! = nil
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
do {
|
||||
try rps = device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
try rps = device!.newRenderPipelineState(with: rpld)
|
||||
} catch let error {
|
||||
self.print("\(error)")
|
||||
}
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable, let rpd = currentRenderPassDescriptor {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0, 0.5, 0.5, 1.0)
|
||||
let command_buffer = device!.newCommandQueue().commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
let commandBuffer = commandQueue!.commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps!)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ struct Vertex {
|
|||
float4 position [[position]];
|
||||
};
|
||||
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]], uint vid [[vertex_id]]) {
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]],
|
||||
uint vid [[vertex_id]]) {
|
||||
return vertices[vid];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
29C87D411C56E93A005F4615 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C87D401C56E93A005F4615 /* AppDelegate.swift */; };
|
||||
29C87D431C56E93A005F4615 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C87D421C56E93A005F4615 /* ViewController.swift */; };
|
||||
29C87D451C56E93A005F4615 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29C87D441C56E93A005F4615 /* Assets.xcassets */; };
|
||||
29C87D481C56E93B005F4615 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29C87D461C56E93B005F4615 /* Main.storyboard */; };
|
||||
29C87D501C56E9C2005F4615 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 29C87D4F1C56E9C2005F4615 /* Shaders.metal */; };
|
||||
29C87D521C56E9DE005F4615 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C87D511C56E9DE005F4615 /* MetalView.swift */; };
|
||||
|
|
@ -18,8 +16,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
29C87D3D1C56E93A005F4615 /* chapter04.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter04.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29C87D401C56E93A005F4615 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29C87D421C56E93A005F4615 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
29C87D441C56E93A005F4615 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29C87D471C56E93B005F4615 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29C87D491C56E93B005F4615 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
29C87D4F1C56E9C2005F4615 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
|
||||
|
|
@ -58,8 +54,6 @@
|
|||
children = (
|
||||
29C87D511C56E9DE005F4615 /* MetalView.swift */,
|
||||
29C87D4F1C56E9C2005F4615 /* Shaders.metal */,
|
||||
29C87D441C56E93A005F4615 /* Assets.xcassets */,
|
||||
29C87D421C56E93A005F4615 /* ViewController.swift */,
|
||||
29C87D461C56E93B005F4615 /* Main.storyboard */,
|
||||
29C87D491C56E93B005F4615 /* Info.plist */,
|
||||
29C87D401C56E93A005F4615 /* AppDelegate.swift */,
|
||||
|
|
@ -94,11 +88,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29C87D3C1C56E93A005F4615 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -125,7 +120,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29C87D451C56E93A005F4615 /* Assets.xcassets in Resources */,
|
||||
29C87D481C56E93B005F4615 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -139,7 +133,6 @@
|
|||
files = (
|
||||
29C87D521C56E9DE005F4615 /* MetalView.swift in Sources */,
|
||||
29C87D501C56E9C2005F4615 /* Shaders.metal in Sources */,
|
||||
29C87D431C56E93A005F4615 /* ViewController.swift in Sources */,
|
||||
29C87D411C56E93A005F4615 /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -194,7 +187,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -232,7 +225,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -241,24 +234,25 @@
|
|||
29C87D4D1C56E93B005F4615 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter04/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter04;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29C87D4E1C56E93B005F4615 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter04/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter04;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -10,17 +10,4 @@ import Cocoa
|
|||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
// Insert code here to initialize your application
|
||||
}
|
||||
|
||||
func applicationWillTerminate(aNotification: NSNotification) {
|
||||
// Insert code here to tear down your application
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11163.2" systemVersion="16A254g" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11163.2"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
|
|
@ -668,7 +668,7 @@
|
|||
<!--View Controller-->
|
||||
<scene sceneID="hIz-AP-VOD">
|
||||
<objects>
|
||||
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="chapter04" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController id="XfG-lQ-9wD" sceneMemberID="viewController">
|
||||
<view key="view" id="m2S-Jp-Qdl" customClass="MetalView" customModule="chapter04" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
|
|
|
|||
|
|
@ -10,59 +10,56 @@ import MetalKit
|
|||
|
||||
class MetalView: MTKView {
|
||||
|
||||
var vertex_buffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState! = nil
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
render()
|
||||
}
|
||||
|
||||
func render() {
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
createBuffer()
|
||||
registerShaders()
|
||||
sendToGPU()
|
||||
}
|
||||
var commandQueue: MTLCommandQueue?
|
||||
var rps: MTLRenderPipelineState?
|
||||
var vertexBuffer: MTLBuffer?
|
||||
|
||||
struct Vertex {
|
||||
var position: vector_float4
|
||||
var color: vector_float4
|
||||
};
|
||||
}
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
createBuffer()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
func createBuffer() {
|
||||
let vertex_data = [Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])]
|
||||
vertex_buffer = device!.newBufferWithBytes(vertex_data, length: sizeof(Vertex) * 3, options:[])
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device!.newCommandQueue()
|
||||
let vertexData = [Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])]
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertexData, length: sizeof(Vertex.self) * 3, options:[])
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
let library = device!.newDefaultLibrary()!
|
||||
let vertex_func = library.newFunctionWithName("vertex_func")
|
||||
let frag_func = library.newFunctionWithName("fragment_func")
|
||||
let vertex_func = library.newFunction(withName: "vertex_func")
|
||||
let frag_func = library.newFunction(withName: "fragment_func")
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vertex_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
do {
|
||||
try rps = device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
try rps = device!.newRenderPipelineState(with: rpld)
|
||||
} catch let error {
|
||||
self.print("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func sendToGPU() {
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable, let rpd = currentRenderPassDescriptor {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let command_buffer = device!.newCommandQueue().commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
let commandBuffer = commandQueue!.commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps!)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ struct Vertex {
|
|||
float4 color;
|
||||
};
|
||||
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]], uint vid [[vertex_id]]) {
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]],
|
||||
uint vid [[vertex_id]]) {
|
||||
return vertices[vid];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
//
|
||||
// ViewController.swift
|
||||
// chapter04
|
||||
//
|
||||
// Created by Marius on 1/26/16.
|
||||
// Copyright © 2016 Marius Horga. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class ViewController: NSViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
override var representedObject: AnyObject? {
|
||||
didSet {
|
||||
// Update the view, if already loaded.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
298037231C62437900FBBC6A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298037221C62437900FBBC6A /* AppDelegate.swift */; };
|
||||
298037271C62437900FBBC6A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 298037261C62437900FBBC6A /* Assets.xcassets */; };
|
||||
2980372A1C62437900FBBC6A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 298037281C62437900FBBC6A /* Main.storyboard */; };
|
||||
298037321C6243CB00FBBC6A /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298037311C6243CB00FBBC6A /* MetalView.swift */; };
|
||||
298037341C62440400FBBC6A /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 298037331C62440400FBBC6A /* Shaders.metal */; };
|
||||
|
|
@ -17,7 +16,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
2980371F1C62437900FBBC6A /* chapter05.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter05.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
298037221C62437900FBBC6A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
298037261C62437900FBBC6A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
298037291C62437900FBBC6A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
2980372B1C62437900FBBC6A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
298037311C6243CB00FBBC6A /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -56,7 +54,6 @@
|
|||
children = (
|
||||
298037311C6243CB00FBBC6A /* MetalView.swift */,
|
||||
298037331C62440400FBBC6A /* Shaders.metal */,
|
||||
298037261C62437900FBBC6A /* Assets.xcassets */,
|
||||
298037281C62437900FBBC6A /* Main.storyboard */,
|
||||
2980372B1C62437900FBBC6A /* Info.plist */,
|
||||
298037221C62437900FBBC6A /* AppDelegate.swift */,
|
||||
|
|
@ -91,11 +88,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
2980371E1C62437900FBBC6A = {
|
||||
CreatedOnToolsVersion = 7.2.1;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -122,7 +120,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
298037271C62437900FBBC6A /* Assets.xcassets in Resources */,
|
||||
2980372A1C62437900FBBC6A /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -190,7 +187,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -228,7 +225,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -237,7 +234,6 @@
|
|||
2980372F1C62437900FBBC6A /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter05/Info.plist;
|
||||
|
|
@ -245,19 +241,21 @@
|
|||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter05;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
298037301C62437900FBBC6A /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter05/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter05;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -10,20 +10,15 @@ import MetalKit
|
|||
|
||||
class MetalView: MTKView {
|
||||
|
||||
var vertex_buffer: MTLBuffer!
|
||||
var uniform_buffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState! = nil
|
||||
var commandQueue: MTLCommandQueue?
|
||||
var rps: MTLRenderPipelineState?
|
||||
var vertexBuffer: MTLBuffer!
|
||||
var uniformBuffer: MTLBuffer!
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
render()
|
||||
}
|
||||
|
||||
func render() {
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
createBuffers()
|
||||
registerShaders()
|
||||
sendToGPU()
|
||||
}
|
||||
|
||||
struct Vertex {
|
||||
|
|
@ -33,7 +28,6 @@ class MetalView: MTKView {
|
|||
|
||||
struct Matrix {
|
||||
var m: [Float]
|
||||
|
||||
init() {
|
||||
m = [1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
|
|
@ -41,23 +35,23 @@ class MetalView: MTKView {
|
|||
0, 0, 0, 1
|
||||
]
|
||||
}
|
||||
|
||||
func translationMatrix(var matrix: Matrix, _ position: float3) -> Matrix {
|
||||
func translationMatrix(_ matrix: Matrix, _ position: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[12] = position.x
|
||||
matrix.m[13] = position.y
|
||||
matrix.m[14] = position.z
|
||||
return matrix
|
||||
}
|
||||
|
||||
func scalingMatrix(var matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
func scalingMatrix(_ matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = scale
|
||||
matrix.m[5] = scale
|
||||
matrix.m[10] = scale
|
||||
matrix.m[15] = 1.0
|
||||
return matrix
|
||||
}
|
||||
|
||||
func rotationMatrix(var matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
func rotationMatrix(_ matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = cos(rot.y) * cos(rot.z)
|
||||
matrix.m[4] = cos(rot.z) * sin(rot.x) * sin(rot.y) - cos(rot.x) * sin(rot.z)
|
||||
matrix.m[8] = cos(rot.x) * cos(rot.z) * sin(rot.y) + sin(rot.x) * sin(rot.z)
|
||||
|
|
@ -70,8 +64,8 @@ class MetalView: MTKView {
|
|||
matrix.m[15] = 1.0
|
||||
return matrix
|
||||
}
|
||||
|
||||
func modelMatrix(var matrix: Matrix) -> Matrix {
|
||||
func modelMatrix(_ matrix: Matrix) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix = rotationMatrix(matrix, float3(0.0, 0.0, 0.1))
|
||||
matrix = scalingMatrix(matrix, 0.25)
|
||||
matrix = translationMatrix(matrix, float3(0.0, 0.5, 0.0))
|
||||
|
|
@ -80,44 +74,45 @@ class MetalView: MTKView {
|
|||
}
|
||||
|
||||
func createBuffers() {
|
||||
let vertex_data = [
|
||||
Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device!.newCommandQueue()
|
||||
let vertex_data = [Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])
|
||||
]
|
||||
vertex_buffer = device!.newBufferWithBytes(vertex_data, length: sizeof(Vertex) * 3, options:[])
|
||||
uniform_buffer = device!.newBufferWithLength(sizeof(Float) * 16, options: [])
|
||||
let bufferPointer = uniform_buffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float) * 16)
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertex_data, length: sizeof(Vertex.self) * 3, options:[])
|
||||
uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
let library = device!.newDefaultLibrary()!
|
||||
let vertex_func = library.newFunctionWithName("vertex_func")
|
||||
let frag_func = library.newFunctionWithName("fragment_func")
|
||||
let vertex_func = library.newFunction(withName: "vertex_func")
|
||||
let frag_func = library.newFunction(withName: "fragment_func")
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vertex_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
do {
|
||||
try rps = device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
try rps = device!.newRenderPipelineState(with: rpld)
|
||||
} catch let error {
|
||||
self.print("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func sendToGPU() {
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let command_buffer = device!.newCommandQueue().commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.setVertexBuffer(uniform_buffer, offset: 0, atIndex: 1)
|
||||
command_encoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
let commandBuffer = device!.newCommandQueue().commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps!)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.setVertexBuffer(uniformBuffer, offset: 0, at: 1)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,23 +7,21 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
292765421C6BDE3400094CA9 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 292765411C6BDE3400094CA9 /* MetalView.swift */; };
|
||||
29DB1AF61C6BDDD500BCC31B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29DB1AF51C6BDDD500BCC31B /* AppDelegate.swift */; };
|
||||
29DB1AFA1C6BDDD500BCC31B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29DB1AF91C6BDDD500BCC31B /* Assets.xcassets */; };
|
||||
29DB1AFD1C6BDDD500BCC31B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29DB1AFB1C6BDDD500BCC31B /* Main.storyboard */; };
|
||||
298451301D47EF08008D81B9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2984512F1D47EF08008D81B9 /* AppDelegate.swift */; };
|
||||
298451351D47EF08008D81B9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 298451331D47EF08008D81B9 /* Main.storyboard */; };
|
||||
298451421D47F0BF008D81B9 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298451411D47F0BF008D81B9 /* MetalView.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
292765411C6BDE3400094CA9 /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
29DB1AF21C6BDDD500BCC31B /* chapter06.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter06.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29DB1AF51C6BDDD500BCC31B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29DB1AF91C6BDDD500BCC31B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29DB1AFC1C6BDDD500BCC31B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29DB1AFE1C6BDDD500BCC31B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
2984512C1D47EF08008D81B9 /* chapter06.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter06.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2984512F1D47EF08008D81B9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
298451341D47EF08008D81B9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
2984513B1D47EF08008D81B9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
298451411D47F0BF008D81B9 /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
29DB1AEF1C6BDDD500BCC31B /* Frameworks */ = {
|
||||
298451291D47EF08008D81B9 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
|
|
@ -33,30 +31,29 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
29DB1AE91C6BDDD400BCC31B = {
|
||||
298451231D47EF07008D81B9 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29DB1AF41C6BDDD500BCC31B /* chapter06 */,
|
||||
29DB1AF31C6BDDD500BCC31B /* Products */,
|
||||
2984512E1D47EF08008D81B9 /* chapter06 */,
|
||||
2984512D1D47EF08008D81B9 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29DB1AF31C6BDDD500BCC31B /* Products */ = {
|
||||
2984512D1D47EF08008D81B9 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29DB1AF21C6BDDD500BCC31B /* chapter06.app */,
|
||||
2984512C1D47EF08008D81B9 /* chapter06.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29DB1AF41C6BDDD500BCC31B /* chapter06 */ = {
|
||||
2984512E1D47EF08008D81B9 /* chapter06 */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
292765411C6BDE3400094CA9 /* MetalView.swift */,
|
||||
29DB1AF91C6BDDD500BCC31B /* Assets.xcassets */,
|
||||
29DB1AFB1C6BDDD500BCC31B /* Main.storyboard */,
|
||||
29DB1AFE1C6BDDD500BCC31B /* Info.plist */,
|
||||
29DB1AF51C6BDDD500BCC31B /* AppDelegate.swift */,
|
||||
298451411D47F0BF008D81B9 /* MetalView.swift */,
|
||||
298451331D47EF08008D81B9 /* Main.storyboard */,
|
||||
2984513B1D47EF08008D81B9 /* Info.plist */,
|
||||
2984512F1D47EF08008D81B9 /* AppDelegate.swift */,
|
||||
);
|
||||
path = chapter06;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -64,13 +61,13 @@
|
|||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
29DB1AF11C6BDDD500BCC31B /* chapter06 */ = {
|
||||
2984512B1D47EF08008D81B9 /* chapter06 */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 29DB1B011C6BDDD500BCC31B /* Build configuration list for PBXNativeTarget "chapter06" */;
|
||||
buildConfigurationList = 2984513E1D47EF08008D81B9 /* Build configuration list for PBXNativeTarget "chapter06" */;
|
||||
buildPhases = (
|
||||
29DB1AEE1C6BDDD500BCC31B /* Sources */,
|
||||
29DB1AEF1C6BDDD500BCC31B /* Frameworks */,
|
||||
29DB1AF01C6BDDD500BCC31B /* Resources */,
|
||||
298451281D47EF08008D81B9 /* Sources */,
|
||||
298451291D47EF08008D81B9 /* Frameworks */,
|
||||
2984512A1D47EF08008D81B9 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
|
|
@ -78,25 +75,28 @@
|
|||
);
|
||||
name = chapter06;
|
||||
productName = chapter06;
|
||||
productReference = 29DB1AF21C6BDDD500BCC31B /* chapter06.app */;
|
||||
productReference = 2984512C1D47EF08008D81B9 /* chapter06.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
29DB1AEA1C6BDDD400BCC31B /* Project object */ = {
|
||||
298451241D47EF07008D81B9 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
LastSwiftUpdateCheck = 0800;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = Marius;
|
||||
TargetAttributes = {
|
||||
29DB1AF11C6BDDD500BCC31B = {
|
||||
CreatedOnToolsVersion = 7.2.1;
|
||||
2984512B1D47EF08008D81B9 = {
|
||||
CreatedOnToolsVersion = 8.0;
|
||||
DevelopmentTeam = C2X9Q6VFVJ;
|
||||
DevelopmentTeamName = "Marius Horga";
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 29DB1AED1C6BDDD400BCC31B /* Build configuration list for PBXProject "chapter06" */;
|
||||
buildConfigurationList = 298451271D47EF07008D81B9 /* Build configuration list for PBXProject "chapter06" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
|
|
@ -104,45 +104,44 @@
|
|||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 29DB1AE91C6BDDD400BCC31B;
|
||||
productRefGroup = 29DB1AF31C6BDDD500BCC31B /* Products */;
|
||||
mainGroup = 298451231D47EF07008D81B9;
|
||||
productRefGroup = 2984512D1D47EF08008D81B9 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
29DB1AF11C6BDDD500BCC31B /* chapter06 */,
|
||||
2984512B1D47EF08008D81B9 /* chapter06 */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
29DB1AF01C6BDDD500BCC31B /* Resources */ = {
|
||||
2984512A1D47EF08008D81B9 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29DB1AFA1C6BDDD500BCC31B /* Assets.xcassets in Resources */,
|
||||
29DB1AFD1C6BDDD500BCC31B /* Main.storyboard in Resources */,
|
||||
298451351D47EF08008D81B9 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
29DB1AEE1C6BDDD500BCC31B /* Sources */ = {
|
||||
298451281D47EF08008D81B9 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
292765421C6BDE3400094CA9 /* MetalView.swift in Sources */,
|
||||
29DB1AF61C6BDDD500BCC31B /* AppDelegate.swift in Sources */,
|
||||
298451421D47F0BF008D81B9 /* MetalView.swift in Sources */,
|
||||
298451301D47EF08008D81B9 /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
29DB1AFB1C6BDDD500BCC31B /* Main.storyboard */ = {
|
||||
298451331D47EF08008D81B9 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
29DB1AFC1C6BDDD500BCC31B /* Base */,
|
||||
298451341D47EF08008D81B9 /* Base */,
|
||||
);
|
||||
name = Main.storyboard;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -150,10 +149,11 @@
|
|||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
29DB1AFF1C6BDDD500BCC31B /* Debug */ = {
|
||||
2984513C1D47EF08008D81B9 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
|
|
@ -161,13 +161,14 @@
|
|||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
|
|
@ -186,18 +187,21 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29DB1B001C6BDDD500BCC31B /* Release */ = {
|
||||
2984513D1D47EF08008D81B9 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
|
|
@ -205,13 +209,14 @@
|
|||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
|
|
@ -224,58 +229,63 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
29DB1B021C6BDDD500BCC31B /* Debug */ = {
|
||||
2984513F1D47EF08008D81B9 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
INFOPLIST_FILE = chapter06/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter06;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.metalkit.chapter06;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE = "";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29DB1B031C6BDDD500BCC31B /* Release */ = {
|
||||
298451401D47EF08008D81B9 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
INFOPLIST_FILE = chapter06/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter06;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.metalkit.chapter06;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
29DB1AED1C6BDDD400BCC31B /* Build configuration list for PBXProject "chapter06" */ = {
|
||||
298451271D47EF07008D81B9 /* Build configuration list for PBXProject "chapter06" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
29DB1AFF1C6BDDD500BCC31B /* Debug */,
|
||||
29DB1B001C6BDDD500BCC31B /* Release */,
|
||||
2984513C1D47EF08008D81B9 /* Debug */,
|
||||
2984513D1D47EF08008D81B9 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
29DB1B011C6BDDD500BCC31B /* Build configuration list for PBXNativeTarget "chapter06" */ = {
|
||||
2984513E1D47EF08008D81B9 /* Build configuration list for PBXNativeTarget "chapter06" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
29DB1B021C6BDDD500BCC31B /* Debug */,
|
||||
29DB1B031C6BDDD500BCC31B /* Release */,
|
||||
2984513F1D47EF08008D81B9 /* Debug */,
|
||||
298451401D47EF08008D81B9 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 29DB1AEA1C6BDDD400BCC31B /* Project object */;
|
||||
rootObject = 298451241D47EF07008D81B9 /* Project object */;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29DB1AF11C6BDDD500BCC31B"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29DB1AF11C6BDDD500BCC31B"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29DB1AF11C6BDDD500BCC31B"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29DB1AF11C6BDDD500BCC31B"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29DB1AF11C6BDDD500BCC31B</key>
|
||||
<key>2984512B1D47EF08008D81B9</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
// AppDelegate.swift
|
||||
// chapter06
|
||||
//
|
||||
// Created by Marius on 2/10/16.
|
||||
// Copyright © 2016 Marius Horga. All rights reserved.
|
||||
// Created by Marius on 7/26/16.
|
||||
// Copyright © 2016 Marius. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import UIKit
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,682 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11163.2" systemVersion="16A254g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11133"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</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="chapter06" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="chapter06" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="About chapter06" 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="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||
<menuItem title="Services" id="NMo-om-nkz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
|
||||
<menuItem title="Hide chapter06" 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 chapter06" 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="File" id="dMs-cI-mzQ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
||||
<items>
|
||||
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
|
||||
<connections>
|
||||
<action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
|
||||
<connections>
|
||||
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open Recent" id="tXI-mr-wws">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
|
||||
<items>
|
||||
<menuItem title="Clear Menu" id="vNY-rz-j42">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="clearRecentDocuments:" target="Ady-hI-5gd" id="Daa-9d-B3U"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
||||
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
||||
<connections>
|
||||
<action selector="performClose:" target="Ady-hI-5gd" id="HmO-Ls-i7Q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
|
||||
<connections>
|
||||
<action selector="saveDocument:" target="Ady-hI-5gd" id="teZ-XB-qJY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
|
||||
<connections>
|
||||
<action selector="saveDocumentAs:" target="Ady-hI-5gd" id="mDf-zr-I0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="KaW-ft-85H">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="revertDocumentToSaved:" target="Ady-hI-5gd" id="iJ3-Pv-kwq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
|
||||
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
|
||||
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="runPageLayout:" target="Ady-hI-5gd" id="Din-rz-gC5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
|
||||
<connections>
|
||||
<action selector="print:" target="Ady-hI-5gd" id="qaZ-4w-aoO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Edit" id="5QF-Oa-p0T">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Edit" id="W48-6f-4Dl">
|
||||
<items>
|
||||
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
|
||||
<connections>
|
||||
<action selector="undo:" target="Ady-hI-5gd" id="M6e-cu-g7V"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
|
||||
<connections>
|
||||
<action selector="redo:" target="Ady-hI-5gd" id="oIA-Rs-6OD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
|
||||
<menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
|
||||
<connections>
|
||||
<action selector="cut:" target="Ady-hI-5gd" id="YJe-68-I9s"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
|
||||
<connections>
|
||||
<action selector="copy:" target="Ady-hI-5gd" id="G1f-GL-Joy"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
||||
<connections>
|
||||
<action selector="paste:" target="Ady-hI-5gd" id="UvS-8e-Qdg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteAsPlainText:" target="Ady-hI-5gd" id="cEh-KX-wJQ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Delete" id="pa3-QI-u2k">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="delete:" target="Ady-hI-5gd" id="0Mk-Ml-PaM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
|
||||
<connections>
|
||||
<action selector="selectAll:" target="Ady-hI-5gd" id="VNm-Mi-diN"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
|
||||
<menuItem title="Find" id="4EN-yA-p0u">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Find" id="1b7-l0-nxx">
|
||||
<items>
|
||||
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="cD7-Qs-BN4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="WD3-Gg-5AJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="NDo-RZ-v9R"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="HOh-sY-3ay"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="U76-nv-p5D"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
|
||||
<connections>
|
||||
<action selector="centerSelectionInVisibleArea:" target="Ady-hI-5gd" id="IOG-6D-g5B"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
|
||||
<items>
|
||||
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
|
||||
<connections>
|
||||
<action selector="showGuessPanel:" target="Ady-hI-5gd" id="vFj-Ks-hy3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
|
||||
<connections>
|
||||
<action selector="checkSpelling:" target="Ady-hI-5gd" id="fz7-VC-reM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
|
||||
<menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleContinuousSpellChecking:" target="Ady-hI-5gd" id="7w6-Qz-0kB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleGrammarChecking:" target="Ady-hI-5gd" id="muD-Qn-j4w"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticSpellingCorrection:" target="Ady-hI-5gd" id="2lM-Qi-WAP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Substitutions" id="9ic-FL-obx">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
|
||||
<items>
|
||||
<menuItem title="Show Substitutions" id="z6F-FW-3nz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontSubstitutionsPanel:" target="Ady-hI-5gd" id="oku-mr-iSq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
|
||||
<menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleSmartInsertDelete:" target="Ady-hI-5gd" id="3IJ-Se-DZD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Quotes" id="hQb-2v-fYv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticQuoteSubstitution:" target="Ady-hI-5gd" id="ptq-xd-QOA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Dashes" id="rgM-f4-ycn">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDashSubstitution:" target="Ady-hI-5gd" id="oCt-pO-9gS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Links" id="cwL-P1-jid">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticLinkDetection:" target="Ady-hI-5gd" id="Gip-E3-Fov"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Data Detectors" id="tRr-pd-1PS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDataDetection:" target="Ady-hI-5gd" id="R1I-Nq-Kbl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Text Replacement" id="HFQ-gK-NFA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticTextReplacement:" target="Ady-hI-5gd" id="DvP-Fe-Py6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Transformations" id="2oI-Rn-ZJC">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Transformations" id="c8a-y6-VQd">
|
||||
<items>
|
||||
<menuItem title="Make Upper Case" id="vmV-6d-7jI">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="uppercaseWord:" target="Ady-hI-5gd" id="sPh-Tk-edu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Make Lower Case" id="d9M-CD-aMd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowercaseWord:" target="Ady-hI-5gd" id="iUZ-b5-hil"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Capitalize" id="UEZ-Bs-lqG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="capitalizeWord:" target="Ady-hI-5gd" id="26H-TL-nsh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Speech" id="xrE-MZ-jX0">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Speech" id="3rS-ZA-NoH">
|
||||
<items>
|
||||
<menuItem title="Start Speaking" id="Ynk-f8-cLZ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="startSpeaking:" target="Ady-hI-5gd" id="654-Ng-kyl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Stop Speaking" id="Oyz-dy-DGm">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="stopSpeaking:" target="Ady-hI-5gd" id="dX8-6p-jy9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Format" id="jxT-CU-nIS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Format" id="GEO-Iw-cKr">
|
||||
<items>
|
||||
<menuItem title="Font" id="Gi5-1S-RQB">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
|
||||
<items>
|
||||
<menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq"/>
|
||||
<menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27"/>
|
||||
<menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq"/>
|
||||
<menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
|
||||
<connections>
|
||||
<action selector="underline:" target="Ady-hI-5gd" id="FYS-2b-JAY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
|
||||
<menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL"/>
|
||||
<menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST"/>
|
||||
<menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
|
||||
<menuItem title="Kern" id="jBQ-r6-VK2">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Kern" id="tlD-Oa-oAM">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="GUa-eO-cwY">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardKerning:" target="Ady-hI-5gd" id="6dk-9l-Ckg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="cDB-IK-hbR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffKerning:" target="Ady-hI-5gd" id="U8a-gz-Maa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Tighten" id="46P-cB-AYj">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="tightenKerning:" target="Ady-hI-5gd" id="hr7-Nz-8ro"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Loosen" id="ogc-rX-tC1">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="loosenKerning:" target="Ady-hI-5gd" id="8i4-f9-FKE"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Ligatures" id="o6e-r0-MWq">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="agt-UL-0e3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardLigatures:" target="Ady-hI-5gd" id="7uR-wd-Dx6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="J7y-lM-qPV">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffLigatures:" target="Ady-hI-5gd" id="iX2-gA-Ilz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use All" id="xQD-1f-W4t">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useAllLigatures:" target="Ady-hI-5gd" id="KcB-kA-TuK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Baseline" id="OaQ-X3-Vso">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Baseline" id="ijk-EB-dga">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="3Om-Ey-2VK">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unscript:" target="Ady-hI-5gd" id="0vZ-95-Ywn"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Superscript" id="Rqc-34-cIF">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="superscript:" target="Ady-hI-5gd" id="3qV-fo-wpU"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Subscript" id="I0S-gh-46l">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="subscript:" target="Ady-hI-5gd" id="Q6W-4W-IGz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Raise" id="2h7-ER-AoG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="raiseBaseline:" target="Ady-hI-5gd" id="4sk-31-7Q9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Lower" id="1tx-W0-xDw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowerBaseline:" target="Ady-hI-5gd" id="OF1-bc-KW4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
|
||||
<menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
|
||||
<connections>
|
||||
<action selector="orderFrontColorPanel:" target="Ady-hI-5gd" id="mSX-Xz-DV3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
|
||||
<menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyFont:" target="Ady-hI-5gd" id="GJO-xA-L4q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteFont:" target="Ady-hI-5gd" id="JfD-CL-leO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Text" id="Fal-I4-PZk">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Text" id="d9c-me-L2H">
|
||||
<items>
|
||||
<menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
|
||||
<connections>
|
||||
<action selector="alignLeft:" target="Ady-hI-5gd" id="zUv-R1-uAa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
|
||||
<connections>
|
||||
<action selector="alignCenter:" target="Ady-hI-5gd" id="spX-mk-kcS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Justify" id="J5U-5w-g23">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="alignJustified:" target="Ady-hI-5gd" id="ljL-7U-jND"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
|
||||
<connections>
|
||||
<action selector="alignRight:" target="Ady-hI-5gd" id="r48-bG-YeY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
|
||||
<menuItem title="Writing Direction" id="H1b-Si-o9J">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
|
||||
<items>
|
||||
<menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="YGs-j5-SAR">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionNatural:" target="Ady-hI-5gd" id="qtV-5e-UBP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="Lbh-J2-qVU">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionLeftToRight:" target="Ady-hI-5gd" id="S0X-9S-QSf"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="jFq-tB-4Kx">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionRightToLeft:" target="Ady-hI-5gd" id="5fk-qB-AqJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
|
||||
<menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="Nop-cj-93Q">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionNatural:" target="Ady-hI-5gd" id="lPI-Se-ZHp"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="BgM-ve-c93">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionLeftToRight:" target="Ady-hI-5gd" id="caW-Bv-w94"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="RB4-Sm-HuC">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionRightToLeft:" target="Ady-hI-5gd" id="EXD-6r-ZUu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
|
||||
<menuItem title="Show Ruler" id="vLm-3I-IUL">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleRuler:" target="Ady-hI-5gd" id="FOx-HJ-KwY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyRuler:" target="Ady-hI-5gd" id="71i-fW-3W2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteRuler:" target="Ady-hI-5gd" id="cSh-wd-qM2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="View" id="H8h-7b-M4v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="View" id="HyV-fh-RgO">
|
||||
<items>
|
||||
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleToolbarShown:" target="Ady-hI-5gd" id="BXY-wc-z0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="runToolbarCustomizationPalette:" target="Ady-hI-5gd" id="pQI-g3-MTW"/>
|
||||
</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="chapter06 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" customModule="chapter06" customModuleProvider="target"/>
|
||||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="75" y="0.0"/>
|
||||
</scene>
|
||||
<!--Window Controller-->
|
||||
<scene sceneID="R2V-B0-nI4">
|
||||
<objects>
|
||||
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
|
||||
<window key="window" title="Window" 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"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
|
||||
</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="75" y="250"/>
|
||||
</scene>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="hIz-AP-VOD">
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="XfG-lQ-9wD" sceneMemberID="viewController">
|
||||
<view key="view" id="m2S-Jp-Qdl" customClass="MetalView" customModule="chapter06" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<viewController id="BYZ-38-t0r" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC" customClass="MetalView" customModule="chapter06" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="75" y="655"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
|
|
@ -18,17 +16,28 @@
|
|||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Marius Horga. All rights reserved.</string>
|
||||
<key>NSMainStoryboardFile</key>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>Main</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
|||
|
|
@ -6,39 +6,36 @@
|
|||
// Copyright © 2016 Marius Horga. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import UIKit
|
||||
|
||||
class MetalView: NSView {
|
||||
class MetalView: UIView {
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
render()
|
||||
var commandQueue: MTLCommandQueue!
|
||||
|
||||
var metalLayer: CAMetalLayer {
|
||||
return self.layer as! CAMetalLayer
|
||||
}
|
||||
|
||||
override class func layerClass() -> AnyClass {
|
||||
return CAMetalLayer.self
|
||||
}
|
||||
|
||||
var metalLayer: CAMetalLayer {
|
||||
return layer as! CAMetalLayer
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device.newCommandQueue()
|
||||
redraw()
|
||||
}
|
||||
|
||||
func render() {
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
metalLayer.device = device
|
||||
metalLayer.pixelFormat = .BGRA8Unorm
|
||||
let drawable = metalLayer.nextDrawable()
|
||||
let texture = drawable!.texture
|
||||
let rpd = MTLRenderPassDescriptor()
|
||||
rpd.colorAttachments[0].texture = texture
|
||||
rpd.colorAttachments[0].loadAction = .Clear
|
||||
rpd.colorAttachments[0].storeAction = .Store
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColor(red: 1, green: 0, blue: 0, alpha: 1)
|
||||
let commandQueue = device.newCommandQueue()
|
||||
private func redraw() {
|
||||
let drawable = metalLayer.nextDrawable()!
|
||||
let descriptor = MTLRenderPassDescriptor()
|
||||
descriptor.colorAttachments[0].clearColor = MTLClearColorMake(0, 1, 1, 1)
|
||||
descriptor.colorAttachments[0].texture = drawable.texture
|
||||
let commandBuffer = commandQueue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: descriptor)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.presentDrawable(drawable!)
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
29B186261C84FF5800E9C0AA /* MathUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B186251C84FF5800E9C0AA /* MathUtils.swift */; };
|
||||
29D8782A1C84D2B0007B5F17 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D878291C84D2B0007B5F17 /* AppDelegate.swift */; };
|
||||
29D8782E1C84D2B0007B5F17 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29D8782D1C84D2B0007B5F17 /* Assets.xcassets */; };
|
||||
29D878311C84D2B0007B5F17 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29D8782F1C84D2B0007B5F17 /* Main.storyboard */; };
|
||||
29D878391C84D309007B5F17 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D878381C84D309007B5F17 /* MetalView.swift */; };
|
||||
29D8783B1C84D335007B5F17 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 29D8783A1C84D335007B5F17 /* Shaders.metal */; };
|
||||
|
|
@ -19,7 +18,6 @@
|
|||
29B186251C84FF5800E9C0AA /* MathUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MathUtils.swift; sourceTree = "<group>"; };
|
||||
29D878261C84D2B0007B5F17 /* chapter07.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chapter07.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29D878291C84D2B0007B5F17 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
29D8782D1C84D2B0007B5F17 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
29D878301C84D2B0007B5F17 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
29D878321C84D2B0007B5F17 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
29D878381C84D309007B5F17 /* MetalView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -59,7 +57,6 @@
|
|||
29D878381C84D309007B5F17 /* MetalView.swift */,
|
||||
29B186251C84FF5800E9C0AA /* MathUtils.swift */,
|
||||
29D8783A1C84D335007B5F17 /* Shaders.metal */,
|
||||
29D8782D1C84D2B0007B5F17 /* Assets.xcassets */,
|
||||
29D8782F1C84D2B0007B5F17 /* Main.storyboard */,
|
||||
29D878321C84D2B0007B5F17 /* Info.plist */,
|
||||
29D878291C84D2B0007B5F17 /* AppDelegate.swift */,
|
||||
|
|
@ -94,11 +91,12 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29D878251C84D2B0007B5F17 = {
|
||||
CreatedOnToolsVersion = 7.2.1;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -125,7 +123,6 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
29D8782E1C84D2B0007B5F17 /* Assets.xcassets in Resources */,
|
||||
29D878311C84D2B0007B5F17 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -194,7 +191,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
|
|
@ -232,7 +229,7 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
|
|
@ -241,24 +238,25 @@
|
|||
29D878361C84D2B0007B5F17 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter07/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter07;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
29D878371C84D2B0007B5F17 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = chapter07/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mhorga.chapter07;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
|
@ -24,14 +24,16 @@ struct Matrix {
|
|||
]
|
||||
}
|
||||
|
||||
func translationMatrix(var matrix: Matrix, _ position: float3) -> Matrix {
|
||||
func translationMatrix(_ matrix: Matrix, _ position: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[12] = position.x
|
||||
matrix.m[13] = position.y
|
||||
matrix.m[14] = position.z
|
||||
return matrix
|
||||
}
|
||||
|
||||
func scalingMatrix(var matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
func scalingMatrix(_ matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = scale
|
||||
matrix.m[5] = scale
|
||||
matrix.m[10] = scale
|
||||
|
|
@ -39,7 +41,8 @@ struct Matrix {
|
|||
return matrix
|
||||
}
|
||||
|
||||
func rotationMatrix(var matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
func rotationMatrix(_ matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = cos(rot.y) * cos(rot.z)
|
||||
matrix.m[4] = cos(rot.z) * sin(rot.x) * sin(rot.y) - cos(rot.x) * sin(rot.z)
|
||||
matrix.m[8] = cos(rot.x) * cos(rot.z) * sin(rot.y) + sin(rot.x) * sin(rot.z)
|
||||
|
|
@ -53,7 +56,8 @@ struct Matrix {
|
|||
return matrix
|
||||
}
|
||||
|
||||
func modelMatrix(var matrix: Matrix) -> Matrix {
|
||||
func modelMatrix(_ matrix: Matrix) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix = rotationMatrix(matrix, float3(0.0, 0.0, 0.1))
|
||||
matrix = scalingMatrix(matrix, 0.25)
|
||||
matrix = translationMatrix(matrix, float3(0.0, 0.5, 0.0))
|
||||
|
|
|
|||
|
|
@ -10,57 +10,58 @@ import MetalKit
|
|||
|
||||
class MetalView: MTKView {
|
||||
|
||||
var vertex_buffer: MTLBuffer!
|
||||
var uniform_buffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState! = nil
|
||||
var commandQueue: MTLCommandQueue?
|
||||
var rps: MTLRenderPipelineState?
|
||||
var vertexBuffer: MTLBuffer!
|
||||
var uniformBuffer: MTLBuffer!
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
createBuffers()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
override func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let command_buffer = device!.newCommandQueue().commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.setVertexBuffer(uniform_buffer, offset: 0, atIndex: 1)
|
||||
command_encoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
}
|
||||
}
|
||||
|
||||
func createBuffers() {
|
||||
let vertex_data = [
|
||||
Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device!.newCommandQueue()
|
||||
let vertex_data = [Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])
|
||||
]
|
||||
vertex_buffer = device!.newBufferWithBytes(vertex_data, length: sizeof(Vertex) * 3, options:[])
|
||||
uniform_buffer = device!.newBufferWithLength(sizeof(Float) * 16, options: [])
|
||||
let bufferPointer = uniform_buffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float) * 16)
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertex_data, length: sizeof(Vertex.self) * 3, options:[])
|
||||
uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
let library = device!.newDefaultLibrary()!
|
||||
let vertex_func = library.newFunctionWithName("vertex_func")
|
||||
let frag_func = library.newFunctionWithName("fragment_func")
|
||||
let vertex_func = library.newFunction(withName: "vertex_func")
|
||||
let frag_func = library.newFunction(withName: "fragment_func")
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vertex_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
do {
|
||||
try rps = device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
try rps = device!.newRenderPipelineState(with: rpld)
|
||||
} catch let error {
|
||||
self.print("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let commandBuffer = device!.newCommandQueue().commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps!)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.setVertexBuffer(uniformBuffer, offset: 0, at: 1)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x: 0, y: 0, width: 300, height: 300)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let delegate = MetalView()
|
||||
let view = MTKView(frame: frame, device: delegate.device)
|
||||
view.delegate = delegate
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ struct Uniforms {
|
|||
float4x4 modelMatrix;
|
||||
};
|
||||
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) {
|
||||
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]],
|
||||
constant Uniforms &uniforms [[buffer(1)]],
|
||||
uint vid [[vertex_id]]) {
|
||||
float4x4 matrix = uniforms.modelMatrix;
|
||||
Vertex in = vertices[vid];
|
||||
Vertex out;
|
||||
|
|
|
|||
|
|
@ -21,14 +21,16 @@ struct Matrix {
|
|||
]
|
||||
}
|
||||
|
||||
func translationMatrix(var matrix: Matrix, _ position: float3) -> Matrix {
|
||||
func translationMatrix(_ matrix: Matrix, _ position: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[12] = position.x
|
||||
matrix.m[13] = position.y
|
||||
matrix.m[14] = position.z
|
||||
return matrix
|
||||
}
|
||||
|
||||
func scalingMatrix(var matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
func scalingMatrix(_ matrix: Matrix, _ scale: Float) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = scale
|
||||
matrix.m[5] = scale
|
||||
matrix.m[10] = scale
|
||||
|
|
@ -36,7 +38,8 @@ struct Matrix {
|
|||
return matrix
|
||||
}
|
||||
|
||||
func rotationMatrix(var matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
func rotationMatrix(_ matrix: Matrix, _ rot: float3) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix.m[0] = cos(rot.y) * cos(rot.z)
|
||||
matrix.m[4] = cos(rot.z) * sin(rot.x) * sin(rot.y) - cos(rot.x) * sin(rot.z)
|
||||
matrix.m[8] = cos(rot.x) * cos(rot.z) * sin(rot.y) + sin(rot.x) * sin(rot.z)
|
||||
|
|
@ -50,7 +53,8 @@ struct Matrix {
|
|||
return matrix
|
||||
}
|
||||
|
||||
func modelMatrix(var matrix: Matrix) -> Matrix {
|
||||
func modelMatrix(matrix: Matrix) -> Matrix {
|
||||
var matrix = matrix
|
||||
matrix = rotationMatrix(matrix, float3(0.0, 0.0, 0.1))
|
||||
matrix = scalingMatrix(matrix, 0.25)
|
||||
matrix = translationMatrix(matrix, float3(0.0, 0.5, 0.0))
|
||||
|
|
|
|||
|
|
@ -1,69 +1,68 @@
|
|||
|
||||
import MetalKit
|
||||
|
||||
public class MetalView: MTKView {
|
||||
public class MetalView: NSObject, MTKViewDelegate {
|
||||
|
||||
var vertex_buffer: MTLBuffer!
|
||||
var uniform_buffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState! = nil
|
||||
public var device: MTLDevice!
|
||||
var queue: MTLCommandQueue!
|
||||
var vertexBuffer: MTLBuffer!
|
||||
var uniformBuffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState!
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override public init(frame frameRect: CGRect, device: MTLDevice?) {
|
||||
super.init(frame: frameRect, device: device)
|
||||
override public init() {
|
||||
super.init()
|
||||
createBuffers()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let command_buffer = device!.newCommandQueue().commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.setVertexBuffer(uniform_buffer, offset: 0, atIndex: 1)
|
||||
command_encoder.drawPrimitives(.Triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
}
|
||||
}
|
||||
|
||||
func createBuffers() {
|
||||
let vertex_data = [
|
||||
Vertex(pos: [-1.0, -1.0, 0.0, 1.0], col: [1, 0, 0, 1]),
|
||||
Vertex(pos: [ 1.0, -1.0, 0.0, 1.0], col: [0, 1, 0, 1]),
|
||||
Vertex(pos: [ 0.0, 1.0, 0.0, 1.0], col: [0, 0, 1, 1])
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
queue = device.newCommandQueue()
|
||||
let vertexData = [Vertex(pos: [-1.0, -1.0, 0.0, 1.0], col: [1, 0, 0, 1]),
|
||||
Vertex(pos: [ 1.0, -1.0, 0.0, 1.0], col: [0, 1, 0, 1]),
|
||||
Vertex(pos: [ 0.0, 1.0, 0.0, 1.0], col: [0, 0, 1, 1])
|
||||
]
|
||||
vertex_buffer = device!.newBufferWithBytes(vertex_data, length: sizeof(Vertex) * 3, options:[])
|
||||
uniform_buffer = device!.newBufferWithLength(sizeof(Float) * 16, options: [])
|
||||
let bufferPointer = uniform_buffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float) * 16)
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertexData, length: sizeof(Vertex.self) * 3, options:[])
|
||||
uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(matrix: Matrix()).m, sizeof(Float.self) * 16)
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
let input: String?
|
||||
let library: MTLLibrary
|
||||
let vert_func: MTLFunction
|
||||
let frag_func: MTLFunction
|
||||
do {
|
||||
input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
library = try device!.newLibraryWithSource(input!, options: nil)
|
||||
//print(library.functionNames)
|
||||
vert_func = library.newFunctionWithName("vertex_func")!
|
||||
frag_func = library.newFunctionWithName("fragment_func")!
|
||||
input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
library = try device!.newLibrary(withSource: input!, options: nil)
|
||||
vert_func = library.newFunction(withName: "vertex_func")!
|
||||
frag_func = library.newFunction(withName: "fragment_func")!
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vert_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
rps = try device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
rps = try device!.newRenderPipelineState(with: rpld)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
}
|
||||
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
if let rpd = view.currentRenderPassDescriptor, let drawable = view.currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.setVertexBuffer(uniformBuffer, offset: 0, at: 1)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='osx'>
|
||||
<playground version='5.0' target-platform='osx' executeOnSourceChanges='false'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
||||
Binary file not shown.
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x: 0, y: 0, width: 300, height: 300)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let delegate = MetalView()
|
||||
let view = MTKView(frame: frame, device: delegate.device)
|
||||
view.delegate = delegate
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func scalingMatrix(scale: Float) -> matrix_float4x4 {
|
|||
return matrix_float4x4(columns:(X, Y, Z, W))
|
||||
}
|
||||
|
||||
func rotationMatrix(angle: Float, _ axis: vector_float3) -> matrix_float4x4 {
|
||||
func rotationMatrix(angle: Float, axis: vector_float3) -> matrix_float4x4 {
|
||||
var X = vector_float4(0, 0, 0, 0)
|
||||
X.x = axis.x * axis.x + (1 - axis.x * axis.x) * cos(angle)
|
||||
X.y = axis.x * axis.y * (1 - cos(angle)) - axis.z * sin(angle)
|
||||
|
|
|
|||
|
|
@ -1,28 +1,26 @@
|
|||
|
||||
import MetalKit
|
||||
|
||||
public class MetalView: MTKView {
|
||||
public class MetalView: NSObject, MTKViewDelegate {
|
||||
|
||||
var vertex_buffer: MTLBuffer!
|
||||
var uniform_buffer: MTLBuffer!
|
||||
var index_buffer: MTLBuffer!
|
||||
var dss: MTLDepthStencilState!
|
||||
public var device: MTLDevice!
|
||||
var queue: MTLCommandQueue!
|
||||
var vertexBuffer: MTLBuffer!
|
||||
var uniformBuffer: MTLBuffer!
|
||||
var indexBuffer: MTLBuffer!
|
||||
var rps: MTLRenderPipelineState!
|
||||
var commandQueue: MTLCommandQueue!
|
||||
var rotation: Float = 0
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override public init(frame frameRect: CGRect, device: MTLDevice?) {
|
||||
super.init(frame: frameRect, device: device)
|
||||
override public init() {
|
||||
super.init()
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
queue = device.newCommandQueue()
|
||||
createBuffers()
|
||||
createPipeline()
|
||||
}
|
||||
|
||||
func createBuffers() {
|
||||
let vertex_data = [
|
||||
let vertexData = [
|
||||
Vertex(pos: [-1.0, -1.0, 1.0, 1.0], col: [1, 1, 1, 1]),
|
||||
Vertex(pos: [ 1.0, -1.0, 1.0, 1.0], col: [1, 0, 0, 1]),
|
||||
Vertex(pos: [ 1.0, 1.0, 1.0, 1.0], col: [1, 1, 0, 1]),
|
||||
|
|
@ -30,71 +28,75 @@ public class MetalView: MTKView {
|
|||
Vertex(pos: [-1.0, -1.0, -1.0, 1.0], col: [0, 0, 1, 1]),
|
||||
Vertex(pos: [ 1.0, -1.0, -1.0, 1.0], col: [1, 0, 1, 1]),
|
||||
Vertex(pos: [ 1.0, 1.0, -1.0, 1.0], col: [0, 0, 0, 1]),
|
||||
Vertex(pos: [-1.0, 1.0, -1.0, 1.0], col: [0, 1, 1, 1])
|
||||
]
|
||||
let index_data: [UInt16] = [
|
||||
0, 1, 2, 2, 3, 0, // front
|
||||
1, 5, 6, 6, 2, 1, // right
|
||||
3, 2, 6, 6, 7, 3, // top
|
||||
4, 5, 1, 1, 0, 4, // bottom
|
||||
4, 0, 3, 3, 7, 4, // left
|
||||
7, 6, 5, 5, 4, 7, // back
|
||||
]
|
||||
vertex_buffer = device!.newBufferWithBytes(vertex_data, length: sizeof(Vertex) * vertex_data.count, options: [])
|
||||
index_buffer = device!.newBufferWithBytes(index_data, length: sizeof(UInt16) * index_data.count , options: [])
|
||||
uniform_buffer = device!.newBufferWithLength(sizeof(matrix_float4x4), options: [])
|
||||
Vertex(pos: [-1.0, 1.0, -1.0, 1.0], col: [0, 1, 1, 1])]
|
||||
|
||||
let indexData: [UInt16] = [0, 1, 2, 2, 3, 0, // front
|
||||
1, 5, 6, 6, 2, 1, // right
|
||||
3, 2, 6, 6, 7, 3, // top
|
||||
4, 5, 1, 1, 0, 4, // bottom
|
||||
4, 0, 3, 3, 7, 4, // left
|
||||
7, 6, 5, 5, 4, 7] // back
|
||||
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertexData, length: sizeof(Vertex.self) * vertexData.count, options: [])
|
||||
indexBuffer = device!.newBuffer(withBytes: indexData, length: sizeof(UInt16.self) * indexData.count , options: [])
|
||||
uniformBuffer = device!.newBuffer(withLength: sizeof(matrix_float4x4.self), options: [])
|
||||
}
|
||||
|
||||
func createPipeline() {
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
let input: String?
|
||||
let library: MTLLibrary
|
||||
let vert_func: MTLFunction
|
||||
let frag_func: MTLFunction
|
||||
do {
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let vert_func = library.newFunctionWithName("vertex_func")!
|
||||
let frag_func = library.newFunctionWithName("fragment_func")!
|
||||
input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
library = try device!.newLibrary(withSource: input!, options: nil)
|
||||
vert_func = library.newFunction(withName: "vertex_func")!
|
||||
frag_func = library.newFunction(withName: "fragment_func")!
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vert_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .BGRA8Unorm
|
||||
rps = try device!.newRenderPipelineStateWithDescriptor(rpld)
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
rps = try device!.newRenderPipelineState(with: rpld)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
commandQueue = device?.newCommandQueue()
|
||||
}
|
||||
|
||||
func update() {
|
||||
let scaled = scalingMatrix(0.5)
|
||||
let scaled = scalingMatrix(scale: 0.5)
|
||||
rotation += 1 / 100 * Float(M_PI) / 4
|
||||
let rotatedY = rotationMatrix(rotation, float3(0, 1, 0))
|
||||
let rotatedX = rotationMatrix(Float(M_PI) / 4, float3(1, 0, 0))
|
||||
let rotatedY = rotationMatrix(angle: rotation, axis: float3(0, 1, 0))
|
||||
let rotatedX = rotationMatrix(angle: Float(M_PI) / 4, axis: float3(1, 0, 0))
|
||||
let modelMatrix = matrix_multiply(matrix_multiply(rotatedX, rotatedY), scaled)
|
||||
let cameraPosition = vector_float3(0, 0, -3)
|
||||
let viewMatrix = translationMatrix(cameraPosition)
|
||||
let aspect = Float(drawableSize.width / drawableSize.height)
|
||||
let projMatrix = projectionMatrix(0, far: 10, aspect: aspect, fovy: 1)
|
||||
let viewMatrix = translationMatrix(position: cameraPosition)
|
||||
// let aspect = Float(view.drawableSize.width / view.drawableSize.height)
|
||||
let projMatrix = projectionMatrix(near: 0, far: 10, aspect: 1, fovy: 1)
|
||||
// let projMatrix = projectionMatrix(0, far: 10, aspect: aspect, fovy: 1)
|
||||
let modelViewProjectionMatrix = matrix_multiply(projMatrix, matrix_multiply(viewMatrix, modelMatrix))
|
||||
let bufferPointer = uniform_buffer.contents()
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
var uniforms = Uniforms(modelViewProjectionMatrix: modelViewProjectionMatrix)
|
||||
memcpy(bufferPointer, &uniforms, sizeof(Uniforms))
|
||||
memcpy(bufferPointer, &uniforms, sizeof(Uniforms.self))
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
update()
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.3, 0.5, 0.5, 1.0)
|
||||
let command_buffer = commandQueue.commandBuffer()
|
||||
let command_encoder = command_buffer.renderCommandEncoderWithDescriptor(rpd)
|
||||
command_encoder.setRenderPipelineState(rps)
|
||||
command_encoder.setFrontFacingWinding(.CounterClockwise)
|
||||
command_encoder.setCullMode(.Back)
|
||||
command_encoder.setVertexBuffer(vertex_buffer, offset: 0, atIndex: 0)
|
||||
command_encoder.setVertexBuffer(uniform_buffer, offset: 0, atIndex: 1)
|
||||
command_encoder.drawIndexedPrimitives(.Triangle, indexCount: index_buffer.length / sizeof(UInt16), indexType: MTLIndexType.UInt16, indexBuffer: index_buffer, indexBufferOffset: 0)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
if let rpd = view.currentRenderPassDescriptor, let drawable = view.currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps)
|
||||
commandEncoder.setFrontFacing(.counterClockwise)
|
||||
commandEncoder.setCullMode(.back)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.setVertexBuffer(uniformBuffer, offset: 0, at: 1)
|
||||
commandEncoder.drawIndexedPrimitives(.triangle, indexCount: indexBuffer.length / sizeof(UInt16.self), indexType: MTLIndexType.uInt16, indexBuffer: indexBuffer, indexBufferOffset: 0)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x: 0, y: 0, width: 300, height: 300)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let delegate = MetalView()
|
||||
let view = MTKView(frame: frame, device: delegate.device)
|
||||
view.delegate = delegate
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -1,46 +1,45 @@
|
|||
|
||||
import MetalKit
|
||||
|
||||
public class MetalView: MTKView {
|
||||
public class MetalView: NSObject, MTKViewDelegate {
|
||||
|
||||
var queue: MTLCommandQueue! = nil
|
||||
var cps: MTLComputePipelineState! = nil
|
||||
public var device: MTLDevice!
|
||||
var queue: MTLCommandQueue!
|
||||
var cps: MTLComputePipelineState!
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override public init(frame frameRect: CGRect, device: MTLDevice?) {
|
||||
super.init(frame: frameRect, device: device)
|
||||
override public init() {
|
||||
super.init()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
if let drawable = currentDrawable {
|
||||
let command_buffer = queue.commandBuffer()
|
||||
let command_encoder = command_buffer.computeCommandEncoder()
|
||||
command_encoder.setComputePipelineState(cps)
|
||||
command_encoder.setTexture(drawable.texture, atIndex: 0)
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
command_encoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
}
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device.newCommandQueue()
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
}
|
||||
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
if let drawable = view.currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x:0, y:0, width:300, height:300)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let delegate = MetalView()
|
||||
let view = MTKView(frame: frame, device: delegate.device)
|
||||
view.delegate = delegate
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -1,56 +1,45 @@
|
|||
|
||||
import MetalKit
|
||||
|
||||
public class MetalView: MTKView {
|
||||
public class MetalView: NSObject, MTKViewDelegate {
|
||||
|
||||
var queue: MTLCommandQueue! = nil
|
||||
var cps: MTLComputePipelineState! = nil
|
||||
public var device: MTLDevice!
|
||||
var queue: MTLCommandQueue!
|
||||
var cps: MTLComputePipelineState!
|
||||
|
||||
var shader =
|
||||
"#include <metal_stdlib> \n" +
|
||||
"using namespace metal;" +
|
||||
"kernel void compute(texture2d<float, access::write> output [[texture(0)]]," +
|
||||
" uint2 gid [[thread_position_in_grid]])" +
|
||||
"{" +
|
||||
" output.write(float4(1, 1, 0, 1), gid);" +
|
||||
"}"
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override public init(frame frameRect: CGRect, device: MTLDevice?) {
|
||||
super.init(frame: frameRect, device: device)
|
||||
override public init() {
|
||||
super.init()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
if let drawable = currentDrawable {
|
||||
let command_buffer = queue.commandBuffer()
|
||||
let command_encoder = command_buffer.computeCommandEncoder()
|
||||
command_encoder.setComputePipelineState(cps)
|
||||
command_encoder.setTexture(drawable.texture, atIndex: 0)
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
command_encoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
command_encoder.endEncoding()
|
||||
command_buffer.presentDrawable(drawable)
|
||||
command_buffer.commit()
|
||||
}
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device.newCommandQueue()
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
// let library = try device!.newLibraryWithSource(shader, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
}
|
||||
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
if let drawable = view.currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x:0, y:0, width:300, height:300)
|
||||
let metalView = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = metalView
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
var mouseBuffer: MTLBuffer!
|
||||
var pos: NSPoint!
|
||||
|
||||
override public func mouseDown(event: NSEvent) {
|
||||
pos = convertPointToLayer(convertPoint(event.locationInWindow, fromView: nil))
|
||||
override public func mouseDown(_ event: NSEvent) {
|
||||
pos = convertToLayer(convert(event.locationInWindow, from: nil))
|
||||
let scale = layer!.contentsScale
|
||||
pos.x *= scale
|
||||
pos.y *= scale
|
||||
|
|
@ -26,21 +26,21 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
super.drawRect(dirtyRect)
|
||||
override public func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
if let drawable = currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, atIndex: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, atIndex: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, atIndex: 1)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, at: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, at: 1)
|
||||
update()
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.presentDrawable(drawable)
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
|
||||
|
|
@ -49,23 +49,23 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
func update() {
|
||||
timer += 0.01
|
||||
var bufferPointer = timerBuffer.contents()
|
||||
memcpy(bufferPointer, &timer, sizeof(Float))
|
||||
memcpy(bufferPointer, &timer, sizeof(Float.self))
|
||||
bufferPointer = mouseBuffer.contents()
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint))
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device!.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
timerBuffer = device!.newBufferWithLength(sizeof(Float), options: [])
|
||||
mouseBuffer = device!.newBufferWithLength(sizeof(NSPoint), options: [])
|
||||
timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
|
||||
mouseBuffer = device!.newBuffer(withLength: sizeof(NSPoint.self), options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x:0, y:0, width:400, height:400)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
var mouseBuffer: MTLBuffer!
|
||||
var pos: NSPoint!
|
||||
|
||||
override public func mouseDown(event: NSEvent) {
|
||||
pos = convertPointToLayer(convertPoint(event.locationInWindow, fromView: nil))
|
||||
override public func mouseDown(_ event: NSEvent) {
|
||||
pos = convertToLayer(convert(event.locationInWindow, from: nil))
|
||||
let scale = layer!.contentsScale
|
||||
pos.x *= scale
|
||||
pos.y *= scale
|
||||
|
|
@ -26,20 +26,20 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
override public func draw(_ dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, atIndex: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, atIndex: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, atIndex: 1)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, at: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, at: 1)
|
||||
update()
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.presentDrawable(drawable)
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
|
||||
|
|
@ -48,23 +48,23 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
func update() {
|
||||
timer += 0.01
|
||||
var bufferPointer = timerBuffer.contents()
|
||||
memcpy(bufferPointer, &timer, sizeof(Float))
|
||||
memcpy(bufferPointer, &timer, sizeof(Float.self))
|
||||
bufferPointer = mouseBuffer.contents()
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint))
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device!.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
timerBuffer = device!.newBufferWithLength(sizeof(Float), options: [])
|
||||
mouseBuffer = device!.newBufferWithLength(sizeof(NSPoint), options: [])
|
||||
timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
|
||||
mouseBuffer = device!.newBuffer(withLength: sizeof(NSPoint.self), options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x:0, y:0, width:400, height:400)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
var mouseBuffer: MTLBuffer!
|
||||
var pos: NSPoint!
|
||||
|
||||
override public func mouseDown(event: NSEvent) {
|
||||
pos = convertPointToLayer(convertPoint(event.locationInWindow, fromView: nil))
|
||||
override public func mouseDown(_ event: NSEvent) {
|
||||
pos = convertToLayer(convert(event.locationInWindow, from: nil))
|
||||
let scale = layer!.contentsScale
|
||||
pos.x *= scale
|
||||
pos.y *= scale
|
||||
|
|
@ -26,20 +26,20 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
registerShaders()
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
override public func draw(_ dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, atIndex: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, atIndex: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, atIndex: 1)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
commandEncoder.setBuffer(mouseBuffer, offset: 0, at: 2)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, at: 1)
|
||||
update()
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.presentDrawable(drawable)
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
|
||||
|
|
@ -48,23 +48,23 @@ public class MetalView: MTKView, NSWindowDelegate {
|
|||
func update() {
|
||||
timer += 0.01
|
||||
var bufferPointer = timerBuffer.contents()
|
||||
memcpy(bufferPointer, &timer, sizeof(Float))
|
||||
memcpy(bufferPointer, &timer, sizeof(Float.self))
|
||||
bufferPointer = mouseBuffer.contents()
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint))
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device!.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
timerBuffer = device!.newBufferWithLength(sizeof(Float), options: [])
|
||||
mouseBuffer = device!.newBufferWithLength(sizeof(NSPoint), options: [])
|
||||
timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
|
||||
mouseBuffer = device!.newBuffer(withLength: sizeof(NSPoint.self), options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
import Cocoa
|
||||
import XCPlayground
|
||||
import MetalKit
|
||||
import PlaygroundSupport
|
||||
|
||||
let device = MTLCreateSystemDefaultDevice()!
|
||||
let frame = NSRect(x:0, y:0, width:400, height:400)
|
||||
let view = MetalView(frame: frame, device: device)
|
||||
XCPlaygroundPage.currentPage.liveView = view
|
||||
let frame = NSRect(x: 0, y: 0, width: 400, height: 400)
|
||||
let delegate = MetalView()
|
||||
let view = MTKView(frame: frame, device: delegate.device)
|
||||
view.delegate = delegate
|
||||
PlaygroundPage.current.liveView = view
|
||||
|
|
|
|||
|
|
@ -1,66 +1,65 @@
|
|||
|
||||
import MetalKit
|
||||
|
||||
public class MetalView: MTKView, NSWindowDelegate {
|
||||
public class MetalView: NSObject, MTKViewDelegate {
|
||||
|
||||
public var device: MTLDevice!
|
||||
var queue: MTLCommandQueue! = nil
|
||||
var cps: MTLComputePipelineState! = nil
|
||||
var timer: Float = 0
|
||||
var timerBuffer: MTLBuffer!
|
||||
var texture: MTLTexture!
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override public init(frame frameRect: CGRect, device: MTLDevice?) {
|
||||
super.init(frame: frameRect, device: device)
|
||||
registerShaders()
|
||||
override public init() {
|
||||
super.init()
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
queue = device!.newCommandQueue()
|
||||
setUpTexture()
|
||||
registerShaders()
|
||||
}
|
||||
|
||||
func setUpTexture() {
|
||||
let path = NSBundle.mainBundle().pathForResource("texture", ofType: "jpg")
|
||||
let path = Bundle.main.pathForResource("texture", ofType: "jpg")
|
||||
let textureLoader = MTKTextureLoader(device: device!)
|
||||
texture = try! textureLoader.newTextureWithContentsOfURL(NSURL(fileURLWithPath: path!), options: nil)
|
||||
texture = try! textureLoader.newTexture(withContentsOf: URL(fileURLWithPath: path!), options: nil)
|
||||
}
|
||||
|
||||
override public func drawRect(dirtyRect: NSRect) {
|
||||
if let drawable = currentDrawable {
|
||||
func registerShaders() {
|
||||
let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
|
||||
let library = try device!.newLibrary(withSource: input, options: nil)
|
||||
let kernel = library.newFunction(withName: "compute")!
|
||||
cps = try device!.newComputePipelineState(with: kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
|
||||
}
|
||||
|
||||
func update() {
|
||||
timer += 0.01
|
||||
let bufferPointer = timerBuffer.contents()
|
||||
memcpy(bufferPointer, &timer, sizeof(Float.self))
|
||||
}
|
||||
|
||||
public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
|
||||
|
||||
public func draw(in view: MTKView) {
|
||||
if let drawable = view.currentDrawable {
|
||||
let commandBuffer = queue.commandBuffer()
|
||||
let commandEncoder = commandBuffer.computeCommandEncoder()
|
||||
commandEncoder.setComputePipelineState(cps)
|
||||
commandEncoder.setTexture(drawable.texture, atIndex: 0)
|
||||
commandEncoder.setTexture(texture, atIndex: 1)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, atIndex: 0)
|
||||
commandEncoder.setTexture(drawable.texture, at: 0)
|
||||
commandEncoder.setTexture(texture, at: 1)
|
||||
commandEncoder.setBuffer(timerBuffer, offset: 0, at: 0)
|
||||
update()
|
||||
let threadGroupCount = MTLSizeMake(8, 8, 1)
|
||||
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1)
|
||||
commandEncoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.presentDrawable(drawable)
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func update() {
|
||||
timer += 0.01
|
||||
let bufferPointer = timerBuffer.contents()
|
||||
memcpy(bufferPointer, &timer, sizeof(Float))
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
queue = device!.newCommandQueue()
|
||||
let path = NSBundle.mainBundle().pathForResource("Shaders", ofType: "metal")
|
||||
do {
|
||||
let input = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
|
||||
let library = try device!.newLibraryWithSource(input, options: nil)
|
||||
let kernel = library.newFunctionWithName("compute")!
|
||||
cps = try device!.newComputePipelineStateWithFunction(kernel)
|
||||
} catch let e {
|
||||
Swift.print("\(e)")
|
||||
}
|
||||
timerBuffer = device!.newBufferWithLength(sizeof(Float), options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue