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 "OgreD3D9VideoModeList.h" 00026 #include "OgreException.h" 00027 00028 namespace Ogre 00029 { 00030 D3D9VideoModeList::D3D9VideoModeList( D3D9Driver* pDriver ) 00031 { 00032 if( NULL == pDriver ) 00033 Except( Exception::ERR_INVALIDPARAMS, "pDriver parameter is NULL", "D3D9VideoModeList::D3D9VideoModeList" ); 00034 00035 mpDriver = pDriver; 00036 enumerate(); 00037 } 00038 00039 D3D9VideoModeList::~D3D9VideoModeList() 00040 { 00041 mpDriver = NULL; 00042 mModeList.clear(); 00043 } 00044 00045 BOOL D3D9VideoModeList::enumerate() 00046 { 00047 UINT iMode; 00048 LPDIRECT3D9 pD3D = mpDriver->getD3D(); 00049 UINT adapter = mpDriver->getAdapterNumber(); 00050 00051 for( iMode=0; iMode < pD3D->GetAdapterModeCount( adapter, D3DFMT_R5G6B5 ); iMode++ ) 00052 { 00053 D3DDISPLAYMODE displayMode; 00054 pD3D->EnumAdapterModes( adapter, D3DFMT_R5G6B5, iMode, &displayMode ); 00055 00056 // Filter out low-resolutions 00057 if( displayMode.Width < 640 || displayMode.Height < 400 ) 00058 continue; 00059 00060 // Check to see if it is already in the list (to filter out refresh rates) 00061 BOOL found = FALSE; 00062 std::vector<D3D9VideoMode>::iterator it; 00063 for( it = mModeList.begin(); it != mModeList.end(); it++ ) 00064 { 00065 D3DDISPLAYMODE oldDisp = it->getDisplayMode(); 00066 if( oldDisp.Width == displayMode.Width && 00067 oldDisp.Height == displayMode.Height && 00068 oldDisp.Format == displayMode.Format ) 00069 { 00070 // Check refresh rate and favour higher if poss 00071 if (oldDisp.RefreshRate < displayMode.RefreshRate) 00072 it->increaseRefreshRate(displayMode.RefreshRate); 00073 found = TRUE; 00074 break; 00075 } 00076 } 00077 00078 if( !found ) 00079 mModeList.push_back( D3D9VideoMode( displayMode ) ); 00080 } 00081 00082 for( iMode=0; iMode < pD3D->GetAdapterModeCount( adapter, D3DFMT_X8R8G8B8 ); iMode++ ) 00083 { 00084 D3DDISPLAYMODE displayMode; 00085 pD3D->EnumAdapterModes( adapter, D3DFMT_X8R8G8B8, iMode, &displayMode ); 00086 00087 // Filter out low-resolutions 00088 if( displayMode.Width < 640 || displayMode.Height < 400 ) 00089 continue; 00090 00091 // Check to see if it is already in the list (to filter out refresh rates) 00092 BOOL found = FALSE; 00093 std::vector<D3D9VideoMode>::iterator it; 00094 for( it = mModeList.begin(); it != mModeList.end(); it++ ) 00095 { 00096 D3DDISPLAYMODE oldDisp = it->getDisplayMode(); 00097 if( oldDisp.Width == displayMode.Width && 00098 oldDisp.Height == displayMode.Height && 00099 oldDisp.Format == displayMode.Format ) 00100 { 00101 // Check refresh rate and favour higher if poss 00102 if (oldDisp.RefreshRate < displayMode.RefreshRate) 00103 it->increaseRefreshRate(displayMode.RefreshRate); 00104 found = TRUE; 00105 break; 00106 } 00107 } 00108 00109 if( !found ) 00110 mModeList.push_back( D3D9VideoMode( displayMode ) ); 00111 } 00112 00113 return TRUE; 00114 } 00115 00116 size_t D3D9VideoModeList::count() 00117 { 00118 return mModeList.size(); 00119 } 00120 00121 D3D9VideoMode* D3D9VideoModeList::item( size_t index ) 00122 { 00123 std::vector<D3D9VideoMode>::iterator p = mModeList.begin(); 00124 00125 return &p[index]; 00126 } 00127 00128 D3D9VideoMode* D3D9VideoModeList::item( const String &name ) 00129 { 00130 std::vector<D3D9VideoMode>::iterator it = mModeList.begin(); 00131 if (it == mModeList.end()) 00132 return NULL; 00133 00134 for (;it != mModeList.end(); ++it) 00135 { 00136 if (it->getDescription() == name) 00137 return &(*it); 00138 } 00139 00140 return NULL; 00141 } 00142 }
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:09 2004