首页 > 解决方案 > 金属渲染通道中没有颜色附件

问题描述

是否有可能MTLRenderPassDescriptor渲染到深度或模板纹理,但没有颜色附件?像这样:

MTLRenderPassDescriptor* textureRenderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
MTLRenderPassStencilAttachmentDescriptor* textureAttachment = [[MTLRenderPassStencilAttachmentDescriptor alloc]init];
textureAttachment.texture = texture;
textureAttachment.loadAction = MTLLoadActionClear;
textureAttachment.storeAction = MTLStoreActionStore;
textureRenderPassDescriptor.stencilAttachment = textureAttachment;

我尝试这样做,但在尝试使用此管道状态时出现以下错误:

failed assertion `For color attachment 0, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set.'

标签: metal

解决方案


正如断言所述,您需要pixelFormat在创建时设置为无效MTLRenderPipelineState

pipelineStateDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormatInvalid;

推荐阅读