Lawrence Zhang
Lawrence Zhang

Reputation: 11

One EAGLContext causes another EAGLContext not towork with iOS OpenGL

I have two classes to show different CIImage. They both have the same way to create OpenGL objects like in the following example.

_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);

after one glkview showing ciImage, I will start another EAGLContext to show different CIImage. The another openGL objects are created like below code.

_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);

I use same way to show ciimage, but they are in different method. 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];
}

if these two EAGLContext objects are created at the same time, two GLKView will show two different video. if one is created first, then another is created later, the later one will show normally, the first will be stuck. I don't know how to fix it, can someone help me? many thanks.

Upvotes: 0

Views: 351

Answers (1)

Lawrence Zhang
Lawrence Zhang

Reputation: 11

after investigating and testing, two GLKViews can show video one by one with below code

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

if no code [EAGLContext setCurrentContext:_context], one GLKView will block another GLKView showing

Upvotes: 0

Related Questions