1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #include "OgreD3D11DriverList.h"
29 #include "OgreLogManager.h"
30 #include "OgreD3D11Device.h"
31 #include "OgreD3D11Driver.h"
32 
33 namespace Ogre
34 {
35 	//-----------------------------------------------------------------------
D3D11DriverList(IDXGIFactoryN * pDXGIFactory)36 	D3D11DriverList::D3D11DriverList( IDXGIFactoryN*	pDXGIFactory )
37 	{
38 		enumerate(pDXGIFactory);
39 	}
40 	//-----------------------------------------------------------------------
~D3D11DriverList(void)41 	D3D11DriverList::~D3D11DriverList(void)
42 	{
43 		for(unsigned i = 0; i < mDriverList.size(); i++)
44 		{
45 			delete (mDriverList[i]);
46 		}
47 		mDriverList.clear();
48 
49 	}
50 	//-----------------------------------------------------------------------
enumerate(IDXGIFactoryN * pDXGIFactory)51 	BOOL D3D11DriverList::enumerate(IDXGIFactoryN*	pDXGIFactory)
52 	{
53 		LogManager::getSingleton().logMessage( "D3D11: Driver Detection Starts" );
54 		// Create the DXGI Factory
55 
56 		for( UINT iAdapter=0; ; iAdapter++ )
57 		{
58 			IDXGIAdapterN* pDXGIAdapter = NULL;
59 			HRESULT hr = pDXGIFactory->EnumAdapters1( iAdapter, &pDXGIAdapter );
60 			if( DXGI_ERROR_NOT_FOUND == hr )
61 			{
62 				hr = S_OK;
63 				break;
64 			}
65 			if( FAILED(hr) )
66 			{
67 				SAFE_RELEASE(pDXGIAdapter);
68 				return false;
69 			}
70 
71 			// we don't want NVIDIA PerfHUD in the list - so - here we filter it out
72 			DXGI_ADAPTER_DESC1 adaptDesc;
73 			if ( SUCCEEDED( pDXGIAdapter->GetDesc1( &adaptDesc ) ) )
74 			{
75 				const bool isPerfHUD = wcscmp( adaptDesc.Description, L"NVIDIA PerfHUD" ) == 0;
76 
77 				if (isPerfHUD)
78 				{
79 					continue;
80 				}
81 			}
82 
83 			mDriverList.push_back(new D3D11Driver(iAdapter,pDXGIAdapter) );
84 
85 			SAFE_RELEASE(pDXGIAdapter);
86 		}
87 
88 		LogManager::getSingleton().logMessage( "D3D11: Driver Detection Ends" );
89 
90 		return TRUE;
91 	}
92 	//-----------------------------------------------------------------------
count() const93 	size_t D3D11DriverList::count() const
94 	{
95 		return mDriverList.size();
96 	}
97 	//-----------------------------------------------------------------------
item(size_t index)98 	D3D11Driver* D3D11DriverList::item( size_t index )
99 	{
100 		return mDriverList.at( index );
101 	}
102 	//-----------------------------------------------------------------------
item(const String & name)103 	D3D11Driver* D3D11DriverList::item( const String &name )
104 	{
105 		vector<D3D11Driver*>::type::iterator it = mDriverList.begin();
106 		if (it == mDriverList.end())
107 			return NULL;
108 
109 		for (;it != mDriverList.end(); ++it)
110 		{
111 			if ((*it)->DriverDescription() == name)
112 				return (*it);
113 		}
114 
115 		return NULL;
116 	}
117 	//-----------------------------------------------------------------------
118 }
119