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 "OgreDDDriverList.h"
|
---|
27 | #include "OgreDDDriver.h"
|
---|
28 | #include "OgreLogManager.h"
|
---|
29 | #include "OgreException.h"
|
---|
30 |
|
---|
31 | namespace Ogre {
|
---|
32 |
|
---|
33 | // Non-member callback functions
|
---|
34 | static BOOL WINAPI DDEnumCallbackEx(GUID FAR *lpGUID,
|
---|
35 | LPSTR lpDriverDescription,
|
---|
36 | LPSTR lpDriverName,
|
---|
37 | LPVOID lpContext,
|
---|
38 | HMONITOR hm)
|
---|
39 | {
|
---|
40 |
|
---|
41 | DDDriverList* driverList;
|
---|
42 |
|
---|
43 | // Use context pointer to add this new object to the list
|
---|
44 | driverList = (DDDriverList*)lpContext;
|
---|
45 | driverList->AddDriver(lpGUID, lpDriverDescription, lpDriverName);
|
---|
46 |
|
---|
47 |
|
---|
48 | // Continue enumeration (to find other cards)
|
---|
49 | return TRUE;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static BOOL WINAPI DDEnumCallback(GUID FAR *lpGUID,
|
---|
53 | LPSTR lpDriverDescription,
|
---|
54 | LPSTR lpDriverName,
|
---|
55 | LPVOID lpContext)
|
---|
56 | {
|
---|
57 | return DDEnumCallbackEx(lpGUID,lpDriverDescription,lpDriverName,lpContext,NULL);
|
---|
58 | }
|
---|
59 |
|
---|
60 | DDDriverList::DDDriverList()
|
---|
61 | {
|
---|
62 | // Default constructor
|
---|
63 | // Will create a new driver list and enumerate it
|
---|
64 |
|
---|
65 | // Enumerate the list
|
---|
66 | enumerate();
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | DDDriverList::~DDDriverList()
|
---|
71 | {
|
---|
72 | for(size_t i=0; i<count(); i++)
|
---|
73 | {
|
---|
74 | item(i)->Cleanup();
|
---|
75 | }
|
---|
76 | // Release drivers
|
---|
77 | mDriverList.clear();
|
---|
78 | }
|
---|
79 |
|
---|
80 | BOOL DDDriverList::enumerate()
|
---|
81 | {
|
---|
82 |
|
---|
83 | LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
|
---|
84 | HINSTANCE h;
|
---|
85 |
|
---|
86 | LogManager::getSingleton().logMessage("----- DirectDraw Detection Starts");
|
---|
87 |
|
---|
88 | h = LoadLibrary("ddraw.dll");
|
---|
89 |
|
---|
90 | // If ddraw.dll doesn't exist in the search path,
|
---|
91 | // then DirectX probably isn't installed, so fail.
|
---|
92 | if (!h)
|
---|
93 | throw Exception(0, "Error loading ddraw.dll", "DDDriverList - enumerate");
|
---|
94 |
|
---|
95 | // Note that you must know which version of the
|
---|
96 | // function to retrieve (see the following text).
|
---|
97 | // For this example, we use the ANSI version.
|
---|
98 | lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(h,"DirectDrawEnumerateExA");
|
---|
99 | // If the function is there, call it to enumerate all display
|
---|
100 | // devices attached to the desktop, and any non-display DirectDraw
|
---|
101 | // devices.
|
---|
102 | if (lpDDEnumEx)
|
---|
103 | lpDDEnumEx(DDEnumCallbackEx, this,
|
---|
104 | DDENUM_ATTACHEDSECONDARYDEVICES |
|
---|
105 | DDENUM_NONDISPLAYDEVICES );
|
---|
106 | else
|
---|
107 | {
|
---|
108 | /*
|
---|
109 | * We must be running on an old version of DirectDraw.
|
---|
110 | * Therefore MultiMon isn't supported. Fall back on
|
---|
111 | * DirectDrawEnumerate to enumerate standard devices on a
|
---|
112 | * single-monitor system.
|
---|
113 | */
|
---|
114 | DirectDrawEnumerate(DDEnumCallback,this);
|
---|
115 |
|
---|
116 | }
|
---|
117 | // If the library was loaded by calling LoadLibrary(),
|
---|
118 | // then you must use FreeLibrary() to let go of it.
|
---|
119 |
|
---|
120 | FreeLibrary(h);
|
---|
121 |
|
---|
122 | LogManager::getSingleton().logMessage("----- DirectDraw Detection Ends");
|
---|
123 |
|
---|
124 | return TRUE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | void DDDriverList::AddDriver(
|
---|
128 | GUID FAR *lpGuid,
|
---|
129 | LPSTR lpDriverDesc,
|
---|
130 | LPSTR lpDriverName )
|
---|
131 | {
|
---|
132 | mDriverList.push_back( DDDriver(lpGuid, lpDriverDesc, lpDriverName) );
|
---|
133 |
|
---|
134 | LogManager::getSingleton().logMessage( LML_NORMAL,
|
---|
135 | String("Detected DirectDraw driver ") + lpDriverDesc );
|
---|
136 | }
|
---|
137 |
|
---|
138 | size_t DDDriverList::count(void) const
|
---|
139 | {
|
---|
140 | return mDriverList.size();
|
---|
141 | }
|
---|
142 |
|
---|
143 | DDDriver* DDDriverList::item(size_t index)
|
---|
144 | {
|
---|
145 | return &mDriverList.at( index );
|
---|
146 | }
|
---|
147 | }
|
---|