Microsoft DirectX 8.1 (C++) |
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® for the display device that your application will use before you create a Direct3D device. If the Direct3D object reports that it supports depth buffering, any hardware devices you create from this Direct3D object will support z-buffering.
To query for depth buffering support, you can use the IDirect3D8::CheckDeviceFormat method, as shown in the following code example.
// The following example assumes that pCaps is a valid pointer to an // initialized D3DCAPS8 structure. if( FAILED( m_pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType, Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ) ) ) return E_FAIL;
CheckDeviceFormat allows 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 IDirect3D8::CheckDepthStencilMatch to 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 CheckDepthStencilMatch to determine depth-stencil compatibility with a render target is illustrated in the following code example.
// 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_pD3D->CheckDepthStencilMatch( pCaps->AdapterOrdinal, pCaps->DeviceType, AdapterFormat, RTFormat, D3DFMT_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 rasterizer, 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.