📄 dxut.cpp
字号:
matchOptions.eVertexProcessing = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eResolution = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferCount = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eMultiSample = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eSwapEffect = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eDepthFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eStencilFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentFlags = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eRefreshRate = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentInterval = DXUTMT_CLOSEST_TO_INPUT;
hr = DXUTFindValidDeviceSettings( pDeviceSettings, pDeviceSettings, &matchOptions );
if( FAILED(hr) ) // the call will fail if no valid devices were found
{
DXUTDisplayErrorMessage( hr );
return DXUT_ERR( L"DXUTFindValidDeviceSettings", hr );
}
}
// Change to a Direct3D device created from the new device settings.
// If there is an existing device, then either reset or recreate the scene
hr = DXUTChangeDevice( pDeviceSettings, NULL, false );
if( FAILED(hr) )
return hr;
return S_OK;
}
//--------------------------------------------------------------------------------------
// Toggle between full screen and windowed
//--------------------------------------------------------------------------------------
HRESULT DXUTToggleFullScreen()
{
HRESULT hr;
DXUTPause( true, true );
// Get the current device settings and flip the windowed state then
// find the closest valid device settings with this change
DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
deviceSettings.pp.Windowed = !deviceSettings.pp.Windowed;
DXUTMatchOptions matchOptions;
matchOptions.eAdapterOrdinal = DXUTMT_PRESERVE_INPUT;
matchOptions.eDeviceType = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eWindowed = DXUTMT_PRESERVE_INPUT;
matchOptions.eAdapterFormat = DXUTMT_IGNORE_INPUT;
matchOptions.eVertexProcessing = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferFormat = DXUTMT_IGNORE_INPUT;
matchOptions.eBackBufferCount = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eMultiSample = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eSwapEffect = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eDepthFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eStencilFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentFlags = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eRefreshRate = DXUTMT_IGNORE_INPUT;
matchOptions.ePresentInterval = DXUTMT_IGNORE_INPUT;
RECT rcWindowClient;
if( deviceSettings.pp.Windowed )
rcWindowClient = GetDXUTState().GetWindowClientRect();
else
rcWindowClient = GetDXUTState().GetFullScreenClientRect();
int nWidth = rcWindowClient.right - rcWindowClient.left;
int nHeight = rcWindowClient.bottom - rcWindowClient.top;
if( nWidth > 0 && nHeight > 0 )
{
matchOptions.eResolution = DXUTMT_CLOSEST_TO_INPUT;
deviceSettings.pp.BackBufferWidth = nWidth;
deviceSettings.pp.BackBufferHeight = nHeight;
}
else
{
matchOptions.eResolution = DXUTMT_IGNORE_INPUT;
}
hr = DXUTFindValidDeviceSettings( &deviceSettings, &deviceSettings, &matchOptions );
if( SUCCEEDED(hr) )
{
// Create a Direct3D device using the new device settings.
// If there is an existing device, then it will either reset or recreate the scene.
hr = DXUTChangeDevice( &deviceSettings, NULL, false );
if( FAILED(hr) )
{
// Failed creating device, try to switch back.
deviceSettings.pp.Windowed = !deviceSettings.pp.Windowed;
if( deviceSettings.pp.Windowed )
rcWindowClient = GetDXUTState().GetWindowClientRect();
else
rcWindowClient = GetDXUTState().GetFullScreenClientRect();
nWidth = rcWindowClient.right - rcWindowClient.left;
nHeight = rcWindowClient.bottom - rcWindowClient.top;
if( nWidth > 0 && nHeight > 0 )
{
matchOptions.eResolution = DXUTMT_CLOSEST_TO_INPUT;
deviceSettings.pp.BackBufferWidth = nWidth;
deviceSettings.pp.BackBufferHeight = nHeight;
}
else
{
matchOptions.eResolution = DXUTMT_IGNORE_INPUT;
}
DXUTFindValidDeviceSettings( &deviceSettings, &deviceSettings, &matchOptions );
HRESULT hr2 = DXUTChangeDevice( &deviceSettings, NULL, false );
if( FAILED(hr2) )
{
// If this failed, then shutdown
DXUTShutdown();
}
}
}
DXUTPause( false, false );
return hr;
}
//--------------------------------------------------------------------------------------
// Toggle between HAL and REF
//--------------------------------------------------------------------------------------
HRESULT DXUTToggleREF()
{
HRESULT hr;
DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
if( deviceSettings.DeviceType == D3DDEVTYPE_HAL )
deviceSettings.DeviceType = D3DDEVTYPE_REF;
else if( deviceSettings.DeviceType == D3DDEVTYPE_REF )
deviceSettings.DeviceType = D3DDEVTYPE_HAL;
DXUTMatchOptions matchOptions;
matchOptions.eAdapterOrdinal = DXUTMT_PRESERVE_INPUT;
matchOptions.eDeviceType = DXUTMT_PRESERVE_INPUT;
matchOptions.eWindowed = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eAdapterFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eVertexProcessing = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eResolution = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferCount = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eMultiSample = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eSwapEffect = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eDepthFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eStencilFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentFlags = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eRefreshRate = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentInterval = DXUTMT_CLOSEST_TO_INPUT;
hr = DXUTFindValidDeviceSettings( &deviceSettings, &deviceSettings, &matchOptions );
if( SUCCEEDED(hr) )
{
// Create a Direct3D device using the new device settings.
// If there is an existing device, then it will either reset or recreate the scene.
hr = DXUTChangeDevice( &deviceSettings, NULL, false );
if( FAILED( hr ) )
{
// Failed creating device, try to switch back.
if( deviceSettings.DeviceType == D3DDEVTYPE_HAL )
deviceSettings.DeviceType = D3DDEVTYPE_REF;
else if( deviceSettings.DeviceType == D3DDEVTYPE_REF )
deviceSettings.DeviceType = D3DDEVTYPE_HAL;
DXUTFindValidDeviceSettings( &deviceSettings, &deviceSettings, &matchOptions );
HRESULT hr2 = DXUTChangeDevice( &deviceSettings, NULL, false );
if( FAILED(hr2) )
{
// If this failed, then shutdown
DXUTShutdown();
}
}
}
return hr;
}
//--------------------------------------------------------------------------------------
// Internal helper function to prepare the enumeration object by creating it if it
// didn't already exist and enumerating if desired.
//--------------------------------------------------------------------------------------
CD3DEnumeration* DXUTPrepareEnumerationObject( bool bEnumerate )
{
// Create a new CD3DEnumeration object and enumerate all devices unless its already been done
CD3DEnumeration* pd3dEnum = GetDXUTState().GetD3DEnumeration();
if( pd3dEnum == NULL )
{
pd3dEnum = DXUTGetEnumeration();
GetDXUTState().SetD3DEnumeration( pd3dEnum );
bEnumerate = true;
}
if( bEnumerate )
{
// Enumerate for each adapter all of the supported display modes,
// device types, adapter formats, back buffer formats, window/full screen support,
// depth stencil formats, multisampling types/qualities, and presentations intervals.
//
// For each combination of device type (HAL/REF), adapter format, back buffer format, and
// IsWindowed it will call the app's ConfirmDevice callback. This allows the app
// to reject or allow that combination based on its caps/etc. It also allows the
// app to change the BehaviorFlags. The BehaviorFlags defaults non-pure HWVP
// if supported otherwise it will default to SWVP, however the app can change this
// through the ConfirmDevice callback.
IDirect3D9* pD3D = DXUTGetD3DObject();
pd3dEnum->Enumerate( pD3D, GetDXUTState().GetIsDeviceAcceptableFunc() );
}
return pd3dEnum;
}
//--------------------------------------------------------------------------------------
// Internal helper function to prepare the settings dialog by creating it if it didn't
// already exist and enumerating if desired.
//--------------------------------------------------------------------------------------
CD3DSettingsDlg* DXUTPrepareSettingsDialog()
{
CD3DSettingsDlg* pD3DSettingsDlg = GetDXUTState().GetD3DSettingsDlg();
if( pD3DSettingsDlg == NULL )
{
HRESULT hr = S_OK;
pD3DSettingsDlg = DXUTGetSettingsDialog();
GetDXUTState().SetD3DSettingsDlg( pD3DSettingsDlg );
if( GetDXUTState().GetDeviceObjectsCreated() )
{
IDirect3DDevice9* pd3dDevice = DXUTGetD3DDevice();
hr = pD3DSettingsDlg->OnCreateDevice( pd3dDevice );
if( FAILED(hr) )
{
DXUT_ERR( L"DXUTPrepareSettingsDialog", hr );
return pD3DSettingsDlg;
}
}
if( GetDXUTState().GetDeviceObjectsReset() )
{
hr = pD3DSettingsDlg->OnResetDevice();
if( FAILED(hr) )
{
DXUT_ERR( L"DXUTPrepareSettingsDialog", hr );
return pD3DSettingsDlg;
}
}
}
return pD3DSettingsDlg;
}
//--------------------------------------------------------------------------------------
// This function tries to find valid device settings based upon the input device settings
// struct and the match options. For each device setting a match option in the
// DXUTMatchOptions struct specifies how the function makes decisions. For example, if
// the caller wants a HAL device with a back buffer format of D3DFMT_A2B10G10R10 but the
// HAL device on the system does not support D3DFMT_A2B10G10R10 however a REF device is
// installed that does, then the function has a choice to either use REF or to change to
// a back buffer format to compatible with the HAL device. The match options lets the
// caller control how these choices are made.
//
// Each match option must be one of the following types:
// DXUTMT_IGNORE_INPUT: Uses the closest valid value to a default
// DXUTMT_PRESERVE_INPUT: Uses the input without change, but may cause no valid device to be found
// DXUTMT_CLOSEST_TO_INPUT: Uses the closest valid value to the input
//
// If pMatchOptions is NULL then, all of the match options are assumed to be DXUTMT_IGNORE_INPUT.
// The function returns failure if no valid device settings can be found otherwise
// the function returns success and the valid device settings are written to pOut.
//--------------------------------------------------------------------------------------
HRESULT DXUTFindValidDeviceSettings( DXUTDeviceSettings* pOut, DXUTDeviceSettings* pIn,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -