Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am getting error code GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT when creating framebuffer on Mac (using glCheckFramebufferStatus).

I am using same code for rendering on Mac and iOS both. Maybe problem is in the buffers initialization. On iOS I am doing it this way:

    CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
    eaglLayer.opaque = YES;

    EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES2;
    m_context = [[EAGLContext alloc] initWithAPI:api];

    if (!m_context) {
        [self release];
        return nil;
    }

    if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
        [self release];
        return nil;
    }

    [self layoutIfNeeded];


    NSLog(@"Using OpenGL ES 2.0");

    [m_context
        renderbufferStorage:GL_RENDERBUFFER
        fromDrawable: eaglLayer];

Variable m_context is object EAGLContext

On the Mac this way:

NSOpenGLPixelFormat *nsglFormat;

NSOpenGLPixelFormatAttribute attr[] = 
{
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFAColorSize, m_colorBits, //16
    NSOpenGLPFADepthSize, m_depthBits, //16
    0 
};


[self setPostsFrameChangedNotifications: YES];

///< Next, initialize the NSOpenGLPixelFormat itself
nsglFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];

///< Check for errors in the creation of the NSOpenGLPixelFormat
if(!nsglFormat) { 
    NSLog(@"Invalid format... terminating."); 
    return nil; 
}


///< Now create the the CocoaGL instance, using initial frame and the NSOpenGLPixelFormat
self = [super initWithFrame:frame pixelFormat:nsglFormat];
[nsglFormat release];

///< If there was an error, we again should probably send an error message to the user
if(!self) { 
    NSLog(@"Self not created... terminating."); 
    return nil; 
}



///< Now  set this context to the current context

[[self openGLContext] makeCurrentContext];

Maybe I am doing anything wrong when I initialize NSOpenGLContext. Can you see any error? Thankyou UPDATE: Initialization of the OpenGL I am doing this way:

int m_width, m_height;


glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                             GL_RENDERBUFFER_WIDTH, &m_width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                             GL_RENDERBUFFER_HEIGHT, &m_height);

// Create the depth buffer.
glGenRenderbuffers(1, &m_depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER,
                      GL_DEPTH_COMPONENT16,
                      m_width,
                      m_height);

// Create the framebuffer object; attach the depth and color buffers.
glGenFramebuffers(1, &m_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                          GL_COLOR_ATTACHMENT0,
                          GL_RENDERBUFFER,
                          m_colorRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                          GL_DEPTH_ATTACHMENT,
                          GL_RENDERBUFFER,
                          m_depthRenderbuffer);

// Bind the color buffer for rendering.
glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);


// Set up some GL state.
glViewport(0, 0, 640, 480);
glEnable(GL_DEPTH_TEST);
share|improve this question
    
Could you please post your corrected code ? I tried to delete the code related to the RenderBuffer but I still get an error. –  user8551 Jul 12 '11 at 9:50
add comment

2 Answers 2

I had the exact same problem when I tried adding a depth buffer to the sample code generated by XCode. You should add code to check for framebuffer completion:

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
// also check glGetError() here

I'm not a Mac expert, but I do remember that the position of the following call is very important:

[m_context renderbufferStorage:GL_RENDERBUFFER fromDrawable: eaglLayer];

On iOS it needs to be before creating the color and depth components of the framebuffer.

Here is my working iOS code:

[EAGLContext setCurrentContext:context];

glGenFramebuffers(1, &frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);

glGenRenderbuffers(1, &colorRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderBuffer);

glGenRenderbuffers(1, &depthRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderBuffer);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));

CheckOpenGLError();
share|improve this answer
    
I have got GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error. What could that mean? –  martin pilch Apr 25 '11 at 13:25
    
The problem is on the Mac not on iOS. –  martin pilch Apr 25 '11 at 13:32
    
and glGetRenderbufferParameteriv return width of framebuffer 0 and height 1072693248. This could be problem –  martin pilch Apr 25 '11 at 13:38
    
You are retrieveing the render buffer width and height before you create it. –  Adal Apr 25 '11 at 15:40
    
My bad... But this does not cause the error –  martin pilch Apr 25 '11 at 16:54
add comment
up vote 0 down vote accepted

Finally I have found the solution. It is necessary NOT to use renderbuffer. So I have to DELETE code to init renderbuffer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.