1 //--------------------------------------------------------------------------------------
2 // File: DXUTSettingsDlg.cpp
3 //
4 // Dialog for selection of device settings
5 //
6 // Copyright (c) Microsoft Corporation. All rights reserved
7 //--------------------------------------------------------------------------------------
8 #include "dxstdafx.h"
9 #include "DXUTgui.h"
10 #include "DXUTsettingsDlg.h"
11 #undef min // use __min instead
12 #undef max // use __max instead
13 
14 
15 //--------------------------------------------------------------------------------------
16 // Internal functions forward declarations
17 //--------------------------------------------------------------------------------------
18 WCHAR* DXUTPresentIntervalToString( UINT pi );
19 WCHAR* DXUTMultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType);
20 WCHAR* DXUTD3DDeviceTypeToString(D3DDEVTYPE devType);
21 WCHAR* DXUTVertexProcessingTypeToString(DWORD vpt);
22 
23 
24 //--------------------------------------------------------------------------------------
25 // Global state
26 //--------------------------------------------------------------------------------------
27 DXUTDeviceSettings g_DeviceSettings;
28 
DXUTGetSettingsDialog()29 CD3DSettingsDlg* DXUTGetSettingsDialog()
30 {
31     // Using an accessor function gives control of the construction order
32     static CD3DSettingsDlg dlg;
33     return &dlg;
34 }
35 
36 
37 //--------------------------------------------------------------------------------------
CD3DSettingsDlg()38 CD3DSettingsDlg::CD3DSettingsDlg()
39 {
40     m_pStateBlock = NULL;
41     m_bActive = false;
42 }
43 
44 
45 //--------------------------------------------------------------------------------------
~CD3DSettingsDlg()46 CD3DSettingsDlg::~CD3DSettingsDlg()
47 {
48     OnDestroyDevice();
49 }
50 
51 
52 //--------------------------------------------------------------------------------------
Init(CDXUTDialogResourceManager * pManager)53 void CD3DSettingsDlg::Init( CDXUTDialogResourceManager* pManager )
54 {
55     assert( pManager );
56     m_Dialog.Init( pManager, false );  // Don't register this dialog.
57     CreateControls();
58 }
59 
60 
61 //--------------------------------------------------------------------------------------
Init(CDXUTDialogResourceManager * pManager,LPCWSTR szControlTextureFileName)62 void CD3DSettingsDlg::Init( CDXUTDialogResourceManager* pManager, LPCWSTR szControlTextureFileName )
63 {
64     assert( pManager );
65     m_Dialog.Init( pManager, false, szControlTextureFileName );  // Don't register this dialog.
66     CreateControls();
67 }
68 
69 
70 //--------------------------------------------------------------------------------------
Init(CDXUTDialogResourceManager * pManager,LPCWSTR pszControlTextureResourcename,HMODULE hModule)71 void CD3DSettingsDlg::Init( CDXUTDialogResourceManager* pManager, LPCWSTR pszControlTextureResourcename, HMODULE hModule )
72 {
73     assert( pManager );
74     m_Dialog.Init( pManager, false, pszControlTextureResourcename, hModule );  // Don't register this dialog.
75     CreateControls();
76 }
77 
78 
79 //--------------------------------------------------------------------------------------
CreateControls()80 void CD3DSettingsDlg::CreateControls()
81 {
82     m_Dialog.EnableKeyboardInput( true );
83     m_Dialog.SetFont( 0, L"Arial", 15, FW_NORMAL );
84     m_Dialog.SetFont( 1, L"Arial", 28, FW_BOLD );
85 
86     // Right-justify static controls
87     CDXUTElement* pElement = m_Dialog.GetDefaultElement( DXUT_CONTROL_STATIC, 0 );
88     if( pElement )
89     {
90         pElement->dwTextFormat = DT_VCENTER | DT_RIGHT;
91 
92         // Title
93         CDXUTStatic* pStatic = NULL;
94         m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Direct3D Settings", 10, 5, 400, 50, false, &pStatic );
95         pElement = pStatic->GetElement( 0 );
96         pElement->iFont = 1;
97         pElement->dwTextFormat = DT_TOP | DT_LEFT;
98     }
99 
100     // DXUTSETTINGSDLG_ADAPTER
101     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Display Adapter", 10, 50, 180, 23 );
102     m_Dialog.AddComboBox( DXUTSETTINGSDLG_ADAPTER, 200, 50, 300, 23 );
103 
104     // DXUTSETTINGSDLG_DEVICE_TYPE
105     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Render Device", 10, 75, 180, 23 );
106     m_Dialog.AddComboBox( DXUTSETTINGSDLG_DEVICE_TYPE, 200, 75, 300, 23 );
107 
108     // DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_FULLSCREEN
109     m_Dialog.AddRadioButton( DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_WINDOWED_GROUP, L"Windowed", 240, 105, 300, 16 );
110     m_Dialog.AddCheckBox( DXUTSETTINGSDLG_DEVICECLIP, L"Clip to device when window spans across multiple monitors", 250, 126, 400, 16 );
111     m_Dialog.AddRadioButton( DXUTSETTINGSDLG_FULLSCREEN, DXUTSETTINGSDLG_WINDOWED_GROUP, L"Full Screen", 240, 147, 300, 16 );
112 
113     // DXUTSETTINGSDLG_ADAPTER_FORMAT
114     m_Dialog.AddStatic( DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL, L"Adapter Format", 10, 180, 180, 23 );
115     m_Dialog.AddComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT, 200, 180, 300, 23 );
116 
117     // DXUTSETTINGSDLG_RESOLUTION
118     m_Dialog.AddStatic( DXUTSETTINGSDLG_RESOLUTION_LABEL, L"Resolution", 10, 205, 180, 23 );
119     m_Dialog.AddComboBox( DXUTSETTINGSDLG_RESOLUTION, 200, 205, 200, 23 );
120     m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION )->SetDropHeight( 106 );
121 
122     // DXUTSETTINGSDLG_RES_SHOW_ALL
123     m_Dialog.AddCheckBox( DXUTSETTINGSDLG_RESOLUTION_SHOW_ALL, L"Show All Aspect Ratios", 420, 205, 200, 23, false );
124 
125     // DXUTSETTINGSDLG_REFRESH_RATE
126     m_Dialog.AddStatic( DXUTSETTINGSDLG_REFRESH_RATE_LABEL, L"Refresh Rate", 10, 230, 180, 23 );
127     m_Dialog.AddComboBox( DXUTSETTINGSDLG_REFRESH_RATE, 200, 230, 300, 23 );
128 
129     // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
130     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Back Buffer Format", 10, 265, 180, 23 );
131     m_Dialog.AddComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT, 200, 265, 300, 23 );
132 
133     // DXUTSETTINGSDLG_DEPTH_STENCIL
134     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Depth/Stencil Format", 10, 290, 180, 23 );
135     m_Dialog.AddComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL, 200, 290, 300, 23 );
136 
137     // DXUTSETTINGSDLG_MULTISAMPLE_TYPE
138     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Multisample Type", 10, 315, 180, 23 );
139     m_Dialog.AddComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE, 200, 315, 300, 23 );
140 
141     // DXUTSETTINGSDLG_MULTISAMPLE_QUALITY
142     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Multisample Quality", 10, 340, 180, 23 );
143     m_Dialog.AddComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY, 200, 340, 300, 23 );
144 
145      // DXUTSETTINGSDLG_VERTEX_PROCESSING
146     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Vertex Processing", 10, 365, 180, 23 );
147     m_Dialog.AddComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING, 200, 365, 300, 23 );
148 
149      // DXUTSETTINGSDLG_PRESENT_INTERVAL
150     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Vertical Sync", 10, 390, 180, 23 );
151     m_Dialog.AddComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL, 200, 390, 300, 23 );
152 
153     // DXUTSETTINGSDLG_OK, DXUTSETTINGSDLG_CANCEL
154     m_Dialog.AddButton( DXUTSETTINGSDLG_OK, L"OK", 230, 435, 73, 31 );
155     m_Dialog.AddButton( DXUTSETTINGSDLG_CANCEL, L"Cancel", 315, 435, 73, 31, 0, true );
156 }
157 
158 
159 //--------------------------------------------------------------------------------------
OnCreateDevice(IDirect3DDevice9 * pd3dDevice)160 HRESULT CD3DSettingsDlg::OnCreateDevice( IDirect3DDevice9* pd3dDevice )
161 {
162     if( pd3dDevice == NULL )
163         return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", E_INVALIDARG );
164 
165     // Create the fonts/textures
166     m_Dialog.SetCallback( StaticOnEvent, (void*) this );
167 
168     return S_OK;
169 }
170 
171 
172 //--------------------------------------------------------------------------------------
173 // Changes the UI defaults to the current device settings
174 //--------------------------------------------------------------------------------------
Refresh()175 HRESULT CD3DSettingsDlg::Refresh()
176 {
177     HRESULT hr = S_OK;
178 
179     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
180     g_DeviceSettings = DXUTGetDeviceSettings();
181 
182     // Fill the UI with the current settings
183     AddDeviceType( g_DeviceSettings.DeviceType );
184     SetWindowed( FALSE != g_DeviceSettings.pp.Windowed );
185     SetDeviceClip( 0 != (g_DeviceSettings.pp.Flags & D3DPRESENTFLAG_DEVICECLIP) );
186     AddAdapterFormat( g_DeviceSettings.AdapterFormat );
187     AddResolution( g_DeviceSettings.pp.BackBufferWidth, g_DeviceSettings.pp.BackBufferHeight );
188     AddRefreshRate( g_DeviceSettings.pp.FullScreen_RefreshRateInHz );
189     AddBackBufferFormat( g_DeviceSettings.pp.BackBufferFormat );
190     AddDepthStencilBufferFormat( g_DeviceSettings.pp.AutoDepthStencilFormat );
191     AddMultisampleType( g_DeviceSettings.pp.MultiSampleType );
192     AddMultisampleQuality( g_DeviceSettings.pp.MultiSampleQuality );
193 
194     if( g_DeviceSettings.BehaviorFlags & D3DCREATE_PUREDEVICE )
195         AddVertexProcessingType( D3DCREATE_PUREDEVICE );
196     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
197         AddVertexProcessingType( D3DCREATE_HARDWARE_VERTEXPROCESSING );
198     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
199         AddVertexProcessingType( D3DCREATE_SOFTWARE_VERTEXPROCESSING );
200     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
201         AddVertexProcessingType( D3DCREATE_MIXED_VERTEXPROCESSING );
202 
203     CD3DEnumDeviceSettingsCombo* pBestDeviceSettingsCombo = pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.AdapterOrdinal, g_DeviceSettings.DeviceType, g_DeviceSettings.AdapterFormat, g_DeviceSettings.pp.BackBufferFormat, (g_DeviceSettings.pp.Windowed != 0) );
204     if( NULL == pBestDeviceSettingsCombo )
205         return DXUT_ERR_MSGBOX( L"GetDeviceSettingsCombo", E_INVALIDARG );
206 
207     // Get the adapters list from CD3DEnumeration object
208     CGrowableArray<CD3DEnumAdapterInfo*>* pAdapterInfoList = pD3DEnum->GetAdapterInfoList();
209 
210     if( pAdapterInfoList->GetSize() == 0 )
211         return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", DXUTERR_NOCOMPATIBLEDEVICES );
212 
213     CDXUTComboBox* pAdapterCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
214     pAdapterCombo->RemoveAllItems();
215 
216     // Add adapters
217     for( int iAdapter=0; iAdapter<pAdapterInfoList->GetSize(); iAdapter++ )
218     {
219         CD3DEnumAdapterInfo* pAdapterInfo = pAdapterInfoList->GetAt(iAdapter);
220         AddAdapter( pAdapterInfo->szUniqueDescription, pAdapterInfo->AdapterOrdinal );
221     }
222 
223     pAdapterCombo->SetSelectedByData( ULongToPtr( g_DeviceSettings.AdapterOrdinal ) );
224 
225     hr = OnAdapterChanged();
226     if( FAILED(hr) )
227         return hr;
228 
229     //m_Dialog.Refresh();
230     CDXUTDialog::SetRefreshTime( (float) DXUTGetTime() );
231 
232     return S_OK;
233 }
234 
235 
236 //--------------------------------------------------------------------------------------
OnResetDevice()237 HRESULT CD3DSettingsDlg::OnResetDevice()
238 {
239     const D3DSURFACE_DESC* pDesc = DXUTGetBackBufferSurfaceDesc();
240     m_Dialog.SetLocation( 0, 0 );
241     m_Dialog.SetSize( pDesc->Width, pDesc->Height );
242     m_Dialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206),
243                                          D3DCOLOR_ARGB(255, 54, 105, 192),
244                                          D3DCOLOR_ARGB(255, 54, 105, 192),
245                                          D3DCOLOR_ARGB(255, 10,  73, 179) );
246 
247 
248     IDirect3DDevice9* pd3dDevice = DXUTGetD3DDevice();
249     pd3dDevice->BeginStateBlock();
250     pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
251     pd3dDevice->EndStateBlock( &m_pStateBlock );
252 
253     return S_OK;
254 }
255 
256 
257 //--------------------------------------------------------------------------------------
OnRender(float fElapsedTime)258 HRESULT CD3DSettingsDlg::OnRender( float fElapsedTime )
259 {
260     IDirect3DDevice9* pd3dDevice = DXUTGetD3DDevice();
261 
262     // Clear the render target and the zbuffer
263     pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x00003F3F, 1.0f, 0);
264 
265     // Render the scene
266     if( SUCCEEDED( pd3dDevice->BeginScene() ) )
267     {
268         m_pStateBlock->Capture();
269         pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
270         m_Dialog.OnRender( fElapsedTime );
271         m_pStateBlock->Apply();
272         pd3dDevice->EndScene();
273     }
274 
275     return S_OK;
276 }
277 
278 
279 //--------------------------------------------------------------------------------------
MsgProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)280 LRESULT CD3DSettingsDlg::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
281 {
282     m_Dialog.MsgProc( hWnd, uMsg, wParam, lParam );
283     if( uMsg == WM_KEYDOWN && wParam == VK_F2 )
284         SetActive( false );
285     return 0;
286 }
287 
288 
289 //--------------------------------------------------------------------------------------
OnLostDevice()290 HRESULT CD3DSettingsDlg::OnLostDevice()
291 {
292     SAFE_RELEASE( m_pStateBlock );
293     return S_OK;
294 }
295 
296 
297 //--------------------------------------------------------------------------------------
OnDestroyDevice()298 HRESULT CD3DSettingsDlg::OnDestroyDevice()
299 {
300     return S_OK;
301 }
302 
303 
304 //--------------------------------------------------------------------------------------
StaticOnEvent(UINT nEvent,int nControlID,CDXUTControl * pControl,void * pUserData)305 void WINAPI CD3DSettingsDlg::StaticOnEvent( UINT nEvent, int nControlID,
306                                             CDXUTControl* pControl, void* pUserData )
307 {
308     CD3DSettingsDlg* pD3DSettings = (CD3DSettingsDlg*) pUserData;
309     if( pD3DSettings )
310         pD3DSettings->OnEvent( nEvent, nControlID, pControl );
311 }
312 
313 
314 //--------------------------------------------------------------------------------------
OnEvent(UINT nEvent,int nControlID,CDXUTControl * pControl)315 void CD3DSettingsDlg::OnEvent( UINT nEvent, int nControlID,
316                                CDXUTControl* pControl )
317 {
318     switch( nControlID )
319     {
320         case DXUTSETTINGSDLG_ADAPTER:               OnAdapterChanged(); break;
321         case DXUTSETTINGSDLG_DEVICE_TYPE:           OnDeviceTypeChanged(); break;
322         case DXUTSETTINGSDLG_WINDOWED:              OnWindowedFullScreenChanged(); break;
323         case DXUTSETTINGSDLG_FULLSCREEN:            OnWindowedFullScreenChanged(); break;
324         case DXUTSETTINGSDLG_ADAPTER_FORMAT:        OnAdapterFormatChanged(); break;
325         case DXUTSETTINGSDLG_RESOLUTION_SHOW_ALL:   OnAdapterFormatChanged(); break;
326         case DXUTSETTINGSDLG_RESOLUTION:            OnResolutionChanged(); break;
327         case DXUTSETTINGSDLG_REFRESH_RATE:          OnRefreshRateChanged(); break;
328         case DXUTSETTINGSDLG_BACK_BUFFER_FORMAT:    OnBackBufferFormatChanged(); break;
329         case DXUTSETTINGSDLG_DEPTH_STENCIL:         OnDepthStencilBufferFormatChanged(); break;
330         case DXUTSETTINGSDLG_MULTISAMPLE_TYPE:      OnMultisampleTypeChanged(); break;
331         case DXUTSETTINGSDLG_MULTISAMPLE_QUALITY:   OnMultisampleQualityChanged(); break;
332         case DXUTSETTINGSDLG_VERTEX_PROCESSING:     OnVertexProcessingChanged(); break;
333         case DXUTSETTINGSDLG_PRESENT_INTERVAL:      OnPresentIntervalChanged(); break;
334         case DXUTSETTINGSDLG_DEVICECLIP:            OnDeviceClipChanged(); break;
335 
336         case DXUTSETTINGSDLG_OK:
337         {
338             if( g_DeviceSettings.pp.Windowed )
339             {
340                 g_DeviceSettings.pp.FullScreen_RefreshRateInHz = 0;
341 
342                 RECT rcClient;
343                 if( DXUTIsWindowed() )
344                     GetClientRect( DXUTGetHWND(), &rcClient );
345                 else
346                     rcClient = DXUTGetWindowClientRectAtModeChange();
347                 DWORD dwWindowWidth  = rcClient.right - rcClient.left;
348                 DWORD dwWindowHeight = rcClient.bottom - rcClient.top;
349 
350                 g_DeviceSettings.pp.BackBufferWidth = dwWindowWidth;
351                 g_DeviceSettings.pp.BackBufferHeight = dwWindowHeight;
352             }
353 
354             if( g_DeviceSettings.pp.MultiSampleType != D3DMULTISAMPLE_NONE )
355             {
356                 g_DeviceSettings.pp.Flags &= ~D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
357             }
358 
359             DXUTCreateDeviceFromSettings( &g_DeviceSettings );
360 
361             SetActive( false );
362             break;
363         }
364 
365         case DXUTSETTINGSDLG_CANCEL:
366         {
367             SetActive( false );
368             break;
369         }
370 
371     }
372 }
373 
374 
375 //-------------------------------------------------------------------------------------
SetDeviceSettingsFromUI()376 HRESULT CD3DSettingsDlg::SetDeviceSettingsFromUI()
377 {
378     CDXUTComboBox* pComboBox;
379     CDXUTRadioButton* pRadioButton;
380 
381     // DXUTSETTINGSDLG_DEVICE_TYPE
382     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
383     g_DeviceSettings.DeviceType = (D3DDEVTYPE) PtrToUlong( pComboBox->GetSelectedData() );
384 
385     // DXUTSETTINGSDLG_WINDOWED
386     pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
387     g_DeviceSettings.pp.Windowed = pRadioButton->GetChecked();
388 
389     // DXUTSETTINGSDLG_ADAPTER_FORMAT
390     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
391     g_DeviceSettings.AdapterFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
392 
393 
394     if( g_DeviceSettings.pp.Windowed )
395     {
396         g_DeviceSettings.pp.BackBufferFormat = D3DFMT_UNKNOWN;
397         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = 0;
398     }
399     else
400     {
401         // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
402         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
403         g_DeviceSettings.pp.BackBufferFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
404 
405         // DXUTSETTINGSDLG_RESOLUTION
406         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
407         DWORD dwResolution = PtrToUlong( pComboBox->GetSelectedData() );
408         g_DeviceSettings.pp.BackBufferWidth = HIWORD( dwResolution );
409         g_DeviceSettings.pp.BackBufferHeight = LOWORD( dwResolution );
410 
411         // DXUTSETTINGSDLG_REFRESH_RATE
412         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
413         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = PtrToUlong( pComboBox->GetSelectedData() );
414     }
415 
416     // DXUTSETTINGSDLG_DEPTH_STENCIL
417     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
418     g_DeviceSettings.pp.AutoDepthStencilFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
419 
420     return S_OK;
421 }
422 
423 
424 //-------------------------------------------------------------------------------------
GetCurrentAdapterInfo()425 CD3DEnumAdapterInfo* CD3DSettingsDlg::GetCurrentAdapterInfo()
426 {
427     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
428     return pD3DEnum->GetAdapterInfo( g_DeviceSettings.AdapterOrdinal );
429 }
430 
431 
432 //-------------------------------------------------------------------------------------
GetCurrentDeviceInfo()433 CD3DEnumDeviceInfo* CD3DSettingsDlg::GetCurrentDeviceInfo()
434 {
435     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
436     return pD3DEnum->GetDeviceInfo( g_DeviceSettings.AdapterOrdinal,
437                                       g_DeviceSettings.DeviceType );
438 }
439 
440 
441 //-------------------------------------------------------------------------------------
GetCurrentDeviceSettingsCombo()442 CD3DEnumDeviceSettingsCombo* CD3DSettingsDlg::GetCurrentDeviceSettingsCombo()
443 {
444     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
445     return pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.AdapterOrdinal,
446                                              g_DeviceSettings.DeviceType,
447                                              g_DeviceSettings.AdapterFormat,
448                                              g_DeviceSettings.pp.BackBufferFormat,
449                                              (g_DeviceSettings.pp.Windowed == TRUE) );
450 }
451 
452 
453 //-------------------------------------------------------------------------------------
OnAdapterChanged()454 HRESULT CD3DSettingsDlg::OnAdapterChanged()
455 {
456     HRESULT hr = S_OK;
457 
458     // Store the adapter index
459     g_DeviceSettings.AdapterOrdinal = GetSelectedAdapter();
460 
461     // DXUTSETTINGSDLG_DEVICE_TYPE
462     CDXUTComboBox* pDeviceTypeComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
463     pDeviceTypeComboBox->RemoveAllItems();
464 
465     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
466     if( pAdapterInfo == NULL )
467         return E_FAIL;
468 
469     for( int iDeviceInfo=0; iDeviceInfo < pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
470     {
471         CD3DEnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
472         AddDeviceType( pDeviceInfo->DeviceType );
473     }
474 
475     pDeviceTypeComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.DeviceType) );
476 
477     hr = OnDeviceTypeChanged();
478     if( FAILED(hr) )
479         return hr;
480 
481     return S_OK;
482 }
483 
484 
485 
486 //-------------------------------------------------------------------------------------
OnDeviceTypeChanged()487 HRESULT CD3DSettingsDlg::OnDeviceTypeChanged()
488 {
489     HRESULT hr = S_OK;
490 
491     g_DeviceSettings.DeviceType = GetSelectedDeviceType();
492 
493     // Update windowed/full screen radio buttons
494     bool bHasWindowedDeviceCombo = false;
495     bool bHasFullScreenDeviceCombo = false;
496 
497     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
498     if( pDeviceInfo == NULL )
499         return E_FAIL;
500 
501     for( int idc = 0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
502     {
503         CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
504 
505         if( pDeviceSettingsCombo->Windowed )
506             bHasWindowedDeviceCombo = true;
507         else
508             bHasFullScreenDeviceCombo = true;
509     }
510 
511     // DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_FULLSCREEN
512     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_WINDOWED, bHasWindowedDeviceCombo );
513     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_FULLSCREEN, bHasFullScreenDeviceCombo );
514 
515     SetWindowed( g_DeviceSettings.pp.Windowed && bHasWindowedDeviceCombo );
516 
517     hr = OnWindowedFullScreenChanged();
518     if( FAILED(hr) )
519         return hr;
520 
521     return S_OK;
522 }
523 
524 
525 
526 //-------------------------------------------------------------------------------------
OnWindowedFullScreenChanged()527 HRESULT CD3DSettingsDlg::OnWindowedFullScreenChanged()
528 {
529     HRESULT hr = S_OK;
530 
531     bool bWindowed = IsWindowed();
532     g_DeviceSettings.pp.Windowed = bWindowed;
533 
534     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL, !bWindowed );
535     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_RESOLUTION_LABEL, !bWindowed );
536     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_REFRESH_RATE_LABEL, !bWindowed );
537 
538     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_ADAPTER_FORMAT, !bWindowed );
539     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_RESOLUTION, !bWindowed );
540     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_RESOLUTION_SHOW_ALL, !bWindowed );
541     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_REFRESH_RATE, !bWindowed );
542     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_DEVICECLIP, bWindowed );
543 
544     bool bDeviceClip = ( 0x0 != (g_DeviceSettings.pp.Flags & D3DPRESENTFLAG_DEVICECLIP) );
545 
546     // If windowed, get the appropriate adapter format from Direct3D
547     if( g_DeviceSettings.pp.Windowed )
548     {
549         IDirect3D9* pD3D = DXUTGetD3DObject();
550         if( pD3D == NULL )
551             return DXTRACE_ERR( L"DXUTGetD3DObject", E_FAIL );
552 
553         D3DDISPLAYMODE mode;
554         hr = pD3D->GetAdapterDisplayMode( g_DeviceSettings.AdapterOrdinal, &mode );
555         if( FAILED(hr) )
556             return DXTRACE_ERR( L"GetAdapterDisplayMode", hr );
557 
558         // Default resolution to the fullscreen res that was last used
559         RECT rc = DXUTGetFullsceenClientRectAtModeChange();
560         if( rc.right == 0 || rc.bottom == 0 )
561         {
562             // If nothing last used, then default to the adapter desktop res
563             g_DeviceSettings.pp.BackBufferWidth = mode.Width;
564             g_DeviceSettings.pp.BackBufferHeight = mode.Height;
565         }
566         else
567         {
568             g_DeviceSettings.pp.BackBufferWidth = rc.right;
569             g_DeviceSettings.pp.BackBufferHeight = rc.bottom;
570         }
571 
572         g_DeviceSettings.AdapterFormat = mode.Format;
573         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = mode.RefreshRate;
574     }
575 
576     const D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
577     const DWORD dwWidth = g_DeviceSettings.pp.BackBufferWidth;
578     const DWORD dwHeight = g_DeviceSettings.pp.BackBufferHeight;
579     const DWORD dwRefreshRate = g_DeviceSettings.pp.FullScreen_RefreshRateInHz;
580 
581     // DXUTSETTINGSDLG_DEVICECLIP
582     SetDeviceClip( bDeviceClip );
583 
584     // DXUTSETTINGSDLG_ADAPTER_FORMAT
585     CDXUTComboBox* pAdapterFormatComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
586     if( pAdapterFormatComboBox == NULL )
587         return E_FAIL;
588     pAdapterFormatComboBox->RemoveAllItems();
589 
590     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
591     if( pDeviceInfo == NULL )
592         return E_FAIL;
593 
594     if( bWindowed )
595     {
596         AddAdapterFormat( adapterFormat );
597     }
598     else
599     {
600         for( int iSettingsCombo=0; iSettingsCombo < pDeviceInfo->deviceSettingsComboList.GetSize(); iSettingsCombo++ )
601         {
602             CD3DEnumDeviceSettingsCombo* pSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt(iSettingsCombo);
603             AddAdapterFormat( pSettingsCombo->AdapterFormat );
604         }
605     }
606 
607     pAdapterFormatComboBox->SetSelectedByData( ULongToPtr(adapterFormat) );
608 
609     hr = OnAdapterFormatChanged();
610     if( FAILED(hr) )
611         return hr;
612 
613     // DXUTSETTINGSDLG_RESOLUTION
614     CDXUTComboBox* pResolutionComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
615 
616     if( bWindowed )
617     {
618         pResolutionComboBox->RemoveAllItems();
619         AddResolution( dwWidth, dwHeight );
620     }
621 
622     pResolutionComboBox->SetSelectedByData( ULongToPtr( MAKELONG(dwWidth, dwHeight) ) );
623 
624     hr = OnResolutionChanged();
625     if( FAILED(hr) )
626         return hr;
627 
628     // DXUTSETTINGSDLG_REFRESH_RATE
629     CDXUTComboBox* pRefreshRateComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
630 
631     if( bWindowed )
632     {
633         pRefreshRateComboBox->RemoveAllItems();
634         AddRefreshRate( dwRefreshRate );
635     }
636 
637     pRefreshRateComboBox->SetSelectedByData( ULongToPtr(dwRefreshRate) );
638 
639     hr = OnRefreshRateChanged();
640     if( FAILED(hr) )
641         return hr;
642 
643     return S_OK;
644 }
645 
646 
647 //-------------------------------------------------------------------------------------
OnAdapterFormatChanged()648 HRESULT CD3DSettingsDlg::OnAdapterFormatChanged()
649 {
650     HRESULT hr = S_OK;
651 
652     // DXUTSETTINGSDLG_ADAPTER_FORMAT
653     D3DFORMAT adapterFormat = GetSelectedAdapterFormat();
654     g_DeviceSettings.AdapterFormat = adapterFormat;
655 
656     // DXUTSETTINGSDLG_RESOLUTION
657     CDXUTComboBox* pResolutionComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
658     pResolutionComboBox->RemoveAllItems();
659 
660     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
661     if( pAdapterInfo == NULL )
662         return E_FAIL;
663 
664     bool bShowAll = m_Dialog.GetCheckBox( DXUTSETTINGSDLG_RESOLUTION_SHOW_ALL )->GetChecked();
665 
666     // Get the desktop aspect ratio
667     D3DDISPLAYMODE dmDesktop;
668     DXUTGetDesktopResolution( g_DeviceSettings.AdapterOrdinal, &dmDesktop.Width, &dmDesktop.Height );
669     float fDesktopAspectRatio = dmDesktop.Width / (float)dmDesktop.Height;
670 
671     for( int idm = 0; idm < pAdapterInfo->displayModeList.GetSize(); idm++ )
672     {
673         D3DDISPLAYMODE DisplayMode = pAdapterInfo->displayModeList.GetAt( idm );
674         float fAspect = (float)DisplayMode.Width / (float)DisplayMode.Height;
675 
676         if( DisplayMode.Format == adapterFormat )
677         {
678             // If "Show All" is not checked, then hide all resolutions
679             // that don't match the aspect ratio of the desktop resolution
680             if( bShowAll || (!bShowAll && fabsf(fDesktopAspectRatio - fAspect) < 0.05f) )
681             {
682                 AddResolution( DisplayMode.Width, DisplayMode.Height );
683             }
684         }
685     }
686 
687     const DWORD dwCurResolution = MAKELONG( g_DeviceSettings.pp.BackBufferWidth,
688                                             g_DeviceSettings.pp.BackBufferHeight );
689 
690     pResolutionComboBox->SetSelectedByData( ULongToPtr(dwCurResolution) );
691 
692     hr = OnResolutionChanged();
693     if( FAILED(hr) )
694         return hr;
695 
696     // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
697     CDXUTComboBox* pBackBufferFormatComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
698     pBackBufferFormatComboBox->RemoveAllItems();
699 
700     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
701     if( pDeviceInfo == NULL )
702         return E_FAIL;
703 
704     const BOOL bWindowed = IsWindowed();
705     bool bHasWindowedBackBuffer = false;
706 
707     for( int idc = 0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
708     {
709         CD3DEnumDeviceSettingsCombo* pDeviceCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
710         if( pDeviceCombo->Windowed == bWindowed &&
711             pDeviceCombo->AdapterFormat == g_DeviceSettings.AdapterFormat )
712         {
713             AddBackBufferFormat( pDeviceCombo->BackBufferFormat );
714             bHasWindowedBackBuffer = true;
715         }
716     }
717 
718     pBackBufferFormatComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.BackBufferFormat) );
719 
720     hr = OnBackBufferFormatChanged();
721     if( FAILED(hr) )
722         return hr;
723 
724     if( !bHasWindowedBackBuffer )
725     {
726         m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_WINDOWED, false );
727 
728         if( g_DeviceSettings.pp.Windowed )
729         {
730             SetWindowed( false );
731 
732             hr = OnWindowedFullScreenChanged();
733             if( FAILED(hr) )
734                 return hr;
735         }
736     }
737 
738     return S_OK;
739 }
740 
741 
742 //-------------------------------------------------------------------------------------
OnResolutionChanged()743 HRESULT CD3DSettingsDlg::OnResolutionChanged()
744 {
745     HRESULT hr = S_OK;
746 
747     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
748     if( pAdapterInfo == NULL )
749         return E_FAIL;
750 
751     // Set resolution
752     DWORD dwWidth, dwHeight;
753     GetSelectedResolution( &dwWidth, &dwHeight );
754     g_DeviceSettings.pp.BackBufferWidth = dwWidth;
755     g_DeviceSettings.pp.BackBufferHeight = dwHeight;
756 
757     DWORD dwRefreshRate = g_DeviceSettings.pp.FullScreen_RefreshRateInHz;
758 
759     // Update the refresh rate list
760     CDXUTComboBox* pRefreshRateComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
761     pRefreshRateComboBox->RemoveAllItems();
762 
763     D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
764     for( int idm = 0; idm < pAdapterInfo->displayModeList.GetSize(); idm++ )
765     {
766         D3DDISPLAYMODE displayMode = pAdapterInfo->displayModeList.GetAt( idm );
767 
768         if( displayMode.Format == adapterFormat &&
769             displayMode.Width == dwWidth &&
770             displayMode.Height == dwHeight )
771         {
772             AddRefreshRate( displayMode.RefreshRate );
773         }
774     }
775 
776     pRefreshRateComboBox->SetSelectedByData( ULongToPtr(dwRefreshRate) );
777 
778     hr = OnRefreshRateChanged();
779     if( FAILED(hr) )
780         return hr;
781 
782     return S_OK;
783 }
784 
785 
786 //-------------------------------------------------------------------------------------
OnRefreshRateChanged()787 HRESULT CD3DSettingsDlg::OnRefreshRateChanged()
788 {
789     // Set refresh rate
790     g_DeviceSettings.pp.FullScreen_RefreshRateInHz = GetSelectedRefreshRate();
791 
792     return S_OK;
793 }
794 
795 
796 //-------------------------------------------------------------------------------------
OnBackBufferFormatChanged()797 HRESULT CD3DSettingsDlg::OnBackBufferFormatChanged()
798 {
799     HRESULT hr = S_OK;
800 
801     g_DeviceSettings.pp.BackBufferFormat = GetSelectedBackBufferFormat();
802 
803     D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
804     D3DFORMAT backBufferFormat = g_DeviceSettings.pp.BackBufferFormat;
805 
806     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
807     if( pDeviceInfo == NULL )
808         return E_FAIL;
809 
810     bool bAllowSoftwareVP, bAllowHardwareVP, bAllowPureHardwareVP, bAllowMixedVP;
811     DXUTGetEnumeration()->GetPossibleVertexProcessingList( &bAllowSoftwareVP, &bAllowHardwareVP,
812                                                            &bAllowPureHardwareVP, &bAllowMixedVP );
813 
814     for( int idc=0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
815     {
816         CD3DEnumDeviceSettingsCombo* pDeviceCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
817 
818         if( pDeviceCombo->Windowed == (g_DeviceSettings.pp.Windowed == TRUE) &&
819             pDeviceCombo->AdapterFormat == adapterFormat &&
820             pDeviceCombo->BackBufferFormat == backBufferFormat )
821         {
822             CDXUTComboBox* pDepthStencilComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
823             pDepthStencilComboBox->RemoveAllItems();
824             pDepthStencilComboBox->SetEnabled( (g_DeviceSettings.pp.EnableAutoDepthStencil == TRUE) );
825 
826             if( g_DeviceSettings.pp.EnableAutoDepthStencil )
827             {
828                 for( int ifmt=0; ifmt < pDeviceCombo->depthStencilFormatList.GetSize(); ifmt++ )
829                 {
830                     D3DFORMAT fmt = pDeviceCombo->depthStencilFormatList.GetAt( ifmt );
831 
832                     AddDepthStencilBufferFormat( fmt );
833                 }
834 
835                 pDepthStencilComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.AutoDepthStencilFormat) );
836             }
837             else
838             {
839                 if( !pDepthStencilComboBox->ContainsItem( L"(not used)" ) )
840                     pDepthStencilComboBox->AddItem( L"(not used)", NULL );
841             }
842 
843             hr = OnDepthStencilBufferFormatChanged();
844             if( FAILED(hr) )
845                 return hr;
846 
847             CDXUTComboBox* pVertexProcessingComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
848             pVertexProcessingComboBox->RemoveAllItems();
849 
850             // Add valid vertex processing types
851             if( bAllowSoftwareVP )
852                 AddVertexProcessingType( D3DCREATE_SOFTWARE_VERTEXPROCESSING );
853 
854             if( bAllowHardwareVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
855                 AddVertexProcessingType( D3DCREATE_HARDWARE_VERTEXPROCESSING );
856 
857             if( bAllowPureHardwareVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_PUREDEVICE )
858                 AddVertexProcessingType( D3DCREATE_PUREDEVICE );
859 
860             if( bAllowMixedVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
861                 AddVertexProcessingType( D3DCREATE_MIXED_VERTEXPROCESSING );
862 
863             if( g_DeviceSettings.BehaviorFlags & D3DCREATE_PUREDEVICE )
864                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_PUREDEVICE) );
865             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
866                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_SOFTWARE_VERTEXPROCESSING) );
867             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
868                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_HARDWARE_VERTEXPROCESSING) );
869             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
870                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_MIXED_VERTEXPROCESSING) );
871 
872             hr = OnVertexProcessingChanged();
873             if( FAILED(hr) )
874                 return hr;
875 
876             CDXUTComboBox* pPresentIntervalComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL );
877             pPresentIntervalComboBox->RemoveAllItems();
878             pPresentIntervalComboBox->AddItem( L"On", ULongToPtr(D3DPRESENT_INTERVAL_DEFAULT) );
879             pPresentIntervalComboBox->AddItem( L"Off", ULongToPtr(D3DPRESENT_INTERVAL_IMMEDIATE) );
880 
881             pPresentIntervalComboBox->SetSelectedByData( ULongToPtr( g_DeviceSettings.pp.PresentationInterval ) );
882 
883             hr = OnPresentIntervalChanged();
884             if( FAILED(hr) )
885                 return hr;
886         }
887     }
888 
889     return S_OK;
890 }
891 
892 
893 //-------------------------------------------------------------------------------------
OnDepthStencilBufferFormatChanged()894 HRESULT CD3DSettingsDlg::OnDepthStencilBufferFormatChanged()
895 {
896     HRESULT hr = S_OK;
897 
898     D3DFORMAT depthStencilBufferFormat = GetSelectedDepthStencilBufferFormat();
899 
900     if( g_DeviceSettings.pp.EnableAutoDepthStencil )
901         g_DeviceSettings.pp.AutoDepthStencilFormat = depthStencilBufferFormat;
902 
903     CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = GetCurrentDeviceSettingsCombo();
904     if( pDeviceSettingsCombo == NULL )
905         return E_FAIL;
906 
907     CDXUTComboBox* pMultisampleTypeCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
908     pMultisampleTypeCombo->RemoveAllItems();
909 
910     for( int ims=0; ims < pDeviceSettingsCombo->multiSampleTypeList.GetSize(); ims++ )
911     {
912         D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt( ims );
913 
914         bool bConflictFound = false;
915         for( int iConf = 0; iConf < pDeviceSettingsCombo->DSMSConflictList.GetSize(); iConf++ )
916         {
917             CD3DEnumDSMSConflict DSMSConf = pDeviceSettingsCombo->DSMSConflictList.GetAt( iConf );
918             if( DSMSConf.DSFormat == depthStencilBufferFormat &&
919                 DSMSConf.MSType == msType )
920             {
921                 bConflictFound = true;
922                 break;
923             }
924         }
925 
926         if( !bConflictFound )
927             AddMultisampleType( msType );
928     }
929 
930     CDXUTComboBox* pMultisampleQualityCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
931     pMultisampleQualityCombo->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.MultiSampleType) );
932 
933     hr = OnMultisampleTypeChanged();
934     if( FAILED(hr) )
935         return hr;
936 
937     return S_OK;
938 }
939 
940 
941 //-------------------------------------------------------------------------------------
OnMultisampleTypeChanged()942 HRESULT CD3DSettingsDlg::OnMultisampleTypeChanged()
943 {
944     HRESULT hr = S_OK;
945 
946     D3DMULTISAMPLE_TYPE multisampleType = GetSelectedMultisampleType();
947     g_DeviceSettings.pp.MultiSampleType = multisampleType;
948 
949     CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = GetCurrentDeviceSettingsCombo();
950     if( pDeviceSettingsCombo == NULL )
951         return E_FAIL;
952 
953     DWORD dwMaxQuality = 0;
954     for( int iType = 0; iType < pDeviceSettingsCombo->multiSampleTypeList.GetSize(); iType++ )
955     {
956         D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt( iType );
957         if( msType == multisampleType )
958         {
959             dwMaxQuality = pDeviceSettingsCombo->multiSampleQualityList.GetAt( iType );
960             break;
961         }
962     }
963 
964     // DXUTSETTINGSDLG_MULTISAMPLE_QUALITY
965     CDXUTComboBox* pMultisampleQualityCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
966     pMultisampleQualityCombo->RemoveAllItems();
967 
968     for( UINT iQuality = 0; iQuality < dwMaxQuality; iQuality++ )
969     {
970         AddMultisampleQuality( iQuality );
971     }
972 
973     pMultisampleQualityCombo->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.MultiSampleQuality) );
974 
975     hr = OnMultisampleQualityChanged();
976     if( FAILED(hr) )
977         return hr;
978 
979     return S_OK;
980 }
981 
982 
983 //-------------------------------------------------------------------------------------
OnMultisampleQualityChanged()984 HRESULT CD3DSettingsDlg::OnMultisampleQualityChanged()
985 {
986     g_DeviceSettings.pp.MultiSampleQuality = GetSelectedMultisampleQuality();
987 
988     return S_OK;
989 }
990 
991 
992 //-------------------------------------------------------------------------------------
OnVertexProcessingChanged()993 HRESULT CD3DSettingsDlg::OnVertexProcessingChanged()
994 {
995     DWORD dwBehavior = g_DeviceSettings.BehaviorFlags;
996 
997     // Clear vertex processing flags
998     dwBehavior &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
999     dwBehavior &= ~D3DCREATE_SOFTWARE_VERTEXPROCESSING;
1000     dwBehavior &= ~D3DCREATE_MIXED_VERTEXPROCESSING;
1001     dwBehavior &= ~D3DCREATE_PUREDEVICE;
1002 
1003     // Determine new flags
1004     DWORD dwNewFlags = GetSelectedVertexProcessingType();
1005     if( dwNewFlags & D3DCREATE_PUREDEVICE )
1006         dwNewFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
1007 
1008     // Make changes
1009     g_DeviceSettings.BehaviorFlags = dwBehavior | dwNewFlags;
1010 
1011     return S_OK;
1012 }
1013 
1014 
1015 //-------------------------------------------------------------------------------------
OnPresentIntervalChanged()1016 HRESULT CD3DSettingsDlg::OnPresentIntervalChanged()
1017 {
1018     g_DeviceSettings.pp.PresentationInterval = GetSelectedPresentInterval();
1019 
1020     return S_OK;
1021 }
1022 
1023 
1024 //-------------------------------------------------------------------------------------
OnDeviceClipChanged()1025 HRESULT CD3DSettingsDlg::OnDeviceClipChanged()
1026 {
1027     if( IsDeviceClip() )
1028         g_DeviceSettings.pp.Flags |= D3DPRESENTFLAG_DEVICECLIP;
1029     else
1030         g_DeviceSettings.pp.Flags &= ~D3DPRESENTFLAG_DEVICECLIP;
1031 
1032     return S_OK;
1033 }
1034 
1035 
1036 //-------------------------------------------------------------------------------------
AddAdapter(const WCHAR * strDescription,UINT iAdapter)1037 void CD3DSettingsDlg::AddAdapter( const WCHAR* strDescription, UINT iAdapter )
1038 {
1039     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
1040 
1041     if( !pComboBox->ContainsItem( strDescription ) )
1042         pComboBox->AddItem( strDescription, ULongToPtr(iAdapter) );
1043 }
1044 
1045 
1046 //-------------------------------------------------------------------------------------
GetSelectedAdapter()1047 UINT CD3DSettingsDlg::GetSelectedAdapter()
1048 {
1049     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
1050 
1051     return PtrToUlong( pComboBox->GetSelectedData() );
1052 }
1053 
1054 
1055 //-------------------------------------------------------------------------------------
AddDeviceType(D3DDEVTYPE devType)1056 void CD3DSettingsDlg::AddDeviceType( D3DDEVTYPE devType )
1057 {
1058     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
1059 
1060     if( !pComboBox->ContainsItem( DXUTD3DDeviceTypeToString(devType) ) )
1061         pComboBox->AddItem( DXUTD3DDeviceTypeToString(devType), ULongToPtr(devType) );
1062 }
1063 
1064 
1065 //-------------------------------------------------------------------------------------
GetSelectedDeviceType()1066 D3DDEVTYPE CD3DSettingsDlg::GetSelectedDeviceType()
1067 {
1068     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
1069 
1070     return (D3DDEVTYPE) PtrToUlong( pComboBox->GetSelectedData() );
1071 }
1072 
1073 
1074 //-------------------------------------------------------------------------------------
SetWindowed(bool bWindowed)1075 void CD3DSettingsDlg::SetWindowed( bool bWindowed )
1076 {
1077     CDXUTRadioButton* pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
1078     pRadioButton->SetChecked( bWindowed );
1079 
1080     pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_FULLSCREEN );
1081     pRadioButton->SetChecked( !bWindowed );
1082 }
1083 
1084 
1085 //-------------------------------------------------------------------------------------
IsWindowed()1086 bool CD3DSettingsDlg::IsWindowed()
1087 {
1088     CDXUTRadioButton* pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
1089     return pRadioButton->GetChecked();
1090 }
1091 
1092 
1093 //-------------------------------------------------------------------------------------
AddAdapterFormat(D3DFORMAT format)1094 void CD3DSettingsDlg::AddAdapterFormat( D3DFORMAT format )
1095 {
1096     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
1097 
1098     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
1099         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr( format ) );
1100 }
1101 
1102 
1103 //-------------------------------------------------------------------------------------
GetSelectedAdapterFormat()1104 D3DFORMAT CD3DSettingsDlg::GetSelectedAdapterFormat()
1105 {
1106     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
1107 
1108     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
1109 }
1110 
1111 
1112 //-------------------------------------------------------------------------------------
AddResolution(DWORD dwWidth,DWORD dwHeight)1113 void CD3DSettingsDlg::AddResolution( DWORD dwWidth, DWORD dwHeight )
1114 {
1115     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
1116 
1117     DWORD dwResolutionData;
1118     WCHAR strResolution[50];
1119     dwResolutionData = MAKELONG( dwWidth, dwHeight );
1120     StringCchPrintf( strResolution, 50, L"%d by %d", dwWidth, dwHeight );
1121 
1122     if( !pComboBox->ContainsItem( strResolution ) )
1123         pComboBox->AddItem( strResolution, ULongToPtr( dwResolutionData ) );
1124 }
1125 
1126 
1127 //-------------------------------------------------------------------------------------
GetSelectedResolution(DWORD * pdwWidth,DWORD * pdwHeight)1128 void CD3DSettingsDlg::GetSelectedResolution( DWORD* pdwWidth, DWORD* pdwHeight )
1129 {
1130     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
1131 
1132     DWORD dwResolution = PtrToUlong( pComboBox->GetSelectedData() );
1133 
1134     *pdwWidth = LOWORD( dwResolution );
1135     *pdwHeight = HIWORD( dwResolution );
1136 }
1137 
1138 
1139 //-------------------------------------------------------------------------------------
AddRefreshRate(DWORD dwRate)1140 void CD3DSettingsDlg::AddRefreshRate( DWORD dwRate )
1141 {
1142     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
1143 
1144     WCHAR strRefreshRate[50];
1145 
1146     if( dwRate == 0 )
1147         StringCchCopy( strRefreshRate, 50, L"Default Rate" );
1148     else
1149         StringCchPrintf( strRefreshRate, 50, L"%d Hz", dwRate );
1150 
1151     if( !pComboBox->ContainsItem( strRefreshRate ) )
1152         pComboBox->AddItem( strRefreshRate, ULongToPtr(dwRate) );
1153 }
1154 
1155 
1156 //-------------------------------------------------------------------------------------
GetSelectedRefreshRate()1157 DWORD CD3DSettingsDlg::GetSelectedRefreshRate()
1158 {
1159     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
1160 
1161     return PtrToUlong( pComboBox->GetSelectedData() );
1162 }
1163 
1164 
1165 //-------------------------------------------------------------------------------------
AddBackBufferFormat(D3DFORMAT format)1166 void CD3DSettingsDlg::AddBackBufferFormat( D3DFORMAT format )
1167 {
1168     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
1169 
1170     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
1171         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr( format ) );
1172 }
1173 
1174 
1175 //-------------------------------------------------------------------------------------
GetSelectedBackBufferFormat()1176 D3DFORMAT CD3DSettingsDlg::GetSelectedBackBufferFormat()
1177 {
1178     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
1179 
1180     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
1181 }
1182 
1183 
1184 //-------------------------------------------------------------------------------------
AddDepthStencilBufferFormat(D3DFORMAT format)1185 void CD3DSettingsDlg::AddDepthStencilBufferFormat( D3DFORMAT format )
1186 {
1187     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
1188 
1189     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
1190         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr(format) );
1191 }
1192 
1193 
1194 //-------------------------------------------------------------------------------------
GetSelectedDepthStencilBufferFormat()1195 D3DFORMAT CD3DSettingsDlg::GetSelectedDepthStencilBufferFormat()
1196 {
1197     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
1198 
1199     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
1200 }
1201 
1202 
1203 //-------------------------------------------------------------------------------------
AddMultisampleType(D3DMULTISAMPLE_TYPE type)1204 void CD3DSettingsDlg::AddMultisampleType( D3DMULTISAMPLE_TYPE type )
1205 {
1206     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
1207 
1208     if( !pComboBox->ContainsItem( DXUTMultisampleTypeToString(type) ) )
1209         pComboBox->AddItem( DXUTMultisampleTypeToString(type), ULongToPtr(type) );
1210 }
1211 
1212 
1213 //-------------------------------------------------------------------------------------
GetSelectedMultisampleType()1214 D3DMULTISAMPLE_TYPE CD3DSettingsDlg::GetSelectedMultisampleType()
1215 {
1216     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
1217 
1218     return (D3DMULTISAMPLE_TYPE) PtrToUlong( pComboBox->GetSelectedData() );
1219 }
1220 
1221 
1222 //-------------------------------------------------------------------------------------
AddMultisampleQuality(DWORD dwQuality)1223 void CD3DSettingsDlg::AddMultisampleQuality( DWORD dwQuality )
1224 {
1225     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
1226 
1227     WCHAR strQuality[50];
1228     StringCchPrintf( strQuality, 50, L"%d", dwQuality );
1229 
1230     if( !pComboBox->ContainsItem( strQuality ) )
1231         pComboBox->AddItem( strQuality, ULongToPtr(dwQuality) );
1232 }
1233 
1234 
1235 //-------------------------------------------------------------------------------------
GetSelectedMultisampleQuality()1236 DWORD CD3DSettingsDlg::GetSelectedMultisampleQuality()
1237 {
1238     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
1239 
1240     return PtrToUlong( pComboBox->GetSelectedData() );
1241 }
1242 
1243 
1244 //-------------------------------------------------------------------------------------
AddVertexProcessingType(DWORD dwType)1245 void CD3DSettingsDlg::AddVertexProcessingType( DWORD dwType )
1246 {
1247     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
1248 
1249     if( !pComboBox->ContainsItem( DXUTVertexProcessingTypeToString(dwType) ) )
1250         pComboBox->AddItem( DXUTVertexProcessingTypeToString(dwType), ULongToPtr(dwType) );
1251 }
1252 
1253 
1254 //-------------------------------------------------------------------------------------
GetSelectedVertexProcessingType()1255 DWORD CD3DSettingsDlg::GetSelectedVertexProcessingType()
1256 {
1257     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
1258 
1259     return PtrToUlong( pComboBox->GetSelectedData() );
1260 }
1261 
1262 
1263 //-------------------------------------------------------------------------------------
GetSelectedPresentInterval()1264 DWORD CD3DSettingsDlg::GetSelectedPresentInterval()
1265 {
1266     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL );
1267 
1268     return PtrToUlong( pComboBox->GetSelectedData() );
1269 }
1270 
1271 
1272 //-------------------------------------------------------------------------------------
SetDeviceClip(bool bDeviceClip)1273 void CD3DSettingsDlg::SetDeviceClip( bool bDeviceClip )
1274 {
1275     CDXUTCheckBox* pCheckBox = m_Dialog.GetCheckBox( DXUTSETTINGSDLG_DEVICECLIP );
1276     pCheckBox->SetChecked( bDeviceClip );
1277 }
1278 
1279 
1280 //-------------------------------------------------------------------------------------
IsDeviceClip()1281 bool CD3DSettingsDlg::IsDeviceClip()
1282 {
1283     CDXUTCheckBox* pCheckBox = m_Dialog.GetCheckBox( DXUTSETTINGSDLG_DEVICECLIP );
1284     return pCheckBox->GetChecked();
1285 }
1286 
1287 
1288 //--------------------------------------------------------------------------------------
1289 // Returns the string for the given D3DDEVTYPE.
1290 //--------------------------------------------------------------------------------------
DXUTD3DDeviceTypeToString(D3DDEVTYPE devType)1291 WCHAR* DXUTD3DDeviceTypeToString(D3DDEVTYPE devType)
1292 {
1293     switch (devType)
1294     {
1295         case D3DDEVTYPE_HAL:        return L"D3DDEVTYPE_HAL";
1296         case D3DDEVTYPE_SW:         return L"D3DDEVTYPE_SW";
1297         case D3DDEVTYPE_REF:        return L"D3DDEVTYPE_REF";
1298         default:                    return L"Unknown devType";
1299     }
1300 }
1301 
1302 
1303 //--------------------------------------------------------------------------------------
1304 // Returns the string for the given D3DMULTISAMPLE_TYPE.
1305 //--------------------------------------------------------------------------------------
DXUTMultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType)1306 WCHAR* DXUTMultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType)
1307 {
1308     switch (MultiSampleType)
1309     {
1310     case D3DMULTISAMPLE_NONE:       return L"D3DMULTISAMPLE_NONE";
1311     case D3DMULTISAMPLE_NONMASKABLE: return L"D3DMULTISAMPLE_NONMASKABLE";
1312     case D3DMULTISAMPLE_2_SAMPLES:  return L"D3DMULTISAMPLE_2_SAMPLES";
1313     case D3DMULTISAMPLE_3_SAMPLES:  return L"D3DMULTISAMPLE_3_SAMPLES";
1314     case D3DMULTISAMPLE_4_SAMPLES:  return L"D3DMULTISAMPLE_4_SAMPLES";
1315     case D3DMULTISAMPLE_5_SAMPLES:  return L"D3DMULTISAMPLE_5_SAMPLES";
1316     case D3DMULTISAMPLE_6_SAMPLES:  return L"D3DMULTISAMPLE_6_SAMPLES";
1317     case D3DMULTISAMPLE_7_SAMPLES:  return L"D3DMULTISAMPLE_7_SAMPLES";
1318     case D3DMULTISAMPLE_8_SAMPLES:  return L"D3DMULTISAMPLE_8_SAMPLES";
1319     case D3DMULTISAMPLE_9_SAMPLES:  return L"D3DMULTISAMPLE_9_SAMPLES";
1320     case D3DMULTISAMPLE_10_SAMPLES: return L"D3DMULTISAMPLE_10_SAMPLES";
1321     case D3DMULTISAMPLE_11_SAMPLES: return L"D3DMULTISAMPLE_11_SAMPLES";
1322     case D3DMULTISAMPLE_12_SAMPLES: return L"D3DMULTISAMPLE_12_SAMPLES";
1323     case D3DMULTISAMPLE_13_SAMPLES: return L"D3DMULTISAMPLE_13_SAMPLES";
1324     case D3DMULTISAMPLE_14_SAMPLES: return L"D3DMULTISAMPLE_14_SAMPLES";
1325     case D3DMULTISAMPLE_15_SAMPLES: return L"D3DMULTISAMPLE_15_SAMPLES";
1326     case D3DMULTISAMPLE_16_SAMPLES: return L"D3DMULTISAMPLE_16_SAMPLES";
1327     default:                        return L"Unknown Multisample Type";
1328     }
1329 }
1330 
1331 
1332 //--------------------------------------------------------------------------------------
1333 // Returns the string for the given vertex processing type
1334 //--------------------------------------------------------------------------------------
DXUTVertexProcessingTypeToString(DWORD vpt)1335 WCHAR* DXUTVertexProcessingTypeToString(DWORD vpt)
1336 {
1337     switch (vpt)
1338     {
1339     case D3DCREATE_SOFTWARE_VERTEXPROCESSING: return L"Software vertex processing";
1340     case D3DCREATE_MIXED_VERTEXPROCESSING:    return L"Mixed vertex processing";
1341     case D3DCREATE_HARDWARE_VERTEXPROCESSING: return L"Hardware vertex processing";
1342     case D3DCREATE_PUREDEVICE:                return L"Pure hardware vertex processing";
1343     default:                                  return L"Unknown vertex processing type";
1344     }
1345 }
1346 
1347 
1348 //--------------------------------------------------------------------------------------
1349 // Returns the string for the given present interval.
1350 //--------------------------------------------------------------------------------------
DXUTPresentIntervalToString(UINT pi)1351 WCHAR* DXUTPresentIntervalToString( UINT pi )
1352 {
1353     switch( pi )
1354     {
1355     case D3DPRESENT_INTERVAL_IMMEDIATE: return L"D3DPRESENT_INTERVAL_IMMEDIATE";
1356     case D3DPRESENT_INTERVAL_DEFAULT:   return L"D3DPRESENT_INTERVAL_DEFAULT";
1357     case D3DPRESENT_INTERVAL_ONE:       return L"D3DPRESENT_INTERVAL_ONE";
1358     case D3DPRESENT_INTERVAL_TWO:       return L"D3DPRESENT_INTERVAL_TWO";
1359     case D3DPRESENT_INTERVAL_THREE:     return L"D3DPRESENT_INTERVAL_THREE";
1360     case D3DPRESENT_INTERVAL_FOUR:      return L"D3DPRESENT_INTERVAL_FOUR";
1361     default:                            return L"Unknown PresentInterval";
1362     }
1363 }
1364 
1365 
1366