📄 xd3denum.cpp
字号:
//-----------------------------------------------------------------------------
// D3DEnumeration.cpp: enumerates D3D adapters, devices, modes, etc.
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "XD3DUtil.h"
#include "XD3DEnum.h"
//-----------------------------------------------------------------------------
// SortModesCallback(): sort callback comparing two D3DDISPLAYMODEs
//-----------------------------------------------------------------------------
static int __cdecl SortModesCallback(const void* arg1, const void* arg2)
{
D3DDISPLAYMODE* pdm1 = (D3DDISPLAYMODE*)arg1;
D3DDISPLAYMODE* pdm2 = (D3DDISPLAYMODE*)arg2;
// the wider display modes sink down, the thinner bubble up
if (pdm1->Width > pdm2->Width) return +1;
if (pdm1->Width < pdm2->Width) return -1;
// the taller display modes sink down, the shorter bubble up
if (pdm1->Height > pdm2->Height) return +1;
if (pdm1->Height < pdm2->Height) return -1;
// the more colorful display modes sink down
if (RGBBITS(pdm1->Format) > RGBBITS(pdm2->Format)) return +1;
if (RGBBITS(pdm1->Format) < RGBBITS(pdm2->Format)) return -1;
// the faster display modes sink down
if (pdm1->RefreshRate > pdm2->RefreshRate) return +1;
if (pdm1->RefreshRate < pdm2->RefreshRate) return -1;
// the two display modes are identical
return 0;
}
//-----------------------------------------------------------------------------
// CXD3DEnum(): constructor, sets up app constraints
//-----------------------------------------------------------------------------
CXD3DEnum::CXD3DEnum()
{
AppMinFullscreenWidth = 640;
AppMinFullscreenHeight = 480;
AppMinRGBBits = 5;
AppMinAlphaBits = 0;
AppMinDepthBits = 15;
AppMinStencilBits = 0;
AppUsesDepthBuffer = true;
AppUsesMixedVP = true;
// we will allow every possible display mode format by default;
// they indicate how many bits are dedicated to each channel (Alpha, Red,
// Green and Blue), with X standing for unused.
// take care to maintain consistency between the format list and the
// 'AppMinRGBBits' and 'AppMinAlphaBits' constraints above.
// Also notice the 10-bit format is only available in fullscreen modes.
AppDisplayFormats.Append(D3DFMT_R5G6B5); // 16-bit, 6 for green
AppDisplayFormats.Append(D3DFMT_X1R5G5B5); // 16-bit, 5 per channel
AppDisplayFormats.Append(D3DFMT_A1R5G5B5); // 16-bit, 1 for alpha
AppDisplayFormats.Append(D3DFMT_X8R8G8B8); // 32-bit, 8 per channel
AppDisplayFormats.Append(D3DFMT_A8R8G8B8); // 32-bit, 8 for alpha
AppDisplayFormats.Append(D3DFMT_A2R10G10B10); // 32-bit, 2 for alpha
// we will allow every backbuffer format by default
AppBackBufferFormats.Append(D3DFMT_R5G6B5);
AppBackBufferFormats.Append(D3DFMT_X1R5G5B5);
AppBackBufferFormats.Append(D3DFMT_A1R5G5B5);
AppBackBufferFormats.Append(D3DFMT_X8R8G8B8);
AppBackBufferFormats.Append(D3DFMT_A8R8G8B8);
AppBackBufferFormats.Append(D3DFMT_A2R10G10B10);
// we will allow every depth/stencil format by default; obviously, D is
// for depth S for stencil, and X unused.
AppDepthStencilFormats.Append(D3DFMT_D16);
AppDepthStencilFormats.Append(D3DFMT_D15S1);
AppDepthStencilFormats.Append(D3DFMT_D24X8);
AppDepthStencilFormats.Append(D3DFMT_D24X4S4);
AppDepthStencilFormats.Append(D3DFMT_D24S8);
AppDepthStencilFormats.Append(D3DFMT_D32);
// we will allow every multisampling type by default, even the nonmaskable,
// to enable the quality levels
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_NONE);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_NONMASKABLE);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_2_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_3_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_4_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_5_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_6_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_7_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_8_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_9_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_10_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_11_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_12_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_13_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_14_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_15_SAMPLES);
AppMultiSamplingTypes.Append(D3DMULTISAMPLE_16_SAMPLES);
}
//-----------------------------------------------------------------------------
// EnumerateDSFormats(): add depth/stencil formats compatible with the device
// and the app to the given device combo
//-----------------------------------------------------------------------------
void CXD3DEnum::EnumerateDSFormats(DeviceCombo* pdc)
{
D3DFORMAT fmt;
// traverse the app defined depth/stencil formats
for (UINT i = 0; i < AppDepthStencilFormats.Length(); i++)
{
fmt = (D3DFORMAT)AppDepthStencilFormats[i];
// check the format against app requirements
if (DEPTHBITS(fmt) < AppMinDepthBits) continue;
if (STENCILBITS(fmt) < AppMinStencilBits) continue;
// is the format available for a depth/stencil surface resource on
// this device?
if (FAILED(m_pd3d->CheckDeviceFormat(pdc->AdapterOrdinal,
pdc->DevType,
pdc->DisplayFormat,
D3DUSAGE_DEPTHSTENCIL,
D3DRTYPE_SURFACE,
fmt)))
continue;
// does it match both the display and back buffer formats?
if (FAILED(m_pd3d->CheckDepthStencilMatch(pdc->AdapterOrdinal,
pdc->DevType,
pdc->DisplayFormat,
pdc->BackBufferFormat,
fmt)))
continue;
// yes, yes!
pdc->DSFormats.Append(fmt);
}
}
//-----------------------------------------------------------------------------
// EnumerateMSTypes(): add multisample types that are compatible with the
// device and the app to the given device combo
//-----------------------------------------------------------------------------
void CXD3DEnum::EnumerateMSTypes(DeviceCombo* pdc)
{
D3DMULTISAMPLE_TYPE msType;
DWORD msQuality;
// traverse the types and check for support
for (UINT i = 0; i < AppMultiSamplingTypes.Length(); i++)
{
msType = (D3DMULTISAMPLE_TYPE)AppMultiSamplingTypes[i];
if (FAILED(m_pd3d->CheckDeviceMultiSampleType(pdc->AdapterOrdinal,
pdc->DevType,
pdc->BackBufferFormat,
pdc->Windowed,
msType,
&msQuality)))
continue;
// supported
pdc->MSTypes.Append(msType);
// important! presentation parameters quality levels are zero-based,
// and the API call returns the number of levels, so we will store
// the maximum value that can be used in other Direct3D API calls,
// i.o., the number of levels. Also notice that both these lists must
// always be accessed with indices in synch.
if (msQuality != 0)
msQuality -= 1;
pdc->MSQualityLevels.Append(msQuality);
}
}
//-----------------------------------------------------------------------------
// EnumerateDSMSConflicts(): find any conflicts between the depth/stencil
// formats and multisample types in the given device combo
//-----------------------------------------------------------------------------
void CXD3DEnum::EnumerateDSMSConflicts(DeviceCombo* pdc)
{
DSMSConflict con;
D3DFORMAT fmt;
D3DMULTISAMPLE_TYPE mst;
// traverse formats
for (UINT i = 0; i < pdc->DSFormats.Length(); i++)
{
fmt = (D3DFORMAT)pdc->DSFormats[i];
// check against multisample types
for (UINT j = 0; j < pdc->MSTypes.Length(); j++)
{
mst = (D3DMULTISAMPLE_TYPE)pdc->MSTypes[j];
// failure to support the combination indicates a conflict; save it
if (FAILED(m_pd3d->CheckDeviceMultiSampleType(pdc->AdapterOrdinal,
pdc->DevType,
fmt,
pdc->Windowed,
mst,
NULL)))
{
con.fmt = fmt;
con.mst = mst;
pdc->DSMSConflicts.Append(con);
}
}
}
}
//-----------------------------------------------------------------------------
// EnumerateVPTypes(): add vertex processing types that are compatible with the
// device and the app to the given device combo
//-----------------------------------------------------------------------------
void CXD3DEnum::EnumerateVPTypes(DeviceInfo* pdi, DeviceCombo* pdc)
{
// by default, every VP type is allowed, even the mixed one; your
// application may have different requirements, i.e. the need for
// a pure hardware device to test a graphics card...
if ((pdi->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
{
if ((pdi->Caps.DevCaps & D3DDEVCAPS_PUREDEVICE) != 0)
pdc->VPTypes.Append(PURE_VP);
pdc->VPTypes.Append(HARD_VP);
if (AppUsesMixedVP)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -