updated to Swift 3
This commit is contained in:
parent
9a34a3ced1
commit
8a4ab80d43
Binary file not shown.
|
|
@ -33,6 +33,16 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
297F43061DE9960800638FC8 /* Supporting files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
298037281C62437900FBBC6A /* Main.storyboard */,
|
||||
2980372B1C62437900FBBC6A /* Info.plist */,
|
||||
298037221C62437900FBBC6A /* AppDelegate.swift */,
|
||||
);
|
||||
name = "Supporting files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
298037161C62437900FBBC6A = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -54,9 +64,7 @@
|
|||
children = (
|
||||
298037311C6243CB00FBBC6A /* MetalView.swift */,
|
||||
298037331C62440400FBBC6A /* Shaders.metal */,
|
||||
298037281C62437900FBBC6A /* Main.storyboard */,
|
||||
2980372B1C62437900FBBC6A /* Info.plist */,
|
||||
298037221C62437900FBBC6A /* AppDelegate.swift */,
|
||||
297F43061DE9960800638FC8 /* Supporting files */,
|
||||
);
|
||||
path = chapter05;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -88,7 +96,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
LastUpgradeCheck = 0810;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
2980371E1C62437900FBBC6A = {
|
||||
|
|
@ -164,8 +172,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 +218,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.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0800"
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue