Render to depth texture

  • Follow


Hi,

I'm using OpenGL FBO's to render into. I used to just use a depth 
renderbuffer, and if multisampled I used this (which works):

glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples,GL_DEPTH24_STENCIL8_EXT,width,height);

My goal is to make the depthbuffer available as a texture in 
postprocessing Cg shaders. So I have to rewrite the above to use 
textures. Not using multisampling I use this (which also works):

     // Create texture
     glGenTextures(1,&texDepth);
     glBindTexture(GL_TEXTURE_2D,texDepth);
     if(flags&CREATE_STENCIL_BUFFER)
     {
       // Depth+stencil packed
       glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, width, 
height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
     } else
     {
       // Just depth
       glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, 
height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
     }
     glTexParameterf(...);
     // And attach it to the FBO so depth renders into this texture
     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texDepth, 0);
     if(flags&CREATE_STENCIL_BUFFER)
     {
       // Add stencil as well
       glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, texDepth, 0);
     }

However, when trying to multisample, I get a black screen. Should I use 
glTexImage2DMultiSample() or something? Anyone knows of a tutorial on 
setting up a multisample FBO where the depth buffer is a texture? 
(instead of just a renderbuffer)

Thanks,
Ruud

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
0
Reply Ruud 1/20/2010 11:48:08 AM

Ruud van Gaal wrote:
> I'm using OpenGL FBO's to render into. I used to just use a depth 
> renderbuffer, and if multisampled I used this (which works):
> 
> glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,samples,GL_DEPTH24_STENCIL8_EXT,width,height); 
> 
> My goal is to make the depthbuffer available as a texture in 
> postprocessing Cg shaders. So I have to rewrite the above to use 
> textures. Not using multisampling I use this (which also works):
....

>     // And attach it to the FBO so depth renders into this texture
>     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
> GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texDepth, 0);
....

> However, when trying to multisample, I get a black screen. Should I use 
> glTexImage2DMultiSample() or something?

I've been working on it a bit (beginning to sound like Skybuck! ;-) ) 
and I made a workaround by using the old renderbuffer approach for the 
multi-sample FBO, and only creating textures for the downsampled 
(anti-aliased) FBO.
It does mean my blit command now include depth buffer (small performance 
hit, 140 vs 128 fps):

glBlitFramebufferEXT(0,0,width,height,0,0,width,height,GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT,GL_NEAREST);

Is there a better way to get access to the depth buffer?

Thanks,
Ruud

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
0
Reply Ruud 1/20/2010 2:35:38 PM


On Jan 20, 3:35=A0pm, Ruud van Gaal <r...@racer.nl> wrote:
> glBlitFramebufferEXT(0,0,width,height,0,0,width,height,GL_COLOR_BUFFER_BI=
T|GL_DEPTH_BUFFER_BIT,GL_NEAREST);
>
> Is there a better way to get access to the depth buffer?
>

Probably not. I haven't used the depth buffer like
this but everything I've done with mutisample
buffers needed me to explicitly downsample the buffer
before I could access the contents.

(Which makes sense - the definition of multisample
 is multiple values per pixel)


--
<\___/>
/ O O \
\_____/  FTB.

http://www.topaz3d.com/  - New 3D editor for real time simulation
0
Reply fungus 1/22/2010 12:46:52 AM

2 Replies
946 Views

(page loaded in 0.054 seconds)

Similiar Articles:













7/23/2012 6:46:13 AM


Reply: