📄 dxutenum.cpp
字号:
}
//--------------------------------------------------------------------------------------
CD3D9EnumDeviceInfo::~CD3D9EnumDeviceInfo( void )
{
CD3D9EnumDeviceSettingsCombo* pDeviceCombo;
for( int i=0; i<deviceSettingsComboList.GetSize(); i++ )
{
pDeviceCombo = deviceSettingsComboList.GetAt(i);
delete pDeviceCombo;
}
deviceSettingsComboList.RemoveAll();
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::ResetPossibleDepthStencilFormats()
{
m_DepthStencilPossibleList.RemoveAll();
m_DepthStencilPossibleList.Add( D3DFMT_D16 );
m_DepthStencilPossibleList.Add( D3DFMT_D15S1 );
m_DepthStencilPossibleList.Add( D3DFMT_D24X8 );
m_DepthStencilPossibleList.Add( D3DFMT_D24S8 );
m_DepthStencilPossibleList.Add( D3DFMT_D24X4S4 );
m_DepthStencilPossibleList.Add( D3DFMT_D32 );
}
//--------------------------------------------------------------------------------------
CGrowableArray<D3DFORMAT>* CD3D9Enumeration::GetPossibleDepthStencilFormatList()
{
return &m_DepthStencilPossibleList;
}
//--------------------------------------------------------------------------------------
CGrowableArray<D3DMULTISAMPLE_TYPE>* CD3D9Enumeration::GetPossibleMultisampleTypeList()
{
return &m_MultiSampleTypeList;
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::ResetPossibleMultisampleTypeList()
{
m_MultiSampleTypeList.RemoveAll();
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONE );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONMASKABLE );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_2_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_3_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_4_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_5_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_6_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_7_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_8_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_9_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_10_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_11_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_12_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_13_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_14_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_15_SAMPLES );
m_MultiSampleTypeList.Add( D3DMULTISAMPLE_16_SAMPLES );
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::GetPossibleVertexProcessingList( bool* pbSoftwareVP, bool* pbHardwareVP, bool* pbPureHarewareVP, bool* pbMixedVP )
{
*pbSoftwareVP = m_bSoftwareVP;
*pbHardwareVP = m_bHardwareVP;
*pbPureHarewareVP = m_bPureHarewareVP;
*pbMixedVP = m_bMixedVP;
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::SetPossibleVertexProcessingList( bool bSoftwareVP, bool bHardwareVP, bool bPureHarewareVP, bool bMixedVP )
{
m_bSoftwareVP = bSoftwareVP;
m_bHardwareVP = bHardwareVP;
m_bPureHarewareVP = bPureHarewareVP;
m_bMixedVP = bMixedVP;
}
//--------------------------------------------------------------------------------------
CGrowableArray<UINT>* CD3D9Enumeration::GetPossiblePresentIntervalList()
{
return &m_PresentIntervalList;
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::ResetPossiblePresentIntervalList()
{
m_PresentIntervalList.RemoveAll();
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_IMMEDIATE );
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_DEFAULT );
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_ONE );
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_TWO );
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_THREE );
m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_FOUR );
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::SetResolutionMinMax( UINT nMinWidth, UINT nMinHeight,
UINT nMaxWidth, UINT nMaxHeight )
{
m_nMinWidth = nMinWidth;
m_nMinHeight = nMinHeight;
m_nMaxWidth = nMaxWidth;
m_nMaxHeight = nMaxHeight;
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::SetRefreshMinMax( UINT nMin, UINT nMax )
{
m_nRefreshMin = nMin;
m_nRefreshMax = nMax;
}
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::SetMultisampleQualityMax( UINT nMax )
{
if( nMax > 0xFFFF )
nMax = 0xFFFF;
m_nMultisampleQualityMax = nMax;
}
//--------------------------------------------------------------------------------------
HRESULT DXUTFindValidD3D9DeviceSettings( DXUTD3D9DeviceSettings* pOut, DXUTD3D9DeviceSettings* pIn, DXUTMatchOptions* pMatchOptions, DXUTD3D9DeviceSettings* pOptimal )
{
// Find the best combination of:
// Adapter Ordinal
// Device Type
// Adapter Format
// Back Buffer Format
// Windowed
// given what's available on the system and the match options combined with the device settings input.
// This combination of settings is encapsulated by the CD3D9EnumDeviceSettingsCombo class.
float fBestRanking = -1.0f;
CD3D9EnumDeviceSettingsCombo* pBestDeviceSettingsCombo = NULL;
D3DDISPLAYMODE adapterDesktopDisplayMode;
IDirect3D9* pD3D = DXUTGetD3D9Object();
CD3D9Enumeration* pd3dEnum = DXUTGetD3D9Enumeration( false );
CGrowableArray<CD3D9EnumAdapterInfo*>* pAdapterList = pd3dEnum->GetAdapterInfoList();
for( int iAdapter=0; iAdapter<pAdapterList->GetSize(); iAdapter++ )
{
CD3D9EnumAdapterInfo* pAdapterInfo = pAdapterList->GetAt(iAdapter);
// Get the desktop display mode of adapter
pD3D->GetAdapterDisplayMode( pAdapterInfo->AdapterOrdinal, &adapterDesktopDisplayMode );
// Enum all the device types supported by this adapter to find the best device settings
for( int iDeviceInfo=0; iDeviceInfo<pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
{
CD3D9EnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
// Enum all the device settings combinations. A device settings combination is
// a unique set of an adapter format, back buffer format, and IsWindowed.
for( int iDeviceCombo=0; iDeviceCombo<pDeviceInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ )
{
CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt(iDeviceCombo);
// If windowed mode the adapter format has to be the same as the desktop
// display mode format so skip any that don't match
if (pDeviceSettingsCombo->Windowed && (pDeviceSettingsCombo->AdapterFormat != adapterDesktopDisplayMode.Format))
continue;
// Skip any combo that doesn't meet the preserve match options
if( false == DXUTDoesD3D9DeviceComboMatchPreserveOptions( pDeviceSettingsCombo, pIn, pMatchOptions ) )
continue;
// Get a ranking number that describes how closely this device combo matches the optimal combo
float fCurRanking = DXUTRankD3D9DeviceCombo( pDeviceSettingsCombo, pOptimal, &adapterDesktopDisplayMode );
// If this combo better matches the input device settings then save it
if( fCurRanking > fBestRanking )
{
pBestDeviceSettingsCombo = pDeviceSettingsCombo;
fBestRanking = fCurRanking;
}
}
}
}
// If no best device combination was found then fail
if( pBestDeviceSettingsCombo == NULL )
return DXUTERR_NOCOMPATIBLEDEVICES;
// Using the best device settings combo found, build valid device settings taking heed of
// the match options and the input device settings
DXUTD3D9DeviceSettings validDeviceSettings;
DXUTBuildValidD3D9DeviceSettings( &validDeviceSettings, pBestDeviceSettingsCombo, pIn, pMatchOptions );
*pOut = validDeviceSettings;
return S_OK;
}
//--------------------------------------------------------------------------------------
// Internal helper function to build a D3D9 device settings structure based upon the match
// options. If the match option is set to ignore, then a optimal default value is used.
// The default value may not exist on the system, but later this will be taken
// into account.
//--------------------------------------------------------------------------------------
void DXUTBuildOptimalD3D9DeviceSettings( DXUTD3D9DeviceSettings* pOptimalDeviceSettings,
DXUTD3D9DeviceSettings* pDeviceSettingsIn,
DXUTMatchOptions* pMatchOptions )
{
IDirect3D9* pD3D = DXUTGetD3D9Object();
D3DDISPLAYMODE adapterDesktopDisplayMode;
ZeroMemory( pOptimalDeviceSettings, sizeof(DXUTD3D9DeviceSettings) );
//---------------------
// Adapter ordinal
//---------------------
if( pMatchOptions->eAdapterOrdinal == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->AdapterOrdinal = D3DADAPTER_DEFAULT;
else
pOptimalDeviceSettings->AdapterOrdinal = pDeviceSettingsIn->AdapterOrdinal;
//---------------------
// Device type
//---------------------
if( pMatchOptions->eDeviceType == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->DeviceType = D3DDEVTYPE_HAL;
else
pOptimalDeviceSettings->DeviceType = pDeviceSettingsIn->DeviceType;
//---------------------
// Windowed
//---------------------
if( pMatchOptions->eWindowed == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.Windowed = TRUE;
else
pOptimalDeviceSettings->pp.Windowed = pDeviceSettingsIn->pp.Windowed;
//---------------------
// Adapter format
//---------------------
if( pMatchOptions->eAdapterFormat == DXUTMT_IGNORE_INPUT )
{
// If windowed, default to the desktop display mode
// If fullscreen, default to the desktop display mode for quick mode change or
// default to D3DFMT_X8R8G8B8 if the desktop display mode is < 32bit
pD3D->GetAdapterDisplayMode( pOptimalDeviceSettings->AdapterOrdinal, &adapterDesktopDisplayMode );
if( pOptimalDeviceSettings->pp.Windowed || DXUTGetD3D9ColorChannelBits(adapterDesktopDisplayMode.Format) >= 8 )
pOptimalDeviceSettings->AdapterFormat = adapterDesktopDisplayMode.Format;
else
pOptimalDeviceSettings->AdapterFormat = D3DFMT_X8R8G8B8;
}
else
{
pOptimalDeviceSettings->AdapterFormat = pDeviceSettingsIn->AdapterFormat;
}
//---------------------
// Vertex processing
//---------------------
if( pMatchOptions->eVertexProcessing == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
pOptimalDeviceSettings->BehaviorFlags = pDeviceSettingsIn->BehaviorFlags;
//---------------------
// Resolution
//---------------------
if( pMatchOptions->eResolution == DXUTMT_IGNORE_INPUT )
{
// If windowed, default to 640x480
// If fullscreen, default to the desktop res for quick mode change
if( pOptimalDeviceSettings->pp.Windowed )
{
pOptimalDeviceSettings->pp.BackBufferWidth = 640;
pOptimalDeviceSettings->pp.BackBufferHeight = 480;
}
else
{
pD3D->GetAdapterDisplayMode( pOptimalDeviceSettings->AdapterOrdinal, &adapterDesktopDisplayMode );
pOptimalDeviceSettings->pp.BackBufferWidth = adapterDesktopDisplayMode.Width;
pOptimalDeviceSettings->pp.BackBufferHeight = adapterDesktopDisplayMode.Height;
}
}
else
{
pOptimalDeviceSettings->pp.BackBufferWidth = pDeviceSettingsIn->pp.BackBufferWidth;
pOptimalDeviceSettings->pp.BackBufferHeight = pDeviceSettingsIn->pp.BackBufferHeight;
}
//---------------------
// Back buffer format
//---------------------
if( pMatchOptions->eBackBufferFormat == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.BackBufferFormat = pOptimalDeviceSettings->AdapterFormat; // Default to match the adapter format
else
pOptimalDeviceSettings->pp.BackBufferFormat = pDeviceSettingsIn->pp.BackBufferFormat;
//---------------------
// Back buffer count
//---------------------
if( pMatchOptions->eBackBufferCount == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.BackBufferCount = 1; // Default to double buffering. Causes less latency than triple buffering
else
pOptimalDeviceSettings->pp.BackBufferCount = pDeviceSettingsIn->pp.BackBufferCount;
//---------------------
// Multisample
//---------------------
if( pMatchOptions->eMultiSample == DXUTMT_IGNORE_INPUT )
{
// Default to no multisampling
pOptimalDeviceSettings->pp.MultiSampleType = D3DMULTISAMPLE_NONE;
pOptimalDeviceSettings->pp.MultiSampleQuality = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -