📄 dxutenum.cpp
字号:
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::BuildDSMSConflictList( CD3D9EnumDeviceSettingsCombo* pDeviceCombo )
{
CD3D9EnumDSMSConflict 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 CD3D9Enumeration::BuildPresentIntervalList( CD3D9EnumDeviceInfo* pDeviceInfo,
CD3D9EnumDeviceSettingsCombo* 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 CD3D9EnumAdapterInfo objects and empty the list
//--------------------------------------------------------------------------------------
void CD3D9Enumeration::ClearAdapterInfoList()
{
CD3D9EnumAdapterInfo* 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
// CD3D9EnumAdapterInfo*
//--------------------------------------------------------------------------------------
CGrowableArray<CD3D9EnumAdapterInfo*>* CD3D9Enumeration::GetAdapterInfoList()
{
return &m_AdapterInfoList;
}
//--------------------------------------------------------------------------------------
CD3D9EnumAdapterInfo* CD3D9Enumeration::GetAdapterInfo( UINT AdapterOrdinal )
{
for( int iAdapter=0; iAdapter<m_AdapterInfoList.GetSize(); iAdapter++ )
{
CD3D9EnumAdapterInfo* pAdapterInfo = m_AdapterInfoList.GetAt(iAdapter);
if( pAdapterInfo->AdapterOrdinal == AdapterOrdinal )
return pAdapterInfo;
}
return NULL;
}
//--------------------------------------------------------------------------------------
CD3D9EnumDeviceInfo* CD3D9Enumeration::GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType )
{
CD3D9EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
if( pAdapterInfo )
{
for( int iDeviceInfo=0; iDeviceInfo<pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
{
CD3D9EnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
if( pDeviceInfo->DeviceType == DeviceType )
return pDeviceInfo;
}
}
return NULL;
}
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
CD3D9EnumDeviceSettingsCombo* CD3D9Enumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed )
{
CD3D9EnumDeviceInfo* pDeviceInfo = GetDeviceInfo( AdapterOrdinal, DeviceType );
if( pDeviceInfo )
{
for( int iDeviceCombo=0; iDeviceCombo<pDeviceInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ )
{
CD3D9EnumDeviceSettingsCombo* 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 WINAPI DXUTGetD3D9ColorChannelBits( 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;
case D3DFMT_A2B10G10R10:
return 10;
case D3DFMT_A8B8G8R8:
return 8;
case D3DFMT_A2R10G10B10:
return 10;
case D3DFMT_A16B16G16R16:
return 16;
default:
return 0;
}
}
//--------------------------------------------------------------------------------------
// Returns the number of alpha channel bits in the specified D3DFORMAT
//--------------------------------------------------------------------------------------
UINT WINAPI DXUTGetAlphaChannelBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_R8G8B8:
return 0;
case D3DFMT_A8R8G8B8:
return 8;
case D3DFMT_X8R8G8B8:
return 0;
case D3DFMT_R5G6B5:
return 0;
case D3DFMT_X1R5G5B5:
return 0;
case D3DFMT_A1R5G5B5:
return 1;
case D3DFMT_A4R4G4B4:
return 4;
case D3DFMT_R3G3B2:
return 0;
case D3DFMT_A8R3G3B2:
return 8;
case D3DFMT_X4R4G4B4:
return 0;
case D3DFMT_A2B10G10R10:
return 2;
case D3DFMT_A8B8G8R8:
return 8;
case D3DFMT_A2R10G10B10:
return 2;
case D3DFMT_A16B16G16R16:
return 16;
default:
return 0;
}
}
//--------------------------------------------------------------------------------------
// Returns the number of depth bits in the specified D3DFORMAT
//--------------------------------------------------------------------------------------
UINT WINAPI DXUTGetDepthBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_D32F_LOCKABLE:
case D3DFMT_D32:
return 32;
case D3DFMT_D24X8:
case D3DFMT_D24S8:
case D3DFMT_D24X4S4:
case D3DFMT_D24FS8:
return 24;
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
return 16;
case D3DFMT_D15S1:
return 15;
default:
return 0;
}
}
//--------------------------------------------------------------------------------------
// Returns the number of stencil bits in the specified D3DFORMAT
//--------------------------------------------------------------------------------------
UINT WINAPI DXUTGetStencilBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
case D3DFMT_D32F_LOCKABLE:
case D3DFMT_D32:
case D3DFMT_D24X8:
return 0;
case D3DFMT_D15S1:
return 1;
case D3DFMT_D24X4S4:
return 4;
case D3DFMT_D24S8:
case D3DFMT_D24FS8:
return 8;
default:
return 0;
}
}
//--------------------------------------------------------------------------------------
// Used to sort D3DDISPLAYMODEs
//--------------------------------------------------------------------------------------
static int __cdecl SortModesCallback( const void* arg1, const void* arg2 )
{
D3DDISPLAYMODE* pdm1 = (D3DDISPLAYMODE*)arg1;
D3DDISPLAYMODE* pdm2 = (D3DDISPLAYMODE*)arg2;
if (pdm1->Width > pdm2->Width)
return 1;
if (pdm1->Width < pdm2->Width)
return -1;
if (pdm1->Height > pdm2->Height)
return 1;
if (pdm1->Height < pdm2->Height)
return -1;
if (pdm1->Format > pdm2->Format)
return 1;
if (pdm1->Format < pdm2->Format)
return -1;
if (pdm1->RefreshRate > pdm2->RefreshRate)
return 1;
if (pdm1->RefreshRate < pdm2->RefreshRate)
return -1;
return 0;
}
//--------------------------------------------------------------------------------------
CD3D9EnumAdapterInfo::~CD3D9EnumAdapterInfo( void )
{
CD3D9EnumDeviceInfo* pDeviceInfo;
for( int i=0; i<deviceInfoList.GetSize(); i++ )
{
pDeviceInfo = deviceInfoList.GetAt(i);
delete pDeviceInfo;
}
deviceInfoList.RemoveAll();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -