1 /**
2  * @file
3  * @brief Shared client functions for windowed and fullscreen graphics interface module.
4  */
5 
6 /*
7 Copyright (C) 1997-2001 Id Software, Inc.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 */
25 
26 #include "cl_video.h"
27 #include "client.h"
28 #include "battlescape/cl_view.h"
29 #include "renderer/r_main.h"
30 #include "renderer/r_sdl.h"
31 #include "ui/ui_main.h"
32 #include "cgame/cl_game.h"
33 
34 viddef_t viddef;	/* global video state; used by other modules */
35 
36 cvar_t* vid_stretch;
37 cvar_t* vid_fullscreen;
38 cvar_t* vid_mode;
39 cvar_t* vid_grabmouse;
40 cvar_t* vid_gamma;
41 cvar_t* vid_ignoregamma;
42 static cvar_t* vid_height;
43 static cvar_t* vid_width;
44 
45 /**
46  * @brief All possible video modes
47  */
48 static const vidmode_t vid_modes[] =
49 {
50 	{  320,  240,  0 },
51 	{  400,  300,  1 },
52 	{  512,  384,  2 },
53 	{  640,  480,  3 },
54 	{  800,  600,  4 },
55 	{  960,  720,  5 },
56 	{ 1024,  768,  6 },
57 	{ 1152,  864,  7 },
58 	{ 1280, 1024,  8 },
59 	{ 1600, 1200,  9 },
60 	{ 2048, 1536, 10 },
61 	{ 1024,  480, 11 }, /* Sony VAIO Pocketbook */
62 	{ 1152,  768, 12 }, /* Apple TiBook */
63 	{ 1280,  854, 13 }, /* Apple TiBook */
64 	{  640,  400, 14 }, /* generic 16:10 widescreen*/
65 	{  800,  500, 15 }, /* as found modern */
66 	{ 1024,  640, 16 }, /* notebooks */
67 	{ 1280,  800, 17 },
68 	{ 1680, 1050, 18 },
69 	{ 1920, 1200, 19 },
70 	{ 1400, 1050, 20 }, /* samsung x20 */
71 	{ 1440,  900, 21 },
72 	{ 1024,  600, 22 }, /* EEE PC */
73 	{  800,  480, 23 }, /* OpenPandora */
74 	{ 1920, 1080, 24 }  /* 1080p */
75 };
76 
77 /**
78  * @brief Returns the amount of available video modes
79  */
VID_GetModeNums(void)80 int VID_GetModeNums (void)
81 {
82 	if (r_sdl_config.numModes > 0)
83 		return r_sdl_config.numModes;
84 	return lengthof(vid_modes);
85 }
86 
VID_GetModeInfo(int modeIndex,vidmode_t * modeInfo)87 bool VID_GetModeInfo (int modeIndex, vidmode_t* modeInfo)
88 {
89 	if (modeIndex < 0) {
90 		modeInfo->width = vid_width->integer;
91 		modeInfo->height = vid_height->integer;
92 	} else if (modeIndex < VID_GetModeNums()) {
93 		int width, height;
94 		if (r_sdl_config.numModes > 0) {
95 			width = r_sdl_config.modes[modeIndex][0];
96 			height = r_sdl_config.modes[modeIndex][1];
97 		} else {
98 			width = vid_modes[modeIndex].width;
99 			height = vid_modes[modeIndex].height;
100 		}
101 		modeInfo->width = width;
102 		modeInfo->height = height;
103 	} else {
104 		return false;
105 	}
106 
107 	return true;
108 }
109 
110 /**
111  * @brief Perform a renderer restart
112  */
VID_Restart_f(void)113 static void VID_Restart_f (void)
114 {
115 	refdef.ready = false;
116 
117 	Com_Printf("renderer restart\n");
118 
119 	R_Shutdown();
120 	R_Init();
121 	UI_Reinit();
122 	/** @todo only reload the skins, not all models */
123 	CL_ViewPrecacheModels();
124 
125 	/** @todo going back into the map isn't working as long as GAME_ReloadMode is called */
126 	/*CL_ViewLoadMedia();*/
127 	GAME_ReloadMode();
128 }
129 
CL_CvarCheckVidGamma(cvar_t * cvar)130 static bool CL_CvarCheckVidGamma (cvar_t* cvar)
131 {
132 	return Cvar_AssertValue(cvar, 0.1, 3.0, false);
133 }
134 
CL_CvarCheckVidMode(cvar_t * cvar)135 static bool CL_CvarCheckVidMode (cvar_t* cvar)
136 {
137 	return Cvar_AssertValue(cvar, -1, VID_GetModeNums(), true);
138 }
139 
VID_Minimize(void)140 void VID_Minimize (void)
141 {
142 #if SDL_VERSION_ATLEAST(2,0,0)
143 	SDL_MinimizeWindow(cls.window);
144 #else
145 	SDL_WM_IconifyWindow();
146 #endif
147 }
148 
149 /**
150  * @sa R_Shutdown
151  */
VID_Init(void)152 void VID_Init (void)
153 {
154 	vid_stretch = Cvar_Get("vid_stretch", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Backward compatibility to stretch the screen with a 4:3 ratio");
155 	vid_fullscreen = Cvar_Get("vid_fullscreen", "1", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Run the game in fullscreen mode");
156 	vid_mode = Cvar_Get("vid_mode", "-1", CVAR_ARCHIVE | CVAR_R_CONTEXT, "The video mode - set to -1 and use vid_width and vid_height to use a custom resolution");
157 	Cvar_SetCheckFunction("vid_mode", CL_CvarCheckVidMode);
158 	vid_grabmouse = Cvar_Get("vid_grabmouse", "0", CVAR_ARCHIVE, "Grab the mouse in the game window - open the console to switch back to your desktop via Alt+Tab");
159 	vid_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE, "Controls the gamma settings");
160 	vid_ignoregamma = Cvar_Get("vid_ignoregamma", "0", CVAR_ARCHIVE, "Don't control the gamma settings if set to 1");
161 	Cvar_SetCheckFunction("vid_gamma", CL_CvarCheckVidGamma);
162 	vid_height = Cvar_Get("vid_height", "768", CVAR_ARCHIVE, "Custom video height - set vid_mode to -1 to use this");
163 	vid_width = Cvar_Get("vid_width", "1024", CVAR_ARCHIVE, "Custom video width - set vid_mode to -1 to use this");
164 
165 	Cmd_AddCommand("vid_restart", VID_Restart_f, "Restart the renderer - or change the resolution");
166 	Cmd_AddCommand("vid_minimize", VID_Minimize, "Minimize the game window");
167 
168 	/* memory pools */
169 	vid_genericPool = Mem_CreatePool("Vid: Generic");
170 	vid_imagePool = Mem_CreatePool("Vid: Image system");
171 	vid_lightPool = Mem_CreatePool("Vid: Light system");
172 	vid_modelPool = Mem_CreatePool("Vid: Model system");
173 
174 	/* Start the graphics mode */
175 	R_Init();
176 }
177