PDA

View Full Version : A simple Stencil Buffer Question



Olumide
04-08-2002, 04:57 AM
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 ?

04-08-2002, 07:59 AM
Originally posted by Olumide:
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 ?



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

Olumide
04-08-2002, 08:56 AM
If this is so (and I dont mean to be cheeky) why are they called per-fragment operations? ... :-{8

harsman
04-08-2002, 09:23 AM
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?

Olumide
04-08-2002, 10:11 AM
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!?!

zed
04-08-2002, 11:12 AM
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)

V-man
04-08-2002, 03:32 PM
Originally posted by Olumide:


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

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