【问题标题】:AVCaptureSession and Cocos2d-x on macOSmacOS 上的 AVCaptureSession 和 Cocos2d-x
【发布时间】:2017-06-16 19:29:50
【问题描述】:

我正在跨平台 Cocos2d-x 游戏中实现游戏记录功能。我设法为 iOS 和 Android 实现了这些功能,但我很难在 macOS 上获得良好的性能。我已经使用 glReadPixels 函数成功实现了游戏录制,但性能非常低。我在我的 Macbook Pro 上获得了大约 10-15 fps。我试图实现 AVCaptureSession 来记录整个屏幕,然后像在 Apple 的 AVScreenShack 示例中一样裁剪所需区域,但我遇到了 Cocos2d-x Renderer 错误。

错误日志如下所示:

OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/2d/CCParticleSystemQuad.cpp postStep 458
OpenGL error 0x0506 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCFrameBuffer.cpp applyFBO 445
FrameBuffer Status Error 33305
OpenGL error 0x0506 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCFrameBuffer.cpp applyFBO 445
FrameBuffer Status Error 33305
FrameBuffer Status Error 33305
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCRenderer.cpp saveRenderState 161
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCTextureAtlas.cpp drawNumberOfQuads 691
FrameBuffer Status Error 33305
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCRenderer.cpp restoreRenderState 192
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/2d/CCParticleSystemQuad.cpp postStep 458
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/2d/CCParticleSystemQuad.cpp postStep 458
OpenGL error 0x0506 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCFrameBuffer.cpp applyFBO 445
FrameBuffer Status Error 33305
OpenGL error 0x0506 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCFrameBuffer.cpp applyFBO 445
FrameBuffer Status Error 33305
FrameBuffer Status Error 33305
OpenGL error 0x0501 in /Users/milosz/Documents/job/butterflix/blix/cocos2d/cocos/renderer/CCRenderer.cpp saveRenderState 161

我的第一个想法是 AVCaptureSession 使用 NSOpengGLContext 来渲染帧,所以我检查了上下文是否发生了变化,但它没有。我还根据我在 iOS 上使用的方法尝试了 CVOpenGLTextureCache,但没有成功。

但是,当我在玩游戏时运行 AVScreenShack 示例时,它会记录整个屏幕并且不会与 Cocos2d-x 渲染器发生冲突。我认为这是因为两个应用程序都在不同的主线程上运行,因此没有发生某种竞争条件。我可以在单个 Mac 应用程序中复制这种行为吗?或者有没有其他方法可以在 MacOS 上录制性能合理的 Cocos2d-x 游戏?

【问题讨论】:

    标签: c++ objective-c macos avfoundation cocos2d-x


    【解决方案1】:

    我遇到了类似的问题,但使用的是 Qt 应用程序。调用 [AVCaptureSession startRunning] 后,我的 OpenGL 停止正常工作。 在我的情况下,当前的 NSOpenGLContext 在调用 startRunning 之后是 nil。 所以我的解决方案是:

    QOpenGLContext *currentContext = QOpenGLContext::currentContext();
    QSurface *currentSurface = currentContext->surface();
    [m_Session startRunning];
    currentContext->makeCurrent(currentSurface);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 2023-03-24
      • 2015-10-08
      • 2018-11-07
      相关资源
      最近更新 更多