Depth Buffering State

Depth buffering is a method of removing hidden lines and surfaces. For a conceptual overview, see What are Depth Buffers?. By default, Direct3D does not use depth buffering. You can update the depth buffering state with the D3DRENDERSTATE_ZENABLE render state, using one of the members of the D3DZBUFFERTYPE enumeration to specify the new state value.

If, for some reason, your application needs to prevent Direct3D from writing to the depth buffer, it can use the D3DRENDERSTATE_ZWRITEENABLE enumerated value, specifying FALSE as the second parameter for the call to IDirect3DDevice3::SetRenderState.

The following code fragment shows how the depth buffer state is set to enable z-buffering:

// This code fragment assumes that lpD3DDevice3 is a valid pointer to
// a Direct3DDevice3.
 
// Enable z-buffering.
lpD3DDevice3->SetRenderState(D3DRENDERSTATE_ZENABLE, 
                             D3DZB_TRUE); // D3DZB_TRUE is the same as TRUE
 

Your application can also use the members of the D3DCMPFUNC enumerated type to select the comparison function that Direct3D uses when performing depth buffering. See D3DRENDERSTATE_ZFUNC.

Z-biasing is a method of displaying one surface in front of another even if their depth values are the same. You can use this technique for a variety of effects. A common example is rendering shadows on walls. Both the shadow and the wall have the same depth value. However, you want your application to show the shadow on the wall. Giving a z-bias to the shadow makes Direct3D display them properly (see D3DRENDERSTATE_ZBIAS).