PDA

View Full Version : How to read stencil buffer in glsl?



andychen
07-14-2014, 05:16 AM
I have two questions about using stencil buffer:
(1) How can I read stencil buffer in glsl?
(2) If (1) is possible, should I bind it as a texture ? How to do it?

Thanks!

Agent D
07-14-2014, 08:48 AM
If you render to an FBO, you can always bind a depth/stencil or stencil only target and after the FBO pass is done bind the
stencil texture as a regular texture and read from it.

Reading from the stencil buffer you are rendering to is AFAIK not possible, as stencil testing (as well as depth testing and blending)
is done on the result of the fragment shader, after the fragment shader for the given fragment has been executed.