source: OGRE/trunk/ogrenew/RenderSystems/Direct3D7/src/OgreDDVideoModeList.cpp @ 657

Revision 657, 4.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreDDVideoModeList.h"
26#include "OgreDDVideoMode.h"
27#include "OgreException.h"
28
29namespace Ogre {
30
31    // Non-member callback functions
32    static HRESULT CALLBACK DDEnumModesCallback(
33                                    LPDDSURFACEDESC2 lpDDSD2,
34                                    LPVOID lpContext)
35    {
36        DDVideoModeList* modeList;
37
38        // Omit any palettised modes
39        if (lpDDSD2->ddpfPixelFormat.dwRGBBitCount >= 16)
40        {
41
42            modeList = (DDVideoModeList*) lpContext;
43
44            modeList->AddMode(lpDDSD2);
45        }
46
47        // Continue enumeration
48        return DDENUMRET_OK;
49    }
50
51
52    DDVideoModeList::DDVideoModeList(LPDIRECTDRAW7 directDraw)
53    {
54        // Will create a  new driver list and enumerate it
55        if (directDraw == NULL)
56            throw Exception(0, "NULL supplied as "
57                "DD interface pointer.", "DDVideoModeList Contructor");
58
59        lpDD7 = directDraw;
60        // Enumerate the list
61        enumerate();
62
63    }
64
65    DDVideoModeList::~DDVideoModeList()
66    {
67        // Release each video mode object
68        std::vector<DDVideoMode>::iterator p = mModeList.begin();
69
70        mModeList.erase(p, p+mModeList.size()-1);
71    }
72
73
74
75
76    BOOL DDVideoModeList::enumerate()
77    {
78        HRESULT hr;
79
80        // Enumerate display modes
81        // Different refresh rates are NOT enumerated (dwFlags = 0)
82        hr = lpDD7->EnumDisplayModes(0, NULL, this, DDEnumModesCallback);
83        if (FAILED(hr))
84            throw Exception(0, "Error enumerating display modes", "DDVideoModeList - enumerate");
85
86
87        return TRUE;
88    }
89
90    void DDVideoModeList::AddMode(LPDDSURFACEDESC2 lpDDSD2)
91    {
92        //DDVideoMode *newMode;
93
94
95        // Create new mode
96        //newMode = new DDVideoMode(lpDDSD2);
97
98        // Add it to my list
99        mModeList.push_back(DDVideoMode(lpDDSD2)/**newMode*/);
100
101
102    }
103
104    unsigned int DDVideoModeList::count(void)
105    {
106        return static_cast< unsigned int >( mModeList.size() );
107    }
108
109    DDVideoMode* DDVideoModeList::item(int index)
110    {
111        // Get an iterator for the vector
112        std::vector<DDVideoMode>::iterator p = mModeList.begin();
113
114        // Return the indexed driver
115        return &p[index];
116
117
118    }
119
120    DDVideoMode* DDVideoModeList::getClosestMatch(int width, int height, int colourDepth)
121    {
122        // Search through looking for closest match
123        int bestDiff, currentDiff, bestIndex;
124        DDVideoMode *vm;
125
126        std::vector<DDVideoMode>::iterator p = mModeList.begin();
127
128
129        bestDiff = 9999;
130        bestIndex = -1;
131        for( unsigned j = 0; j < count(); j++ )
132        {
133            currentDiff = 0;
134            vm = &p[j];
135            currentDiff += abs(vm->mWidth - width);
136            currentDiff += abs(vm->mHeight - height);
137            currentDiff += abs(vm->mColourDepth - colourDepth);
138
139            if (currentDiff < bestDiff)
140            {
141                bestDiff = currentDiff;
142                bestIndex = j;
143            }
144
145            /* We Love Intel's Compilers :) */
146            if (currentDiff == 0)
147                break; // No point continuing, direct match
148        }
149
150        return &p[bestIndex];
151    }
152
153}
154
155
Note: See TracBrowser for help on using the repository browser.