updated to Swift 4

This commit is contained in:
Marius Horga 2017-10-31 23:18:30 -05:00 committed by GitHub
parent c8c2c5deef
commit 77a0878f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -26,18 +26,15 @@ public class MetalViewDelegate: NSObject, MTKViewDelegate {
particles = [Particle](repeatElement(Particle(), count: 1000)) particles = [Particle](repeatElement(Particle(), count: 1000))
particlesBuffer = device.makeBuffer(length: particles.count * MemoryLayout<Particle>.stride, options: [])! particlesBuffer = device.makeBuffer(length: particles.count * MemoryLayout<Particle>.stride, options: [])!
var pointer = particlesBuffer.contents().bindMemory(to: Particle.self, capacity: particles.count) var pointer = particlesBuffer.contents().bindMemory(to: Particle.self, capacity: particles.count)
for _ in particles.enumerated() { for _ in particles {
pointer.pointee.initialMatrix = translate(by: [Float(drand48()) / 10, Float(drand48()) * 10, 0]) pointer.pointee.initialMatrix = translate(by: [Float(drand48()) / 10, Float(drand48()) * 10, 0])
pointer.pointee.color = float4(0.2, 0.6, 0.9, 1) pointer.pointee.color = float4(0.2, 0.6, 0.9, 1)
pointer = pointer.advanced(by: 1) pointer = pointer.advanced(by: 1)
} }
let allocator = MTKMeshBufferAllocator(device: device) let allocator = MTKMeshBufferAllocator(device: device)
let sphere = MDLMesh(sphereWithExtent: [0.01, 0.01, 0.01], segments: [8, 8], inwardNormals: false, geometryType: .triangles, allocator: allocator) let sphere = MDLMesh(sphereWithExtent: [0.01, 0.01, 0.01], segments: [8, 8], inwardNormals: false, geometryType: .triangles, allocator: allocator)
do { do { model = try MTKMesh(mesh: sphere, device: device) }
model = try MTKMesh(mesh: sphere, device: device) catch let e { print(e) }
} catch let e {
Swift.print("\(e)")
}
} }
func initializeMetal() { func initializeMetal() {