source: GTP/trunk/App/Games/Jungle_Rumble/src/common/dxutenum.cpp @ 1378

Revision 1378, 31.7 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1//--------------------------------------------------------------------------------------
2// File: DXUTEnum.cpp
3//
4// Enumerates D3D adapters, devices, modes, etc.
5//
6// Copyright (c) Microsoft Corporation. All rights reserved.
7//--------------------------------------------------------------------------------------
8#include "dxstdafx.h"
9#undef min // use __min instead
10#undef max // use __max instead
11
12
13//--------------------------------------------------------------------------------------
14// Forward declarations
15//--------------------------------------------------------------------------------------
16static int __cdecl SortModesCallback( const void* arg1, const void* arg2 );
17UINT DXUTStencilBits( D3DFORMAT fmt );
18UINT DXUTDepthBits( D3DFORMAT fmt );
19UINT DXUTAlphaChannelBits( D3DFORMAT fmt );
20UINT DXUTColorChannelBits( D3DFORMAT fmt );
21CD3DEnumeration* DXUTGetEnumeration()
22{
23    // Using an accessor function gives control of the construction order
24    static CD3DEnumeration d3denum;
25    return &d3denum;
26}
27
28
29//--------------------------------------------------------------------------------------
30CD3DEnumeration::CD3DEnumeration()
31{
32    m_pD3D = NULL;
33    m_IsDeviceAcceptableFunc = NULL;
34    m_pIsDeviceAcceptableFuncUserContext = NULL;
35    m_bRequirePostPixelShaderBlending = true;
36
37    m_nMinWidth = 640;
38    m_nMinHeight = 480;
39    m_nMaxWidth = UINT_MAX;
40    m_nMaxHeight = UINT_MAX;
41
42    m_nRefreshMin = 0;
43    m_nRefreshMax = UINT_MAX;
44
45    m_nMultisampleQualityMax = 0xFFFF;
46
47    ResetPossibleDepthStencilFormats();
48    ResetPossibleMultisampleTypeList();                                   
49    ResetPossiblePresentIntervalList();
50    SetPossibleVertexProcessingList( true, true, true, false );
51}
52
53
54//--------------------------------------------------------------------------------------
55CD3DEnumeration::~CD3DEnumeration()
56{
57    ClearAdapterInfoList();
58}
59
60
61
62//--------------------------------------------------------------------------------------
63// Enumerates available D3D adapters, devices, modes, etc.
64//--------------------------------------------------------------------------------------
65HRESULT CD3DEnumeration::Enumerate( IDirect3D9* pD3D,
66                                    LPDXUTCALLBACKISDEVICEACCEPTABLE IsDeviceAcceptableFunc,
67                                    void* pIsDeviceAcceptableFuncUserContext )
68{
69    if( pD3D == NULL )
70    {
71        pD3D = DXUTGetD3DObject();
72        if( pD3D == NULL )
73            return DXUTERR_NODIRECT3D;
74    }
75
76    m_pD3D = pD3D;
77    m_IsDeviceAcceptableFunc = IsDeviceAcceptableFunc;
78    m_pIsDeviceAcceptableFuncUserContext = pIsDeviceAcceptableFuncUserContext;
79
80    HRESULT hr;
81    ClearAdapterInfoList();
82    CGrowableArray<D3DFORMAT> adapterFormatList;
83
84    const D3DFORMAT allowedAdapterFormatArray[] =
85    {   
86        D3DFMT_X8R8G8B8,
87        D3DFMT_X1R5G5B5,
88        D3DFMT_R5G6B5,
89        D3DFMT_A2R10G10B10
90    };
91    const UINT allowedAdapterFormatArrayCount  = sizeof(allowedAdapterFormatArray) / sizeof(allowedAdapterFormatArray[0]);
92
93    UINT numAdapters = pD3D->GetAdapterCount();
94    for (UINT adapterOrdinal = 0; adapterOrdinal < numAdapters; adapterOrdinal++)
95    {
96        CD3DEnumAdapterInfo* pAdapterInfo = new CD3DEnumAdapterInfo;
97        if( pAdapterInfo == NULL )
98            return E_OUTOFMEMORY;
99
100        pAdapterInfo->AdapterOrdinal = adapterOrdinal;
101        pD3D->GetAdapterIdentifier(adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier);
102
103        // Get list of all display modes on this adapter. 
104        // Also build a temporary list of all display adapter formats.
105        adapterFormatList.RemoveAll();
106
107        for( UINT iFormatList = 0; iFormatList < allowedAdapterFormatArrayCount; iFormatList++ )
108        {
109            D3DFORMAT allowedAdapterFormat = allowedAdapterFormatArray[iFormatList];
110            UINT numAdapterModes = pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat );
111            for (UINT mode = 0; mode < numAdapterModes; mode++)
112            {
113                D3DDISPLAYMODE displayMode;
114                pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode );
115
116                if( displayMode.Width < m_nMinWidth ||
117                    displayMode.Height < m_nMinHeight ||
118                    displayMode.Width > m_nMaxWidth ||
119                    displayMode.Height > m_nMaxHeight ||
120                    displayMode.RefreshRate < m_nRefreshMin ||
121                    displayMode.RefreshRate > m_nRefreshMax )
122                {
123                    continue;
124                }
125
126                pAdapterInfo->displayModeList.Add( displayMode );
127               
128                if( !adapterFormatList.Contains(displayMode.Format) )
129                    adapterFormatList.Add( displayMode.Format );
130            }
131
132        }
133
134        D3DDISPLAYMODE displayMode;
135        pD3D->GetAdapterDisplayMode( adapterOrdinal, &displayMode );
136        if( !adapterFormatList.Contains(displayMode.Format) )
137            adapterFormatList.Add( displayMode.Format );
138
139        // Sort displaymode list
140        ::qsort( pAdapterInfo->displayModeList.GetData(),
141               pAdapterInfo->displayModeList.GetSize(), sizeof( D3DDISPLAYMODE ),
142               SortModesCallback );
143
144        // Get info for each device on this adapter
145        if( FAILED( EnumerateDevices( pAdapterInfo, &adapterFormatList ) ) )
146        {
147            delete pAdapterInfo;
148            continue;
149        }
150
151        // If at least one device on this adapter is available and compatible
152        // with the app, add the adapterInfo to the list
153        if( pAdapterInfo->deviceInfoList.GetSize() > 0 )
154        {
155            hr = m_AdapterInfoList.Add( pAdapterInfo );
156            if( FAILED(hr) )
157                return hr;
158        } else
159            delete pAdapterInfo;
160    }
161
162    bool bUniqueDesc = true;
163    CD3DEnumAdapterInfo* pAdapterInfo;
164    for( int i=0; i<m_AdapterInfoList.GetSize(); i++ )
165    {
166        CD3DEnumAdapterInfo* pAdapterInfo1 = m_AdapterInfoList.GetAt(i);
167
168        for( int j=i+1; j<m_AdapterInfoList.GetSize(); j++ )
169        {
170            CD3DEnumAdapterInfo* pAdapterInfo2 = m_AdapterInfoList.GetAt(j);
171            if( _stricmp( pAdapterInfo1->AdapterIdentifier.Description,
172                          pAdapterInfo2->AdapterIdentifier.Description ) == 0 )
173            {
174                bUniqueDesc = false;
175                break;
176            }
177        }
178
179        if( !bUniqueDesc )
180            break;
181    }
182
183    for( int i=0; i<m_AdapterInfoList.GetSize(); i++ )
184    {
185        pAdapterInfo = m_AdapterInfoList.GetAt(i);
186
187        MultiByteToWideChar( CP_ACP, 0,
188                             pAdapterInfo->AdapterIdentifier.Description, -1,
189                             pAdapterInfo->szUniqueDescription, 100 );
190        pAdapterInfo->szUniqueDescription[100] = 0;
191
192        if( !bUniqueDesc )
193        {
194            WCHAR sz[100];
195            StringCchPrintf( sz, 100, L" (#%d)", pAdapterInfo->AdapterOrdinal );
196            StringCchCat( pAdapterInfo->szUniqueDescription, 256, sz );
197
198        }
199    }
200
201    return S_OK;
202}
203
204
205
206//--------------------------------------------------------------------------------------
207// Enumerates D3D devices for a particular adapter.
208//--------------------------------------------------------------------------------------
209HRESULT CD3DEnumeration::EnumerateDevices( CD3DEnumAdapterInfo* pAdapterInfo, CGrowableArray<D3DFORMAT>* pAdapterFormatList )
210{
211    HRESULT hr;
212
213    const D3DDEVTYPE devTypeArray[] =
214    {
215        D3DDEVTYPE_HAL,
216        D3DDEVTYPE_SW,
217        D3DDEVTYPE_REF
218    };
219    const UINT devTypeArrayCount = sizeof(devTypeArray) / sizeof(devTypeArray[0]);
220
221    // Enumerate each Direct3D device type
222    for( UINT iDeviceType = 0; iDeviceType < devTypeArrayCount; iDeviceType++ )
223    {
224        CD3DEnumDeviceInfo* pDeviceInfo = new CD3DEnumDeviceInfo;
225        if( pDeviceInfo == NULL )
226            return E_OUTOFMEMORY;
227
228        // Fill struct w/ AdapterOrdinal and D3DDEVTYPE
229        pDeviceInfo->DeviceType = devTypeArray[iDeviceType];
230
231        // Store device caps
232        if( FAILED( hr = m_pD3D->GetDeviceCaps( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType,
233                                                &pDeviceInfo->Caps ) ) )
234        {
235            delete pDeviceInfo;
236            continue;
237        }
238
239        // Create a dummy device to verify that we really can create of this type.
240        D3DDISPLAYMODE Mode;
241        m_pD3D->GetAdapterDisplayMode(0, &Mode);
242        D3DPRESENT_PARAMETERS pp;
243        ZeroMemory( &pp, sizeof(D3DPRESENT_PARAMETERS) );
244        pp.BackBufferWidth  = 1;
245        pp.BackBufferHeight = 1;
246        pp.BackBufferFormat = Mode.Format;
247        pp.BackBufferCount  = 1;
248        pp.SwapEffect       = D3DSWAPEFFECT_COPY;
249        pp.Windowed         = TRUE;
250        pp.hDeviceWindow    = DXUTGetHWNDFocus();
251        IDirect3DDevice9 *pDevice;
252        if( FAILED( hr = m_pD3D->CreateDevice( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, DXUTGetHWNDFocus(),
253                                          D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice ) ) )
254        {
255            if( hr == D3DERR_NOTAVAILABLE )
256            {
257                delete pDeviceInfo;
258                continue;
259            }
260        }
261        SAFE_RELEASE( pDevice );
262
263        // Get info for each devicecombo on this device
264        if( FAILED( hr = EnumerateDeviceCombos( pAdapterInfo, pDeviceInfo, pAdapterFormatList ) ) )
265        {
266            delete pDeviceInfo;
267            continue;
268        }
269
270        // If at least one devicecombo for this device is found,
271        // add the deviceInfo to the list
272        if (pDeviceInfo->deviceSettingsComboList.GetSize() > 0 )
273            pAdapterInfo->deviceInfoList.Add( pDeviceInfo );
274        else
275            delete pDeviceInfo;
276    }
277
278    return S_OK;
279}
280
281
282
283//--------------------------------------------------------------------------------------
284// Enumerates DeviceCombos for a particular device.
285//--------------------------------------------------------------------------------------
286HRESULT CD3DEnumeration::EnumerateDeviceCombos( CD3DEnumAdapterInfo* pAdapterInfo, CD3DEnumDeviceInfo* pDeviceInfo, CGrowableArray<D3DFORMAT>* pAdapterFormatList )
287{
288    const D3DFORMAT backBufferFormatArray[] =
289    {   
290        D3DFMT_A8R8G8B8,
291        D3DFMT_X8R8G8B8,
292        D3DFMT_A2R10G10B10,
293        D3DFMT_R5G6B5,
294        D3DFMT_A1R5G5B5,
295        D3DFMT_X1R5G5B5
296    };
297    const UINT backBufferFormatArrayCount = sizeof(backBufferFormatArray) / sizeof(backBufferFormatArray[0]);
298
299    // See which adapter formats are supported by this device
300    for( int iFormat=0; iFormat<pAdapterFormatList->GetSize(); iFormat++ )
301    {
302        D3DFORMAT adapterFormat = pAdapterFormatList->GetAt(iFormat);
303
304        for( UINT iBackBufferFormat = 0; iBackBufferFormat < backBufferFormatArrayCount; iBackBufferFormat++ )
305        {
306            D3DFORMAT backBufferFormat = backBufferFormatArray[iBackBufferFormat];
307
308            for( int nWindowed = 0; nWindowed < 2; nWindowed++)
309            {
310                if( !nWindowed && pAdapterInfo->displayModeList.GetSize() == 0 )
311                    continue;
312
313                if (FAILED( m_pD3D->CheckDeviceType( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType,
314                                                     adapterFormat, backBufferFormat, nWindowed )))
315                {
316                    continue;
317                }
318
319                if( m_bRequirePostPixelShaderBlending )
320                {
321                    // If the backbuffer format doesn't support D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
322                    // then alpha test, pixel fog, render-target blending, color write enable, and dithering.
323                    // are not supported.
324                    if( FAILED( m_pD3D->CheckDeviceFormat( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType,
325                                                           adapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
326                                                           D3DRTYPE_TEXTURE, backBufferFormat ) ) )
327                    {
328                        continue;
329                    }
330                }
331
332                // If an application callback function has been provided, make sure this device
333                // is acceptable to the app.
334                if( m_IsDeviceAcceptableFunc != NULL )
335                {
336                    if( !m_IsDeviceAcceptableFunc( &pDeviceInfo->Caps, adapterFormat, backBufferFormat, FALSE != nWindowed, m_pIsDeviceAcceptableFuncUserContext ) )
337                        continue;
338                }
339               
340                // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed
341                // DeviceCombo that is supported by the system and acceptable to the app. We still
342                // need to find one or more suitable depth/stencil buffer format,
343                // multisample type, and present interval.
344                CD3DEnumDeviceSettingsCombo* pDeviceCombo = new CD3DEnumDeviceSettingsCombo;
345                if( pDeviceCombo == NULL )
346                    return E_OUTOFMEMORY;
347
348                pDeviceCombo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal;
349                pDeviceCombo->DeviceType = pDeviceInfo->DeviceType;
350                pDeviceCombo->AdapterFormat = adapterFormat;
351                pDeviceCombo->BackBufferFormat = backBufferFormat;
352                pDeviceCombo->Windowed = (nWindowed != 0);
353               
354                BuildDepthStencilFormatList( pDeviceCombo );
355                BuildMultiSampleTypeList( pDeviceCombo );
356                if (pDeviceCombo->multiSampleTypeList.GetSize() == 0)
357                {
358                    delete pDeviceCombo;
359                    continue;
360                }
361                BuildDSMSConflictList( pDeviceCombo );
362                BuildPresentIntervalList(pDeviceInfo, pDeviceCombo );
363                pDeviceCombo->pAdapterInfo = pAdapterInfo;
364                pDeviceCombo->pDeviceInfo = pDeviceInfo;
365
366                pDeviceInfo->deviceSettingsComboList.Add( pDeviceCombo );
367           
368            }
369        }
370    }
371
372    return S_OK;
373}
374
375
376
377//--------------------------------------------------------------------------------------
378// Adds all depth/stencil formats that are compatible with the device
379//       and app to the given D3DDeviceCombo.
380//--------------------------------------------------------------------------------------
381void CD3DEnumeration::BuildDepthStencilFormatList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
382{
383    D3DFORMAT depthStencilFmt;
384    for( int idsf = 0; idsf < m_DepthStecilPossibleList.GetSize(); idsf++ )
385    {
386        depthStencilFmt = m_DepthStecilPossibleList.GetAt(idsf);
387        if (SUCCEEDED(m_pD3D->CheckDeviceFormat(pDeviceCombo->AdapterOrdinal,
388                pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat,
389                D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFmt)))
390        {
391            if (SUCCEEDED(m_pD3D->CheckDepthStencilMatch(pDeviceCombo->AdapterOrdinal,
392                    pDeviceCombo->DeviceType, pDeviceCombo->AdapterFormat,
393                    pDeviceCombo->BackBufferFormat, depthStencilFmt)))
394            {
395                pDeviceCombo->depthStencilFormatList.Add( depthStencilFmt );
396            }
397        }
398    }
399}
400
401
402
403
404//--------------------------------------------------------------------------------------
405// Adds all multisample types that are compatible with the device and app to
406//       the given D3DDeviceCombo.
407//--------------------------------------------------------------------------------------
408void CD3DEnumeration::BuildMultiSampleTypeList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
409{
410    D3DMULTISAMPLE_TYPE msType;
411    DWORD msQuality;
412    for( int imst = 0; imst < m_MultiSampleTypeList.GetSize(); imst++ )
413    {
414        msType = m_MultiSampleTypeList.GetAt(imst);
415        if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal,
416                pDeviceCombo->DeviceType, pDeviceCombo->BackBufferFormat,
417                pDeviceCombo->Windowed, msType, &msQuality ) ) )
418        {
419            pDeviceCombo->multiSampleTypeList.Add( msType );
420            if( msQuality > m_nMultisampleQualityMax+1 )
421                msQuality = m_nMultisampleQualityMax+1;
422            pDeviceCombo->multiSampleQualityList.Add( msQuality );
423        }
424    }
425}
426
427
428
429
430//--------------------------------------------------------------------------------------
431// Find any conflicts between the available depth/stencil formats and
432//       multisample types.
433//--------------------------------------------------------------------------------------
434void CD3DEnumeration::BuildDSMSConflictList( CD3DEnumDeviceSettingsCombo* pDeviceCombo )
435{
436    CD3DEnumDSMSConflict DSMSConflict;
437
438    for( int iDS=0; iDS<pDeviceCombo->depthStencilFormatList.GetSize(); iDS++ )
439    {
440        D3DFORMAT dsFmt = pDeviceCombo->depthStencilFormatList.GetAt(iDS);
441
442        for( int iMS=0; iMS<pDeviceCombo->multiSampleTypeList.GetSize(); iMS++ )
443        {
444            D3DMULTISAMPLE_TYPE msType = pDeviceCombo->multiSampleTypeList.GetAt(iMS);
445
446            if( FAILED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, pDeviceCombo->DeviceType,
447                                                            dsFmt, pDeviceCombo->Windowed, msType, NULL ) ) )
448            {
449                DSMSConflict.DSFormat = dsFmt;
450                DSMSConflict.MSType = msType;
451                pDeviceCombo->DSMSConflictList.Add( DSMSConflict );
452            }
453        }
454    }
455}
456
457
458
459//--------------------------------------------------------------------------------------
460// Adds all present intervals that are compatible with the device and app
461//       to the given D3DDeviceCombo.
462//--------------------------------------------------------------------------------------
463void CD3DEnumeration::BuildPresentIntervalList( CD3DEnumDeviceInfo* pDeviceInfo,
464                                                CD3DEnumDeviceSettingsCombo* pDeviceCombo )
465{
466    UINT pi;
467    for( int ipi = 0; ipi < m_PresentIntervalList.GetSize(); ipi++ )
468    {
469        pi = m_PresentIntervalList.GetAt(ipi);
470        if( pDeviceCombo->Windowed )
471        {
472            if( pi == D3DPRESENT_INTERVAL_TWO ||
473                pi == D3DPRESENT_INTERVAL_THREE ||
474                pi == D3DPRESENT_INTERVAL_FOUR )
475            {
476                // These intervals are not supported in windowed mode.
477                continue;
478            }
479        }
480        // Note that D3DPRESENT_INTERVAL_DEFAULT is zero, so you
481        // can't do a caps check for it -- it is always available.
482        if( pi == D3DPRESENT_INTERVAL_DEFAULT ||
483            (pDeviceInfo->Caps.PresentationIntervals & pi) )
484        {
485            pDeviceCombo->presentIntervalList.Add( pi );
486        }
487    }
488}
489
490
491
492//--------------------------------------------------------------------------------------
493// Release all the allocated CD3DEnumAdapterInfo objects and empty the list
494//--------------------------------------------------------------------------------------
495void CD3DEnumeration::ClearAdapterInfoList()
496{
497    CD3DEnumAdapterInfo* pAdapterInfo;
498    for( int i=0; i<m_AdapterInfoList.GetSize(); i++ )
499    {
500        pAdapterInfo = m_AdapterInfoList.GetAt(i);
501        delete pAdapterInfo;
502    }
503
504    m_AdapterInfoList.RemoveAll();
505}
506
507
508
509//--------------------------------------------------------------------------------------
510// Call GetAdapterInfoList() after Enumerate() to get a STL vector of
511//       CD3DEnumAdapterInfo*
512//--------------------------------------------------------------------------------------
513CGrowableArray<CD3DEnumAdapterInfo*>* CD3DEnumeration::GetAdapterInfoList()
514{
515    return &m_AdapterInfoList;
516}
517
518
519
520//--------------------------------------------------------------------------------------
521CD3DEnumAdapterInfo* CD3DEnumeration::GetAdapterInfo( UINT AdapterOrdinal )
522{
523    for( int iAdapter=0; iAdapter<m_AdapterInfoList.GetSize(); iAdapter++ )
524    {
525        CD3DEnumAdapterInfo* pAdapterInfo = m_AdapterInfoList.GetAt(iAdapter);
526        if( pAdapterInfo->AdapterOrdinal == AdapterOrdinal )
527            return pAdapterInfo;
528    }
529
530    return NULL;
531}
532
533
534//--------------------------------------------------------------------------------------
535CD3DEnumDeviceInfo* CD3DEnumeration::GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType )
536{
537    CD3DEnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
538    if( pAdapterInfo )
539    {
540        for( int iDeviceInfo=0; iDeviceInfo<pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
541        {
542            CD3DEnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
543            if( pDeviceInfo->DeviceType == DeviceType )
544                return pDeviceInfo;
545        }
546    }
547
548    return NULL;
549}
550
551
552//--------------------------------------------------------------------------------------
553//
554//--------------------------------------------------------------------------------------
555CD3DEnumDeviceSettingsCombo* CD3DEnumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed )
556{
557    CD3DEnumDeviceInfo* pDeviceInfo = GetDeviceInfo( AdapterOrdinal, DeviceType );
558    if( pDeviceInfo )
559    {
560        for( int iDeviceCombo=0; iDeviceCombo<pDeviceInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ )
561        {
562            CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt(iDeviceCombo);
563            if( pDeviceSettingsCombo->AdapterFormat == AdapterFormat &&
564                pDeviceSettingsCombo->BackBufferFormat == BackBufferFormat &&
565                pDeviceSettingsCombo->Windowed == bWindowed )
566                return pDeviceSettingsCombo;
567        }
568    }
569
570    return NULL;
571}
572
573
574//--------------------------------------------------------------------------------------
575// Returns the number of color channel bits in the specified D3DFORMAT
576//--------------------------------------------------------------------------------------
577UINT DXUTColorChannelBits( D3DFORMAT fmt )
578{
579    switch( fmt )
580    {
581        case D3DFMT_R8G8B8:
582            return 8;
583        case D3DFMT_A8R8G8B8:
584            return 8;
585        case D3DFMT_X8R8G8B8:
586            return 8;
587        case D3DFMT_R5G6B5:
588            return 5;
589        case D3DFMT_X1R5G5B5:
590            return 5;
591        case D3DFMT_A1R5G5B5:
592            return 5;
593        case D3DFMT_A4R4G4B4:
594            return 4;
595        case D3DFMT_R3G3B2:
596            return 2;
597        case D3DFMT_A8R3G3B2:
598            return 2;
599        case D3DFMT_X4R4G4B4:
600            return 4;
601        case D3DFMT_A2B10G10R10:
602            return 10;
603        case D3DFMT_A8B8G8R8:
604            return 8;
605        case D3DFMT_A2R10G10B10:
606            return 10;
607        case D3DFMT_A16B16G16R16:
608            return 16;
609        default:
610            return 0;
611    }
612}
613
614
615
616
617//--------------------------------------------------------------------------------------
618// Returns the number of alpha channel bits in the specified D3DFORMAT
619//--------------------------------------------------------------------------------------
620UINT DXUTAlphaChannelBits( D3DFORMAT fmt )
621{
622    switch( fmt )
623    {
624        case D3DFMT_R8G8B8:
625            return 0;
626        case D3DFMT_A8R8G8B8:
627            return 8;
628        case D3DFMT_X8R8G8B8:
629            return 0;
630        case D3DFMT_R5G6B5:
631            return 0;
632        case D3DFMT_X1R5G5B5:
633            return 0;
634        case D3DFMT_A1R5G5B5:
635            return 1;
636        case D3DFMT_A4R4G4B4:
637            return 4;
638        case D3DFMT_R3G3B2:
639            return 0;
640        case D3DFMT_A8R3G3B2:
641            return 8;
642        case D3DFMT_X4R4G4B4:
643            return 0;
644        case D3DFMT_A2B10G10R10:
645            return 2;
646        case D3DFMT_A8B8G8R8:
647            return 8;
648        case D3DFMT_A2R10G10B10:
649            return 2;
650        case D3DFMT_A16B16G16R16:
651            return 16;
652        default:
653            return 0;
654    }
655}
656
657
658
659
660//--------------------------------------------------------------------------------------
661// Returns the number of depth bits in the specified D3DFORMAT
662//--------------------------------------------------------------------------------------
663UINT DXUTDepthBits( D3DFORMAT fmt )
664{
665    switch( fmt )
666    {
667        case D3DFMT_D32F_LOCKABLE:
668        case D3DFMT_D32:
669            return 32;
670
671        case D3DFMT_D24X8:
672        case D3DFMT_D24S8:
673        case D3DFMT_D24X4S4:
674        case D3DFMT_D24FS8:
675            return 24;
676
677        case D3DFMT_D16_LOCKABLE:
678        case D3DFMT_D16:
679            return 16;
680
681        case D3DFMT_D15S1:
682            return 15;
683
684        default:
685            return 0;
686    }
687}
688
689
690
691
692//--------------------------------------------------------------------------------------
693// Returns the number of stencil bits in the specified D3DFORMAT
694//--------------------------------------------------------------------------------------
695UINT DXUTStencilBits( D3DFORMAT fmt )
696{
697    switch( fmt )
698    {
699        case D3DFMT_D16_LOCKABLE:
700        case D3DFMT_D16:
701        case D3DFMT_D32F_LOCKABLE:
702        case D3DFMT_D32:
703        case D3DFMT_D24X8:
704            return 0;
705
706        case D3DFMT_D15S1:
707            return 1;
708
709        case D3DFMT_D24X4S4:
710            return 4;
711
712        case D3DFMT_D24S8:
713        case D3DFMT_D24FS8:
714            return 8;
715
716        default:
717            return 0;
718    }
719}
720
721
722
723//--------------------------------------------------------------------------------------
724// Used to sort D3DDISPLAYMODEs
725//--------------------------------------------------------------------------------------
726static int __cdecl SortModesCallback( const void* arg1, const void* arg2 )
727{
728    D3DDISPLAYMODE* pdm1 = (D3DDISPLAYMODE*)arg1;
729    D3DDISPLAYMODE* pdm2 = (D3DDISPLAYMODE*)arg2;
730
731    if (pdm1->Width > pdm2->Width)
732        return 1;
733    if (pdm1->Width < pdm2->Width)
734        return -1;
735    if (pdm1->Height > pdm2->Height)
736        return 1;
737    if (pdm1->Height < pdm2->Height)
738        return -1;
739    if (pdm1->Format > pdm2->Format)
740        return 1;
741    if (pdm1->Format < pdm2->Format)
742        return -1;
743    if (pdm1->RefreshRate > pdm2->RefreshRate)
744        return 1;
745    if (pdm1->RefreshRate < pdm2->RefreshRate)
746        return -1;
747    return 0;
748}
749
750
751
752//--------------------------------------------------------------------------------------
753CD3DEnumAdapterInfo::~CD3DEnumAdapterInfo( void )
754{
755    CD3DEnumDeviceInfo* pDeviceInfo;
756    for( int i=0; i<deviceInfoList.GetSize(); i++ )
757    {
758        pDeviceInfo = deviceInfoList.GetAt(i);
759        delete pDeviceInfo;
760    }
761    deviceInfoList.RemoveAll();
762}
763
764
765
766
767//--------------------------------------------------------------------------------------
768CD3DEnumDeviceInfo::~CD3DEnumDeviceInfo( void )
769{
770    CD3DEnumDeviceSettingsCombo* pDeviceCombo;
771    for( int i=0; i<deviceSettingsComboList.GetSize(); i++ )
772    {
773        pDeviceCombo = deviceSettingsComboList.GetAt(i);
774        delete pDeviceCombo;
775    }
776    deviceSettingsComboList.RemoveAll();
777}
778
779
780//--------------------------------------------------------------------------------------
781void CD3DEnumeration::ResetPossibleDepthStencilFormats()
782{
783    m_DepthStecilPossibleList.RemoveAll();
784    m_DepthStecilPossibleList.Add( D3DFMT_D16 );
785    m_DepthStecilPossibleList.Add( D3DFMT_D15S1 );
786    m_DepthStecilPossibleList.Add( D3DFMT_D24X8 );
787    m_DepthStecilPossibleList.Add( D3DFMT_D24S8 );
788    m_DepthStecilPossibleList.Add( D3DFMT_D24X4S4 );
789    m_DepthStecilPossibleList.Add( D3DFMT_D32 );
790}
791
792
793//--------------------------------------------------------------------------------------
794CGrowableArray<D3DFORMAT>* CD3DEnumeration::GetPossibleDepthStencilFormatList()
795{
796    return &m_DepthStecilPossibleList;
797}
798
799
800//--------------------------------------------------------------------------------------
801CGrowableArray<D3DMULTISAMPLE_TYPE>* CD3DEnumeration::GetPossibleMultisampleTypeList()
802{
803    return &m_MultiSampleTypeList;
804}
805
806
807//--------------------------------------------------------------------------------------
808void CD3DEnumeration::ResetPossibleMultisampleTypeList()
809{
810    m_MultiSampleTypeList.RemoveAll();
811    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONE );
812    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_NONMASKABLE );
813    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_2_SAMPLES );
814    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_3_SAMPLES );
815    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_4_SAMPLES );
816    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_5_SAMPLES );
817    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_6_SAMPLES );
818    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_7_SAMPLES );
819    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_8_SAMPLES );
820    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_9_SAMPLES );
821    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_10_SAMPLES );
822    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_11_SAMPLES );
823    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_12_SAMPLES );
824    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_13_SAMPLES );
825    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_14_SAMPLES );
826    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_15_SAMPLES );
827    m_MultiSampleTypeList.Add( D3DMULTISAMPLE_16_SAMPLES );
828}
829
830
831//--------------------------------------------------------------------------------------
832void CD3DEnumeration::GetPossibleVertexProcessingList( bool* pbSoftwareVP, bool* pbHardwareVP, bool* pbPureHarewareVP, bool* pbMixedVP )
833{
834    *pbSoftwareVP = m_bSoftwareVP;
835    *pbHardwareVP = m_bHardwareVP;
836    *pbPureHarewareVP = m_bPureHarewareVP;
837    *pbMixedVP = m_bMixedVP;
838}
839
840
841//--------------------------------------------------------------------------------------
842void CD3DEnumeration::SetPossibleVertexProcessingList( bool bSoftwareVP, bool bHardwareVP, bool bPureHarewareVP, bool bMixedVP )
843{
844    m_bSoftwareVP = bSoftwareVP;
845    m_bHardwareVP = bHardwareVP;
846    m_bPureHarewareVP = bPureHarewareVP;
847    m_bMixedVP = bMixedVP;
848}
849
850
851//--------------------------------------------------------------------------------------
852CGrowableArray<UINT>* CD3DEnumeration::GetPossiblePresentIntervalList()
853{
854    return &m_PresentIntervalList;
855}
856
857
858//--------------------------------------------------------------------------------------
859void CD3DEnumeration::ResetPossiblePresentIntervalList()
860{
861    m_PresentIntervalList.RemoveAll();
862    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_IMMEDIATE );
863    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_DEFAULT );
864    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_ONE );
865    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_TWO );
866    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_THREE );
867    m_PresentIntervalList.Add( D3DPRESENT_INTERVAL_FOUR );
868}
869
870
871//--------------------------------------------------------------------------------------
872void CD3DEnumeration::SetResolutionMinMax( UINT nMinWidth, UINT nMinHeight,
873                                           UINT nMaxWidth, UINT nMaxHeight )
874{
875    m_nMinWidth = nMinWidth;
876    m_nMinHeight = nMinHeight;
877    m_nMaxWidth = nMaxWidth;
878    m_nMaxHeight = nMaxHeight;
879}
880
881
882//--------------------------------------------------------------------------------------
883void CD3DEnumeration::SetRefreshMinMax( UINT nMin, UINT nMax )
884{
885    m_nRefreshMin = nMin;
886    m_nRefreshMax = nMax;
887}
888
889
890//--------------------------------------------------------------------------------------
891void CD3DEnumeration::SetMultisampleQualityMax( UINT nMax )
892{
893    if( nMax > 0xFFFF )
894        nMax = 0xFFFF;
895    m_nMultisampleQualityMax = nMax;
896}
897
Note: See TracBrowser for help on using the repository browser.