Pass in pixel format instead of whole view

This commit is contained in:
Eryn Wells 2018-10-11 16:00:59 -07:00
parent 3808463e55
commit a755a4f3de

View file

@ -34,7 +34,7 @@ public class Renderer: NSObject, MTKViewDelegate {
let view = delegate.metalView let view = delegate.metalView
view.device = device view.device = device
configure(pixelPipelineWithView: view) configure(pixelPipelineWithPixelFormta: view.colorPixelFormat)
try! delegate.field.setupMetal(withDevice: device) try! delegate.field.setupMetal(withDevice: device)
} }
@ -69,7 +69,7 @@ public class Renderer: NSObject, MTKViewDelegate {
self.delegate = delegate self.delegate = delegate
} }
private func configure(pixelPipelineWithView view: MTKView) { private func configure(pixelPipelineWithPixelFormta pixelFormat: MTLPixelFormat) {
guard let library = library else { guard let library = library else {
fatalError("Couldn't get Metal library") fatalError("Couldn't get Metal library")
} }
@ -82,7 +82,7 @@ public class Renderer: NSObject, MTKViewDelegate {
pipelineDesc.vertexFunction = vertexShader pipelineDesc.vertexFunction = vertexShader
pipelineDesc.fragmentFunction = fragmentShader pipelineDesc.fragmentFunction = fragmentShader
if let renderAttachment = pipelineDesc.colorAttachments[0] { if let renderAttachment = pipelineDesc.colorAttachments[0] {
renderAttachment.pixelFormat = view.colorPixelFormat renderAttachment.pixelFormat = pixelFormat
// Pulled all this from SO. I don't know what it means, but it makes the alpha channel work. // Pulled all this from SO. I don't know what it means, but it makes the alpha channel work.
// TODO: Learn what this means??? // TODO: Learn what this means???
// https://stackoverflow.com/q/43727335/1174185 // https://stackoverflow.com/q/43727335/1174185