Newbie FBO Completeness questions

Started by
3 comments, last by fcoelho 13 years, 10 months ago
Hi All -

I'm exploring FBO's, and I have a few questions about FBO completeness.

I started by setting up my render targets with RenderBuffers that were the same size as my Window. (1024x768, I'm working on Windows XP).

glGenFramebuffers( 1, &fbo_id );glBindFramebuffer( GL_FRAMEBUFFER, fbo_id );glGenRenderbuffers( 1, &depthbuf_id );glBindRenderbuffer( GL_RENDERBUFFER, depthbuf_id );glRenderbufferStorageMultisample( GL_RENDERBUFFER, 0, GL_DEPTH_COMPONENT, w, h );	glGenRenderbuffers( 1, &colorbuf_id );glBindRenderbuffer( GL_RENDERBUFFER, colorbuf_id );glRenderbufferStorageMultisample( GL_RENDERBUFFER, 0, GL_RGBA, w, h );glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuf_id );glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf_id );glBindFramebuffer( GL_FRAMEBUFFER, 0 ); //restore rendering to default framebuffer


This worked fine, no problems. I upped the Multisample values, and got some MSAA, lost some framerate, just as expected. Then I tried to use Textures instead of Render Buffers, and I'm getting FRAMEBUFFER_INCOMPLETE_ATTACHMENT errors.

glGenFramebuffers( 1, &fbo_id );glBindFramebuffer( GL_FRAMEBUFFER, fbo_id );glGenTextures( 1, &depthbuf_id );glBindTexture( GL_TEXTURE_2D, depthbuf_id );glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, w, h, 0, GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE, 0 );glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthbuf_id, 0 );printf("%x\n", glCheckFramebufferStatus( GL_FRAMEBUFFER )); //INCOMPLETE_ATTACHMENTglGenTextures( 1, &colorbuf_id );glBindTexture( GL_TEXTURE_2D, colorbuf_id );glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf_id, 0 );printf("%x\n", glCheckFramebufferStatus( GL_FRAMEBUFFER )); //INCOMPLETE_ATTACHMENT


I'm running on a rather old (but not ancient) GeForce 8400M GS. I have a recent driver which is telling me I support OGL 3.2. It also tells me that I support GL_ARB_framebuffer_object (as opposed to GL_EXT_framebuffer_object)

I first thought that it might be a power of two problem, my first attempt used TEXTURE_RECTANGLE as the target. My driver advertises that I support GL_ARB_texture_rectangle, and GL_ARB_texture_non_power_of_two. I also read atthe Khronos website that the supported color formats for "Color attachable images" were very limited (like GL_RGBA4), which is just confusing to me (after all, isn't the color renderbuffer in my top example a "color attachable image"?) Also, that doesn't line up with this really old NVidia presentation.

So, basically, I'm left thinking that I'm just missing some obvious step, and I'm looking in all the wrong places for the mistake. Does anyone with better eyes than me see a problem?

One other quick thing I changed - when I started messing with the FBO code, I removed the depth buffer from my Window PixelFormatDescriptor - I figured that at the end of my post processing, I would just blit the output to the main window, so depth wouldn't be necessary.

Anyhow, thanks for any help!
...
Advertisement
try changing this line:
glRenderbufferStorageMultisample( GL_RENDERBUFFER, 0, GL_DEPTH_COMPONENT, w, h );
to
glRenderbufferStorage( GL_RENDERBUFFER, 0, GL_DEPTH_COMPONENT, w, h );

One other thing you might want to do, easiest and definately a must if the above doesnt work.
Create a simple global method:

glCheckError() { assert(glGetError() == GL_NO_ERROR); }

and call this after every gl* function call - obviously you can remove them when you find the problem, but I usually keep em.

-Danu

EDIT: just noticed you're not setting your textures filtering options, this is more likely to be the culprit

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

place those just after you call glTexImage2D..
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Your problem is that you aren't setting the MIN/MAG filters, set them to something like NEAREST or LINEAR, and it will work.

Also, about GL_RGBA4, you're looking at OpenGL ES documentation, and you're using OpenGL (also called Desktop OpenGL), both aren't the same.
Awesome! Thanks guys!

The min/mag filters were in fact the problem! That's weird. For some reason, I thought OGL would choose good defaults for me. I haven't looked at my texture code in years, and given all the extensions complexity, I probably should have known better.

@silvermace - Good call on the GLError checking. I should have been more vigilant about that.

@Huntsman - I should also have my eyes checked on the path for that Khronos stuff. It was in fact OGL ES. Thanks for the heads up!

Rate++ for both you guys :)
...
Quote:I thought OGL would choose good defaults for me.

It actually does. Its just that the defaults for MIN/MAG_FILTER are GL_MIPMAP_NEAREST_LINEAR/GL_LINEAR, and since you don't generate mipmaps the textures are incomplete, causing the FBO to be attachment incomplete.

This topic is closed to new replies.

Advertisement