如何更改Metal中的pixelFormat? [英] How do I change the pixelFormat in Metal?

查看:358
本文介绍了如何更改Metal中的pixelFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试使用bgra8Unorm以外的任何其他选项,它将崩溃,并显示

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

-[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1192:断言失败对于颜色附件0,渲染管道的pixelFormat(MTLPixelFormatBGRA8Unorm_sRGB)与帧缓冲区的pixelFormat(MTLPixelFormatBGRA8Unorm)不匹配.

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

然后如何更改帧缓冲区的pixelFormat?我希望能够做到这一点:

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

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm_srgb

代替这个

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm

同样,这是尝试修复愚蠢的错误.

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

推荐答案

您需要在此处定义的MetalView:

You need the MetalView defined here:

var MetalView: MTKView {
    return view as! MTKView
}

然后在viewDidLoad:

MetalView.colorPixelFormat = .bgra8Unorm_srgb

然后我可以这样做:

PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm_srgb

我自己弄清楚了!

这篇关于如何更改Metal中的pixelFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆