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