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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreD3D7RenderSystem.h"
|
---|
26 | #include "OgreD3D7DeviceList.h"
|
---|
27 | #include "OgreD3D7Device.h"
|
---|
28 | #include "OgreDDDriver.h"
|
---|
29 | #include "OgreLogManager.h"
|
---|
30 | #include "OgreException.h"
|
---|
31 |
|
---|
32 | namespace Ogre
|
---|
33 | {
|
---|
34 |
|
---|
35 | // Non-member callback functions
|
---|
36 | static HRESULT CALLBACK D3DEnumDevicesCallback(
|
---|
37 | LPSTR lpDeviceDescription,
|
---|
38 | LPSTR lpDeviceName,
|
---|
39 | LPD3DDEVICEDESC7 lpD3DDeviceDesc,
|
---|
40 | LPVOID lpContext)
|
---|
41 | {
|
---|
42 | D3DDeviceList* deviceList;
|
---|
43 |
|
---|
44 | deviceList = (D3DDeviceList*) lpContext;
|
---|
45 |
|
---|
46 | deviceList->AddDevice(lpDeviceDescription, lpDeviceName,
|
---|
47 | lpD3DDeviceDesc);
|
---|
48 |
|
---|
49 | // Continue enumeration
|
---|
50 | return D3DENUMRET_OK;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | D3DDeviceList::D3DDeviceList(LPDIRECT3D7 direct3D)
|
---|
55 | {
|
---|
56 | // Will create a new driver list and enumerate it
|
---|
57 | if (direct3D == NULL)
|
---|
58 | throw Exception(Exception::ERR_INVALIDPARAMS, "NULL has been incorrectly passed as a "
|
---|
59 | "D3D interface pointer.", "D3DDeviceList Contructor");
|
---|
60 |
|
---|
61 | lpD3D = direct3D;
|
---|
62 | // Enumerate the list
|
---|
63 | enumerate();
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | D3DDeviceList::~D3DDeviceList()
|
---|
68 | {
|
---|
69 | for(size_t i=0; i<count(); i++)
|
---|
70 | {
|
---|
71 | item(i)->Cleanup();
|
---|
72 | }
|
---|
73 | mDeviceList.clear();
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | BOOL D3DDeviceList::enumerate()
|
---|
79 | {
|
---|
80 | HRESULT hr;
|
---|
81 |
|
---|
82 | LogManager::getSingleton().logMessage("----- Direct3D Detection Starts");
|
---|
83 |
|
---|
84 | hr = lpD3D->EnumDevices(D3DEnumDevicesCallback, this);
|
---|
85 | if (FAILED(hr))
|
---|
86 | throw Exception(Exception::ERR_RENDERINGAPI_ERROR, "Error enumerating 3D devices", "D3DDeviceList - enumerate");
|
---|
87 |
|
---|
88 | LogManager::getSingleton().logMessage("----- Direct3D Detection Ends");
|
---|
89 |
|
---|
90 | return TRUE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | void D3DDeviceList::AddDevice(LPSTR lpDeviceDesc,
|
---|
94 | LPSTR lpDeviceName,
|
---|
95 | LPD3DDEVICEDESC7 lpD3DDeviceDesc)
|
---|
96 | {
|
---|
97 | D3DDevice *newD3D;
|
---|
98 |
|
---|
99 | // Check to see if this is a duff driver
|
---|
100 | // Handle specific device GUIDs. NullDevice renders nothing
|
---|
101 | if (IsEqualGUID(lpD3DDeviceDesc->deviceGUID, IID_IDirect3DNullDevice))
|
---|
102 | return;
|
---|
103 |
|
---|
104 |
|
---|
105 | // Create new driver
|
---|
106 | newD3D = new D3DDevice(lpD3D, lpDeviceDesc, lpDeviceName, lpD3DDeviceDesc);
|
---|
107 |
|
---|
108 | // Add it to my list
|
---|
109 | mDeviceList.push_back(*newD3D);
|
---|
110 |
|
---|
111 | delete newD3D;
|
---|
112 | }
|
---|
113 |
|
---|
114 | size_t D3DDeviceList::count(void)
|
---|
115 | {
|
---|
116 | return mDeviceList.size();
|
---|
117 | }
|
---|
118 |
|
---|
119 | D3DDevice* D3DDeviceList::item(size_t index)
|
---|
120 | {
|
---|
121 | return &mDeviceList[index];
|
---|
122 | }
|
---|
123 |
|
---|
124 | D3DDevice* D3DDeviceList::getBest(unsigned int minColourDepth)
|
---|
125 | {
|
---|
126 |
|
---|
127 | std::vector<D3DDevice>::iterator p = mDeviceList.begin();
|
---|
128 | std::vector<D3DDevice>::iterator bestDevice = mDeviceList.end();
|
---|
129 | static D3DDevice* savedBest = 0;
|
---|
130 |
|
---|
131 | if (savedBest)
|
---|
132 | return savedBest;
|
---|
133 | LogManager::getSingleton().logMessage("Determining best 3D Device...");
|
---|
134 |
|
---|
135 | // For now, just get ANY hardware device that can match the following
|
---|
136 | // minimum requirements
|
---|
137 | // 2. Colour depth = primary surface colour depth
|
---|
138 | // Add preference to TnL devices
|
---|
139 | while (p != mDeviceList.end())
|
---|
140 | {
|
---|
141 | if (p->HardwareAccelerated())
|
---|
142 | {
|
---|
143 | // Check minimum render depth
|
---|
144 | if ( (p->RenderBitDepth() >= minColourDepth))
|
---|
145 | {
|
---|
146 | // Ok, minimum caps have been satisfied so we can consider using HW
|
---|
147 | // Any device yet?
|
---|
148 | if (bestDevice == mDeviceList.end())
|
---|
149 | bestDevice = p;
|
---|
150 | // Always override SW device
|
---|
151 | else if (!bestDevice->HardwareAccelerated())
|
---|
152 | bestDevice = p;
|
---|
153 | // Add preference to HW TnL
|
---|
154 | else if (p->CanHWTransformAndLight())
|
---|
155 | bestDevice = p;
|
---|
156 |
|
---|
157 | }
|
---|
158 | }
|
---|
159 | else
|
---|
160 | {
|
---|
161 | // Software device, save for fallback
|
---|
162 | if (bestDevice == mDeviceList.end())
|
---|
163 | bestDevice = p;
|
---|
164 | }
|
---|
165 |
|
---|
166 | p++;
|
---|
167 |
|
---|
168 | }
|
---|
169 |
|
---|
170 | LogManager::getSingleton().logMessage("Best 3D Device is: " + bestDevice->DeviceDescription());
|
---|
171 |
|
---|
172 | savedBest = &(*bestDevice);
|
---|
173 | return savedBest;
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 | } // Namespace
|
---|