OpenGL-ES, iPhone and intermittent error: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES (0x8CD6)

I have an application that uses OpenGL-ES and EAGLContext in a UIView - very similar to the Apple GLPaint example application.

It may seem that I see this error on my iPhone 4, but not on my iPad.

Basically, it works very well. However, I get GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES from glCheckFramebufferStatusOES () in the createFrameBuffer method. The reason is because backingWidth and backingHeight are 0.

I'm trying to understand the relationship between myself) self.layer and its size - which is not (0,0) - and the values ​​for backingWidth and backingHeight. My UIView and its CALayer are the "correct" size, and glGetRenderbufferParameterivOES () returns 0 for GL_RENDERBUFFER_WIDTH_OES and GL_RENDERBUFFER_HEIGHT_OES.

Here is my createFrameBuffer method that works most of the time.

- (BOOL)createFramebuffer
 { 
 // Generate IDs for a framebuffer object and a color renderbuffer
 glGenFramebuffersOES(1, &viewFramebuffer);
 glGenRenderbuffersOES(1, &viewRenderbuffer);

 glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

 glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

 // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer)
 // allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view).
 [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];

 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

 //DLog(@" backing size = (%d, %d)", backingWidth, backingHeight);
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
 DLog(@" backing size = (%d, %d)", backingWidth, backingHeight);


 err = glGetError();
 if (err != GL_NO_ERROR)
  DLog(@"Error. glError: 0x%04X", err);

 // For this sample, we also need a depth buffer, so we'll create and attach one via another renderbuffer.
 glGenRenderbuffersOES(1, &depthRenderbuffer);
 glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);

 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 0x%X", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
  return NO;
  }

 return YES;
 }

When backingWidth and backingHeight are nonzero, then there is no error returned from glCheckFramebufferStatusOES ().

+3
source share
2 answers

. , opengl Apple renderbuffer layoutSubviews. , oppanl iPhone, , layoutSubviews renderbuffer. , , . , CAlayers .., .

, , EagleView - - . , , .

, , , . , .

Apple, , , , layoutsubviews, :

// The framebuffer will be re-created at the beginning of the next 
   setFramebuffer method call.

-

+7

, Apple OpenGL-ES, destroyFramebuffer, createFramebuffer, drawView layoutSubviews.

, drawView, , drawView , layoutSubviews . :

- (void) layoutSubviews
{
 [EAGLContext setCurrentContext:context];

 [self destroyFramebuffer];

 // Create the framebuffer in drawView instead as needed, as before create 
 // would occasionally happen when the view wasn't servicable (?) and cause 
 // a crash. Additionally, send the drawView call to the main UI thread 
 // (ALA PostMessage in Win32) so that it is deferred until this function 
 // returns and the message loop has a chance to process other stuff, etc 
 // so the EAGLView will be ready to use when createFramebuffer is finally 
 // called and the glGetRenderbufferParameterivOES calls to get the backing 
 // width and height for the render buffer will always work (occasionally I 
 // would see them come back as zero on my old first gen phone, and this 
 // crashes OpenGL.)
 //
 // Also, using this original method, I would see memory warnings in the 
 // debugger console window with my iPad when rotating (not all the time, 
 // but pretty frequently.)  These seem to have gone away using this new 
 // deferred method...
 [self performSelectorOnMainThread:@selector(drawView) 
                        withObject:nil 
                     waitUntilDone:NO];
}

0

Source: https://habr.com/ru/post/1772967/


All Articles