Pyrogenesis  trunk
VideoMode.h
Go to the documentation of this file.
1 /* Copyright (C) 2014 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_VIDEOMODE
19 #define INCLUDED_VIDEOMODE
20 
21 typedef struct SDL_Window SDL_Window;
22 
24 {
25 public:
26  CVideoMode();
27 
28  /**
29  * Initialise the video mode, for use in an SDL-using application.
30  */
31  bool InitSDL();
32 
33  /**
34  * Initialise parts of the video mode, for use in Atlas (which uses
35  * wxWidgets instead of SDL for GL).
36  * Currently this just tries to enable S3TC.
37  */
38  bool InitNonSDL();
39 
40  /**
41  * Shut down after InitSDL/InitNonSDL, so that they can be used again.
42  */
43  void Shutdown();
44 
45  /**
46  * Resize the SDL window and associated graphics stuff to the new size.
47  */
48  bool ResizeWindow(int w, int h);
49 
50  /**
51  * Switch to fullscreen or windowed mode.
52  */
53  bool SetFullscreen(bool fullscreen);
54 
55  /**
56  * Switch between fullscreen and windowed mode.
57  */
58  bool ToggleFullscreen();
59 
60  /**
61  * Update window position, to restore later if necessary (SDL2 only).
62  */
63  void UpdatePosition(int x, int y);
64 
65  /**
66  * Update the graphics code to start drawing to the new size.
67  * This should be called after the GL context has been resized.
68  * This can also be used when the GL context is managed externally, not via SDL.
69  */
70  static void UpdateRenderer(int w, int h);
71 
72  int GetXRes();
73  int GetYRes();
74  int GetBPP();
75 
76  int GetDesktopXRes();
77  int GetDesktopYRes();
78  int GetDesktopBPP();
79  int GetDesktopFreq();
80 
82 
83 private:
84  void ReadConfig();
85  int GetBestBPP();
86  bool SetVideoMode(int w, int h, int bpp, bool fullscreen);
87  void EnableS3TC();
88 
89  /**
90  * Remember whether Init has been called. (This isn't used for anything
91  * important, just for verifying that the callers call our methods in
92  * the right order.)
93  */
95 
97 
98  // Initial desktop settings
103 
104  // Config file settings (0 if unspecified)
111 
112  // If we're fullscreen, size/position of window when we were last windowed (or the default window
113  // size/position if we started fullscreen), to support switching back to the old window size/position
118 
119  // Whether we're currently being displayed fullscreen
121 
122  // The last mode selected
126 };
127 
128 extern CVideoMode g_VideoMode;
129 
130 #endif // INCLUDED_VIDEOMODE
int m_CurrentH
Definition: VideoMode.h:124
int GetDesktopFreq()
Definition: VideoMode.cpp:480
bool SetVideoMode(int w, int h, int bpp, bool fullscreen)
Definition: VideoMode.cpp:72
int GetDesktopXRes()
Definition: VideoMode.cpp:462
int GetYRes()
Definition: VideoMode.cpp:450
bool ToggleFullscreen()
Switch between fullscreen and windowed mode.
Definition: VideoMode.cpp:395
bool m_ConfigFullscreen
Definition: VideoMode.h:109
CVideoMode g_VideoMode
Definition: VideoMode.cpp:47
bool ResizeWindow(int w, int h)
Resize the SDL window and associated graphics stuff to the new size.
Definition: VideoMode.cpp:309
int m_WindowedY
Definition: VideoMode.h:117
int m_ConfigH
Definition: VideoMode.h:106
void Shutdown()
Shut down after InitSDL/InitNonSDL, so that they can be used again.
Definition: VideoMode.cpp:274
int m_WindowedX
Definition: VideoMode.h:116
SDL_Window * GetWindow()
Definition: VideoMode.cpp:486
int m_PreferredH
Definition: VideoMode.h:100
int m_CurrentBPP
Definition: VideoMode.h:125
int m_ConfigW
Definition: VideoMode.h:105
int m_WindowedW
Definition: VideoMode.h:114
int m_PreferredW
Definition: VideoMode.h:99
static void UpdateRenderer(int w, int h)
Update the graphics code to start drawing to the new size.
Definition: VideoMode.cpp:409
CVideoMode()
Definition: VideoMode.cpp:49
bool InitNonSDL()
Initialise parts of the video mode, for use in Atlas (which uses wxWidgets instead of SDL for GL)...
Definition: VideoMode.cpp:261
int m_PreferredBPP
Definition: VideoMode.h:101
int m_WindowedH
Definition: VideoMode.h:115
struct SDL_Window SDL_Window
Definition: VideoMode.h:21
int m_CurrentW
Definition: VideoMode.h:123
int m_ConfigBPP
Definition: VideoMode.h:107
int m_PreferredFreq
Definition: VideoMode.h:102
void UpdatePosition(int x, int y)
Update window position, to restore later if necessary (SDL2 only).
Definition: VideoMode.cpp:400
int m_ConfigDisplay
Definition: VideoMode.h:108
bool m_IsInitialised
Remember whether Init has been called.
Definition: VideoMode.h:94
int GetDesktopYRes()
Definition: VideoMode.cpp:468
int GetDesktopBPP()
Definition: VideoMode.cpp:474
bool SetFullscreen(bool fullscreen)
Switch to fullscreen or windowed mode.
Definition: VideoMode.cpp:334
SDL_Window * m_Window
Definition: VideoMode.h:96
int GetBestBPP()
Definition: VideoMode.cpp:435
int GetXRes()
Definition: VideoMode.cpp:444
bool m_ConfigForceS3TCEnable
Definition: VideoMode.h:110
int GetBPP()
Definition: VideoMode.cpp:456
bool m_IsFullscreen
Definition: VideoMode.h:120
bool InitSDL()
Initialise the video mode, for use in an SDL-using application.
Definition: VideoMode.cpp:164
void ReadConfig()
Definition: VideoMode.cpp:59
Definition: VideoMode.h:23
void EnableS3TC()
Definition: VideoMode.cpp:287