Bug 4395 - Depth Buffer Clearing
Summary: Depth Buffer Clearing
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: x86 (IA32) Windows (All)
: high major
Assignee: mesa-dev
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-08 04:05 UTC by Roy Walmsley
Modified: 2009-08-24 12:23 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Roy Walmsley 2005-09-08 04:05:00 UTC
In framebuffer.c line 66 the _DepthMaxF member of the frame buffer is 
calculated for a 32 bit depth by converting the integer 0xffffffff to float. 
The correct answer is 4294967295.0 However on MSVC (version 6) with float 
storage this is rounded to 4.29497e9.

Subsequently on clearing the depth buffer in the file s_depth.c line 1282 the 
_DepthMaxF is read, multiplied by ctx->Depth.Clear (which is 1.0 in my case) 
and then converted back to unsigned integer. The result is 0x00000000. 
Consequently the buffer is cleared to zero and all drawing involving depth 
testing fails the depth test and therefore no rendering takes place.

This happens because of the rounding that occurred in the original setup of the 
_DepthMaxF member.

I verified this by expanding the line 1282 of s_depth.c as follows:

GLuint tmpClearValue1 = ((GLuint) ctx->Depth.Clear) * ctx->DrawBuffer-
>_DepthMax;
GLuint tmpClearValue2 = (GLuint) (ctx->Depth.clear * ctx->DrawBuffer-
>_DepthMaxF);
const GLuint clearValue = tmpClearValue2 == 0 && tmpClearValue1 > 0 ? 
tmpClearValue1 : tmpClearValue2;

This checks for the overflow situation occurring and provides the correct value 
of 0xffffffff for the clear value in that situation. Rendering then correctly 
takes place.
Comment 1 Brian Paul 2005-09-08 06:57:25 UTC
Since ctx->Depth.Clear is almost always one, it's better to check for that value
and use the integer depthMax value as-is.  Use the float value otherwise.
I've checked in this fix.
Comment 2 Adam Jackson 2009-08-24 12:23:24 UTC
Mass version move, cvs -> git


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.