Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rendering the depth buffer to screen


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 03 January 2014 - 02:00 PM

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? 



Sponsor:

#2 richardurich   Members   -  Reputation: 1187

Like
1Likes
Like

Posted 03 January 2014 - 03:08 PM

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.



#3 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 03 January 2014 - 03:52 PM

I use both, but I only want the depth component from the combined buffer, is that not possible to get?



#4 richardurich   Members   -  Reputation: 1187

Like
1Likes
Like

Posted 03 January 2014 - 09:11 PM

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.



#5 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 04 January 2014 - 05:16 AM

Just curious, the stencil component is then accessed using .y?



#6 richardurich   Members   -  Reputation: 1187

Like
1Likes
Like

Posted 04 January 2014 - 08:50 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS