OpenGL ES in another thread is not drawing on physical device
I have put my OpenGL ES initialization in another thread with 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_RE开发者_如何学PythonNDERBUFFER_OES, viewRenderbuffer);
and then draw it to screen
BOOL rel = [EAGLContext setCurrentContext:context];
drawPixels(backingWidth, backingHeight, framebuf1, texID);
rel = [context presentRenderbuffer:GL_RENDERBUFFER_OES];
the buffer is displaying in simulator, but on a device, all I get is a black screen. do I need to configure something else?
OpenGL contexts can be active in only one thread on a time. So you've first to detach the context from one thread and reattach it in another one. It looks like your code lacks the detaching.
精彩评论