Picking a Direct3D Device

[Previous] [Next]

After all that enumeration, it's finally time to decide which Direct3D device to use. If you're using the enumeration code in the Direct3D framework, this is easy: just call D3DEnum_SelectDefaultDevice. It looks for a Direct3D device that supports windowed mode and as much hardware acceleration as possible (and hasn't been rejected by your device confirmation function). Here's its code:

 //------------------------------------------------------------------- // Name: D3DEnum_SelectDefaultDevice // Desc: Picks a default device, preferably hardware and desktop //       compatible //------------------------------------------------------------------- HRESULT D3DEnum_SelectDefaultDevice( D3DEnum_DeviceInfo** ppDevice,                                      DWORD dwFlags ) {     // Check arguments.     if( NULL == ppDevice )         return E_INVALIDARG;     // Get access to the enumerated device list.     D3DEnum_DeviceInfo* pDeviceList;     DWORD               dwNumDevices;     D3DEnum_GetDevices( &pDeviceList, &dwNumDevices );     // Look for windowable software, hardware, and hardware     // TnL devices.     D3DEnum_DeviceInfo* pRefRastDevice     = NULL;     D3DEnum_DeviceInfo* pSoftwareDevice    = NULL;     D3DEnum_DeviceInfo* pHardwareDevice    = NULL;     D3DEnum_DeviceInfo* pHardwareTnLDevice = NULL;     for( DWORD i=0; i<dwNumDevices; i++ )     {         if( pDeviceList[i].bDesktopCompatible )         {             if( pDeviceList[i].bHardware )             {                 if( (*pDeviceList[i].pDeviceGUID) ==                      IID_IDirect3DTnLHalDevice )                     pHardwareTnLDevice = &pDeviceList[i];                 else                     pHardwareDevice = &pDeviceList[i];             }             else             {                 if( (*pDeviceList[i].pDeviceGUID) ==                      IID_IDirect3DRefDevice )                     pRefRastDevice = &pDeviceList[i];                 else                     pSoftwareDevice = &pDeviceList[i];             }         }     }     // Prefer a hardware TnL device first, then a non-TnL hardware      // device, and finally, a software device.     if( 0 == ( dwFlags & D3DENUM_SOFTWAREONLY ) &&               pHardwareTnLDevice )         (*ppDevice) = pHardwareTnLDevice;     else if( 0 == ( dwFlags & D3DENUM_SOFTWAREONLY ) &&                   pHardwareDevice )         (*ppDevice) = pHardwareDevice;     else if( pSoftwareDevice )         (*ppDevice) = pSoftwareDevice;     else if( pRefRastDevice )         (*ppDevice) = pRefRastDevice;     else         return D3DENUMERR_NOCOMPATIBLEDEVICES;     // Set the windowed state of the newly selected device.       (*ppDevice)->bWindowed = TRUE;     return S_OK; } 

Your program might have different requirements or preferences for the default Direct3D device. For example, you might want to always default to a full-screen configuration. If this is the case, you can write your own device-selection function.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net