1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _GLOBAL_RENDERING_H
4 #define _GLOBAL_RENDERING_H
5 
6 #include "System/creg/creg_cond.h"
7 #include "System/Misc/SpringTime.h"
8 
9 struct SDL_Window;
10 
11 /**
12  * @brief Globally accessible unsynced, rendering related data
13  *
14  * Contains globally accessible rendering related data
15  * that does not remain synced.
16  */
17 class CGlobalRendering {
18 	CR_DECLARE_STRUCT(CGlobalRendering)
19 
20 	CGlobalRendering();
21 
22 public:
23 	void PostInit();
24 	void SetFullScreen(bool configFullScreen, bool cmdLineWindowed, bool cmdLineFullScreen);
25 	void SetViewSize(int vsx, int vsy);
26 	void SetDualScreenParams();
27 	void UpdateViewPortGeometry();
28 	void UpdatePixelGeometry();
29 
30 
31 	/**
32 	 * @brief time offset
33 	 *
34 	 * Time in number of frames since last update
35 	 * (for interpolation)
36 	 */
37 	float timeOffset;
38 
39 	/**
40 	 * @brief last frame time
41 	 *
42 	 * How long the last draw cycle took in real time (MILLIseconds)
43 	 */
44 	float lastFrameTime;
45 
46 	/// the starting time in tick for last draw frame
47 	spring_time lastFrameStart;
48 
49 	/// 0.001f * gu->simFPS, used for rendering
50 	float weightedSpeedFactor;
51 
52 	/// the draw frame number (never 0)
53 	unsigned int drawFrame;
54 
55 	/// Frames Per Second
56 	float FPS;
57 
58 	/// the window state (0=normal,1=maximized,2=minimized)
59 	/// note don't change values without updating MyX11SetWindowState()!!!
60 	enum {
61 		WINSTATE_DEFAULT   = 0,
62 		WINSTATE_MAXIMIZED = 1,
63 		WINSTATE_MINIMIZED = 2
64 	};
65 	int winState;
66 
67 	/// the screen size in pixels
68 	int screenSizeX;
69 	int screenSizeY;
70 
71 	/// the window position relative to the screen's bottom-left corner
72 	int winPosX;
73 	int winPosY;
74 
75 	/// the window size in pixels
76 	int winSizeX;
77 	int winSizeY;
78 
79 	/// the viewport position relative to the window's bottom-left corner
80 	int viewPosX;
81 	int viewPosY;
82 
83 	/// the viewport size in pixels
84 	int viewSizeX;
85 	int viewSizeY;
86 
87 	/// size of one pixel in viewport coordinates, i.e. 1/viewSizeX and 1/viewSizeY
88 	float pixelX;
89 	float pixelY;
90 
91 	/**
92 	 * @brief aspect ratio
93 	 *
94 	 * (float)viewSizeX / (float)viewSizeY
95 	 */
96 	float aspectRatio;
97 
98 	/**
99 	 * @brief view range
100 	 *
101 	 * Player's view range
102 	 */
103 	float zNear;
104 	float viewRange;
105 
106 
107 	/**
108 	 * @brief FSAA
109 	 *
110 	 * Level of full-screen anti-aliasing
111 	 */
112 	int FSAA;
113 
114 	/**
115 	 * @brief maxTextureSize
116 	 *
117 	 * maximum 2D texture size
118 	 */
119 	int maxTextureSize;
120 
121 	bool drawSky;
122 	bool drawWater;
123 	bool drawGround;
124 	bool drawMapMarks;
125 
126 	/**
127 	 * @brief draw fog
128 	 *
129 	 * Whether fog (of war) is drawn or not
130 	 */
131 	bool drawFog;
132 
133 	/**
134 	 * @brief draw debug
135 	 *
136 	 * Whether debugging info is drawn
137 	 */
138 	bool drawdebug;
139 
140 	/**
141 	 * @brief draw debug
142 	 *
143 	 * Whether debugging info is drawn
144 	 */
145 	bool drawdebugtraceray;
146 
147 	/**
148 	 * Does the user want team colored nanospray?
149 	 */
150 	bool teamNanospray;
151 
152 
153 	/**
154 	 * @brief active video
155 	 *
156 	 * Whether the graphics need to be drawn
157 	 */
158 	bool active;
159 
160 	/**
161 	 * @brief compressTextures
162 	 *
163 	 * If set, many (not all) textures will compressed on run-time.
164 	*/
165 	bool compressTextures;
166 
167 	/**
168 	 * @brief GPU driver's vendor
169 	 *
170 	 * These can be used to enable workarounds for bugs in their drivers.
171 	 * Note, you should always give the user the possiblity to override such workarounds via config-tags.
172 	 */
173 	bool haveATI;
174 	bool haveMesa;
175 	bool haveIntel;
176 	bool haveNvidia;
177 
178 	/**
179 	 * @brief collection of some ATI bugfixes
180 	 *
181 	 * enables some ATI bugfixes
182 	 */
183 	bool atiHacks;
184 
185 	/**
186 	 * @brief if the GPU (drivers) support NonPowerOfTwoTextures
187 	 *
188 	 * Especially some ATI cards report that they support NPOTs, but they don't (or just very limited).
189 	 */
190 	bool supportNPOTs;
191 
192 	/**
193 	 * @brief support24bitDepthBuffers
194 	 *
195 	 * if GL_DEPTH_COMPONENT24 is supported (many ATIs don't do so)
196 	 */
197 	bool support24bitDepthBuffers;
198 
199 	bool supportRestartPrimitive;
200 
201 	/**
202 	 * Shader capabilities
203 	 */
204 	bool haveARB;
205 	bool haveGLSL;
206 
207 	/**
208 	 * @brief maxSmoothPointSize
209 	 *
210 	 * maximum smooth point size (driver might fallback in software rendering if larger)
211 	 */
212 	float maxSmoothPointSize;
213 
214 	/**
215 	 * Shader capabilities
216 	 */
217 	int glslMaxVaryings;
218 	int glslMaxAttributes;
219 	int glslMaxDrawBuffers;
220 	int glslMaxRecommendedIndices;
221 	int glslMaxRecommendedVertices;
222 	int glslMaxUniformBufferBindings;
223 	int glslMaxUniformBufferSize; ///< in bytes
224 
225 	/**
226 	 * @brief dual screen mode
227 	 * In dual screen mode, the screen is split up between a game screen and a minimap screen.
228 	 * In this case viewSizeX is half of the actual GL viewport width,
229 	 */
230 	bool dualScreenMode;
231 
232 	/**
233 	 * @brief dual screen minimap on left
234 	 * In dual screen mode, allow the minimap to either be shown on the left or the right display.
235 	 * Minimap on the right is the default.
236 	 */
237 	bool dualScreenMiniMapOnLeft;
238 
239 	/**
240 	 * @brief full-screen or windowed rendering
241 	 */
242 	bool fullScreen;
243 
244 	SDL_Window* window;
245 
246 	/**
247 	* @brief max view range in elmos
248 	*/
249 	static const float MAX_VIEW_RANGE;
250 
251 	/**
252 	* @brief near z-plane distance in elmos
253 	*/
254 	static const float NEAR_PLANE;
255 
256 
257 	/// magic constant to reduce overblending on SMF maps
258 	/// (scales the MapInfo::light_t::ground*Color values)
259 	static const float SMF_INTENSITY_MULT;
260 };
261 
262 extern CGlobalRendering* globalRendering;
263 
264 #endif /* _GLOBAL_RENDERING_H */
265