这里合适的 MTLRegion 参数是什么?
What is a proper MTLRegion param here?
我需要从 UnsafeRawPointer
创建一个 MTLTexture
,我尝试这样做:
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
}
根据文档,这是正确的方法,所以,首先,我创建了 MTLTextureDescriptor
,然后我创建了一个 MTLTexture
,最后我需要按顺序传递我的像素数据为此,我使用 replace
方法。
我不明白这里的第一个参数是什么的问题region
?我应该在那里传递什么?
使用MTLRegion 结构来确定要更新纹理的哪一部分。此示例使用图像数据填充整个纹理;所以创建一个覆盖整个纹理的区域。
MTLRegion region = {
{ 0, 0, 0 }, // MTLOrigin
{texture.width, texture.height, 1} // MTLSize
};
Swift:
let region = MTLRegion.init(origin: MTLOrigin.init(x: 0, y: 0, z: 0), size: MTLSize.init(width: texture.width, height: texture.height, depth: 1));
我需要从 UnsafeRawPointer
创建一个 MTLTexture
,我尝试这样做:
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
}
根据文档,这是正确的方法,所以,首先,我创建了 MTLTextureDescriptor
,然后我创建了一个 MTLTexture
,最后我需要按顺序传递我的像素数据为此,我使用 replace
方法。
我不明白这里的第一个参数是什么的问题region
?我应该在那里传递什么?
使用MTLRegion 结构来确定要更新纹理的哪一部分。此示例使用图像数据填充整个纹理;所以创建一个覆盖整个纹理的区域。
MTLRegion region = {
{ 0, 0, 0 }, // MTLOrigin
{texture.width, texture.height, 1} // MTLSize
};
Swift:
let region = MTLRegion.init(origin: MTLOrigin.init(x: 0, y: 0, z: 0), size: MTLSize.init(width: texture.width, height: texture.height, depth: 1));