PDA

View Full Version : FBO: depth buffer as texture



supagu
06-17-2005, 07:46 PM
im wanting to do shadow mapping with some Cg.

now i've got an FBO set up with colour (just so i can see the thing) and a depth buffer, the depth buffer is 24bit, is there some way i can use the depth buffer as a texture? and will i be able to grab float values from it? ie. can i treat it as a float texture?

alternatively should i encode the depths in my colour texture? can you encode a float as RGBA somehow?

Overmind
06-18-2005, 12:10 AM
Just bind a depth texture instead of a depth renderbuffer to the FBO.

supagu
06-18-2005, 01:30 AM
okay, i tried just this:


glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, texture, 0);

but gives me the FBO error: unsupported format

ie. similar problem as this fellow:
http://www.flipcode.com/cgi-bin/fcmsg.cgi?thread_show=25864&msg=205080

i have a geforce 6600gt

Overmind
06-18-2005, 05:23 AM
Have you disabled mipmapping? Try setting both filters to NEAREST, afaik mipmapping is not supported with depth textures...

supagu
06-18-2005, 08:32 PM
hrmm okay im getting another error when i set filtering to nearest saying:

frame buffer incomplete, missing read buffer.

not sure what this means?

supagu
06-19-2005, 02:10 AM
okay, i worked it out, i need to have a texture bound with GL_COLOR_ATTACHMENT0_EXT even though i dont want to render colour, which is a bit annoying, as i assume i would be loosing performance there.

Mazy
06-19-2005, 02:37 AM
Have you set the read and drawBuffer to gl_none?

arekkusu
06-19-2005, 07:27 AM
Please re-read section 4.4.4.2 of the spec. (http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt) See also example code (7), "Render to depth texture with no color attachments."