Question

I need both a stencil and depth buffer for my OpenGL app. The depth buffer at least needs to be rendered to texture via a framebuffer object, so that I can do deferred shading and other post-processing effects. I already have this framebuffer set up (using GL_DEPTH24_STENCIL8), but I have some concerns and questions.

First, I would like to use a 32-bit floating-point depth buffer. The GL_DEPTH32F_STENCIL8 option seems to be the most obvious. What I would like to know is, what is the actual memory footprint of this format? Logically it would be 40 bits, but knowing what I do about alignment, it wouldn't surprise me if they padded it to 64, and many sources say that's exactly what happens. I would like to know for sure.

Perhaps keeping the depth and stencil buffers separate would be better for me? Do I have to worry about this not being supported? How about cache efficiency, as stencil and depth tests are often performed together?

PS. I'm not using multisampling.

Was it helpful?

Solution

GL_DEPTH32F_STENCIL8 is a 64-bit format; 32-bit for depth, 8-bit for stencil and 24-bit for alignment.

Sometimes knowing both of the desktop graphics APIs comes in handy, as this is the same format that was added to D3D10. D3D makes the size of its formats much easier to grasp just by looking at their name.

In D3D, the format is known as DXGI_FORMAT_D32_FLOAT_S8X24_UINT:

   D32_FLOAT indicates that it stores 32-bit depth (floating-point)

   S8X24_UINT indicates that it stores 8-bit stencil + 24-bit unused (unsigned integer)

D3D is nice in that formats explicitly announce when there are unused bits for the purpose of padding (this is what Xn in a format indicates). There is no color-renderable 8-bit RGB format in D3D because that messes with alignment; they are all RGBX or some permutation of the 4 in order to produce a 32-bit pixel.


To give you an authoritative answer I will refer you to the extension which first added this format to GL:

GL_ARB_depth_buffer_float

Overview

[...]

Additionally, this extension provides new packed depth/stencil pixel formats (see EXT_packed_depth_stencil) that have 64-bit pixels consisting of a 32-bit floating-point depth value, 8 bits of stencil, and 24 unused bits. A packed depth/stencil texture internal format is also provided.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top