Microsoft DirectX 8.1 (Visual Basic) |
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 Direct3D8.CheckDeviceFormat method, as shown in the following code example.
' The following example assumes that g_D3D, AdapterOrdinal, ' DeviceType, and Format are properly initialized values. g_D3D.CheckDeviceFormat AdapterOrdinal, DeviceType, Format, _ D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, _ D3DFMT_D16
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 Direct3D8.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.
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.