//-------------------------------------------------------------------------------------- // Enumerates DeviceCombos for a particular device. //-------------------------------------------------------------------------------------- HRESULT CD3DEnumeration::EnumerateDeviceCombos( CD3DEnumAdapterInfo* pAdapterInfo, CD3DEnumDeviceInfo* pDeviceInfo, CGrowableArray<D3DFORMAT>* pAdapterFormatList ) { const D3DFORMAT backBufferFormatArray[] = { D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A2R10G10B10, D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5 }; const UINT backBufferFormatArrayCount = sizeof(backBufferFormatArray) / sizeof(backBufferFormatArray[0]); // See which adapter formats are supported by this device for( NxI32 iFormat=0; iFormat<pAdapterFormatList->GetSize(); iFormat++ ) { D3DFORMAT adapterFormat = pAdapterFormatList->GetAt(iFormat); for( UINT iBackBufferFormat = 0; iBackBufferFormat < backBufferFormatArrayCount; iBackBufferFormat++ ) { D3DFORMAT backBufferFormat = backBufferFormatArray[iBackBufferFormat]; for( NxI32 nWindowed = 0; nWindowed < 2; nWindowed++) { if( !nWindowed && pAdapterInfo->displayModeList.GetSize() == 0 ) continue; if (FAILED( m_pD3D->CheckDeviceType( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, adapterFormat, backBufferFormat, nWindowed ))) { continue; } if( m_bRequirePostPixelShaderBlending ) { // If the backbuffer format doesn't support D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING // then alpha test, pixel fog, render-target blending, color write enable, and dithering. // are not supported. if( FAILED( m_pD3D->CheckDeviceFormat( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, adapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_TEXTURE, backBufferFormat ) ) ) { continue; } } // If an application callback function has been provided, make sure this device // is acceptable to the app. if( m_IsDeviceAcceptableFunc != NULL ) { if( !m_IsDeviceAcceptableFunc( &pDeviceInfo->Caps, adapterFormat, backBufferFormat, FALSE != nWindowed, m_pIsDeviceAcceptableFuncUserContext ) ) continue; } // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed // DeviceCombo that is supported by the system and acceptable to the app. We still // need to find one or more suitable depth/stencil buffer format, // multisample type, and present interval. CD3DEnumDeviceSettingsCombo* pDeviceCombo = MEMALLOC_NEW(CD3DEnumDeviceSettingsCombo); if( pDeviceCombo == NULL ) return E_OUTOFMEMORY; pDeviceCombo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal; pDeviceCombo->DeviceType = pDeviceInfo->DeviceType; pDeviceCombo->AdapterFormat = adapterFormat; pDeviceCombo->BackBufferFormat = backBufferFormat; pDeviceCombo->Windowed = (nWindowed != 0); BuildDepthStencilFormatList( pDeviceCombo ); BuildMultiSampleTypeList( pDeviceCombo ); if (pDeviceCombo->multiSampleTypeList.GetSize() == 0) { delete pDeviceCombo; continue; } BuildDSMSConflictList( pDeviceCombo ); BuildPresentIntervalList(pDeviceInfo, pDeviceCombo ); pDeviceCombo->pAdapterInfo = pAdapterInfo; pDeviceCombo->pDeviceInfo = pDeviceInfo; pDeviceInfo->deviceSettingsComboList.Add( pDeviceCombo ); } } } return S_OK; }
//----------------------------------------------------------------------------- // Name: EnumerateDeviceCombos // Desc: Enumerates DeviceCombos for a particular device. //----------------------------------------------------------------------------- HRESULT CD3DEnumeration::EnumerateDeviceCombos( D3DDeviceInfo* pDeviceInfo, CArrayList* pAdapterFormatList ) { const D3DFORMAT backBufferFormatArray[] = { D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A2R10G10B10, D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5 }; const UINT backBufferFormatArrayCount = sizeof(backBufferFormatArray) / sizeof(backBufferFormatArray[0]); bool isWindowedArray[] = { false, true }; // See which adapter formats are supported by this device D3DFORMAT adapterFormat; for( UINT iaf = 0; iaf < pAdapterFormatList->Count(); iaf++ ) { adapterFormat = *(D3DFORMAT*)pAdapterFormatList->GetPtr(iaf); D3DFORMAT backBufferFormat; for( UINT ibbf = 0; ibbf < backBufferFormatArrayCount; ibbf++ ) { backBufferFormat = backBufferFormatArray[ibbf]; if (AlphaChannelBits(backBufferFormat) < AppMinAlphaChannelBits) continue; bool isWindowed; for( UINT iiw = 0; iiw < 2; iiw++) { isWindowed = isWindowedArray[iiw]; if (!isWindowed && AppRequiresWindowed) continue; if (isWindowed && AppRequiresFullscreen) continue; if (FAILED(m_pD3D->CheckDeviceType(pDeviceInfo->AdapterOrdinal, pDeviceInfo->DevType, adapterFormat, backBufferFormat, isWindowed))) { continue; } // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed // DeviceCombo that is supported by the system. We still need to confirm that it's // compatible with the app, and find one or more suitable depth/stencil buffer format, // multisample type, vertex processing type, and present interval. D3DDeviceCombo* pDeviceCombo = NULL; pDeviceCombo = new D3DDeviceCombo; if( pDeviceCombo == NULL ) return E_OUTOFMEMORY; pDeviceCombo->pDepthStencilFormatList = new CArrayList( AL_VALUE, sizeof( D3DFORMAT ) ); pDeviceCombo->pMultiSampleTypeList = new CArrayList( AL_VALUE, sizeof( D3DMULTISAMPLE_TYPE ) ); pDeviceCombo->pMultiSampleQualityList = new CArrayList( AL_VALUE, sizeof( DWORD ) ); pDeviceCombo->pDSMSConflictList = new CArrayList( AL_VALUE, sizeof( D3DDSMSConflict ) ); pDeviceCombo->pVertexProcessingTypeList = new CArrayList( AL_VALUE, sizeof( VertexProcessingType ) ); pDeviceCombo->pPresentIntervalList = new CArrayList( AL_VALUE, sizeof( UINT ) ); if( pDeviceCombo->pDepthStencilFormatList == NULL || pDeviceCombo->pMultiSampleTypeList == NULL || pDeviceCombo->pMultiSampleQualityList == NULL || pDeviceCombo->pDSMSConflictList == NULL || pDeviceCombo->pVertexProcessingTypeList == NULL || pDeviceCombo->pPresentIntervalList == NULL ) { delete pDeviceCombo; return E_OUTOFMEMORY; } pDeviceCombo->AdapterOrdinal = pDeviceInfo->AdapterOrdinal; pDeviceCombo->DevType = pDeviceInfo->DevType; pDeviceCombo->AdapterFormat = adapterFormat; pDeviceCombo->BackBufferFormat = backBufferFormat; pDeviceCombo->IsWindowed = isWindowed; if (AppUsesDepthBuffer) { BuildDepthStencilFormatList(pDeviceCombo); if (pDeviceCombo->pDepthStencilFormatList->Count() == 0) { delete pDeviceCombo; continue; } } BuildMultiSampleTypeList(pDeviceCombo); if (pDeviceCombo->pMultiSampleTypeList->Count() == 0) { delete pDeviceCombo; continue; } BuildDSMSConflictList(pDeviceCombo); BuildVertexProcessingTypeList(pDeviceInfo, pDeviceCombo); if (pDeviceCombo->pVertexProcessingTypeList->Count() == 0) { delete pDeviceCombo; continue; } BuildPresentIntervalList(pDeviceInfo, pDeviceCombo); pDeviceInfo->pDeviceComboList->Add(pDeviceCombo); } } } return S_OK; }