quick copy of stencil to color

It looks like there is no efficient way to do this. No extensions to help?
I would have to do glReadPixels?

GL_NV_copy_depth_to_color comes close, but I would like to copy stencil to a texture.

GL_ARB_depth_texture has the right idea but GL_ARB_any_texture would be more valuable.

Maybe you can try to use stencil test to control your content in the dst alpha plane. Then copy it to a texture.

That’s one trick but it is limited.

If depth test fails then you cant modify the color buffers but you can do whatever you want with the stencil.

Do you have a way to make a exact copy of a 8 bit stencil into an 8 bit alpha?

>>If depth test fails then you cant modify the color buffers but you can do whatever you want with the stencil.

That’s true.

>>Do you have a way to make a exact copy of a 8 bit stencil into an 8 bit alpha?

Once I used logic_op to write to different bitfields in the dst alpha plane. I don’t know if it fits your need.

Originally posted by V-man:
[b]That’s one trick but it is limited.

If depth test fails then you cant modify the color buffers but you can do whatever you want with the stencil.

Do you have a way to make a exact copy of a 8 bit stencil into an 8 bit alpha?[/b]

It may possible to this in 8 passes.
Clear the color buffer, and use glBend with each stencil bit with the color values 128, 64, 32…
Or I’m wrong?

I was thinking about this. It sounds nasty because of the number of passes but should work.

Inet, is this what you ment by logic_op?

What I mean is something like this:

glLogicOp(GL_OR);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE);
glColor4ub(0,0,0,(1<<i)); //here encode what u want to set.
glEnable(GL_COLOR_LOGIC_OP);
DrawScreenQuad();
glDisable(GL_COLOR_LOGIC_OP);

By the way, just curious, what do u want to do with this stencil-buffer-to-texture copying?

I was considering this for doing a feedback trick.