Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreD3D7DeviceList.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreD3D7RenderSystem.h"
    00026 #include "OgreD3D7DeviceList.h"
    00027 #include "OgreD3D7Device.h"
    00028 #include "OgreDDDriver.h"
    00029 #include "OgreLogManager.h"
    00030 #include "OgreException.h"
    00031
    00032 namespace Ogre
    00033 {
    00034
    00035     // Non-member callback functions
    00036     static HRESULT CALLBACK D3DEnumDevicesCallback(
    00037                                     LPSTR lpDeviceDescription,
    00038                                     LPSTR lpDeviceName,
    00039                                     LPD3DDEVICEDESC7 lpD3DDeviceDesc,
    00040                                     LPVOID lpContext)
    00041     {
    00042         D3DDeviceList* deviceList;
    00043
    00044         deviceList = (D3DDeviceList*) lpContext;
    00045
    00046         deviceList->AddDevice(lpDeviceDescription, lpDeviceName,
    00047                                 lpD3DDeviceDesc);
    00048
    00049         // Continue enumeration
    00050         return D3DENUMRET_OK;
    00051     }
    00052
    00053
    00054     D3DDeviceList::D3DDeviceList(LPDIRECT3D7 direct3D)
    00055     {
    00056         // Will create a  new driver list and enumerate it
    00057         if (direct3D == NULL)
    00058             throw Exception(Exception::ERR_INVALIDPARAMS, "NULL has been incorrectly passed as a "
    00059                 "D3D interface pointer.", "D3DDeviceList Contructor");
    00060
    00061         lpD3D = direct3D;
    00062         // Enumerate the list
    00063         enumerate();
    00064
    00065     }
    00066
    00067     D3DDeviceList::~D3DDeviceList()
    00068     {
    00069         for(size_t i=0; i<count(); i++)
    00070         {
    00071             item(i)->Cleanup();
    00072         }
    00073         mDeviceList.clear();
    00074
    00075     }
    00076
    00077
    00078     BOOL D3DDeviceList::enumerate()
    00079     {
    00080         HRESULT hr;
    00081
    00082         LogManager::getSingleton().logMessage("----- Direct3D Detection Starts");
    00083
    00084         hr = lpD3D->EnumDevices(D3DEnumDevicesCallback, this);
    00085         if (FAILED(hr))
    00086             throw Exception(Exception::ERR_RENDERINGAPI_ERROR, "Error enumerating 3D devices", "D3DDeviceList - enumerate");
    00087
    00088         LogManager::getSingleton().logMessage("----- Direct3D Detection Ends");
    00089
    00090         return TRUE;
    00091     }
    00092
    00093     void D3DDeviceList::AddDevice(LPSTR lpDeviceDesc,
    00094                                        LPSTR lpDeviceName,
    00095                                        LPD3DDEVICEDESC7 lpD3DDeviceDesc)
    00096     {
    00097         D3DDevice *newD3D;
    00098
    00099         // Check to see if this is a duff driver
    00100         // Handle specific device GUIDs. NullDevice renders nothing
    00101         if (IsEqualGUID(lpD3DDeviceDesc->deviceGUID, IID_IDirect3DNullDevice))
    00102             return;
    00103
    00104
    00105         // Create new driver
    00106         newD3D = new D3DDevice(lpD3D, lpDeviceDesc, lpDeviceName, lpD3DDeviceDesc);
    00107
    00108         // Add it to my list
    00109         mDeviceList.push_back(*newD3D);
    00110
    00111         delete newD3D;
    00112     }
    00113
    00114     size_t D3DDeviceList::count(void)
    00115     {
    00116         return mDeviceList.size();
    00117     }
    00118
    00119     D3DDevice* D3DDeviceList::item(size_t index)
    00120     {
    00121         return &mDeviceList[index];
    00122     }
    00123
    00124     D3DDevice* D3DDeviceList::getBest(unsigned int minColourDepth)
    00125     {
    00126         char msg[255];
    00127
    00128         std::vector<D3DDevice>::iterator p = mDeviceList.begin();
    00129         std::vector<D3DDevice>::iterator bestDevice = mDeviceList.end();
    00130         static D3DDevice* savedBest = 0;
    00131
    00132         if (savedBest)
    00133             return savedBest;
    00134         LogManager::getSingleton().logMessage("Determining best 3D Device...");
    00135
    00136         // For now, just get ANY hardware device that can match the following
    00137         // minimum requirements
    00138         // 2. Colour depth = primary surface colour depth
    00139         // Add preference to TnL devices
    00140         while (p != mDeviceList.end())
    00141         {
    00142             if (p->HardwareAccelerated())
    00143             {
    00144                 // Check minimum render depth
    00145                 if ( (p->RenderBitDepth() >= minColourDepth))
    00146                 {
    00147                     // Ok, minimum caps have been satisfied so we can consider using HW
    00148                     // Any device yet?
    00149                     if (bestDevice == mDeviceList.end())
    00150                         bestDevice = p;
    00151                     // Always override SW device
    00152                     else if (!bestDevice->HardwareAccelerated())
    00153                         bestDevice = p;
    00154                     // Add preference to HW TnL
    00155                     else if (p->CanHWTransformAndLight())
    00156                         bestDevice = p;
    00157
    00158                 }
    00159             }
    00160             else
    00161             {
    00162                 // Software device, save for fallback
    00163                 if (bestDevice == mDeviceList.end())
    00164                     bestDevice = p;
    00165             }
    00166
    00167             p++;
    00168
    00169         }
    00170
    00171         sprintf(msg, "Best 3D Device is: %s", bestDevice->DeviceDescription().c_str());
    00172         LogManager::getSingleton().logMessage(msg);
    00173
    00174         savedBest = &(*bestDevice);
    00175         return savedBest;
    00176
    00177     }
    00178
    00179 } // Namespace

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:18 2004