【发布时间】:2016-09-23 12:36:13
【问题描述】:
生成由 CVPixelBuffer 支持的 MTLTexture 的正确方法是什么?
我有以下代码,但似乎泄露了:
func PixelBufferToMTLTexture(pixelBuffer:CVPixelBuffer) -> MTLTexture
{
var texture:MTLTexture!
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
let format:MTLPixelFormat = .BGRA8Unorm
var textureRef : Unmanaged<CVMetalTextureRef>?
let status = CVMetalTextureCacheCreateTextureFromImage(nil,
videoTextureCache!.takeUnretainedValue(),
pixelBuffer,
nil,
format,
width,
height,
0,
&textureRef)
if(status == kCVReturnSuccess)
{
texture = CVMetalTextureGetTexture(textureRef!.takeUnretainedValue())
}
return texture
}
【问题讨论】:
-
您是如何确定存在内存泄漏的?什么样的物体在泄漏?
-
您是否使用它来渲染带有某种过滤器的肝脏摄像头馈送?请看看我的问题:stackoverflow.com/questions/53898780/…
-
什么是videoTextureCache?
-
@RoiMulia 你可以使用developer.apple.com/documentation/metal/…:它展示了如何使用 CVMetalTextureCacheCreate 创建纹理缓存