我已将我的OpenGL ES初始化与CAEAGLLayer放在另一个线程中。
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:group];
if (!context || ![EAGLContext setCurrentContext:context])
{
[self release];
}
// Create system framebuffer object. The backing will be allocated in -reshapeFramebuffer
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
然后将其绘制到屏幕
BOOL rel = [EAGLContext setCurrentContext:context];
drawPixels(backingWidth, backingHeight, framebuf1, texID);
rel = [context presentRenderbuffer:GL_RENDERBUFFER_OES];
缓冲区正在模拟器中显示,但在设备上,我得到的只是黑屏。 我需要配置别的吗?
答案 0 :(得分:2)
OpenGL上下文一次只能在一个线程中处于活动状态。因此,您首先要从一个线程中分离上下文,然后将其重新附加到另一个线程中。看起来你的代码缺乏分离。