简体   繁体   中英

Off Screen Rendering

In off screen rendering in metal

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"

Here the texture is in Clear color. Is it possible to load a image texture and is it posible to render the image texture in Draw Method

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

I'm not sure what you're asking.

  • There's MTLTextureLoader for creating textures initialized with the contents of an image.
  • You can use the replace(region:...) methods of MTLTexture to fill all or part of a texture with image data.
  • You can use MTLBlitCommandEncoder to copy data from one texture to (all or part of) another or from a buffer to a texture.
  • You can draw to a texture or write to it from a compute shader.

It's a general-purpose API. There are many ways to do the things you seem to be asking. What have you tried? In what way did those attempts fail to achieve what you want?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM