split core renderer stuff into metal subfolder

This commit is contained in:
2024-09-12 11:37:08 +10:00
parent 667201fe49
commit d7cb051fb7
9 changed files with 173 additions and 160 deletions

View File

@ -0,0 +1,23 @@
import Metal
internal struct PipelineOptions: Hashable {
let colorFormat: MTLPixelFormat, depthFormat: MTLPixelFormat
let shader: Shader
let blendFunc: BlendFunc
}
internal extension PipelineOptions {
func createPipeline(_ device: MTLDevice) throws -> MTLRenderPipelineState {
let pipeDescription = MTLRenderPipelineDescriptor()
pipeDescription.vertexFunction = self.shader.vertexProgram
pipeDescription.fragmentFunction = self.shader.fragmentProgram
pipeDescription.colorAttachments[0].pixelFormat = self.colorFormat
self.blendFunc.setBlend(colorAttachment: &pipeDescription.colorAttachments[0])
pipeDescription.depthAttachmentPixelFormat = self.depthFormat
do {
return try device.makeRenderPipelineState(descriptor: pipeDescription)
} catch {
throw RendererError.initFailure("Failed to create pipeline state: \(error.localizedDescription)")
}
}
}