diff --git a/ch01/chapter01.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch01/chapter01.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..e8bc402
Binary files /dev/null and b/ch01/chapter01.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter01.xcscheme b/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter01.xcscheme
new file mode 100644
index 0000000..eca02c6
--- /dev/null
+++ b/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter01.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..f5ae71c
--- /dev/null
+++ b/ch01/chapter01.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter01.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 29400C781C3AEE1300345568
+
+ primary
+
+
+
+
+
diff --git a/ch02/chapter02.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch02/chapter02.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..19dcdfe
Binary files /dev/null and b/ch02/chapter02.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter02.xcscheme b/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter02.xcscheme
new file mode 100644
index 0000000..9033806
--- /dev/null
+++ b/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter02.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..107843d
--- /dev/null
+++ b/ch02/chapter02.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter02.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 29E74ACC1C4159D60023A39A
+
+ primary
+
+
+
+
+
diff --git a/ch02/chapter02/MetalView.swift b/ch02/chapter02/MetalView.swift
index c251709..48617b0 100644
--- a/ch02/chapter02/MetalView.swift
+++ b/ch02/chapter02/MetalView.swift
@@ -20,8 +20,8 @@ class MetalView: MTKView {
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)
+ let commandBuffer = device!.makeCommandQueue().makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: rpd)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch03/chapter03.xcodeproj/project.pbxproj b/ch03/chapter03.xcodeproj/project.pbxproj
index fa3436a..c5ec438 100644
--- a/ch03/chapter03.xcodeproj/project.pbxproj
+++ b/ch03/chapter03.xcodeproj/project.pbxproj
@@ -88,7 +88,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Marius Horga";
TargetAttributes = {
29CB598B1C4461E90004DB55 = {
@@ -164,8 +164,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
@@ -208,8 +210,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
diff --git a/ch03/chapter03.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch03/chapter03.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..b3ee8cc
Binary files /dev/null and b/ch03/chapter03.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter03.xcscheme b/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter03.xcscheme
new file mode 100644
index 0000000..3c0d619
--- /dev/null
+++ b/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter03.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..d621961
--- /dev/null
+++ b/ch03/chapter03.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter03.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 29CB598B1C4461E90004DB55
+
+ primary
+
+
+
+
+
diff --git a/ch03/chapter03/MetalView.swift b/ch03/chapter03/MetalView.swift
index 1090eb0..e7512d2 100644
--- a/ch03/chapter03/MetalView.swift
+++ b/ch03/chapter03/MetalView.swift
@@ -22,21 +22,21 @@ class MetalView: MTKView {
func render() {
device = MTLCreateSystemDefaultDevice()!
- commandQueue = device!.newCommandQueue()
+ commandQueue = device!.makeCommandQueue()
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 dataSize = vertexData!.count * MemoryLayout.size
+ vertexBuffer = device!.makeBuffer(bytes: vertexData!, length: dataSize, options: [])
let library = device!.newDefaultLibrary()!
- let vertex_func = library.newFunction(withName: "vertex_func")
- let frag_func = library.newFunction(withName: "fragment_func")
+ let vertex_func = library.makeFunction(name: "vertex_func")
+ let frag_func = library.makeFunction(name: "fragment_func")
let rpld = MTLRenderPipelineDescriptor()
rpld.vertexFunction = vertex_func
rpld.fragmentFunction = frag_func
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
do {
- try rps = device!.newRenderPipelineState(with: rpld)
+ try rps = device!.makeRenderPipelineState(descriptor: rpld)
} catch let error {
self.print("\(error)")
}
@@ -45,11 +45,11 @@ class MetalView: MTKView {
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 commandBuffer = commandQueue!.commandBuffer()
- let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
+ let commandBuffer = commandQueue!.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: rpd)
commandEncoder.setRenderPipelineState(rps!)
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
- commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
+ commandEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch04/chapter04.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch04/chapter04.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..e170f36
Binary files /dev/null and b/ch04/chapter04.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter04.xcscheme b/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter04.xcscheme
new file mode 100644
index 0000000..36f111c
--- /dev/null
+++ b/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter04.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..65aa13b
--- /dev/null
+++ b/ch04/chapter04.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter04.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 29C87D3C1C56E93A005F4615
+
+ primary
+
+
+
+
+
diff --git a/ch05/chapter05.xcodeproj/project.pbxproj b/ch05/chapter05.xcodeproj/project.pbxproj
index c2db75a..f296239 100644
--- a/ch05/chapter05.xcodeproj/project.pbxproj
+++ b/ch05/chapter05.xcodeproj/project.pbxproj
@@ -88,7 +88,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Marius Horga";
TargetAttributes = {
2980371E1C62437900FBBC6A = {
@@ -164,8 +164,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
@@ -208,8 +210,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
diff --git a/ch05/chapter05.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch05/chapter05.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..2d13d85
Binary files /dev/null and b/ch05/chapter05.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter05.xcscheme b/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter05.xcscheme
new file mode 100644
index 0000000..45e4f67
--- /dev/null
+++ b/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter05.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..9b6e229
--- /dev/null
+++ b/ch05/chapter05.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter05.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 2980371E1C62437900FBBC6A
+
+ primary
+
+
+
+
+
diff --git a/ch05/chapter05/MetalView.swift b/ch05/chapter05/MetalView.swift
index eea4d47..73ad3bf 100644
--- a/ch05/chapter05/MetalView.swift
+++ b/ch05/chapter05/MetalView.swift
@@ -75,41 +75,41 @@ class MetalView: MTKView {
func createBuffers() {
device = MTLCreateSystemDefaultDevice()!
- commandQueue = device!.newCommandQueue()
+ commandQueue = device!.makeCommandQueue()
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])
]
- vertexBuffer = device!.newBuffer(withBytes: vertex_data, length: sizeof(Vertex.self) * 3, options:[])
- uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
+ vertexBuffer = device!.makeBuffer(bytes: vertex_data, length: MemoryLayout.size * 3, options:[])
+ uniformBuffer = device!.makeBuffer(length: MemoryLayout.size * 16, options: [])
let bufferPointer = uniformBuffer.contents()
- memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
+ memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, MemoryLayout.size * 16)
}
func registerShaders() {
let library = device!.newDefaultLibrary()!
- let vertex_func = library.newFunction(withName: "vertex_func")
- let frag_func = library.newFunction(withName: "fragment_func")
+ let vertex_func = library.makeFunction(name: "vertex_func")
+ let frag_func = library.makeFunction(name: "fragment_func")
let rpld = MTLRenderPipelineDescriptor()
rpld.vertexFunction = vertex_func
rpld.fragmentFunction = frag_func
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
do {
- try rps = device!.newRenderPipelineState(with: rpld)
+ try rps = device!.makeRenderPipelineState(descriptor: rpld)
} catch let error {
self.print("\(error)")
}
}
override func draw(_ dirtyRect: NSRect) {
- if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
+ if let rpd = currentRenderPassDescriptor, let 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)
+ let commandBuffer = device!.makeCommandQueue().makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: 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.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch06/chapter06.xcodeproj/project.pbxproj b/ch06/chapter06.xcodeproj/project.pbxproj
index 04ca30b..9e591b4 100644
--- a/ch06/chapter06.xcodeproj/project.pbxproj
+++ b/ch06/chapter06.xcodeproj/project.pbxproj
@@ -85,13 +85,14 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = Marius;
TargetAttributes = {
2984512B1D47EF08008D81B9 = {
CreatedOnToolsVersion = 8.0;
- DevelopmentTeam = C2X9Q6VFVJ;
+ DevelopmentTeam = 8JG22Q59U3;
DevelopmentTeamName = "Marius Horga";
+ LastSwiftMigration = 0810;
ProvisioningStyle = Automatic;
};
};
@@ -164,8 +165,10 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -187,7 +190,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -212,8 +215,10 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -229,7 +234,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -242,6 +247,7 @@
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ DEVELOPMENT_TEAM = 8JG22Q59U3;
INFOPLIST_FILE = chapter06/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.metalkit.chapter06;
@@ -256,6 +262,7 @@
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ DEVELOPMENT_TEAM = 8JG22Q59U3;
INFOPLIST_FILE = chapter06/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.metalkit.chapter06;
diff --git a/ch06/chapter06.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch06/chapter06.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..c1ba807
Binary files /dev/null and b/ch06/chapter06.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter06.xcscheme b/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter06.xcscheme
new file mode 100644
index 0000000..ec3e3fb
--- /dev/null
+++ b/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter06.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..9b1a329
--- /dev/null
+++ b/ch06/chapter06.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter06.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 2984512B1D47EF08008D81B9
+
+ primary
+
+
+
+
+
diff --git a/ch06/chapter06/MetalView.swift b/ch06/chapter06/MetalView.swift
index 58fccb5..7481562 100755
--- a/ch06/chapter06/MetalView.swift
+++ b/ch06/chapter06/MetalView.swift
@@ -6,7 +6,9 @@
// Copyright © 2016 Marius Horga. All rights reserved.
//
+import Foundation
import UIKit
+import MetalKit
class MetalView: UIView {
@@ -16,24 +18,24 @@ class MetalView: UIView {
return self.layer as! CAMetalLayer
}
- override class func layerClass() -> AnyClass {
+ override class var layerClass : AnyClass {
return CAMetalLayer.self
}
override func didMoveToWindow() {
super.didMoveToWindow()
let device = MTLCreateSystemDefaultDevice()!
- commandQueue = device.newCommandQueue()
+ commandQueue = device.makeCommandQueue()
redraw()
}
- private func redraw() {
+ fileprivate 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.renderCommandEncoder(with: descriptor)
+ let commandBuffer = commandQueue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: descriptor)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch07/chapter07.xcodeproj/project.pbxproj b/ch07/chapter07.xcodeproj/project.pbxproj
index 2bb7acb..f6c1591 100644
--- a/ch07/chapter07.xcodeproj/project.pbxproj
+++ b/ch07/chapter07.xcodeproj/project.pbxproj
@@ -91,12 +91,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Marius Horga";
TargetAttributes = {
29D878251C84D2B0007B5F17 = {
CreatedOnToolsVersion = 7.2.1;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
};
};
@@ -168,8 +168,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
@@ -212,8 +214,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
diff --git a/ch07/chapter07.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch07/chapter07.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..6f71a9e
Binary files /dev/null and b/ch07/chapter07.xcodeproj/project.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter07.xcscheme b/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter07.xcscheme
new file mode 100644
index 0000000..1f22050
--- /dev/null
+++ b/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/chapter07.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist b/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..f85199c
--- /dev/null
+++ b/ch07/chapter07.xcodeproj/xcuserdata/chenyungui.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,22 @@
+
+
+
+
+ SchemeUserState
+
+ chapter07.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 29D878251C84D2B0007B5F17
+
+ primary
+
+
+
+
+
diff --git a/ch07/chapter07/MetalView.swift b/ch07/chapter07/MetalView.swift
index 975c572..fd1add0 100644
--- a/ch07/chapter07/MetalView.swift
+++ b/ch07/chapter07/MetalView.swift
@@ -23,27 +23,27 @@ class MetalView: MTKView {
func createBuffers() {
device = MTLCreateSystemDefaultDevice()!
- commandQueue = device!.newCommandQueue()
+ commandQueue = device!.makeCommandQueue()
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])
]
- vertexBuffer = device!.newBuffer(withBytes: vertex_data, length: sizeof(Vertex.self) * 3, options:[])
- uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
+ vertexBuffer = device!.makeBuffer(bytes: vertex_data, length: MemoryLayout.size * 3, options:[])
+ uniformBuffer = device!.makeBuffer(length: MemoryLayout.size * 16, options: [])
let bufferPointer = uniformBuffer.contents()
- memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
+ memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, MemoryLayout.size * 16)
}
func registerShaders() {
let library = device!.newDefaultLibrary()!
- let vertex_func = library.newFunction(withName: "vertex_func")
- let frag_func = library.newFunction(withName: "fragment_func")
+ let vertex_func = library.makeFunction(name: "vertex_func")
+ let frag_func = library.makeFunction(name: "fragment_func")
let rpld = MTLRenderPipelineDescriptor()
rpld.vertexFunction = vertex_func
rpld.fragmentFunction = frag_func
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
do {
- try rps = device!.newRenderPipelineState(with: rpld)
+ try rps = device!.makeRenderPipelineState(descriptor: rpld)
} catch let error {
self.print("\(error)")
}
@@ -51,14 +51,14 @@ class MetalView: MTKView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
- if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
+ if let rpd = currentRenderPassDescriptor, let 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)
+ let commandBuffer = device!.makeCommandQueue().makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: 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.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch08/chapter08.playground/Sources/MetalView.swift b/ch08/chapter08.playground/Sources/MetalView.swift
index 61a864c..a425315 100644
--- a/ch08/chapter08.playground/Sources/MetalView.swift
+++ b/ch08/chapter08.playground/Sources/MetalView.swift
@@ -17,33 +17,33 @@ public class MetalView: NSObject, MTKViewDelegate {
func createBuffers() {
device = MTLCreateSystemDefaultDevice()
- queue = device.newCommandQueue()
+ queue = device.makeCommandQueue()
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])
]
- vertexBuffer = device!.newBuffer(withBytes: vertexData, length: sizeof(Vertex.self) * 3, options:[])
- uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
+ vertexBuffer = device!.makeBuffer(bytes: vertexData, length: MemoryLayout.size * 3, options:[])
+ uniformBuffer = device!.makeBuffer(length: MemoryLayout.size * 16, options: [])
let bufferPointer = uniformBuffer.contents()
- memcpy(bufferPointer, Matrix().modelMatrix(matrix: Matrix()).m, sizeof(Float.self) * 16)
+ memcpy(bufferPointer, Matrix().modelMatrix(matrix: Matrix()).m, MemoryLayout.size * 16)
}
func registerShaders() {
- let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
+ let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
let input: String?
let library: MTLLibrary
let vert_func: MTLFunction
let frag_func: MTLFunction
do {
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")!
+ library = try device!.makeLibrary(source: input!, options: nil)
+ vert_func = library.makeFunction(name: "vertex_func")!
+ frag_func = library.makeFunction(name: "fragment_func")!
let rpld = MTLRenderPipelineDescriptor()
rpld.vertexFunction = vert_func
rpld.fragmentFunction = frag_func
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
- rps = try device!.newRenderPipelineState(with: rpld)
+ rps = try device!.makeRenderPipelineState(descriptor: rpld)
} catch let e {
Swift.print("\(e)")
}
@@ -54,12 +54,12 @@ public class MetalView: NSObject, MTKViewDelegate {
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)
+ let commandBuffer = queue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: 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.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
commandEncoder.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
diff --git a/ch08/chapter08.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch08/chapter08.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..e2baa9c
Binary files /dev/null and b/ch08/chapter08.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch08/chapter08.playground/timeline.xctimeline b/ch08/chapter08.playground/timeline.xctimeline
deleted file mode 100644
index bf468af..0000000
--- a/ch08/chapter08.playground/timeline.xctimeline
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
diff --git a/ch09/chapter09.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch09/chapter09.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..613bd59
Binary files /dev/null and b/ch09/chapter09.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch10/chapter10.playground/Sources/MetalView.swift b/ch10/chapter10.playground/Sources/MetalView.swift
index 393222e..879e690 100755
--- a/ch10/chapter10.playground/Sources/MetalView.swift
+++ b/ch10/chapter10.playground/Sources/MetalView.swift
@@ -14,13 +14,13 @@ public class MetalView: NSObject, MTKViewDelegate {
func registerShaders() {
device = MTLCreateSystemDefaultDevice()!
- queue = device.newCommandQueue()
- let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
+ queue = device.makeCommandQueue()
+ let path = Bundle.main.path(forResource: "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)
+ let library = try device.makeLibrary(source: input, options: nil)
+ let kernel = library.makeFunction(name: "compute")!
+ cps = try device.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
@@ -30,8 +30,8 @@ public class MetalView: NSObject, MTKViewDelegate {
public func draw(in view: MTKView) {
if let drawable = view.currentDrawable {
- let commandBuffer = queue.commandBuffer()
- let commandEncoder = commandBuffer.computeCommandEncoder()
+ let commandBuffer = queue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(cps)
commandEncoder.setTexture(drawable.texture, at: 0)
let threadGroupCount = MTLSizeMake(8, 8, 1)
diff --git a/ch10/chapter10.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch10/chapter10.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..b9c4bd9
Binary files /dev/null and b/ch10/chapter10.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch11/chapter11.playground/Sources/MetalView.swift b/ch11/chapter11.playground/Sources/MetalView.swift
index db61db1..7f9fc82 100755
--- a/ch11/chapter11.playground/Sources/MetalView.swift
+++ b/ch11/chapter11.playground/Sources/MetalView.swift
@@ -14,13 +14,13 @@ public class MetalView: NSObject, MTKViewDelegate {
func registerShaders() {
device = MTLCreateSystemDefaultDevice()!
- queue = device.newCommandQueue()
- let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
+ queue = device.makeCommandQueue()
+ let path = Bundle.main.path(forResource: "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)
+ let library = try device.makeLibrary(source: input, options: nil)
+ let kernel = library.makeFunction(name: "compute")!
+ cps = try device.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
@@ -30,8 +30,8 @@ public class MetalView: NSObject, MTKViewDelegate {
public func draw(in view: MTKView) {
if let drawable = view.currentDrawable {
- let commandBuffer = queue.commandBuffer()
- let commandEncoder = commandBuffer.computeCommandEncoder()
+ let commandBuffer = queue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(cps)
commandEncoder.setTexture(drawable.texture, at: 0)
let threadGroupCount = MTLSizeMake(8, 8, 1)
diff --git a/ch11/chapter11.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch11/chapter11.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..70bc446
Binary files /dev/null and b/ch11/chapter11.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch12/chapter12.playground/Sources/MetalView.swift b/ch12/chapter12.playground/Sources/MetalView.swift
index 9cc48fd..e84b3f7 100755
--- a/ch12/chapter12.playground/Sources/MetalView.swift
+++ b/ch12/chapter12.playground/Sources/MetalView.swift
@@ -10,7 +10,7 @@ public class MetalView: MTKView, NSWindowDelegate {
var mouseBuffer: MTLBuffer!
var pos: NSPoint!
- override public func mouseDown(_ event: NSEvent) {
+ override public func mouseDown(with event: NSEvent) {
pos = convertToLayer(convert(event.locationInWindow, from: nil))
let scale = layer!.contentsScale
pos.x *= scale
@@ -29,8 +29,8 @@ public class MetalView: MTKView, NSWindowDelegate {
override public func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
if let drawable = currentDrawable {
- let commandBuffer = queue.commandBuffer()
- let commandEncoder = commandBuffer.computeCommandEncoder()
+ let commandBuffer = queue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(cps)
commandEncoder.setTexture(drawable.texture, at: 0)
commandEncoder.setBuffer(mouseBuffer, offset: 0, at: 2)
@@ -49,23 +49,23 @@ public class MetalView: MTKView, NSWindowDelegate {
func update() {
timer += 0.01
var bufferPointer = timerBuffer.contents()
- memcpy(bufferPointer, &timer, sizeof(Float.self))
+ memcpy(bufferPointer, &timer, MemoryLayout.size)
bufferPointer = mouseBuffer.contents()
- memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
+ memcpy(bufferPointer, &pos, MemoryLayout.size)
}
func registerShaders() {
- queue = device!.newCommandQueue()
- let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
+ queue = device!.makeCommandQueue()
+ let path = Bundle.main.path(forResource: "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)
+ let library = try device!.makeLibrary(source: input, options: nil)
+ let kernel = library.makeFunction(name: "compute")!
+ cps = try device!.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
- timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
- mouseBuffer = device!.newBuffer(withLength: sizeof(NSPoint.self), options: [])
+ timerBuffer = device!.makeBuffer(length: MemoryLayout.size, options: [])
+ mouseBuffer = device!.makeBuffer(length: MemoryLayout.size, options: [])
}
}
diff --git a/ch12/chapter12.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch12/chapter12.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..42f166a
Binary files /dev/null and b/ch12/chapter12.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch13/chapter13.playground/Sources/MetalView.swift b/ch13/chapter13.playground/Sources/MetalView.swift
index 2a6bdcb..e41a720 100755
--- a/ch13/chapter13.playground/Sources/MetalView.swift
+++ b/ch13/chapter13.playground/Sources/MetalView.swift
@@ -10,7 +10,7 @@ public class MetalView: MTKView, NSWindowDelegate {
var mouseBuffer: MTLBuffer!
var pos: NSPoint!
- override public func mouseDown(_ event: NSEvent) {
+ override public func mouseDown(with event: NSEvent) {
pos = convertToLayer(convert(event.locationInWindow, from: nil))
let scale = layer!.contentsScale
pos.x *= scale
@@ -28,8 +28,8 @@ public class MetalView: MTKView, NSWindowDelegate {
override public func draw(_ dirtyRect: NSRect) {
if let drawable = currentDrawable {
- let commandBuffer = queue.commandBuffer()
- let commandEncoder = commandBuffer.computeCommandEncoder()
+ let commandBuffer = queue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(cps)
commandEncoder.setTexture(drawable.texture, at: 0)
commandEncoder.setBuffer(mouseBuffer, offset: 0, at: 2)
@@ -48,23 +48,23 @@ public class MetalView: MTKView, NSWindowDelegate {
func update() {
timer += 0.01
var bufferPointer = timerBuffer.contents()
- memcpy(bufferPointer, &timer, sizeof(Float.self))
+ memcpy(bufferPointer, &timer, MemoryLayout.size)
bufferPointer = mouseBuffer.contents()
- memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
+ memcpy(bufferPointer, &pos, MemoryLayout.size)
}
func registerShaders() {
- queue = device!.newCommandQueue()
- let path = Bundle.main.pathForResource("Shaders", ofType: "metal")
+ queue = device!.makeCommandQueue()
+ let path = Bundle.main.path(forResource: "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)
+ let library = try device!.makeLibrary(source: input, options: nil)
+ let kernel = library.makeFunction(name: "compute")!
+ cps = try device!.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
- timerBuffer = device!.newBuffer(withLength: sizeof(Float.self), options: [])
- mouseBuffer = device!.newBuffer(withLength: sizeof(NSPoint.self), options: [])
+ timerBuffer = device!.makeBuffer(length: MemoryLayout.size, options: [])
+ mouseBuffer = device!.makeBuffer(length: MemoryLayout.size, options: [])
}
}
diff --git a/ch13/chapter13.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch13/chapter13.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..e199c5a
Binary files /dev/null and b/ch13/chapter13.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/ch14/chapter14.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate b/ch14/chapter14.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..ca9289d
Binary files /dev/null and b/ch14/chapter14.playground/playground.xcworkspace/xcuserdata/chenyungui.xcuserdatad/UserInterfaceState.xcuserstate differ