📄 d3denumeration.cpp
字号:
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: EnumerateDevices
// Desc: Enumerates D3D devices for a particular adapter.
//-----------------------------------------------------------------------------
HRESULT CD3DEnumeration::EnumerateDevices( D3DAdapterInfo* pAdapterInfo,
CArrayList* pAdapterFormatList )
{
const D3DDEVTYPE devTypeArray[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_SW, D3DDEVTYPE_REF };
const UINT devTypeArrayCount = sizeof(devTypeArray) / sizeof(devTypeArray[0]);
HRESULT hr;
D3DDeviceInfo* pDeviceInfo = NULL;
for( UINT idt = 0; idt < devTypeArrayCount; idt++ )
{
pDeviceInfo = new D3DDeviceInfo;
if( pDeviceInfo == NULL )
return E_OUTOFMEMORY;
pDeviceInfo->pDeviceComboList = new CArrayList( AL_REFERENCE );
if( pDeviceInfo->pDeviceComboList == NULL )
{
delete pDeviceInfo;
return E_OUTOFMEMORY;
}
pDeviceInfo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal;
pDeviceInfo->DevType = devTypeArray[idt];
if( FAILED( m_pD3D->GetDeviceCaps( pAdapterInfo->AdapterOrdinal,
pDeviceInfo->DevType, &pDeviceInfo->Caps ) ) )
{
delete pDeviceInfo;
continue;
}
// Get info for each devicecombo on this device
if( FAILED( hr = EnumerateDeviceCombos(pDeviceInfo, pAdapterFormatList) ) )
{
delete pDeviceInfo;
return hr;
}
// If at least one devicecombo for this device is found,
// add the deviceInfo to the list
if (pDeviceInfo->pDeviceComboList->Count() == 0)
{
delete pDeviceInfo;
continue;
}
pAdapterInfo->pDeviceInfoList->Add(pDeviceInfo);
}
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;
}
//-----------------------------------------------------------------------------
// Name: BuildDepthStencilFormatList
// Desc: Adds all depth/stencil formats that are compatible with the device
// and app to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildDepthStencilFormatList( D3DDeviceCombo* pDeviceCombo )
{
const D3DFORMAT depthStencilFormatArray[] =
{
D3DFMT_D16,
D3DFMT_D15S1,
D3DFMT_D24X8,
D3DFMT_D24S8,
D3DFMT_D24X4S4,
D3DFMT_D32,
};
const UINT depthStencilFormatArrayCount = sizeof(depthStencilFormatArray) /
sizeof(depthStencilFormatArray[0]);
D3DFORMAT depthStencilFmt;
for( UINT idsf = 0; idsf < depthStencilFormatArrayCount; idsf++ )
{
depthStencilFmt = depthStencilFormatArray[idsf];
if (DepthBits(depthStencilFmt) < AppMinDepthBits)
continue;
if (StencilBits(depthStencilFmt) < AppMinStencilBits)
continue;
if (SUCCEEDED(m_pD3D->CheckDeviceFormat(pDeviceCombo->AdapterOrdinal,
pDeviceCombo->DevType, pDeviceCombo->AdapterFormat,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFmt)))
{
if (SUCCEEDED(m_pD3D->CheckDepthStencilMatch(pDeviceCombo->AdapterOrdinal,
pDeviceCombo->DevType, pDeviceCombo->AdapterFormat,
pDeviceCombo->BackBufferFormat, depthStencilFmt)))
{
pDeviceCombo->pDepthStencilFormatList->Add(&depthStencilFmt);
}
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildMultiSampleTypeList
// Desc: Adds all multisample types that are compatible with the device and app to
// the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildMultiSampleTypeList( D3DDeviceCombo* pDeviceCombo )
{
const D3DMULTISAMPLE_TYPE msTypeArray[] = {
D3DMULTISAMPLE_NONE,
D3DMULTISAMPLE_NONMASKABLE,
D3DMULTISAMPLE_2_SAMPLES,
D3DMULTISAMPLE_3_SAMPLES,
D3DMULTISAMPLE_4_SAMPLES,
D3DMULTISAMPLE_5_SAMPLES,
D3DMULTISAMPLE_6_SAMPLES,
D3DMULTISAMPLE_7_SAMPLES,
D3DMULTISAMPLE_8_SAMPLES,
D3DMULTISAMPLE_9_SAMPLES,
D3DMULTISAMPLE_10_SAMPLES,
D3DMULTISAMPLE_11_SAMPLES,
D3DMULTISAMPLE_12_SAMPLES,
D3DMULTISAMPLE_13_SAMPLES,
D3DMULTISAMPLE_14_SAMPLES,
D3DMULTISAMPLE_15_SAMPLES,
D3DMULTISAMPLE_16_SAMPLES,
};
const UINT msTypeArrayCount = sizeof(msTypeArray) / sizeof(msTypeArray[0]);
D3DMULTISAMPLE_TYPE msType;
DWORD msQuality;
for( UINT imst = 0; imst < msTypeArrayCount; imst++ )
{
msType = msTypeArray[imst];
if (SUCCEEDED(m_pD3D->CheckDeviceMultiSampleType(pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType,
pDeviceCombo->BackBufferFormat, pDeviceCombo->IsWindowed, msType, &msQuality)))
{
pDeviceCombo->pMultiSampleTypeList->Add(&msType);
pDeviceCombo->pMultiSampleQualityList->Add( &msQuality );
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildDSMSConflictList
// Desc: Find any conflicts between the available depth/stencil formats and
// multisample types.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildDSMSConflictList( D3DDeviceCombo* pDeviceCombo )
{
D3DDSMSConflict DSMSConflict;
for( UINT ids = 0; ids < pDeviceCombo->pDepthStencilFormatList->Count(); ids++ )
{
D3DFORMAT dsFmt = *(D3DFORMAT*)pDeviceCombo->pDepthStencilFormatList->GetPtr(ids);
for( UINT ims = 0; ims < pDeviceCombo->pMultiSampleTypeList->Count(); ims++ )
{
D3DMULTISAMPLE_TYPE msType = *(D3DMULTISAMPLE_TYPE*)pDeviceCombo->pMultiSampleTypeList->GetPtr(ims);
if( FAILED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType,
dsFmt, pDeviceCombo->IsWindowed, msType, NULL ) ) )
{
DSMSConflict.DSFormat = dsFmt;
DSMSConflict.MSType = msType;
pDeviceCombo->pDSMSConflictList->Add( &DSMSConflict );
}
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildVertexProcessingTypeList
// Desc: Adds all vertex processing types that are compatible with the device
// and app to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildVertexProcessingTypeList( D3DDeviceInfo* pDeviceInfo,
D3DDeviceCombo* pDeviceCombo )
{
VertexProcessingType vpt;
if ((pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
{
if ((pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_PUREDEVICE) != 0)
{
if (ConfirmDeviceCallback == NULL ||
ConfirmDeviceCallback(&pDeviceInfo->Caps, PURE_HARDWARE_VP, pDeviceCombo->BackBufferFormat))
{
vpt = PURE_HARDWARE_VP;
pDeviceCombo->pVertexProcessingTypeList->Add(&vpt);
}
}
if (ConfirmDeviceCallback == NULL ||
ConfirmDeviceCallback(&pDeviceInfo->Caps, HARDWARE_VP, pDeviceCombo->BackBufferFormat))
{
vpt = HARDWARE_VP;
pDeviceCombo->pVertexProcessingTypeList->Add(&vpt);
}
if (AppUsesMixedVP && (ConfirmDeviceCallback == NULL ||
ConfirmDeviceCallback(&pDeviceInfo->Caps, MIXED_VP, pDeviceCombo->BackBufferFormat)))
{
vpt = MIXED_VP;
pDeviceCombo->pVertexProcessingTypeList->Add(&vpt);
}
}
if (ConfirmDeviceCallback == NULL ||
ConfirmDeviceCallback(&pDeviceInfo->Caps, SOFTWARE_VP, pDeviceCombo->BackBufferFormat))
{
vpt = SOFTWARE_VP;
pDeviceCombo->pVertexProcessingTypeList->Add(&vpt);
}
}
//-----------------------------------------------------------------------------
// Name: BuildPresentIntervalList
// Desc: Adds all present intervals that are compatible with the device and app
// to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildPresentIntervalList( D3DDeviceInfo* pDeviceInfo,
D3DDeviceCombo* pDeviceCombo )
{
const UINT piArray[] = {
D3DPRESENT_INTERVAL_IMMEDIATE,
D3DPRESENT_INTERVAL_DEFAULT,
D3DPRESENT_INTERVAL_ONE,
D3DPRESENT_INTERVAL_TWO,
D3DPRESENT_INTERVAL_THREE,
D3DPRESENT_INTERVAL_FOUR,
};
const UINT piArrayCount = sizeof(piArray) / sizeof(piArray[0]);
UINT pi;
for( UINT ipi = 0; ipi < piArrayCount; ipi++ )
{
pi = piArray[ipi];
if( pDeviceCombo->IsWindowed )
{
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->pPresentIntervalList->Add( &pi );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -