source: GTP/trunk/App/Demos/Illum/StochasticIteration/Common/DXUTSettingsDlg.cpp @ 1808

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