この Stackoverflow の投稿の質問には、Obj-C で書かれていますが、回答が含まれています。ただ、基本的にDong Fengさんが指摘しているように、深度テクスチャは自分で作成・管理する必要があります。
これは、深度テクスチャを作成する方法の Swift 4 スニペットです。
func buildDepthTexture(_ device: MTLDevice, _ size: CGSize) -> MTLTexture {
let desc = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: .depth32Float_stencil8,
width: Int(size.width), height: Int(size.height), mipmapped: false)
desc.storageMode = .private
desc.usage = .renderTarget
return device.makeTexture(descriptor: desc)!
}
そして、ここにあなたがそれをに添付する必要がある方法がありますMTLRenderPassDescriptor
let renderPassDesc = MTLRenderPassDescriptor()
let depthAttachment = renderPassDesc.depthAttachment!
// depthTexture is created using the above function
depthAttachment.texture = depthTexture
depthAttachment.clearDepth = 1.0
depthAttachment.storeAction = .dontCare
// Maybe set up color attachment, etc.