我有一个CVPixelBuffer
我正在尝试在屏幕上有效地绘制。
转变为低效率的方式NSImage
可以工作,但速度非常慢,丢掉了大约 40% 的帧数。
因此,我尝试使用将其渲染在屏幕上CIContext
's drawImage:inRect:fromRect
. The CIContext
被初始化为NSOpenGLContext
谁的视图设置为我的 VC 视图。当我有新图像时,我调用drawImage
方法不会吐出任何错误...但也不会在屏幕上显示任何内容(当我的上下文设置不正确时,它会记录错误)。
我试图找到一个在 MacOS 上如何完成此操作的示例,但现在一切似乎都适用于 iOS。
EDIT:
这是我正在使用的一些代码。我省略了不相关的部分
On viewDidLoad
我初始化 GL 和 CI 上下文
NSOpenGLPixelFormatAttribute pixelFormatAttr[] = {
kCGLPFAAllRenderers, 0
};
NSOpenGLPixelFormat *glPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: pixelFormatAttr];
NSOpenGLContext *glContext = [[NSOpenGLContext alloc] initWithFormat:glPixelFormat shareContext:nil];
glContext.view = self.view;
self.ciContext = [CIContext contextWithCGLContext:glContext.CGLContextObj pixelFormat:glPixelFormat.CGLPixelFormatObj colorSpace:nil options:nil];
然后,当新框架准备好时,我会:
dispatch_async(dispatch_get_main_queue(), ^{
[vc.ciContext drawImage:ciImage inRect:vc.view.bounds fromRect:ciImage.extent];
vc.isRendering = NO;
});
我不确定我在正确的地方调用了draw,但我似乎无法找出它应该去哪里。
If the CVPixelBuffer
有kCVPixelBufferIOSurfaceCoreAnimationCompatibilityKey https://developer.apple.com/documentation/corevideo/kcvpixelbufferiosurfacecoreanimationcompatibilitykey属性,后盾IOSurface https://developer.apple.com/documentation/iosurface(通过检索CVPixelBufferGetIOSurface https://developer.apple.com/documentation/corevideo/1456690-cvpixelbuffergetiosurface) 可以直接传递给contents https://developer.apple.com/documentation/quartzcore/calayer/1410773-contents的财产CALayer
.
这可能是最有效的显示方式CVPixelBuffer
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)