📄 dxutenum.cpp
字号:
{
D3DFORMAT adapterFormat = pAdapterFormatList->GetAt(iFormat);
for( UINT iBackBufferFormat = 0; iBackBufferFormat < backBufferFormatArrayCount; iBackBufferFormat++ )
{
D3DFORMAT backBufferFormat = backBufferFormatArray[iBackBufferFormat];
for( int 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 = 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;
}
//--------------------------------------------------------------------------------------
// Adds all depth/stencil formats that are compatible with the device
// and app to the given D3DDeviceCombo.
//--------------------------------------------------------------------------------------
void CD3DEnumeration::BuildDepthStencilFormatList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
{
D3DFORMAT depthStencilFmt;
for( int idsf = 0; idsf < m_DepthStecilPossibleList.GetSize(); idsf++ )
{
depthStencilFmt = m_DepthStecilPossibleList.GetAt(idsf);
if (SUCCEEDED(m_pD3D->CheckDeviceFormat(pDeviceCombo->AdapterOrdinal,
pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFmt)))
{
if (SUCCEEDED(m_pD3D->CheckDepthStencilMatch(pDeviceCombo->AdapterOrdinal,
pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat,
pDeviceCombo->BackBufferFormat, depthStencilFmt)))
{
pDeviceCombo->depthStencilFormatList.Add( depthStencilFmt );
}
}
}
}
//--------------------------------------------------------------------------------------
// Adds all multisample types that are compatible with the device and app to
// the given D3DDeviceCombo.
//--------------------------------------------------------------------------------------
void CD3DEnumeration::BuildMultiSampleTypeList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
{
D3DMULTISAMPLE_TYPE msType;
DWORD msQuality;
for( int imst = 0; imst < m_MultiSampleTypeList.GetSize(); imst++ )
{
msType = m_MultiSampleTypeList.GetAt(imst);
if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal,
pDeviceCombo->DeviceType, pDeviceCombo->BackBufferFormat,
pDeviceCombo->Windowed, msType, &msQuality ) ) )
{
pDeviceCombo->multiSampleTypeList.Add( msType );
if( msQuality > m_nMultisampleQualityMax+1 )
msQuality = m_nMultisampleQualityMax+1;
pDeviceCombo->multiSampleQualityList.Add( msQuality );
}
}
}
//--------------------------------------------------------------------------------------
// Find any conflicts between the available depth/stencil formats and
// multisample types.
//--------------------------------------------------------------------------------------
void CD3DEnumeration::BuildDSMSConflictList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
{
CD3DEnumDSMSConflict DSMSConflict;
for( int iDS=0; iDS<pDeviceCombo->depthStencilFormatList.GetSize(); iDS++ )
{
D3DFORMAT dsFmt = pDeviceCombo->depthStencilFormatList.GetAt(iDS);
for( int iMS=0; iMS<pDeviceCombo->multiSampleTypeList.GetSize(); iMS++ )
{
D3DMULTISAMPLE_TYPE msType = pDeviceCombo->multiSampleTypeList.GetAt(iMS);
if( FAILED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, pDeviceCombo->DeviceType,
dsFmt, pDeviceCombo->Windowed, msType, NULL ) ) )
{
DSMSConflict.DSFormat = dsFmt;
DSMSConflict.MSType = msType;
pDeviceCombo->DSMSConflictList.Add( DSMSConflict );
}
}
}
}
//--------------------------------------------------------------------------------------
// Adds all present intervals that are compatible with the device and app
// to the given D3DDeviceCombo.
//--------------------------------------------------------------------------------------
void CD3DEnumeration::BuildPresentIntervalList( CD3DEnumDeviceInfo* pDeviceInfo,
CD3DEnumDeviceSettingsCombo* pDeviceCombo )
{
UINT pi;
for( int ipi = 0; ipi < m_PresentIntervalList.GetSize(); ipi++ )
{
pi = m_PresentIntervalList.GetAt(ipi);
if( pDeviceCombo->Windowed )
{
if( pi == D3DPRESENT_INTERVAL_TWO ||
pi == D3DPRESENT_INTERVAL_THREE ||
pi == D3DPRESENT_INTERVAL_FOUR )
{
// These intervals are not supported in windowed mode.
continue;
}
}
// Note that D3DPRESENT_INTERVAL_DEFAULT is zero, so you
// can't do a caps check for it -- it is always available.
if( pi == D3DPRESENT_INTERVAL_DEFAULT ||
(pDeviceInfo->Caps.PresentationIntervals & pi) )
{
pDeviceCombo->presentIntervalList.Add( pi );
}
}
}
//--------------------------------------------------------------------------------------
// Release all the allocated CD3DEnumAdapterInfo objects and empty the list
//--------------------------------------------------------------------------------------
void CD3DEnumeration::ClearAdapterInfoList()
{
CD3DEnumAdapterInfo* pAdapterInfo;
for( int i=0; i<m_AdapterInfoList.GetSize(); i++ )
{
pAdapterInfo = m_AdapterInfoList.GetAt(i);
delete pAdapterInfo;
}
m_AdapterInfoList.RemoveAll();
}
//--------------------------------------------------------------------------------------
// Call GetAdapterInfoList() after Enumerate() to get a STL vector of
// CD3DEnumAdapterInfo*
//--------------------------------------------------------------------------------------
CGrowableArray<CD3DEnumAdapterInfo*>* CD3DEnumeration::GetAdapterInfoList()
{
return &m_AdapterInfoList;
}
//--------------------------------------------------------------------------------------
CD3DEnumAdapterInfo* CD3DEnumeration::GetAdapterInfo( UINT AdapterOrdinal )
{
for( int iAdapter=0; iAdapter<m_AdapterInfoList.GetSize(); iAdapter++ )
{
CD3DEnumAdapterInfo* pAdapterInfo = m_AdapterInfoList.GetAt(iAdapter);
if( pAdapterInfo->AdapterOrdinal == AdapterOrdinal )
return pAdapterInfo;
}
return NULL;
}
//--------------------------------------------------------------------------------------
CD3DEnumDeviceInfo* CD3DEnumeration::GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType )
{
CD3DEnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
if( pAdapterInfo )
{
for( int iDeviceInfo=0; iDeviceInfo<pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
{
CD3DEnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
if( pDeviceInfo->DeviceType == DeviceType )
return pDeviceInfo;
}
}
return NULL;
}
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
CD3DEnumDeviceSettingsCombo* CD3DEnumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed )
{
CD3DEnumDeviceInfo* pDeviceInfo = GetDeviceInfo( AdapterOrdinal, DeviceType );
if( pDeviceInfo )
{
for( int iDeviceCombo=0; iDeviceCombo<pDeviceInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ )
{
CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt(iDeviceCombo);
if( pDeviceSettingsCombo->AdapterFormat == AdapterFormat &&
pDeviceSettingsCombo->BackBufferFormat == BackBufferFormat &&
pDeviceSettingsCombo->Windowed == bWindowed )
return pDeviceSettingsCombo;
}
}
return NULL;
}
//--------------------------------------------------------------------------------------
// Returns the number of color channel bits in the specified D3DFORMAT
//--------------------------------------------------------------------------------------
UINT DXUTColorChannelBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_R8G8B8:
return 8;
case D3DFMT_A8R8G8B8:
return 8;
case D3DFMT_X8R8G8B8:
return 8;
case D3DFMT_R5G6B5:
return 5;
case D3DFMT_X1R5G5B5:
return 5;
case D3DFMT_A1R5G5B5:
return 5;
case D3DFMT_A4R4G4B4:
return 4;
case D3DFMT_R3G3B2:
return 2;
case D3DFMT_A8R3G3B2:
return 2;
case D3DFMT_X4R4G4B4:
return 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -