Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

As with any feature, the driver that your application uses might not support all types of depth buffering. Always check the driver's capabilities. Although most drivers support z-based depth buffering, not all will support w-based depth buffering. Drivers do not fail if you attempt to enable an unsupported scheme. They fall back on another depth buffering method instead, or sometimes disable depth buffering altogether, which can result in scenes rendered with extreme depth-sorting artifacts.

You can check for general support for depth buffers by querying Microsoft® Direct3D® Mobile for the display device that your application will use before you create a Direct3D Mobile device. If the Direct3DMobile object reports that it supports depth buffering, any hardware devices you create from this Direct3DMobile object will support z-buffering.

To query for depth buffering support, you can use the IDirect3DMobile::CheckDeviceFormatmethod, as shown in the following code example.

Copy Code
// The following example assumes that pCaps is a valid pointer to
an 
// initialized D3DMCAPS structure.
	if( FAILED( m_pD3DM->CheckDeviceFormat(
pCaps->AdapterOrdinal, 
											pCaps->DeviceType,
Format, 
											0, 
										 
D3DMRTYPEFLAG_DEPTHSTENCIL,
											D3DMFMT_D16 ) ) )
		return E_FAIL;

CheckDeviceFormatallows you to choose a device to create based on the capabilities of that device. In this case, devices that do not support 16-bit depth buffers are rejected.

In addition, you can use IDirect3DMobile::CheckDepthStencilMatchto determine whether a supported depth-stencil format is compatible with the render target format in the display mode, particularly if a depth format must be equal to the render target format.

Using CheckDepthStencilMatchto determine depth-stencil compatibility with a render target is shown in the following code example.

Copy Code
// Reject devices that cannot create a render target of RTFormat
while
// the back buffer is of RTFormat and the depth-stencil buffer is
// at least 8 bits of stencil.
if( FAILED( m_pD3DM->CheckDepthStencilMatch(
pCaps->AdapterOrdinal,
											 pCaps->DeviceType, 
											 AdapterFormat, 
											 RTFormat, 
											 D3DMFMT_D24S8 ) ) )
		return E_FAIL;

Once you know that the driver supports depth buffers, you can verify w-buffer support. Although depth buffers are supported for all software rasterizers, w-buffers are supported only by the reference driver, which is not suited for use by real-world applications. Regardless of the type of device your application uses, verify support for w-buffers before you attempt to enable w-based depth buffering.

To determine support for w-buffers
  1. After creating your device, call the IDirect3DMobileDevice::GetDeviceCapsmethod, passing an initialized D3DMCAPSstructure.

  2. After the call, the LineCapsmember contains information about the driver's support for rendering primitives.

  3. If the RasterCapsmember of this structure contains the D3DMPRASTERCAPS_WBUFFER flag (see D3DMPRASTERCAPS Values), then the driver supports w-based depth buffering for that primitive type.

For general information about depth buffering, see Depth Buffers.

See Also