Sign in to follow this  
ZaiPpA

Can GPU programs read/write to the stencil buffer?

Recommended Posts

ZaiPpA    122
Hi. I'm doing a small post-processing effects framework, and i would like it to be as general as possible (that's funnier, i'll learn more and i can do more effects). So far i can ping-pong with the color and depth buffers (using FBOs). I'm wondering if i could include the stencil buffer in my framework as well. It seems like shaders can't really access the buffer. I must admit that i haven't really used stencil buffers before, so i'm sorry if my question shows this. :) So my questions:
  • can fragment programs write to the stencil buffer at all? (i looked at the Cg info and found nothing and there is no STENCIL semantic. GLSL perhaps?)
  • if they can't write directly to the stencil buffer, can they affect the values of the buffer indirectly somehow?
  • can fragment programs read from the stencil buffer?
Thanx for any pointers!

Share this post


Link to post
Share on other sites
dpadam450    2357
My guess is that its not programmable. If you enable stencil testing and set it up in your application, it will happen before or after the shader.

As for reading from the buffer, you could try glCopyTexImage with some kind of GL_STENCIL_BITS flag or something.

Share this post


Link to post
Share on other sites
oc2k1    138
Reading/writing is not possible. The number of depth/stencil samples can be different to the number of fragments if a MSAA mode is used. The best idea would be to render into a color rendertarget and copy the rendered image with a PBO to the stencilbuffer.

Share this post


Link to post
Share on other sites
ZaiPpA    122
Hi, sorry for late reply. Thanks for your replies! Glad to finally be sure the stencil buffer can't be accessed from fragment programs :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this