//------------------------------------------------------------------------------------- VOID CDXUTEffectMap::Reset() { D3DXMatrixIdentity( &m_matWorld ); D3DXMatrixIdentity( &m_matView ); D3DXMatrixIdentity( &m_matProjection ); // Reset all the stored parameter lists for( UINT iSemantic = 0; iSemantic < NUM_DXUT_SEMANTICS; iSemantic++ ) { for( UINT iObject = 0; iObject < NUM_DXUT_OBJECTS; iObject++ ) { for( UINT iIndex = 0; iIndex < MAX_INDEX; iIndex++ ) { CGrowableArray<ParamList>* pBinding = &m_Bindings[ iSemantic ][ iObject ][ iIndex ]; // Clear nested arrays first for( int iParamList = 0; iParamList < pBinding->GetSize(); iParamList++ ) { pBinding->GetAt( iParamList ).Reset(); } // Remove all the bound parameter lists pBinding->RemoveAll(); } } } }
//-------------------------------------------------------------------------------------- // Enumerates available D3D adapters, devices, modes, etc. //-------------------------------------------------------------------------------------- HRESULT CD3DEnumeration::Enumerate( IDirect3D9* pD3D, LPDXUTCALLBACKISDEVICEACCEPTABLE IsDeviceAcceptableFunc, void* pIsDeviceAcceptableFuncUserContext ) { if( pD3D == NULL ) { pD3D = DXUTGetD3DObject(); if( pD3D == NULL ) return DXUTERR_NODIRECT3D; } m_pD3D = pD3D; m_IsDeviceAcceptableFunc = IsDeviceAcceptableFunc; m_pIsDeviceAcceptableFuncUserContext = pIsDeviceAcceptableFuncUserContext; HRESULT hr; ClearAdapterInfoList(); CGrowableArray<D3DFORMAT> adapterFormatList; const D3DFORMAT allowedAdapterFormatArray[] = { D3DFMT_X8R8G8B8, D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_A2R10G10B10 }; const UINT allowedAdapterFormatArrayCount = sizeof(allowedAdapterFormatArray) / sizeof(allowedAdapterFormatArray[0]); UINT numAdapters = pD3D->GetAdapterCount(); for (UINT adapterOrdinal = 0; adapterOrdinal < numAdapters; adapterOrdinal++) { CD3DEnumAdapterInfo* pAdapterInfo = MEMALLOC_NEW(CD3DEnumAdapterInfo); if( pAdapterInfo == NULL ) return E_OUTOFMEMORY; pAdapterInfo->AdapterOrdinal = adapterOrdinal; pD3D->GetAdapterIdentifier(adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier); // Get list of all display modes on this adapter. // Also build a temporary list of all display adapter formats. adapterFormatList.RemoveAll(); for( UINT iFormatList = 0; iFormatList < allowedAdapterFormatArrayCount; iFormatList++ ) { D3DFORMAT allowedAdapterFormat = allowedAdapterFormatArray[iFormatList]; UINT numAdapterModes = pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat ); for (UINT mode = 0; mode < numAdapterModes; mode++) { D3DDISPLAYMODE displayMode; pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode ); if( displayMode.Width < m_nMinWidth || displayMode.Height < m_nMinHeight || displayMode.Width > m_nMaxWidth || displayMode.Height > m_nMaxHeight || displayMode.RefreshRate < m_nRefreshMin || displayMode.RefreshRate > m_nRefreshMax ) { continue; } pAdapterInfo->displayModeList.Add( displayMode ); if( !adapterFormatList.Contains(displayMode.Format) ) adapterFormatList.Add( displayMode.Format ); } } D3DDISPLAYMODE displayMode; pD3D->GetAdapterDisplayMode( adapterOrdinal, &displayMode ); if( !adapterFormatList.Contains(displayMode.Format) ) adapterFormatList.Add( displayMode.Format ); // Sort displaymode list ::qsort( pAdapterInfo->displayModeList.GetData(), pAdapterInfo->displayModeList.GetSize(), sizeof( D3DDISPLAYMODE ), SortModesCallback ); // Get info for each device on this adapter if( FAILED( EnumerateDevices( pAdapterInfo, &adapterFormatList ) ) ) { delete pAdapterInfo; continue; } // If at least one device on this adapter is available and compatible // with the app, add the adapterInfo to the list if( pAdapterInfo->deviceInfoList.GetSize() > 0 ) { hr = m_AdapterInfoList.Add( pAdapterInfo ); if( FAILED(hr) ) return hr; } else delete pAdapterInfo; } bool bUniqueDesc = true; CD3DEnumAdapterInfo* pAdapterInfo; for( NxI32 i=0; i<m_AdapterInfoList.GetSize(); i++ ) { CD3DEnumAdapterInfo* pAdapterInfo1 = m_AdapterInfoList.GetAt(i); for( NxI32 j=i+1; j<m_AdapterInfoList.GetSize(); j++ ) { CD3DEnumAdapterInfo* pAdapterInfo2 = m_AdapterInfoList.GetAt(j); if( _stricmp( pAdapterInfo1->AdapterIdentifier.Description, pAdapterInfo2->AdapterIdentifier.Description ) == 0 ) { bUniqueDesc = false; break; } } if( !bUniqueDesc ) break; } for( NxI32 i=0; i<m_AdapterInfoList.GetSize(); i++ ) { pAdapterInfo = m_AdapterInfoList.GetAt(i); MultiByteToWideChar( CP_ACP, 0, pAdapterInfo->AdapterIdentifier.Description, -1, pAdapterInfo->szUniqueDescription, 100 ); pAdapterInfo->szUniqueDescription[100] = 0; if( !bUniqueDesc ) { WCHAR sz[100]; StringCchPrintf( sz, 100, L" (#%d)", pAdapterInfo->AdapterOrdinal ); StringCchCat( pAdapterInfo->szUniqueDescription, 256, sz ); } } return S_OK; }