Microsoft DirectX 8.0 (Visual Basic)

What Is a Stencil Buffer?

The stencil buffer enables or disables drawing to the rendering target surface on a pixel-by-pixel basis. At its most fundamental level, it enables applications to mask sections of the rendered image so that they are not displayed. Applications often use stencil buffers for special effects such as dissolves, decaling, and outlining. For details, see Stencil Buffer Techniques.

Stencil buffer information is embedded in the z-buffer data. Your application can use Direct3D8.CheckDeviceFormat to check for hardware stencil support, 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_D24S8
If Err.Number <> D3D_OK Then 
    ' Handle the error.
End If

CheckDeviceFormat allows you to choose a device to create based on the capabilities of that device. In this case, devices that do not support 8-bit stencil buffers set Err.Number to an error value. Note that this is only one possible use for CheckDeviceFormat; for details see Determining Hardware Support.

To determine the stencil buffer limitations of a device, query the StencilCaps member of the D3DCAPS8 type for its supported stencil buffer operations.