Search code examples
openglopengl-4stencilsopengl-extensions

How to utilize GL_ARB_stencil_texturing


From what I've read, to sample the stencil texture in the shader I need to set the GL_DEPTH_STENCIL_TEXTURE_MODE, so I did this:

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_COMPONENTS);

but I get an invalid enum... Why would that be?


Solution

  • According to the man page, the correct enum value for this call would be GL_STENCIL_COMPONENT, not GL_STENCIL_COMPONENTS (note the trailing S).

    As it turns out, the man page is wrong. Which unfortunately is not unusual. If you look it up in the spec (e.g. table 8.17 on page 225 in the OpenGL 4.5 spec document), the valid values for DEPTH_STENCIL_TEXTURE_MODE are GL_DEPTH_COMPONENT and GL_STENCIL_INDEX.

    Based on this, the call should be:

    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
    

    This feature requires OpenGL 4.3 or higher.

    GL_STENCIL_COMPONENTS is a valid argument for glGetInternvalFormativ(), but not for glTexParameteri().