我正在做通常的EAGLVIEw / ES2Render.
在启动时,使用以下代码创建frambuffer成功:
- (BOol) createFramebuffers{ [EAGLContext setCurrentContext:_mainContext]; // [ A ] On-screen // 1. Framebuffer glGenFramebuffers(1,&_mainFramebuffer); bindFramebuffer(_mainFramebuffer); // 2. color buffer glGenRenderbuffers(1,&_maincolorbuffer); bindRenderbuffer(_maincolorbuffer); // Adjust size to vIEw's layer: CAEAGLLayer* layer = (CAEAGLLayer*)[_vIEw layer]; if (![_mainContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]) { // something went horribly wrong NSLog(@"-[ES2Renderer createFramebuffers]: Failed to obtain renderbuffer storage from layer!"); return NO; } // query new size: glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_WIDTH,&_backingWIDth); glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_HEIGHT,&_backingHeight); // Attach to color: glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_color_ATTACHMENT0,GL_RENDERBUFFER,_maincolorbuffer); // 3. Depth buffer glGenRenderbuffers(1,&_depthBuffer); bindRenderbuffer(_depthBuffer); if (_useStencilBuffer) { // Depth + Stencil // Allocate storage: glrenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8_OES,_backingWIDth,_backingHeight); // Attach to depth: glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,_depthBuffer); // Attach to stencil: glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,_depthBuffer); } else{ // Depth only // Allocate storage: glrenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24_OES,_backingHeight); // Attachto depth: glFramebufferRenderbuffer(GL_FRAMEBUFFER,_depthBuffer); } // 4. ValIDate the set: GLenum framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE) { // Something went wrong! NSLog(@"-[ES2Renderer createFramebuffers]: Failed to make complete framebuffer object: %@",[self stringFromFramebufferStauts:framebufferStatus]); return NO; } // [ B ] off-screen (Render-to-texture) // 1. Framebuffer glGenFramebuffers(1,&_transFramebuffer); bindFramebuffer(_transFramebuffer); // 2. Depth buffer glGenRenderbuffers(1,&_transDepthBuffer); bindRenderbuffer(_transDepthBuffer); if (_useStencilBuffer) { // Allocate storage: glrenderbufferStorage(GL_RENDERBUFFER,_transDepthBuffer); // Attach to stencil: glFramebufferRenderbuffer(GL_FRAMEBUFFER,_transDepthBuffer); } else{ // Allocate storage glrenderbufferStorage(GL_RENDERBUFFER,_transDepthBuffer); } // 3. Textures (color buffers) gluint* texPtrs[2] = {&_transTexture1,&_transTexture2}; for (NSUInteger i=0; i < 2; i++) { gluint* texPtr = texPtrs[i]; // Create: glGenTextures(1,texPtr); // Bind: bindTexture2D(*texPtr); // Configure for pixel-aligned use: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); // Allocate storage: glTexImage2D(GL_TEXTURE_2D,GL_RGBA,_backingHeight,GL_UNSIGNED_BYTE,0); // Attach: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_TEXTURE_2D,*texPtr,0); framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); // ValIDate: if ( framebufferStatus != GL_FRAMEBUFFER_COMPLETE) { // Something went wrong! NSLog(@"-[ES2Renderer createFramebuffers]: Failed to make complete framebuffer object: %@",[self stringFromFramebufferStauts:framebufferStatus]); return NO; } } // Final State: bindFramebuffer(_mainFramebuffer); bindRenderbuffer(_maincolorbuffer); bindTexture2D(0); NSLog(@"-[ES2Renderer createFramebuffers] Succeeded."); return YES;}
不久之后,UIVIEw的-layoutSubvIEws被调用,然后我执行-resizefromLayer ::
- (BOol) resizefromLayer:(CAEAGLLayer *)layer{ // [ A ] On screen framebuffer bindFramebuffer(_mainFramebuffer); // 1. Resize color buffer bindRenderbuffer(_maincolorbuffer); if (![_mainContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]) { // Something went wrong return NO; // <-- SECOND TIME ON,THIS HAPPENS } // query new size: glGetRenderbufferParameteriv(GL_RENDERBUFFER,&_backingHeight); // 2. Resize depth buffer bindRenderbuffer(_depthBuffer); if (_useStencilBuffer) { // (Depth & Stencil) glrenderbufferStorage(GL_RENDERBUFFER,_backingHeight); } else{ // (Depth only) glrenderbufferStorage(GL_FRAMEBUFFER,_backingHeight); } // ...ValIDate: GLenum framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE) { // Something went wrong! NSLog(@"-[ES2Renderer resizefromLayer:]: Failed to make complete framebuffer object: %@",[self stringFromFramebufferStauts:glCheckFramebufferStatus(GL_FRAMEBUFFER)]); return NO; } // [ B ] Off screen (render-to-terxture) framebuffer bindFramebuffer(_transFramebuffer); // 1. Resize depth buffer bindRenderbuffer(_transDepthBuffer); if (_useStencilBuffer) { glrenderbufferStorage(GL_RENDERBUFFER,_backingHeight); } else{ glrenderbufferStorage(GL_RENDERBUFFER,_backingHeight); } // 2. Resize textures gluint* texPtrs[2] = {&_transTexture1,&_transTexture2}; for (NSUInteger i=0; i < 2; i++) { gluint* texPtr = texPtrs[i]; // Bind: bindTexture2D(*texPtr); // Configure for pixel-aligned use: glTexParameteri(GL_TEXTURE_2D,0); // ValIDate: if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { // Something went wrong! Nsstring* statusstring = [self stringFromFramebufferStauts:glCheckFramebufferStatus(GL_FRAMEBUFFER)]; NSLog(@"-[ES2Renderer resizefromLayer:]: Failed to make complete framebuffer object: %@",statusstring); return NO; } } bindFramebuffer(_mainFramebuffer); bindRenderbuffer(_maincolorbuffer); // Pass new ortho projection to shaders [self initializeModelVIEwMatrix]; [self initializeSpriteProgram]; // Set new vIEwport glVIEwport(0,_backingHeight); NSLog(@"-[ES2Renderer resizefromLayer:]: Succeeded."); return YES;}
我所做的一切都不是特别的.我有一个单独的帧缓冲区来渲染场景过渡,有两个纹理可以附加到颜色和深度.
第二次-renderbufferStorage:fromDrawable:被调用(-layoutSubvIEws – > resizefromLayer :),它总是失败(返回NO);在此之前调用glGetError()不会导致错误,但在返回GL_INVALID_OPERATION后立即调用它.
如果我忽略了这一点并继续,glGetRenderbufferParameteriv()仍然可以获得正确的宽度和高度(分别在iPhone 5上为640和1136),但glCheckFramebufferStatus()将返回GL_FRAMEBUFFER_UNSUPPORTED.
或者,我跳过上面的resizefromLayer:并将其替换为:
- (BOol) resizefromLayer:(CAEAGLLayer *)layer{ [self destroyFramebuffers]; return [self createFramebuffers];}
…但是同样的错误仍然存在(-renderStorage:fromDrawable:Failed;这次是在-createFramebuffers中).
现在,我只返回YES(我的应用只支持肖像,所以实际上没有发生屏幕尺寸变化),但我真的想修复它,因为有一天我需要支持景观等…
解决方法 renderbufferStorage:fromDrawable:失败的一个可能原因是_mainContext不是当时的当前上下文.尽管似乎没有其他上下文可以窃取“当前”状态,但我建议在对该上下文关联的对象上运行的任何gl或EAGL代码之前调用[EAGLContext setCurrentContext:_mainContext](例如,在resizefromLayer的开头:方法). 总结以上是内存溢出为你收集整理的ios – – [EAGLContext renderbufferStorage:fromDrawable:]第二次失败?全部内容,希望文章能够帮你解决ios – – [EAGLContext renderbufferStorage:fromDrawable:]第二次失败?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)