How do I change the pixelFormat in Metal?

旧时模样 提交于 2020-06-28 03:53:30

问题


If I try anyting other than bgra8Unorm, it will crash, saying,

-[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1192: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatBGRA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGRA8Unorm).'

How do I change the framebuffer's pixelFormat then? I want to be able to do this:

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm_srgb

Instead of this

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm

Again, this is an attempt to fix this stupid bug.


回答1:


You need the MetalView defined here:

var MetalView: MTKView {
    return view as! MTKView
}

Then in viewDidLoad:

MetalView.colorPixelFormat = .bgra8Unorm_srgb

Then I can do this:

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm_srgb

I figured it out myself yay!



来源:https://stackoverflow.com/questions/61811045/how-do-i-change-the-pixelformat-in-metal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!