渲染到金属以外的屏幕外帧缓冲区

时间:2018-07-23 10:42:10

标签: swift textures metal metalkit

我尝试创建输出纹理并将其设置为colorattachments [0] 在renderpassDesriptor中,而不是curentdrawable.texture中。换句话说,场景被渲染到屏幕外的帧缓冲区中

let textureDescriptor = MTLTextureDescriptor()
textureDescriptor.textureType = MTLTextureType.type2DMultisample 
textureDescriptor.width = drawable.texture.width
textureDescriptor.height = drawable.texture.height
textureDescriptor.sampleCount = 4
textureDescriptor.pixelFormat = .bgra8Unorm
textureDescriptor.storageMode = .private
textureDescriptor.usage = .renderTarget

let sampleTex = device.makeTexture(descriptor: textureDescriptor)

let renderPassDescriptor = MTLRenderPassDescriptor()
renderPassDescriptor.colorAttachments[0].texture = sampleTex
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor =
                MTLClearColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
renderPassDescriptor.colorAttachments[0].storeAction = .store
屏幕外帧缓冲区绑定为纹理。所以我需要做的是将屏幕外的帧缓冲纹理设置为当前的可播放纹理。这意味着我渲染到屏幕外纹理而不是直接渲染到屏幕上的内容应显示为当前可绘制对象。有什么建议吗?

0 个答案:

没有答案