Sign in to follow this  

Stencil buffer and FBO

Recommended Posts

ok, as I play with FBO, I see that (atleast) nVidia hardware does not do stencil buffer in FBO, but I _NEED_ the stencil buffer.. now my question: how can I get stenciling to work with an FBO system? I use the stencil buffer a great deal to mark regions to draw or to not to draw... what to do?

Share this post

Link to post
Share on other sites
this is what I have read, so I though to do that, I would do this:

glGenTextures(1, &stencil_depth_tex);
glBindTexture(GL_TEXTURE_2D, stencil_depth_tex);
glTexImage2D(GL_TEXTURE_2D, 0, //target and mipmap level
width, height, //size of texture
0, //border size
GL_DEPTH_STENCIL_EXT, //format of of data we are uploading to to the texture (ignored)
GL_UNSIGNED_INT_24_8_EXT, //type of of data we are uploading to to the texture (ignored)
NULL //no data uploaded
//attatch the depth/stencil texture to both the stencil and depth render objects.
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, stencil_depth_tex, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, stencil_depth_tex, 0);

now, when I use my FBO (together with some color texture buffers) I get GL_FRAMEBUFFER_UNSUPPORTED_EXT for the return value from glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT).. my hardware is nVidia GeForce6600GT.. also have my code setup to call glGetError after every gl call which is not in a glBegin/glEnd pair, and I get the openGL error GL_INVALID_FRAMEBUFFER_OPERATION_EXT on a glPopAtrrib after I unbind my FBO...

am I using the depth_stencil texture incorrectly to attach it to both the stencil and depth buffers of the FBO? I have not seen an explicit example sing GL_packed_depth_stencil extension with FBO...

note: if I replace the junk of the above with

//generate the depth render buffer
glGenRenderbuffersEXT(1, &depth_rbo);
//bind the render buffer so we can manipulate it.
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rbo);
//allocate the necessary room for it as a depth buffer.
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
//attach it to the framebuffer obeject.

the FBO works just dandy... nay help would be most appreciated.

Share this post

Link to post
Share on other sites
I though of doing an edit, but I figued the solution would be best in a seperate post. This solved the problem:

adding the line


before specifying the depth_stencil_texture made it work just fine, my guess is that for some reason, the FBO path in the driver freaks out if mipmaps are needed in a depth_stencil texture, but I do not see *why* since the I am writing to mip map level 0.. oh well... I am not even trying to look at them either....

atleast that is sorted out :)

[Edited by - kRogue on June 9, 2007 3:38:55 PM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this