[5] | 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-2006 Torus Knot Software Ltd |
---|
| 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 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #include "OgreD3D9VideoModeList.h" |
---|
| 30 | #include "OgreException.h" |
---|
| 31 | |
---|
| 32 | namespace Ogre |
---|
| 33 | { |
---|
| 34 | D3D9VideoModeList::D3D9VideoModeList( D3D9Driver* pDriver ) |
---|
| 35 | { |
---|
| 36 | if( NULL == pDriver ) |
---|
| 37 | OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "pDriver parameter is NULL", "D3D9VideoModeList::D3D9VideoModeList" ); |
---|
| 38 | |
---|
| 39 | mpDriver = pDriver; |
---|
| 40 | enumerate(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | D3D9VideoModeList::~D3D9VideoModeList() |
---|
| 44 | { |
---|
| 45 | mpDriver = NULL; |
---|
| 46 | mModeList.clear(); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | BOOL D3D9VideoModeList::enumerate() |
---|
| 50 | { |
---|
| 51 | UINT iMode; |
---|
| 52 | LPDIRECT3D9 pD3D = mpDriver->getD3D(); |
---|
| 53 | UINT adapter = mpDriver->getAdapterNumber(); |
---|
| 54 | |
---|
| 55 | for( iMode=0; iMode < pD3D->GetAdapterModeCount( adapter, D3DFMT_R5G6B5 ); iMode++ ) |
---|
| 56 | { |
---|
| 57 | D3DDISPLAYMODE displayMode; |
---|
| 58 | pD3D->EnumAdapterModes( adapter, D3DFMT_R5G6B5, iMode, &displayMode ); |
---|
| 59 | |
---|
| 60 | // Filter out low-resolutions |
---|
| 61 | if( displayMode.Width < 640 || displayMode.Height < 400 ) |
---|
| 62 | continue; |
---|
| 63 | |
---|
| 64 | // Check to see if it is already in the list (to filter out refresh rates) |
---|
| 65 | BOOL found = FALSE; |
---|
| 66 | std::vector<D3D9VideoMode>::iterator it; |
---|
| 67 | for( it = mModeList.begin(); it != mModeList.end(); it++ ) |
---|
| 68 | { |
---|
| 69 | D3DDISPLAYMODE oldDisp = it->getDisplayMode(); |
---|
| 70 | if( oldDisp.Width == displayMode.Width && |
---|
| 71 | oldDisp.Height == displayMode.Height && |
---|
| 72 | oldDisp.Format == displayMode.Format ) |
---|
| 73 | { |
---|
| 74 | // Check refresh rate and favour higher if poss |
---|
| 75 | if (oldDisp.RefreshRate < displayMode.RefreshRate) |
---|
| 76 | it->increaseRefreshRate(displayMode.RefreshRate); |
---|
| 77 | found = TRUE; |
---|
| 78 | break; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if( !found ) |
---|
| 83 | mModeList.push_back( D3D9VideoMode( displayMode ) ); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | for( iMode=0; iMode < pD3D->GetAdapterModeCount( adapter, D3DFMT_X8R8G8B8 ); iMode++ ) |
---|
| 87 | { |
---|
| 88 | D3DDISPLAYMODE displayMode; |
---|
| 89 | pD3D->EnumAdapterModes( adapter, D3DFMT_X8R8G8B8, iMode, &displayMode ); |
---|
| 90 | |
---|
| 91 | // Filter out low-resolutions |
---|
| 92 | if( displayMode.Width < 640 || displayMode.Height < 400 ) |
---|
| 93 | continue; |
---|
| 94 | |
---|
| 95 | // Check to see if it is already in the list (to filter out refresh rates) |
---|
| 96 | BOOL found = FALSE; |
---|
| 97 | std::vector<D3D9VideoMode>::iterator it; |
---|
| 98 | for( it = mModeList.begin(); it != mModeList.end(); it++ ) |
---|
| 99 | { |
---|
| 100 | D3DDISPLAYMODE oldDisp = it->getDisplayMode(); |
---|
| 101 | if( oldDisp.Width == displayMode.Width && |
---|
| 102 | oldDisp.Height == displayMode.Height && |
---|
| 103 | oldDisp.Format == displayMode.Format ) |
---|
| 104 | { |
---|
| 105 | // Check refresh rate and favour higher if poss |
---|
| 106 | if (oldDisp.RefreshRate < displayMode.RefreshRate) |
---|
| 107 | it->increaseRefreshRate(displayMode.RefreshRate); |
---|
| 108 | found = TRUE; |
---|
| 109 | break; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if( !found ) |
---|
| 114 | mModeList.push_back( D3D9VideoMode( displayMode ) ); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return TRUE; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | size_t D3D9VideoModeList::count() |
---|
| 121 | { |
---|
| 122 | return mModeList.size(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | D3D9VideoMode* D3D9VideoModeList::item( size_t index ) |
---|
| 126 | { |
---|
| 127 | std::vector<D3D9VideoMode>::iterator p = mModeList.begin(); |
---|
| 128 | |
---|
| 129 | return &p[index]; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | D3D9VideoMode* D3D9VideoModeList::item( const String &name ) |
---|
| 133 | { |
---|
| 134 | std::vector<D3D9VideoMode>::iterator it = mModeList.begin(); |
---|
| 135 | if (it == mModeList.end()) |
---|
| 136 | return NULL; |
---|
| 137 | |
---|
| 138 | for (;it != mModeList.end(); ++it) |
---|
| 139 | { |
---|
| 140 | if (it->getDescription() == name) |
---|
| 141 | return &(*it); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | return NULL; |
---|
| 145 | } |
---|
| 146 | } |
---|