Fix runtime errors

This commit is contained in:
daemyung jang 2022-03-21 00:08:39 +09:00
parent 4cbae6cbfc
commit 8298f258c7
No known key found for this signature in database
GPG Key ID: 44160C9958A9C67B
2 changed files with 10 additions and 18 deletions

View File

@ -72,9 +72,9 @@ public class Renderer: NSObject {
func buildPipelineState() {
do {
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
let source = try String(contentsOfFile: path, encoding: .utf8)
let library = try device.makeLibrary(source: source, options: nil)
guard let library = device.makeDefaultLibrary() else {
fatalError("Can't make default library")
}
let fragmentFunction = library.makeFunction(name: "fragment_main")
let descriptor = MTLRenderPipelineDescriptor()
descriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
@ -86,12 +86,8 @@ public class Renderer: NSObject {
try terrain.pipelineState = device.makeRenderPipelineState(descriptor: descriptor)
// skybox pipeline state
guard let skyboxPath = Bundle.main.path(forResource: "Skybox", ofType: "metal") else { return }
let skyboxSource = try String(contentsOfFile: skyboxPath, encoding: .utf8)
let skyboxLibrary = try device.makeLibrary(source: skyboxSource, options: nil)
descriptor.vertexFunction = skyboxLibrary.makeFunction(name: "vertex_skybox")
descriptor.fragmentFunction = skyboxLibrary.makeFunction(name: "fragment_skybox")
descriptor.vertexFunction = library.makeFunction(name: "vertex_skybox")
descriptor.fragmentFunction = library.makeFunction(name: "fragment_skybox")
descriptor.vertexDescriptor = MTKMetalVertexDescriptorFromModelIO(skybox.vertexDescriptor)
try skyboxPipelineState = device.makeRenderPipelineState(descriptor: descriptor)

View File

@ -72,9 +72,9 @@ public class Renderer: NSObject {
func buildPipelineState() {
do {
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { return }
let source = try String(contentsOfFile: path, encoding: .utf8)
let library = try device.makeLibrary(source: source, options: nil)
guard let library = device.makeDefaultLibrary() else {
fatalError("Can't make default library")
}
let fragmentFunction = library.makeFunction(name: "fragment_main")
let descriptor = MTLRenderPipelineDescriptor()
descriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
@ -86,12 +86,8 @@ public class Renderer: NSObject {
try terrain.pipelineState = device.makeRenderPipelineState(descriptor: descriptor)
// skybox pipeline state
guard let skyboxPath = Bundle.main.path(forResource: "Skybox", ofType: "metal") else { return }
let skyboxSource = try String(contentsOfFile: skyboxPath, encoding: .utf8)
let skyboxLibrary = try device.makeLibrary(source: skyboxSource, options: nil)
descriptor.vertexFunction = skyboxLibrary.makeFunction(name: "vertex_skybox")
descriptor.fragmentFunction = skyboxLibrary.makeFunction(name: "fragment_skybox")
descriptor.vertexFunction = library.makeFunction(name: "vertex_skybox")
descriptor.fragmentFunction = library.makeFunction(name: "fragment_skybox")
descriptor.vertexDescriptor = MTKMetalVertexDescriptorFromModelIO(skybox.vertexDescriptor)
try skyboxPipelineState = device.makeRenderPipelineState(descriptor: descriptor)