Debian Codegraph @

engine/core/video/devicecaps.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_DEVICECAPS_H
23 #define FIFE_DEVICECAPS_H
24
25 // Standard C++ library includes
26 #include <string>
27 #include <vector>
28
29 // Platform specific includes
30
31 // 3rd party library includes
32
33 // FIFE includes
34 // These includes are split up in two parts, separated by one empty line
35 // First block: files included from the FIFE root src directory
36 // Second block: files included from the same folder
37 #include "util/structures/rect.h"
38
39 namespace FIFE {
40
41 class ScreenMode {
42 public:
43 /** Default Constructor
44 * @note You shouldn't construct these objects yourself. This default
45 * constructor was provided because swig complained that was none.
46 */
47 ScreenMode();
48 ScreenMode(uint16_t width, uint16_t height, uint16_t bpp, uint32_t SDLFlags);
49 ScreenMode(uint16_t width, uint16_t height, uint16_t bpp, uint16_t rate, uint32_t SDLFlags);
50 ScreenMode(const ScreenMode& rhs);
51
52 /** Destructor.
53 */
54 ~ScreenMode() {};
55
56 bool operator <(const ScreenMode& rhs) const;
57
58 /** Returns the width of the screen mode.
59 * @note If both width and height are 0 it means that ALL modes are available
60 * for use with the specified flags. Most likely this is a windowed mode.
61 */
62 uint16_t getWidth() const { return m_width; };
63
64 /** Returns the height of the screen mode.
65 * @note If both width and height are 0 it means that ALL modes are available
66 * for use with the specified flags. Most likely this is a windowed mode.
67 */
68 uint16_t getHeight() const { return m_height; };
69
70 /** Returns the number of bits per pixel this mode uses.
71 */
72 uint16_t getBPP() const { return m_bpp; };
73
74 /** Returns the refresh rate in Hz of this mode.
75 */
76 uint16_t getRefreshRate() const { return m_refreshRate; }
77
78 /** Returns the SDL flags used when testing this mode.
79 */
80 uint32_t getSDLFlags() const { return m_SDLFlags; };
81
82 /** True if this is a fullscreen mode. False if it is a windowed mode.
83 */
84 bool isFullScreen() const { return (m_SDLFlags & SDL_WINDOW_FULLSCREEN) ? true : false;};
85
86 /** True if this mode uses the OpenGL renderer. False otherwise.
87 */
88 bool isOpenGL() const { return (m_SDLFlags & SDL_WINDOW_OPENGL) ? true : false; };
89
90 /** Is this screen mode an SDL only screen mode
91 */
92 bool isSDL() const { return (!(m_SDLFlags & SDL_WINDOW_OPENGL)) ? true : false; };
93
94 /** Sets the pixel format enum.
95 */
96 void setFormat(uint32_t format) { m_format = format;}
97
98 /** Returns the pixel format enum.
99 */
100 uint32_t getFormat() const { return m_format; }
101
102 /** Sets the display index.
103 */
104 void setDisplay(uint8_t display) { m_display = display; }
105
106 /** Returns the display index.
107 */
108 uint8_t getDisplay() const { return m_display; }
109
110 /** Sets the render driver name.
111 */
112 void setRenderDriverName(const std::string driver) { m_renderDriver = driver; }
113
114 /** Returns the render driver name. Default is "".
115 */
116 const std::string& getRenderDriverName() const { return m_renderDriver; }
117
118 /** Sets the index of the render driver used by SDL.
119 */
120 void setRenderDriverIndex(int8_t index) { m_renderDriverIndex = index; }
121
122 /** Returns the index of the render driver. Default is -1.
123 */
124 int8_t getRenderDriverIndex() const { return m_renderDriverIndex; }
125
126 //OpenGL, windowed
127 static const uint32_t WINDOWED_OPENGL = SDL_WINDOW_OPENGL;
128 //OpenGL, fullscreen
129 static const uint32_t FULLSCREEN_OPENGL = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN;
130 //SDL, windowed
131 static const uint32_t WINDOWED_SDL = 0;
132 //SDL, fullscreen
133 static const uint32_t FULLSCREEN_SDL = SDL_WINDOW_FULLSCREEN;
134
135 private:
136 uint16_t m_width;
137 uint16_t m_height;
138 uint16_t m_bpp;
139 uint16_t m_refreshRate;
140 uint32_t m_SDLFlags;
141 uint32_t m_format;
142 uint8_t m_display;
143 std::string m_renderDriver;
144 int8_t m_renderDriverIndex;
145 }; //ScreenMode
146
147 class DeviceCaps {
148 public:
149 /** Constructor.
150 */
151 DeviceCaps();
152
153 /** Destructor.
154 */
155 ~DeviceCaps();
156
157 /** Should be called AFTER SDL_Init() has been called
158 */
159 void fillDeviceCaps();
160
161 /** Clears all information gathered for the device
162 */
163 void reset();
164
165 /** Gets the available video drivers for your operating system
166 */
167 std::vector<std::string> getAvailableVideoDrivers() const { return m_availableVideoDrivers; };
168
169 /** Gets the available render drivers for your operating system
170 */
171 std::vector<std::string> getAvailableRenderDrivers() const { return m_availableRenderDrivers; };
172
173 /** Returns a vector containing screen modes.
174 */
175 std::vector<ScreenMode> getSupportedScreenModes() const { return m_screenModes; };
176
177 /** Gets the nearest valid screen mode based on the arguments passed
178 */
179 ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs) const;
180
181 /** Gets the nearest valid screen mode based on the arguments passed
182 */
183 ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs, uint16_t refresh, uint8_t display = 0) const;
184
185 /** Returns the name of the current video driver.
186 */
187 std::string getVideoDriverName() const { return m_videoDriverName; }
188
189 /** Sets the name of the video driver.
190 */
191 void setVideoDriverName(const std::string& driver) { m_videoDriverName = driver; }
192
193 /** Returns the name of the current render driver or
194 * an empty string to initialize the first one supporting the requested flags.
195 */
196 std::string getRenderDriverName() const { return m_renderDriverName; }
197
198 /** Sets the name of the render driver.
199 */
200 void setRenderDriverName(const std::string& driver);
201
202 /** Returns the number of displays.
203 */
204 uint8_t getDisplayCount() const;
205
206 /** Returns the display name for the given display index.
207 */
208 std::string getDisplayName(uint8_t display = 0) const;
209
210 /** Returns the SDL_PixelFormatEnum of the desktop for the given display index.
211 */
212 uint32_t getDesktopFormat(uint8_t display = 0) const;
213
214 /** Returns the refresh rate in Hz of the desktop for the given display index.
215 */
216 int32_t getDesktopRefreshRate(uint8_t display = 0) const;
217
218 /** Returns the width of the desktop resolution for the given display index.
219 */
220 int32_t getDesktopWidth(uint8_t display = 0) const;
221
222 /** Returns the height of the desktop resolution for the given display index.
223 */
224 int32_t getDesktopHeight(uint8_t display = 0) const;
225
226 /** Returns the bounding points for the given display index.
227 */
228 Rect getDisplayBounds(uint8_t display = 0) const;
229
230 private:
231 std::vector<ScreenMode> m_screenModes;
232 std::string m_videoDriverName;
233 std::vector<std::string> m_availableVideoDrivers;
234
235 std::string m_renderDriverName;
236 int8_t m_renderDriverIndex;
237 std::vector<std::string> m_availableRenderDrivers;
238
239 /** Called in the constructor. No need for anyone to call this
240 */
241 void fillAvailableDrivers();
242 }; //DeviceCaps
243 } //FIFE
244
245
246
247 #endif //FIFE_DEVICECAPS_H