Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GL_LEQUAL and GL_GEQUAL depth buffer test modes

102 views
Skip to first unread message

Antonio Calomeni

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to

Hi.

Maybe I'm misunderstanding some stuff here, but anyway, here it goes:

I used GL_LEQUAL as the depth testing func, which means that the
current pixel will be drawn if it's z is LESS or EQUAL to the z that's in
the depth buffer at the moment, at that position, right?

I reset all stuff... so the depth buffer is full with zero's.(right?)
I tested drawing a flat quad on the Y axis at z = -1.0f, using GL_GEQUAL and
it didn't work, and that makes sense, since GEQUAL the test is GREATER than
or EQUAL. Since -1.0f was less than the current depth buffer value, it was
skipped.

So I tested with LEQUAL, drawing a quad the same way at Z= -1.0f. And it
worked. Fine. -1.0f was LESS than the depth buffer values.
So, RIGHT BELOW the code that draws this previous square, I added code that
draws a quad the same way but at Z = -0.8f. So I thought: since the pixels
will be drawn if their z's are LESS than or EQUAL to the depth buffer, this
quad won't be draw, since it's z's are GREATER than the depth buffer's, now
full with -1.0f's.... But the quad appeared, in front of the previous one.
And now I can't understand why!

Thanks in advance.

Antonio Calomeni
calo...@unisys.com.br

Paul Martz

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to
Antonio Calomeni <calo...@unisys.com.br> wrote in message
news:38994908...@news.supernews.com...

> I used GL_LEQUAL as the depth testing func, which means that the
> current pixel will be drawn if it's z is LESS or EQUAL to the z that's in
> the depth buffer at the moment, at that position, right?

Good so far.

> I reset all stuff... so the depth buffer is full with zero's.(right?)

If you mean what happens when you clear the depth buffer,this depends on
what you have set glClearDepth to. By default, it's set to 1.0, which means
the maximum Z value is stored in the depth buffer. If you set it to 0, then
the minimum Z value is stored in the depth buffer.

The actual value stored in the depth buffer is device dependant, but OpenGL
maps the minimum to 0.0 and the maximum to 1.0. This is called the device
coordinate Z value.

> I tested drawing a flat quad on the Y axis at z = -1.0f, using GL_GEQUAL
and
> it didn't work, and that makes sense, since GEQUAL the test is GREATER
than
> or EQUAL. Since -1.0f was less than the current depth buffer value, it was
> skipped.

You have your coordinate spaces confused. It you draw a primitive at Z=-1.0,
specified in object space, it gets transformed down to device coordinate
space before it is written into the depth buffer. There are many reasons why
it might not be rendered, such as it was clipped by one of the clipping
planes, etc. Assuming it wasn't, my guess is that you cleared the depth
buffer to the maximum depth value (the default), and the device coordinate Z
value of your primitive was less than the maximum depth value, and since you
set GL_GEQUAL, it failed the depth test.

> So I tested with LEQUAL, drawing a quad the same way at Z= -1.0f. And it
> worked. Fine. -1.0f was LESS than the depth buffer values.

Rather, the transformed device coordinate Z of the primitive was less than
the stored maximum Z clear value.

> So, RIGHT BELOW the code that draws this previous square, I added code
that
> draws a quad the same way but at Z = -0.8f. So I thought: since the pixels
> will be drawn if their z's are LESS than or EQUAL to the depth buffer,
this
> quad won't be draw, since it's z's are GREATER than the depth buffer's,
now
> full with -1.0f's.... But the quad appeared, in front of the previous one.
> And now I can't understand why!

Assuming you have set up a normal viewing transform, a quad at object space
Z of -0.8 would be in front of a quad at Z=-1.0. Positive Z is towards the
eye. The resulting transformed device coordinate Z value would be less than
the Z of the previous quad. Objects closer to the eye have smaller depth
values. With test set to GL_LEQUAL, as you did, it is no surprise that this
quad passed the depth test.

You should read the red book chapter on transformations, it will be
enlightening for you.
--
-Paul Martz
Hewlett Packard Technical Solutions Lab
Remove DONTSPAM to reply

Antonio Calomeni

unread,
Feb 2, 2000, 3:00:00 AM2/2/00
to
On Tue, 1 Feb 2000 14:58:24 -0700, "Paul Martz" <ma...@DONTSPAMgplmail.fc.hp.com> wrote:


>
>Assuming you have set up a normal viewing transform, a quad at object space
>Z of -0.8 would be in front of a quad at Z=-1.0. Positive Z is towards the
>eye. The resulting transformed device coordinate Z value would be less than
>the Z of the previous quad. Objects closer to the eye have smaller depth
>values. With test set to GL_LEQUAL, as you did, it is no surprise that this
>quad passed the depth test.
>

So it's not a pure math comparison, like -0.8 isn't LESS than -1.0.
What we take into consideration is the pixel's depth. And since positive Z is toward the
user, coming out of the screen, this pixel at z=-0.8 has LESS depth than that one at
z=1.0f. So it passed the test.

>You should read the red book chapter on transformations, it will be
>enlightening for you.

I am. Thanks.

Paul Martz

unread,
Feb 2, 2000, 3:00:00 AM2/2/00
to
Antonio Calomeni <calo...@unisys.com.br> wrote in message
news:3897af1...@news.supernews.com...

> On Tue, 1 Feb 2000 14:58:24 -0700, "Paul Martz"
<ma...@DONTSPAMgplmail.fc.hp.com> wrote:
> So it's not a pure math comparison, like -0.8 isn't LESS than -1.0.

As I said before, you have your coordinate spaces confused. It *is* a pure
math comparison -- but it takes place in device coordinate space, not object
coordinate space.

> What we take into consideration is the pixel's depth.

Yes, in *device* coordinate space. The depth test is performed in device
coords.

> And since positive Z is toward the
> user,

True in *object* coordinate space. In device coordinate space, max Z is
furthest from the eye, and min Z is closest to the eye.

0 new messages