Share via


Creating a Direct3D Mobile Device

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

Once your application has determined which device types are available on its host hardware it can create an actual device. A call to the IDirect3DMobile::CreateDevice method will instantiate an object for the device and return an IDirect3DMobileDevice interface for it.

As part of the call to IDirect3DMobile::CreateDevice the application must specify a valid window handle that will be the focus for Direct3D Mobile operations until the device is destroyed. This device creation call also establishes the threading behavior for the device.

By default, Microsoft® Direct3D® Mobile is capable of synchronizing access to its data structures such that multiple threads in the application can access Direct3D Mobile concurrently. You can turn off this default behavior to achieve better performance in your application if your application is not multithreaded or if your application provides its own synchronization.

The other variable that an application provides is a pointer to a D3DMPRESENT_PARAMETERS structure. This structure defines the behavior of the swap chain that is implicitly created when the device is created.

Note

All rendering devices created by a given Direct3D Mobile object share the same physical resources. Although your application can create multiple rendering devices from a single Direct3DMobile object, because they share the same hardware, your application will incur extreme performance penalties.

To create a Direct3D Mobile device, your application must first create a Direct3DMobile object, as explained in Direct3DMobile Object.

First, initialize values for the D3DMPRESENT_PARAMETERS structure that is used to create the Direct3D device. The following code example shows a windowed application where the back buffer is flipped to the front buffer on VSYNC only.

LPDIRECT3DMOBILEDEVICE d3dmDevice = NULL;

D3DMPRESENT_PARAMETERS d3dmpp; 

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

Next, create the Direct3D Mobile device. The following IDirect3DMobile::CreateDevice call specifies the default adapter, the default device, and support for multithreading.

if( FAILED( g_pD3DM->CreateDevice( D3DADAPTER_DEFAULT,
                                   D3DDEVTYPE_DEFAULT, hWnd,
                                   D3DMCREATE_MULTITHREADED,
                                   &d3dmpp, &d3dmDevice ) ) )
    return E_FAIL;

Note that a call to create, release, or reset the device should happen only on the same thread as the window procedure of the focus window.

After creating the device, set its state.

See Also

Concepts

Using Devices