1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_VIDEOMODE
19 #define INCLUDED_VIDEOMODE
21 #include "ps/CStrForward.h"
22 #include "renderer/backend/Backend.h"
26 typedef struct SDL_Window SDL_Window
;
43 * Initialise the video mode, for use in an SDL-using application.
48 * Initialise parts of the video mode, for use in Atlas (which uses
49 * wxWidgets instead of SDL for GL).
54 * Shut down after InitSDL/InitNonSDL, so that they can be used again.
59 * Creates a backend device. Also we use wxWidgets in Atlas so we don't need
60 * to create one for that case.
62 bool CreateBackendDevice(const bool createSDLContext
);
65 * Resize the SDL window and associated graphics stuff to the new size.
67 bool ResizeWindow(int w
, int h
);
70 * Set scale and tell dependent compoenent to recompute sizes.
72 void Rescale(float scale
);
75 * Switch to fullscreen or windowed mode.
77 bool SetFullscreen(bool fullscreen
);
80 * Returns true if window runs in fullscreen mode.
82 bool IsInFullscreen() const;
85 * Switch between fullscreen and windowed mode.
87 bool ToggleFullscreen();
90 * Update window position, to restore later if necessary (SDL2 only).
92 void UpdatePosition(int x
, int y
);
95 * Update the graphics code to start drawing to the new size.
96 * This should be called after the GL context has been resized.
97 * This can also be used when the GL context is managed externally, not via SDL.
99 static void UpdateRenderer(int w
, int h
);
105 bool IsVSyncEnabled() const;
107 int GetDesktopXRes() const;
108 int GetDesktopYRes() const;
109 int GetDesktopBPP() const;
110 int GetDesktopFreq() const;
112 float GetScale() const;
114 SDL_Window
* GetWindow();
116 void SetWindowIcon();
118 void SetCursor(const CStrW
& name
);
121 Renderer::Backend::IDevice
* GetBackendDevice() { return m_BackendDevice
.get(); }
126 bool SetVideoMode(int w
, int h
, int bpp
, bool fullscreen
);
128 bool TryCreateBackendDevice(SDL_Window
* window
);
129 void DowngradeBackendSettingAfterCreationFailure();
132 * Remember whether Init has been called. (This isn't used for anything
133 * important, just for verifying that the callers call our methods in
136 bool m_IsInitialised
= false;
138 SDL_Window
* m_Window
= nullptr;
140 // Initial desktop settings.
141 // Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).
142 int m_PreferredW
= 0;
143 int m_PreferredH
= 0;
144 int m_PreferredBPP
= 0;
145 int m_PreferredFreq
= 0;
147 float m_Scale
= 1.0f
;
149 // Config file settings (0 if unspecified)
153 int m_ConfigDisplay
= 0;
154 bool m_ConfigEnableHiDPI
= false;
155 bool m_ConfigVSync
= false;
157 // (m_ConfigFullscreen defaults to false, so users don't get stuck if
158 // e.g. half the filesystem is missing and the config files aren't loaded).
159 bool m_ConfigFullscreen
= false;
161 // If we're fullscreen, size/position of window when we were last windowed (or the default window
162 // size/position if we started fullscreen), to support switching back to the old window size/position
168 // Whether we're currently being displayed fullscreen
169 bool m_IsFullscreen
= false;
171 // The last mode selected
177 std::unique_ptr
<CCursor
> m_Cursor
;
179 Renderer::Backend::Backend m_Backend
= Renderer::Backend::Backend::GL
;
180 std::unique_ptr
<Renderer::Backend::IDevice
> m_BackendDevice
;
183 extern CVideoMode g_VideoMode
;
185 #endif // INCLUDED_VIDEOMODE