在金属屏幕外渲染
let textureDescriptors = MTLTextureDescriptor()
textureDescriptors.textureType = MTLTextureType.type2D
let screenRatio = UIScreen.main.scale
textureDescriptors.width = Int((DrawingManager.shared.size?.width)!) * Int(screenRatio)
textureDescriptors.height = Int((DrawingManager.shared.size?.height)!) * Int(screenRatio)
textureDescriptors.pixelFormat = .bgra8Unorm
textureDescriptors.storageMode = .shared
textureDescriptors.usage = [.renderTarget, .shaderRead]
ssTexture = device.makeTexture(descriptor: textureDescriptors)
ssTexture.label = "ssTexture"
此处的纹理为“透明”颜色。是否可以加载图像纹理并且可以在Draw方法中渲染图像纹理
let renderPass = MTLRenderPassDescriptor()
renderPass.colorAttachments[0].loadAction = .clear
renderPass.colorAttachments[0].clearColor = MTLClearColorMake( 0.0, 0.0, 0.0, 0.0)
renderPass.colorAttachments[0].texture = ssTexture
renderPass.colorAttachments[0].storeAction = .store
答案 0 :(得分:2)
我不确定您要问什么。
MTLTextureLoader
用于创建以图像内容初始化的纹理。replace(region:...)
的{{1}}方法用图像数据填充全部或部分纹理。MTLTexture
将数据从一个纹理复制到另一纹理(全部或部分),或从缓冲区复制到纹理。这是一个通用API。有很多方法可以完成您似乎要问的事情。你尝试了什么?这些尝试以什么方式未能实现您想要的?