Sign in to follow this  

Can GPU programs read/write to the stencil buffer?

This topic is 3663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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

This topic is 3663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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