Direct3D Device Objects

You can create a Direct3D device object by calling the IDirectDrawSurface::QueryInterface method for a backbuffer surface. The following example calls the IDirectDraw::CreateSurface and IDirectDrawSurface::GetAttachedSurface methods to retrieve the backbuffer surface.

lpDirectDraw->CreateSurface(

lpDDSurfDesc, // Address of a DDSURFACEDESC structure

lpFrontBuffer, // Address of a DIRECTDRAWSURFACE structure

pUnkOuter); // NULL

lpFrontBuffer->GetAttachedSurface(

&ddscaps, // Address of a DDSCAPS structure

&lpBackBuffer); // Address of a DIRECTDRAWSURFACE structure

lpBackBuffer->QueryInterface(

GUIDforID3DDevice, // ID for IDirect3DDevice interface

lpD3DDevice); // Address of a DIRECT3DDEVICE object

The first parameter of the call to the IDirectDrawSurface::QueryInterface method for the back buffer is the globally unique identifier (GUID) for the IDirect3DDevice interface. You can retrieve this GUID by calling the IDirect3D::EnumDevices method; the system supplies the GUID when it calls the D3DENUMDEVICESCALLBACK callback function you supply in the call to IDirect3D::EnumDevices.

A Direct3D device object resides on (or "is owned by") the interface list and has its own list of execute buffers and viewports. It also has a list of textures and materials, each of which points both to the next texture or material in the list and back to the device. For more information about this hierarchy, see Object Connectivity.

The methods of the IDirect3DDevice interface report hardware capabilities, maintain a list of viewports, manipulate matrix objects, and execute execute-buffer objects.

Matrices appear to you only as handles. You can create a Direct3D matrix by calling the IDirect3DDevice::CreateMatrix method, and you can set the contents of the matrix by calling the IDirect3DDevice::SetMatrix method. Matrix handles are used in execute buffers.