Jump to content
  • Advertisement
Sign in to follow this  
KaiserJohan

OpenGL Rendering the depth buffer to screen

This topic is 2118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using OpenGl 4.3 deferred renderer and I've setup my depth buffer for my FBO as following:

 

GLCALL(glGenRenderbuffers(1, &mDepthbuffer));
GLCALL(glBindRenderbuffer(GL_RENDERBUFFER, mDepthbuffer));
GLCALL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_DEPTH32F_STENCIL8, windowWidth, windowHeight));
GLCALL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mDepthbuffer));
GLCALL(glBindRenderbuffer(GL_RENDERBUFFER, 0));

 

When I debug normals, positions, etc I can just set that color attachments using glReadBuffer and then glBlitFramebuffer to the default FBO. But the depth buffer is a DEPTH_STENCIL Renderbuffer - what is the best way of getting its contents to the screen? 

Share this post


Link to post
Share on other sites
Advertisement

http://www.geeks3d.com/20091216/geexlab-how-to-visualize-the-depth-buffer-in-glsl/ seems like what you want.

 

If you need generic access, you can read depth buffer with glReadPixels. You can also do PBO juggling if you need better performance than glReadPixels.

 

And just to make sure you're not mixing the two, GL_DEPTH_COMPONENT is depth buffer while GL_DEPTH_STENCIL is both the depth and stencil buffer.

Share this post


Link to post
Share on other sites

It's fine to use both. You'll most likely deal with GL_DEPTH24_STENCIL8 format. You can access the depth component with .x (xyzw) or .r (rgba). Nothing real complicated, so I'm sure you'll be fine. Just remember it's 0..1 and not -1..1.

Share this post


Link to post
Share on other sites

This answer is going to assume you're going to be using textures, which appears to be the preferred method going forward (OpenGL now requires support in 4.4).

 

You can't access both depth and stencil information from the same sampler since stencil is 8-bit unsigned int, and depth is 24-bit float. A texture can't have 2 formats like that. For stencil information, you'll be using a usampler* (unsigned) and GL_STENCIL_INDEX. For depth, you'll use a sampler* and GL_DEPTH_COMPONENT. The stencil data is in the last 8-bit component, so the A of RGBA.

 

You can use ARB_stencil_texturing if you don't have OpenGL 4.4. Unless absolutely necessary, I wouldn't bother learning older methods. Be sure to make 2 copies of the texture (or 2 views) since you can't have both formats on the same texture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!