【问题标题】:One EAGLContext causes another EAGLContext not towork with iOS OpenGL一个 EAGLContext 导致另一个 EAGLContext 不能与 iOS OpenGL 一起工作
【发布时间】:2017-10-19 17:28:03
【问题描述】:

我有两个类来展示不同的 CIImage。它们都有相同的方式来创建 OpenGL 对象,如下例所示。

_context = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES3];
    _coreImageContext = [CIContext contextWithEAGLContext:_context];
    _localCameraView = [[GLKView alloc]initWithFrame:self.localCameraViewPlayingRect context:_context];
    _localCameraView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    _localCameraView.context = _context;
    glGenRenderbuffers(1, &_renderBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);

在一个 glkview 显示 ciImage 之后,我将启动另一个 EAGLContext 来显示不同的 CIImage。另一个 openGL 对象的创建如下代码。

_context = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES3];
        _coreImageContext = [CIContext contextWithEAGLContext:_context];
        _cameraView = [[GLKView alloc]initWithFrame:self.playingRect context:_context];
        _cameraView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
        _cameraView.context = _context;
        glGenRenderbuffers(1, &_renderBuffer);
        glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);

我使用相同的方式显示 ciimage,但它们的方式不同。 1.

    if(_coreImageContext && _context)
{
    [_cameraConnectorLocker lock];
    if(_cameraConnectorLocker && _context)
    {
        [_coreImageContext drawImage:ciImage inRect:CGRectMake(0, 0, self.cameraView.drawableWidth, self.cameraView.drawableHeight) fromRect:[ciImage extent]];
        [_context presentRenderbuffer:GL_RENDERBUFFER];

    }
    [_cameraConnectorLocker unlock];
}

2.

if(_coreImageContext && _context)
{
    [_outputVideoLock lock];
    if (_coreImageContext && _context) {

        [_coreImageContext drawImage:image inRect:CGRectMake(0, 0, self.localCameraView.drawableWidth, self.localCameraView.drawableHeight) fromRect:[image extent]];
        [_context presentRenderbuffer:GL_RENDERBUFFER];

    }
    [_outputVideoLock unlock];
}

如果这两个 EAGLContext 对象同时创建,两个 GLKView 会显示两个不同的视频。 如果先创建一个,然后再创建另一个,后一个会正常显示,第一个会卡住。 我不知道如何解决它,有人可以帮助我吗?非常感谢。

【问题讨论】:

    标签: objective-c opengl-es ciimage eaglcontext


    【解决方案1】:

    经过调查测试,两个GLKViews可以用下面的代码一张一张的显示视频

     _context = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES3];
        [EAGLContext setCurrentContext:_context];
    

    如果没有代码 [EAGLContext setCurrentContext:_context],一个 GLKView 将阻止另一个 GLKView 显示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 2012-06-17
      相关资源
      最近更新 更多