I need to create a MTLTexture from the UnsafeRawPointer, I try to do it in such a way:
private func createTexture(frame: UnsafeMutableRawPointer) -> MTLTexture? {
let textureOjb: UnsafeMutableRawPointer = frame_get_texture_obj(frame)
let ti: TextureInfo = texture_get_info(textureOjb)
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: MTLPixelFormat.rgba8Unorm,
width: Int(ti.width),
height: Int(ti.height),
mipmapped: false)
textureDescriptor.usage = [.shaderWrite, .shaderRead]
guard let texture: MTLTexture = device?.makeTexture(descriptor: textureDescriptor) else
{
logger?.log(severity: .error, msg: "create texture FAILED.")
return nil
}
let data: UnsafeRawPointer = UnsafeRawPointer(ti.pixels)
texture.replace(region: <#T##MTLRegion#>, mipmapLevel: 0, withBytes: data, bytesPerRow: Int(ti.stride))
return texture
}
According to the documentation, it is the correct approach, so, first of all, I created MTLTextureDescriptor, then I created a MTLTexture and finally I need to pass my pixels data in order to do it I use replace method.
The problem that I don't understand what is the first param here region? What should I pass there?