一个EAGLContext会导致另一个EAGLContext无法与iOS OpenGL配合使用



我有两个类来显示不同的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将显示两个不同的视频。如果先创建一个,然后再创建另一个,后一个将正常显示,第一个将被卡住。我不知道怎么修,有人能帮我吗?非常感谢。

经过调查和测试,两个GLKView可以使用以下代码逐个显示视频

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

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

最新更新