我有两个类来显示不同的 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 会显示两个不同的视频。如果先创建一个,然后再创建另一个,后一个会正常显示,第一个会卡住。我不知道如何解决它,有人可以帮助我吗?非常感谢。