A simple Stencil Buffer Question

I would like to know; is the stencil test (as determined by glStencilFunc() ) performed:

(a) over the entire window or
(b) ONLY in portion of the window actually occupied by fragmnents ?

Originally posted by Olumide:
[b]I would like to know; is the stencil test (as determined by glStencilFunc() ) performed:

(a) over the entire window or
(b) ONLY in portion of the window actually occupied by fragmnents ?

[/b]

Fragments?? The stencil buffer test applies all over the drawing rectangle (this is the window surface)

If this is so (and I dont mean to be cheeky) why are they called per-fragment operations? … :-{8

Because they’re applied to all fragments generated by OpengGL. A fragment is basically a bundle of state used to update one (or more if youre multisampling) pixel in the framebuffer. The test is applied when you generate fragments by drawing stuff with OpenGL so it is valid everywhere. However, anything drawn when the stencil test wasn’t enabled will not be affected if you suddenly enable it. Did that clear things up?

So your answer is (a)! … That would mean the calls

glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
Draw_Anything();

Writes the value 1 to the ENTIRE Stencil Buffer (i.e to the extent of the drawing window) regardless of the fact that the fragments generated by Draw_Anything() do not cover the window!?!

perhaps u should state what u want to use stencil for?
perhaps this ie one example of stencil?
A/clear stencil (stencil 0)
B/enable stencil writes
C/draw polygons (stencil values get 1)

D/ read back the screen seeing how many 1’s in stencil buffer (ie how many pixels were writen)
or
D/ enable stencil testing so that the next polygons will get drawn only if stencil is set to 1 (only draw to a certain region)
or
D/ enable stencil testing so that the next polygons will get drawn only if stencil is set to 0 (zero overdraw)

Originally posted by Olumide:
[b]

Writes the value 1 to the ENTIRE Stencil Buffer (i.e to the extent of the drawing window) regardless of the fact that the fragments generated by Draw_Anything() do not cover the window!?![/b]

No, fragments are generated when you render a primitive. Those fragments go through the stencil test and they either fail or pass. So that means the entire window (opengl surface) is not tested against, only where rasterization may occur. This is similar to a z-buffer test, or even rendering a triangle.

If you render a triangle, and the triangle only occupies a section of your window, that area is painted, and not the entire window!!!

V-man