I have a 3D project based on the EAGLView exemple from Apple.
I have a very stange bug with the context ( I think ), my context is create by using :
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
On init the 3D view it's work, and on layout subview, my frameBuffer is destroy an create again. But in some case, the framebuffer is not create. I have search with the debugger I have find the problem become from the context "creation":
- (BOOL)createFramebuffer
{
NSLog(@"[EAGLVIEW] create framebuffer");
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
//////// HERE, some time the context is 0 /////////
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
//////////////////////
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &bac开发者_开发知识库kingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
// On génère le tampon de profondeur -- bah oui, on fait de la 3D
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
// On paramètre le tampon :
// - avec les dimensions que l'on veut
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
//glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, backingWidth, backingHeight);
// - avec la profondeur que l'on veut
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
return YES;
}
I don't understand why it's work or not. When i have this bug, i turn my iphone for force to execute layoutSubview, and it's work. it's very strange.
what are the reason for the context not create at second and it's ok just after.
You have not posted the code showing how you actually created the context, just using it. Your context creation should look something like this
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context])
return false;
And if the context is 0 (which mean nil) then you will have detected it before hand.
精彩评论