In OpenGL, what is the difference between GL_DEPTH_COMPONENT and GL_DEPTH_STENCIL? I have looked around and have been unable to find a clear explanation.

Information on their usage with GLSL would also be appreciated (mainly DEPTH_STENCIL).

Thanks for any help.

  • \$\begingroup\$ Do you require an explanation of the stencil itself or just these constants? \$\endgroup\$
    – Jon
    Commented Apr 24, 2015 at 8:42
  • \$\begingroup\$ I'd like to know if it possible to use it with GLSL samplers? Currently I access depth using the r channel, and want to know if the stencil can be used through the alpha channel. \$\endgroup\$
    – Cimera42
    Commented Apr 24, 2015 at 10:05
  • \$\begingroup\$ Also, do you have to use glStencilMask, or can the value of the stencil be set directly through shader output? \$\endgroup\$
    – Cimera42
    Commented Apr 24, 2015 at 10:09
  • \$\begingroup\$ The stencil is not explicitly readable or writable. Instead, it can be configured to track a number of "statistics" about all draw() calls since clear() (configured for writes) and/or "filter" the pixels that are affected by all future draw() calls (configured for reads). \$\endgroup\$
    – Jon
    Commented Apr 24, 2015 at 10:11
  • \$\begingroup\$ This has a few examples explained \$\endgroup\$
    – Jon
    Commented Apr 24, 2015 at 10:14

1 Answer 1


It is typical to use a 32-bit depth-buffer:

GL_DEPTH_COMPONENT32F //internal format
GL_DEPTH_COMPONENT    //depth only
GL_FLOAT              //float(32-bit depth)

If you also wish to utilize the stencil buffer, it is typical to dedicate 8 of those 32-bits to the stencil:

GL_DEPTH24_STENCIL8   //internal format
GL_DEPTH_STENCIL      //depth + stencil
GL_UNSIGNED_INT_24_8  //ushort(24-bit depth) + uchar(stencil)

If you require 32-bit precision for depth, but also require the stencil:

GL_DEPTH32F_STENCIL8               //internal format
GL_DEPTH_STENCIL                   //depth + stencil
GL_FLOAT_32_UNSIGNED_INT_24_8_REV  //float(32-bit depth) + ushort(spare) + uchar(stencil)

Refer to the last chart under "Description".

Stencil diagram:

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .