Depth-Stencil Textures

Instead of an image, a texture can hold depth and stencil values, one of each per texel, using the texture format GL_DEPTH_STENCIL. This is the typical way a framebuffer will store the rendered z component for depth and the stencil value, as discussed in detail in Chapter 4, “Color, Pixels, and Framebuffers”. When texturing from a depth-stencil texture, by default a shader will read the depth. However, as of version 4.3, a shader can also read the stencil value. To do so, the application must set GL_DEPTH_STENCIL_TEXTURE_MODE to GL_STENCIL_COMPONENTS and the shader must use an integer sampler type.

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.