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