Share via


Creating a Depth Buffer (Windows Embedded CE 6.0)

1/6/2010

A depth buffer is a property of the device. To create a depth buffer that is managed by Microsoft® Direct3D® Mobile, set the appropriate members of the D3DMPRESENT_PARAMETERS structure as shown in the following code example.

    D3DMPRESENT_PARAMETERS d3dmpp; 

    ZeroMemory( &d3dmpp, sizeof(d3dmpp) );
    d3dmpp.Windowed               = TRUE;
    d3dmpp.SwapEffect             = D3DMSWAPEFFECT_COPY_VSYNC;
    d3dmpp.EnableAutoDepthStencil = TRUE;
    d3dmpp.AutoDepthStencilFormat = D3DMFMT_D16;

By setting the EnableAutoDepthStencil member to TRUE, you instruct Direct3D Mobile to manage depth buffers for the application. Note that AutoDepthStencilFormat must be set to a valid depth buffer format. The D3DMFMT_D16 flag specifies a 16-bit depth buffer, if one is available.

The following call to the IDirect3DMobile::CreateDevice method creates a device that then creates a depth buffer.

if( FAILED( g_pD3DM->CreateDevice( D3DMADAPTER_DEFAULT,
                                   D3DMDEVTYPE_HAL, hWnd,
                                   D3DMCREATE_MULTITHREADED,
                                   &d3dpp, &d3dDevice ) ) )
    return E_FAIL;

The depth buffer is automatically set as the render target of the device. When the device is reset, the depth buffer is automatically destroyed and recreated in the new size.

To create a new depth buffer surface, use the IDirect3DMobileDevice::CreateDepthStencilSurface method.

To set a new depth-buffer surface for the device, use the IDirect3DMobileDevice::SetRenderTarget method.

To use the depth buffer in your application, you need to enable the depth buffer. For details, see Enabling Depth Buffering.

See Also

Concepts

Depth Buffers