From 8298f258c7687bd3a7d7ef3fa173ab594909f749 Mon Sep 17 00:00:00 2001 From: daemyung jang Date: Mon, 21 Mar 2022 00:08:39 +0900 Subject: [PATCH] Fix runtime errors --- .../skybox.playground/Sources/Renderer.swift | 14 +++++--------- .../skybox.playground/Sources/Renderer.swift | 14 +++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/12-environment/projects/skybox.playground/Sources/Renderer.swift b/12-environment/projects/skybox.playground/Sources/Renderer.swift index 2b68961..face502 100644 --- a/12-environment/projects/skybox.playground/Sources/Renderer.swift +++ b/12-environment/projects/skybox.playground/Sources/Renderer.swift @@ -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) diff --git a/12-environment/skybox.playground/Sources/Renderer.swift b/12-environment/skybox.playground/Sources/Renderer.swift index 2b68961..face502 100644 --- a/12-environment/skybox.playground/Sources/Renderer.swift +++ b/12-environment/skybox.playground/Sources/Renderer.swift @@ -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)