update to swift 3, Xcode 8.1
This commit is contained in:
parent
54d44001bf
commit
4a466f831e
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29400C781C3AEE1300345568"
|
||||
BuildableName = "chapter01.app"
|
||||
BlueprintName = "chapter01"
|
||||
ReferencedContainer = "container:chapter01.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29400C781C3AEE1300345568"
|
||||
BuildableName = "chapter01.app"
|
||||
BlueprintName = "chapter01"
|
||||
ReferencedContainer = "container:chapter01.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29400C781C3AEE1300345568"
|
||||
BuildableName = "chapter01.app"
|
||||
BlueprintName = "chapter01"
|
||||
ReferencedContainer = "container:chapter01.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29400C781C3AEE1300345568"
|
||||
BuildableName = "chapter01.app"
|
||||
BlueprintName = "chapter01"
|
||||
ReferencedContainer = "container:chapter01.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter01.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29400C781C3AEE1300345568</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29E74ACC1C4159D60023A39A"
|
||||
BuildableName = "chapter02.app"
|
||||
BlueprintName = "chapter02"
|
||||
ReferencedContainer = "container:chapter02.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29E74ACC1C4159D60023A39A"
|
||||
BuildableName = "chapter02.app"
|
||||
BlueprintName = "chapter02"
|
||||
ReferencedContainer = "container:chapter02.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29E74ACC1C4159D60023A39A"
|
||||
BuildableName = "chapter02.app"
|
||||
BlueprintName = "chapter02"
|
||||
ReferencedContainer = "container:chapter02.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29E74ACC1C4159D60023A39A"
|
||||
BuildableName = "chapter02.app"
|
||||
BlueprintName = "chapter02"
|
||||
ReferencedContainer = "container:chapter02.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter02.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29E74ACC1C4159D60023A39A</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 = "-";
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29CB598B1C4461E90004DB55"
|
||||
BuildableName = "chapter03.app"
|
||||
BlueprintName = "chapter03"
|
||||
ReferencedContainer = "container:chapter03.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29CB598B1C4461E90004DB55"
|
||||
BuildableName = "chapter03.app"
|
||||
BlueprintName = "chapter03"
|
||||
ReferencedContainer = "container:chapter03.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29CB598B1C4461E90004DB55"
|
||||
BuildableName = "chapter03.app"
|
||||
BlueprintName = "chapter03"
|
||||
ReferencedContainer = "container:chapter03.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29CB598B1C4461E90004DB55"
|
||||
BuildableName = "chapter03.app"
|
||||
BlueprintName = "chapter03"
|
||||
ReferencedContainer = "container:chapter03.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter03.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29CB598B1C4461E90004DB55</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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<Float>.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()
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29C87D3C1C56E93A005F4615"
|
||||
BuildableName = "chapter04.app"
|
||||
BlueprintName = "chapter04"
|
||||
ReferencedContainer = "container:chapter04.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29C87D3C1C56E93A005F4615"
|
||||
BuildableName = "chapter04.app"
|
||||
BlueprintName = "chapter04"
|
||||
ReferencedContainer = "container:chapter04.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29C87D3C1C56E93A005F4615"
|
||||
BuildableName = "chapter04.app"
|
||||
BlueprintName = "chapter04"
|
||||
ReferencedContainer = "container:chapter04.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29C87D3C1C56E93A005F4615"
|
||||
BuildableName = "chapter04.app"
|
||||
BlueprintName = "chapter04"
|
||||
ReferencedContainer = "container:chapter04.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter04.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29C87D3C1C56E93A005F4615</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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 = "-";
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2980371E1C62437900FBBC6A"
|
||||
BuildableName = "chapter05.app"
|
||||
BlueprintName = "chapter05"
|
||||
ReferencedContainer = "container:chapter05.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2980371E1C62437900FBBC6A"
|
||||
BuildableName = "chapter05.app"
|
||||
BlueprintName = "chapter05"
|
||||
ReferencedContainer = "container:chapter05.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2980371E1C62437900FBBC6A"
|
||||
BuildableName = "chapter05.app"
|
||||
BlueprintName = "chapter05"
|
||||
ReferencedContainer = "container:chapter05.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2980371E1C62437900FBBC6A"
|
||||
BuildableName = "chapter05.app"
|
||||
BlueprintName = "chapter05"
|
||||
ReferencedContainer = "container:chapter05.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter05.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>2980371E1C62437900FBBC6A</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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<Vertex>.size * 3, options:[])
|
||||
uniformBuffer = device!.makeBuffer(length: MemoryLayout<Float>.size * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, MemoryLayout<Float>.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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2984512B1D47EF08008D81B9"
|
||||
BuildableName = "chapter06.app"
|
||||
BlueprintName = "chapter06"
|
||||
ReferencedContainer = "container:chapter06.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter06.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>2984512B1D47EF08008D81B9</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 = "-";
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29D878251C84D2B0007B5F17"
|
||||
BuildableName = "chapter07.app"
|
||||
BlueprintName = "chapter07"
|
||||
ReferencedContainer = "container:chapter07.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29D878251C84D2B0007B5F17"
|
||||
BuildableName = "chapter07.app"
|
||||
BlueprintName = "chapter07"
|
||||
ReferencedContainer = "container:chapter07.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29D878251C84D2B0007B5F17"
|
||||
BuildableName = "chapter07.app"
|
||||
BlueprintName = "chapter07"
|
||||
ReferencedContainer = "container:chapter07.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "29D878251C84D2B0007B5F17"
|
||||
BuildableName = "chapter07.app"
|
||||
BlueprintName = "chapter07"
|
||||
ReferencedContainer = "container:chapter07.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>chapter07.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>29D878251C84D2B0007B5F17</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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<Vertex>.size * 3, options:[])
|
||||
uniformBuffer = device!.makeBuffer(length: MemoryLayout<Float>.size * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, MemoryLayout<Float>.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()
|
||||
|
|
|
|||
|
|
@ -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<Vertex>.size * 3, options:[])
|
||||
uniformBuffer = device!.makeBuffer(length: MemoryLayout<Float>.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<Float>.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()
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
||||
Binary file not shown.
|
|
@ -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)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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<Float>.size)
|
||||
bufferPointer = mouseBuffer.contents()
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
|
||||
memcpy(bufferPointer, &pos, MemoryLayout<NSPoint>.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<Float>.size, options: [])
|
||||
mouseBuffer = device!.makeBuffer(length: MemoryLayout<NSPoint>.size, options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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<Float>.size)
|
||||
bufferPointer = mouseBuffer.contents()
|
||||
memcpy(bufferPointer, &pos, sizeof(NSPoint.self))
|
||||
memcpy(bufferPointer, &pos, MemoryLayout<NSPoint>.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<Float>.size, options: [])
|
||||
mouseBuffer = device!.makeBuffer(length: MemoryLayout<NSPoint>.size, options: [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue