10 #define XINPUT_GAMEPAD_DPAD_UP 0x0001
11 #define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
12 #define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
13 #define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
14 #define XINPUT_GAMEPAD_START 0x0010
15 #define XINPUT_GAMEPAD_BACK 0x0020
16 #define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
17 #define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
18 #define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
19 #define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
20 #define XINPUT_GAMEPAD_A 0x1000
21 #define XINPUT_GAMEPAD_B 0x2000
22 #define XINPUT_GAMEPAD_X 0x4000
23 #define XINPUT_GAMEPAD_Y 0x8000
24 #define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
25 #define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
26 #define XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30
27 #define XUSER_INDEX_ANY 0x000000FF
29 typedef struct xinput_gamepad_s
41 typedef struct xinput_state_s
44 xinput_gamepad_t Gamepad;
48 typedef struct xinput_keystroke_s
58 DWORD (WINAPI *qXInputGetState)(DWORD index, xinput_state_t *state);
59 DWORD (WINAPI *qXInputGetKeystroke)(DWORD index, DWORD reserved, xinput_keystroke_t *keystroke);
61 qboolean vid_xinputinitialized = false;
62 int vid_xinputindex = -1;
68 // AK FIXME -> input_dest
69 qboolean in_client_mouse = true;
71 // AK where should it be placed ?
72 float in_mouse_x, in_mouse_y;
73 float in_windowmouse_x, in_windowmouse_y;
75 // LordHavoc: if window is hidden, don't update screen
76 qboolean vid_hidden = true;
77 // LordHavoc: if window is not the active window, don't hog as much CPU time,
78 // let go of the mouse, turn off sound, and restore system gamma ramps...
79 qboolean vid_activewindow = true;
81 vid_joystate_t vid_joystate;
84 cvar_t joy_xinputavailable = {CVAR_READONLY, "joy_xinputavailable", "0", "indicates which devices are being reported by the Windows XInput API (first controller = 1, second = 2, third = 4, fourth = 8, added together)"};
86 cvar_t joy_active = {CVAR_READONLY, "joy_active", "0", "indicates that a joystick is active (detected and enabled)"};
87 cvar_t joy_detected = {CVAR_READONLY, "joy_detected", "0", "number of joysticks detected by engine"};
88 cvar_t joy_enable = {CVAR_SAVE, "joy_enable", "0", "enables joystick support"};
89 cvar_t joy_index = {0, "joy_index", "0", "selects which joystick to use if you have multiple (0 uses the first controller, 1 uses the second, ...)"};
90 cvar_t joy_axisforward = {0, "joy_axisforward", "1", "which joystick axis to query for forward/backward movement"};
91 cvar_t joy_axisside = {0, "joy_axisside", "0", "which joystick axis to query for right/left movement"};
92 cvar_t joy_axisup = {0, "joy_axisup", "-1", "which joystick axis to query for up/down movement"};
93 cvar_t joy_axispitch = {0, "joy_axispitch", "3", "which joystick axis to query for looking up/down"};
94 cvar_t joy_axisyaw = {0, "joy_axisyaw", "2", "which joystick axis to query for looking right/left"};
95 cvar_t joy_axisroll = {0, "joy_axisroll", "-1", "which joystick axis to query for tilting head right/left"};
96 cvar_t joy_deadzoneforward = {0, "joy_deadzoneforward", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
97 cvar_t joy_deadzoneside = {0, "joy_deadzoneside", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
98 cvar_t joy_deadzoneup = {0, "joy_deadzoneup", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
99 cvar_t joy_deadzonepitch = {0, "joy_deadzonepitch", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
100 cvar_t joy_deadzoneyaw = {0, "joy_deadzoneyaw", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
101 cvar_t joy_deadzoneroll = {0, "joy_deadzoneroll", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
102 cvar_t joy_sensitivityforward = {0, "joy_sensitivityforward", "-1", "movement multiplier"};
103 cvar_t joy_sensitivityside = {0, "joy_sensitivityside", "1", "movement multiplier"};
104 cvar_t joy_sensitivityup = {0, "joy_sensitivityup", "1", "movement multiplier"};
105 cvar_t joy_sensitivitypitch = {0, "joy_sensitivitypitch", "1", "movement multiplier"};
106 cvar_t joy_sensitivityyaw = {0, "joy_sensitivityyaw", "-1", "movement multiplier"};
107 cvar_t joy_sensitivityroll = {0, "joy_sensitivityroll", "1", "movement multiplier"};
108 cvar_t joy_axiskeyevents = {CVAR_SAVE, "joy_axiskeyevents", "0", "generate uparrow/leftarrow etc. keyevents for joystick axes, use if your joystick driver is not generating them"};
109 cvar_t joy_axiskeyevents_deadzone = {CVAR_SAVE, "joy_axiskeyevents_deadzone", "0.5", "deadzone value for axes"};
110 cvar_t joy_x360_axisforward = {0, "joy_x360_axisforward", "1", "which joystick axis to query for forward/backward movement"};
111 cvar_t joy_x360_axisside = {0, "joy_x360_axisside", "0", "which joystick axis to query for right/left movement"};
112 cvar_t joy_x360_axisup = {0, "joy_x360_axisup", "-1", "which joystick axis to query for up/down movement"};
113 cvar_t joy_x360_axispitch = {0, "joy_x360_axispitch", "3", "which joystick axis to query for looking up/down"};
114 cvar_t joy_x360_axisyaw = {0, "joy_x360_axisyaw", "2", "which joystick axis to query for looking right/left"};
115 cvar_t joy_x360_axisroll = {0, "joy_x360_axisroll", "-1", "which joystick axis to query for tilting head right/left"};
116 cvar_t joy_x360_deadzoneforward = {0, "joy_x360_deadzoneforward", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
117 cvar_t joy_x360_deadzoneside = {0, "joy_x360_deadzoneside", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
118 cvar_t joy_x360_deadzoneup = {0, "joy_x360_deadzoneup", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
119 cvar_t joy_x360_deadzonepitch = {0, "joy_x360_deadzonepitch", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
120 cvar_t joy_x360_deadzoneyaw = {0, "joy_x360_deadzoneyaw", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
121 cvar_t joy_x360_deadzoneroll = {0, "joy_x360_deadzoneroll", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
122 cvar_t joy_x360_sensitivityforward = {0, "joy_x360_sensitivityforward", "1", "movement multiplier"};
123 cvar_t joy_x360_sensitivityside = {0, "joy_x360_sensitivityside", "1", "movement multiplier"};
124 cvar_t joy_x360_sensitivityup = {0, "joy_x360_sensitivityup", "1", "movement multiplier"};
125 cvar_t joy_x360_sensitivitypitch = {0, "joy_x360_sensitivitypitch", "-1", "movement multiplier"};
126 cvar_t joy_x360_sensitivityyaw = {0, "joy_x360_sensitivityyaw", "-1", "movement multiplier"};
127 cvar_t joy_x360_sensitivityroll = {0, "joy_x360_sensitivityroll", "1", "movement multiplier"};
129 // VorteX: more info cvars, mostly set in VID_CheckExtensions
130 cvar_t gl_info_vendor = {CVAR_READONLY, "gl_info_vendor", "", "indicates brand of graphics chip"};
131 cvar_t gl_info_renderer = {CVAR_READONLY, "gl_info_renderer", "", "indicates graphics chip model and other information"};
132 cvar_t gl_info_version = {CVAR_READONLY, "gl_info_version", "", "indicates version of current renderer. begins with 1.0.0, 1.1.0, 1.2.0, 1.3.1 etc."};
133 cvar_t gl_info_extensions = {CVAR_READONLY, "gl_info_extensions", "", "indicates extension list found by engine, space separated."};
134 cvar_t gl_info_platform = {CVAR_READONLY, "gl_info_platform", "", "indicates GL platform: WGL, GLX, or AGL."};
135 cvar_t gl_info_driver = {CVAR_READONLY, "gl_info_driver", "", "name of driver library (opengl32.dll, libGL.so.1, or whatever)."};
137 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1", "use fullscreen (1) or windowed (0)"};
138 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640", "resolution"};
139 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480", "resolution"};
140 cvar_t vid_bitsperpixel = {CVAR_READONLY, "vid_bitsperpixel", "32", "how many bits per pixel to render at (this is not currently configurable)"};
141 cvar_t vid_samples = {CVAR_SAVE, "vid_samples", "1", "how many anti-aliasing samples per pixel to request from the graphics driver (4 is recommended, 1 is faster)"};
142 cvar_t vid_refreshrate = {CVAR_SAVE, "vid_refreshrate", "60", "refresh rate to use, in hz (higher values flicker less, if supported by your monitor)"};
143 cvar_t vid_userefreshrate = {CVAR_SAVE, "vid_userefreshrate", "0", "set this to 1 to make vid_refreshrate used, or to 0 to let the engine choose a sane default"};
144 cvar_t vid_stereobuffer = {CVAR_SAVE, "vid_stereobuffer", "0", "enables 'quad-buffered' stereo rendering for stereo shutterglasses, HMD (head mounted display) devices, or polarized stereo LCDs, if supported by your drivers"};
145 // the density cvars are completely optional, set and use when something needs to have a density-independent size.
146 // TODO: set them when changing resolution, setting them from the commandline will be independent from the resolution - use only if you have a native fixed resolution.
147 // values for the Samsung Galaxy SIII, Snapdragon version: 2.000000 density, 304.799988 xdpi, 303.850464 ydpi
148 cvar_t vid_touchscreen_density = {0, "vid_touchscreen_density", "2.0", "Standard quantized screen density multiplier (see Android documentation for DisplayMetrics), similar values are given on iPhoneOS"};
149 cvar_t vid_touchscreen_xdpi = {0, "vid_touchscreen_xdpi", "300", "Horizontal DPI of the screen (only valid on Android currently)"};
150 cvar_t vid_touchscreen_ydpi = {0, "vid_touchscreen_ydpi", "300", "Vertical DPI of the screen (only valid on Android currently)"};
152 cvar_t vid_vsync = {CVAR_SAVE, "vid_vsync", "0", "sync to vertical blank, prevents 'tearing' (seeing part of one frame and part of another on the screen at the same time), automatically disabled when doing timedemo benchmarks"};
153 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1", "whether to use the mouse in windowed mode (fullscreen always does)"};
154 cvar_t vid_grabkeyboard = {CVAR_SAVE, "vid_grabkeyboard", "0", "whether to grab the keyboard when mouse is active (prevents use of volume control keys, music player keys, etc on some keyboards)"};
155 cvar_t vid_minwidth = {0, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"};
156 cvar_t vid_minheight = {0, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"};
157 cvar_t gl_finish = {0, "gl_finish", "0", "make the cpu wait for the graphics processor at the end of each rendered frame (can help with strange input or video lag problems on some machines)"};
158 cvar_t vid_sRGB = {CVAR_SAVE, "vid_sRGB", "0", "if hardware is capable, modify rendering to be gamma corrected for the sRGB color standard (computer monitors, TVs), recommended"};
159 cvar_t vid_sRGB_fallback = {CVAR_SAVE, "vid_sRGB_fallback", "0", "do an approximate sRGB fallback if not properly supported by hardware (2: also use the fallback if framebuffer is 8bit, 3: always use the fallback even if sRGB is supported)"};
161 cvar_t vid_touchscreen = {0, "vid_touchscreen", "0", "Use touchscreen-style input (no mouse grab, track mouse motion only while button is down, screen areas for mimicing joystick axes and buttons"};
162 cvar_t vid_touchscreen_showkeyboard = {0, "vid_touchscreen_showkeyboard", "0", "shows the platform's screen keyboard for text entry, can be set by csqc or menu qc if it wants to receive text input, does nothing if the platform has no screen keyboard"};
163 cvar_t vid_touchscreen_supportshowkeyboard = {CVAR_READONLY, "vid_touchscreen_supportshowkeyboard", "0", "indicates if the platform supports a virtual keyboard"};
164 cvar_t vid_stick_mouse = {CVAR_SAVE, "vid_stick_mouse", "0", "have the mouse stuck in the center of the screen" };
165 cvar_t vid_resizable = {CVAR_SAVE, "vid_resizable", "0", "0: window not resizable, 1: resizable, 2: window can be resized but the framebuffer isn't adjusted" };
166 cvar_t vid_desktopfullscreen = {CVAR_SAVE, "vid_desktopfullscreen", "1", "force desktop resolution for fullscreen; also use some OS dependent tricks for better fullscreen integration"};
168 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1", "inverse gamma correction value, a brightness effect that does not affect white or black, and tends to make the image grey and dull"};
169 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1", "brightness of white (values above 1 give a brighter image with increased color saturation, unlike v_gamma)"};
170 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0", "brightness of black, useful for monitors that are too dark"};
171 cvar_t v_contrastboost = {CVAR_SAVE, "v_contrastboost", "1", "by how much to multiply the contrast in dark areas (1 is no change)"};
172 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0", "enables black-grey-white color correction curve controls"};
173 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0", "desired color of black"};
174 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0", "desired color of black"};
175 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0", "desired color of black"};
176 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5", "desired color of grey"};
177 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5", "desired color of grey"};
178 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5", "desired color of grey"};
179 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1", "desired color of white"};
180 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1", "desired color of white"};
181 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1", "desired color of white"};
182 cvar_t v_glslgamma_2d = {CVAR_SAVE, "v_glslgamma_2d", "1", "applies GLSL gamma to 2d pictures (HUD, fonts)"};
183 cvar_t v_psycho = {0, "v_psycho", "0", "easter egg - R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667"};
185 // brand of graphics chip
186 const char *gl_vendor;
187 // graphics chip model and other information
188 const char *gl_renderer;
189 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
190 const char *gl_version;
191 // extensions list, space separated
192 const char *gl_extensions;
194 const char *gl_platform;
195 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
199 GLboolean (GLAPIENTRY *qglIsBuffer) (GLuint buffer);
200 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
201 GLboolean (GLAPIENTRY *qglIsFramebuffer)(GLuint framebuffer);
202 GLboolean (GLAPIENTRY *qglIsQuery)(GLuint qid);
203 GLboolean (GLAPIENTRY *qglIsRenderbuffer)(GLuint renderbuffer);
204 GLboolean (GLAPIENTRY *qglUnmapBuffer) (GLenum target);
205 GLenum (GLAPIENTRY *qglCheckFramebufferStatus)(GLenum target);
206 GLenum (GLAPIENTRY *qglGetError)(void);
207 GLint (GLAPIENTRY *qglGetAttribLocation)(GLuint programObj, const GLchar *name);
208 GLint (GLAPIENTRY *qglGetUniformLocation)(GLuint programObj, const GLchar *name);
209 GLuint (GLAPIENTRY *qglCreateProgram)(void);
210 GLuint (GLAPIENTRY *qglCreateShader)(GLenum shaderType);
211 GLuint (GLAPIENTRY *qglGetDebugMessageLogARB)(GLuint count, GLsizei bufSize, GLenum* sources, GLenum* types, GLuint* ids, GLenum* severities, GLsizei* lengths, GLchar* messageLog);
212 GLuint (GLAPIENTRY *qglGetUniformBlockIndex)(GLuint program, const char* uniformBlockName);
213 GLvoid (GLAPIENTRY *qglBindFramebuffer)(GLenum target, GLuint framebuffer);
214 GLvoid (GLAPIENTRY *qglBindRenderbuffer)(GLenum target, GLuint renderbuffer);
215 GLvoid (GLAPIENTRY *qglBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
216 GLvoid (GLAPIENTRY *qglDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers);
217 GLvoid (GLAPIENTRY *qglDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers);
218 GLvoid (GLAPIENTRY *qglFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
219 GLvoid (GLAPIENTRY *qglFramebufferTexture1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
220 GLvoid (GLAPIENTRY *qglFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
221 GLvoid (GLAPIENTRY *qglFramebufferTexture3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer);
222 GLvoid (GLAPIENTRY *qglFramebufferTextureLayer)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
223 GLvoid (GLAPIENTRY *qglGenFramebuffers)(GLsizei n, GLuint *framebuffers);
224 GLvoid (GLAPIENTRY *qglGenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
225 GLvoid (GLAPIENTRY *qglGenerateMipmap)(GLenum target);
226 GLvoid (GLAPIENTRY *qglGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
227 GLvoid (GLAPIENTRY *qglGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params);
228 GLvoid (GLAPIENTRY *qglRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
229 GLvoid (GLAPIENTRY *qglRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
230 GLvoid* (GLAPIENTRY *qglMapBuffer) (GLenum target, GLenum access);
231 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
232 const GLubyte* (GLAPIENTRY *qglGetStringi)(GLenum name, GLuint index);
233 void (GLAPIENTRY *qglActiveTexture)(GLenum texture);
234 void (GLAPIENTRY *qglAttachShader)(GLuint containerObj, GLuint obj);
235 void (GLAPIENTRY *qglBeginQuery)(GLenum target, GLuint qid);
236 void (GLAPIENTRY *qglBindAttribLocation)(GLuint programObj, GLuint index, const GLchar *name);
237 void (GLAPIENTRY *qglBindBuffer) (GLenum target, GLuint buffer);
238 void (GLAPIENTRY *qglBindBufferBase)(GLenum target, GLuint index, GLuint buffer);
239 void (GLAPIENTRY *qglBindBufferRange)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
240 void (GLAPIENTRY *qglBindFragDataLocation)(GLuint programObj, GLuint index, const GLchar *name);
241 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
242 void (GLAPIENTRY *qglBindVertexArray)(GLuint array);
243 void (GLAPIENTRY *qglBlendEquation)(GLenum); // also supplied by GL_blend_subtract
244 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
245 void (GLAPIENTRY *qglBlendFuncSeparate)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
246 void (GLAPIENTRY *qglBufferData) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
247 void (GLAPIENTRY *qglBufferSubData) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
248 void (GLAPIENTRY *qglClear)(GLbitfield mask);
249 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
250 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
251 void (GLAPIENTRY *qglClearStencil)(GLint s);
252 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
253 void (GLAPIENTRY *qglCompileShader)(GLuint shaderObj);
254 void (GLAPIENTRY *qglCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
255 void (GLAPIENTRY *qglCompressedTexImage3D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
256 void (GLAPIENTRY *qglCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
257 void (GLAPIENTRY *qglCompressedTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
258 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
259 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
260 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
261 void (GLAPIENTRY *qglCullFace)(GLenum mode);
262 void (GLAPIENTRY *qglDebugMessageCallbackARB)(GLDEBUGPROCARB callback, const GLvoid* userParam);
263 void (GLAPIENTRY *qglDebugMessageControlARB)(GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, GLboolean enabled);
264 void (GLAPIENTRY *qglDebugMessageInsertARB)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf);
265 void (GLAPIENTRY *qglDeleteBuffers) (GLsizei n, const GLuint *buffers);
266 void (GLAPIENTRY *qglDeleteProgram)(GLuint obj);
267 void (GLAPIENTRY *qglDeleteQueries)(GLsizei n, const GLuint *ids);
268 void (GLAPIENTRY *qglDeleteShader)(GLuint obj);
269 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
270 void (GLAPIENTRY *qglDeleteVertexArrays)(GLsizei n, const GLuint *arrays);
271 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
272 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
273 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
274 void (GLAPIENTRY *qglDepthRangef)(GLclampf near_val, GLclampf far_val);
275 void (GLAPIENTRY *qglDetachShader)(GLuint containerObj, GLuint attachedObj);
276 void (GLAPIENTRY *qglDisable)(GLenum cap);
277 void (GLAPIENTRY *qglDisableVertexAttribArray)(GLuint index);
278 void (GLAPIENTRY *qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
279 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
280 void (GLAPIENTRY *qglDrawBuffers)(GLsizei n, const GLenum *bufs);
281 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
282 void (GLAPIENTRY *qglEnable)(GLenum cap);
283 void (GLAPIENTRY *qglEnableVertexAttribArray)(GLuint index);
284 void (GLAPIENTRY *qglEndQuery)(GLenum target);
285 void (GLAPIENTRY *qglFinish)(void);
286 void (GLAPIENTRY *qglFlush)(void);
287 void (GLAPIENTRY *qglGenBuffers) (GLsizei n, GLuint *buffers);
288 void (GLAPIENTRY *qglGenQueries)(GLsizei n, GLuint *ids);
289 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
290 void (GLAPIENTRY *qglGenVertexArrays)(GLsizei n, GLuint *arrays);
291 void (GLAPIENTRY *qglGetActiveAttrib)(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
292 void (GLAPIENTRY *qglGetActiveUniform)(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
293 void (GLAPIENTRY *qglGetActiveUniformBlockName)(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, char* uniformBlockName);
294 void (GLAPIENTRY *qglGetActiveUniformBlockiv)(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params);
295 void (GLAPIENTRY *qglGetActiveUniformName)(GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei* length, char* uniformName);
296 void (GLAPIENTRY *qglGetActiveUniformsiv)(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params);
297 void (GLAPIENTRY *qglGetAttachedShaders)(GLuint containerObj, GLsizei maxCount, GLsizei *count, GLuint *obj);
298 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
299 void (GLAPIENTRY *qglGetCompressedTexImage)(GLenum target, GLint lod, void *img);
300 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
301 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
302 void (GLAPIENTRY *qglGetIntegeri_v)(GLenum target, GLuint index, GLint* data);
303 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
304 void (GLAPIENTRY *qglGetPointerv)(GLenum pname, GLvoid** params);
305 void (GLAPIENTRY *qglGetProgramInfoLog)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
306 void (GLAPIENTRY *qglGetProgramiv)(GLuint obj, GLenum pname, GLint *params);
307 void (GLAPIENTRY *qglGetQueryObjectiv)(GLuint qid, GLenum pname, GLint *params);
308 void (GLAPIENTRY *qglGetQueryObjectuiv)(GLuint qid, GLenum pname, GLuint *params);
309 void (GLAPIENTRY *qglGetQueryiv)(GLenum target, GLenum pname, GLint *params);
310 void (GLAPIENTRY *qglGetShaderInfoLog)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
311 void (GLAPIENTRY *qglGetShaderSource)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *source);
312 void (GLAPIENTRY *qglGetShaderiv)(GLuint obj, GLenum pname, GLint *params);
313 void (GLAPIENTRY *qglGetTexImage)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
314 void (GLAPIENTRY *qglGetTexLevelParameterfv)(GLenum target, GLint level, GLenum pname, GLfloat *params);
315 void (GLAPIENTRY *qglGetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint *params);
316 void (GLAPIENTRY *qglGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
317 void (GLAPIENTRY *qglGetTexParameteriv)(GLenum target, GLenum pname, GLint *params);
318 void (GLAPIENTRY *qglGetUniformIndices)(GLuint program, GLsizei uniformCount, const char** uniformNames, GLuint* uniformIndices);
319 void (GLAPIENTRY *qglGetUniformfv)(GLuint programObj, GLint location, GLfloat *params);
320 void (GLAPIENTRY *qglGetUniformiv)(GLuint programObj, GLint location, GLint *params);
321 void (GLAPIENTRY *qglGetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid **pointer);
322 void (GLAPIENTRY *qglGetVertexAttribdv)(GLuint index, GLenum pname, GLdouble *params);
323 void (GLAPIENTRY *qglGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat *params);
324 void (GLAPIENTRY *qglGetVertexAttribiv)(GLuint index, GLenum pname, GLint *params);
325 void (GLAPIENTRY *qglHint)(GLenum target, GLenum mode);
326 void (GLAPIENTRY *qglLinkProgram)(GLuint programObj);
327 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
328 void (GLAPIENTRY *qglPointSize)(GLfloat size);
329 void (GLAPIENTRY *qglPolygonMode)(GLenum face, GLenum mode);
330 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
331 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
332 void (GLAPIENTRY *qglGetPointerv)(GLenum pname, GLvoid** params);
333 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
334 void (GLAPIENTRY *qglSampleCoverage)(GLclampf value, GLboolean invert);
335 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
336 void (GLAPIENTRY *qglShaderSource)(GLuint shaderObj, GLsizei count, const GLchar **string, const GLint *length);
337 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
338 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
339 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
340 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
341 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
342 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
343 void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
344 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
345 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
346 void (GLAPIENTRY *qglTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
347 void (GLAPIENTRY *qglUniform1f)(GLint location, GLfloat v0);
348 void (GLAPIENTRY *qglUniform1fv)(GLint location, GLsizei count, const GLfloat *value);
349 void (GLAPIENTRY *qglUniform1i)(GLint location, GLint v0);
350 void (GLAPIENTRY *qglUniform1iv)(GLint location, GLsizei count, const GLint *value);
351 void (GLAPIENTRY *qglUniform2f)(GLint location, GLfloat v0, GLfloat v1);
352 void (GLAPIENTRY *qglUniform2fv)(GLint location, GLsizei count, const GLfloat *value);
353 void (GLAPIENTRY *qglUniform2i)(GLint location, GLint v0, GLint v1);
354 void (GLAPIENTRY *qglUniform2iv)(GLint location, GLsizei count, const GLint *value);
355 void (GLAPIENTRY *qglUniform3f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
356 void (GLAPIENTRY *qglUniform3fv)(GLint location, GLsizei count, const GLfloat *value);
357 void (GLAPIENTRY *qglUniform3i)(GLint location, GLint v0, GLint v1, GLint v2);
358 void (GLAPIENTRY *qglUniform3iv)(GLint location, GLsizei count, const GLint *value);
359 void (GLAPIENTRY *qglUniform4f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
360 void (GLAPIENTRY *qglUniform4fv)(GLint location, GLsizei count, const GLfloat *value);
361 void (GLAPIENTRY *qglUniform4i)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
362 void (GLAPIENTRY *qglUniform4iv)(GLint location, GLsizei count, const GLint *value);
363 void (GLAPIENTRY *qglUniformBlockBinding)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
364 void (GLAPIENTRY *qglUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
365 void (GLAPIENTRY *qglUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
366 void (GLAPIENTRY *qglUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
367 void (GLAPIENTRY *qglUseProgram)(GLuint programObj);
368 void (GLAPIENTRY *qglValidateProgram)(GLuint programObj);
369 void (GLAPIENTRY *qglVertexAttrib1d)(GLuint index, GLdouble v0);
370 void (GLAPIENTRY *qglVertexAttrib1dv)(GLuint index, const GLdouble *v);
371 void (GLAPIENTRY *qglVertexAttrib1f)(GLuint index, GLfloat v0);
372 void (GLAPIENTRY *qglVertexAttrib1fv)(GLuint index, const GLfloat *v);
373 void (GLAPIENTRY *qglVertexAttrib1s)(GLuint index, GLshort v0);
374 void (GLAPIENTRY *qglVertexAttrib1sv)(GLuint index, const GLshort *v);
375 void (GLAPIENTRY *qglVertexAttrib2d)(GLuint index, GLdouble v0, GLdouble v1);
376 void (GLAPIENTRY *qglVertexAttrib2dv)(GLuint index, const GLdouble *v);
377 void (GLAPIENTRY *qglVertexAttrib2f)(GLuint index, GLfloat v0, GLfloat v1);
378 void (GLAPIENTRY *qglVertexAttrib2fv)(GLuint index, const GLfloat *v);
379 void (GLAPIENTRY *qglVertexAttrib2s)(GLuint index, GLshort v0, GLshort v1);
380 void (GLAPIENTRY *qglVertexAttrib2sv)(GLuint index, const GLshort *v);
381 void (GLAPIENTRY *qglVertexAttrib3d)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2);
382 void (GLAPIENTRY *qglVertexAttrib3dv)(GLuint index, const GLdouble *v);
383 void (GLAPIENTRY *qglVertexAttrib3f)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2);
384 void (GLAPIENTRY *qglVertexAttrib3fv)(GLuint index, const GLfloat *v);
385 void (GLAPIENTRY *qglVertexAttrib3s)(GLuint index, GLshort v0, GLshort v1, GLshort v2);
386 void (GLAPIENTRY *qglVertexAttrib3sv)(GLuint index, const GLshort *v);
387 void (GLAPIENTRY *qglVertexAttrib4Nbv)(GLuint index, const GLbyte *v);
388 void (GLAPIENTRY *qglVertexAttrib4Niv)(GLuint index, const GLint *v);
389 void (GLAPIENTRY *qglVertexAttrib4Nsv)(GLuint index, const GLshort *v);
390 void (GLAPIENTRY *qglVertexAttrib4Nub)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
391 void (GLAPIENTRY *qglVertexAttrib4Nubv)(GLuint index, const GLubyte *v);
392 void (GLAPIENTRY *qglVertexAttrib4Nuiv)(GLuint index, const GLuint *v);
393 void (GLAPIENTRY *qglVertexAttrib4Nusv)(GLuint index, const GLushort *v);
394 void (GLAPIENTRY *qglVertexAttrib4bv)(GLuint index, const GLbyte *v);
395 void (GLAPIENTRY *qglVertexAttrib4d)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
396 void (GLAPIENTRY *qglVertexAttrib4dv)(GLuint index, const GLdouble *v);
397 void (GLAPIENTRY *qglVertexAttrib4f)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
398 void (GLAPIENTRY *qglVertexAttrib4fv)(GLuint index, const GLfloat *v);
399 void (GLAPIENTRY *qglVertexAttrib4iv)(GLuint index, const GLint *v);
400 void (GLAPIENTRY *qglVertexAttrib4s)(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3);
401 void (GLAPIENTRY *qglVertexAttrib4sv)(GLuint index, const GLshort *v);
402 void (GLAPIENTRY *qglVertexAttrib4ubv)(GLuint index, const GLubyte *v);
403 void (GLAPIENTRY *qglVertexAttrib4uiv)(GLuint index, const GLuint *v);
404 void (GLAPIENTRY *qglVertexAttrib4usv)(GLuint index, const GLushort *v);
405 void (GLAPIENTRY *qglVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
406 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
410 #define sscanf sscanf_s
413 typedef struct glfunction_s
415 const char *extension;
422 // functions we look for - both core and extensions - it's okay if some of these are NULL for unsupported extensions.
423 static glfunction_t openglfuncs[] =
425 {"core", "glActiveTexture", (void **) &qglActiveTexture},
426 {"core", "glAttachShader", (void **) &qglAttachShader},
427 {"core", "glBeginQuery", (void **) &qglBeginQuery},
428 {"core", "glBindAttribLocation", (void **) &qglBindAttribLocation},
429 {"core", "glBindBuffer", (void **) &qglBindBuffer},
430 {"core", "glBindBufferBase", (void **) &qglBindBufferBase},
431 {"core", "glBindBufferRange", (void **) &qglBindBufferRange},
432 {"core", "glBindFramebuffer", (void **) &qglBindFramebuffer},
433 {"core", "glBindRenderbuffer", (void **) &qglBindRenderbuffer},
434 {"core", "glBindTexture", (void **) &qglBindTexture},
435 {"core", "glBindVertexArray", (void **) &qglBindVertexArray},
436 {"core", "glBlendEquation", (void **) &qglBlendEquation},
437 {"core", "glBlendFunc", (void **) &qglBlendFunc},
438 {"core", "glBlendFuncSeparate", (void **) &qglBlendFuncSeparate},
439 {"core", "glBlitFramebuffer", (void **) &qglBlitFramebuffer},
440 {"core", "glBufferData", (void **) &qglBufferData},
441 {"core", "glBufferSubData", (void **) &qglBufferSubData},
442 {"core", "glCheckFramebufferStatus", (void **) &qglCheckFramebufferStatus},
443 {"core", "glClear", (void **) &qglClear},
444 {"core", "glClearColor", (void **) &qglClearColor},
445 {"core", "glClearDepth", (void **) &qglClearDepth},
446 {"core", "glClearStencil", (void **) &qglClearStencil},
447 {"core", "glColorMask", (void **) &qglColorMask},
448 {"core", "glCompileShader", (void **) &qglCompileShader},
449 {"core", "glCompressedTexImage2D", (void **) &qglCompressedTexImage2D},
450 {"core", "glCompressedTexImage3D", (void **) &qglCompressedTexImage3D},
451 {"core", "glCompressedTexSubImage2D", (void **) &qglCompressedTexSubImage2D},
452 {"core", "glCompressedTexSubImage3D", (void **) &qglCompressedTexSubImage3D},
453 {"core", "glCopyTexImage2D", (void **) &qglCopyTexImage2D},
454 {"core", "glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
455 {"core", "glCopyTexSubImage3D", (void **) &qglCopyTexSubImage3D},
456 {"core", "glCreateProgram", (void **) &qglCreateProgram},
457 {"core", "glCreateShader", (void **) &qglCreateShader},
458 {"core", "glCullFace", (void **) &qglCullFace},
459 {"core", "glDeleteBuffers", (void **) &qglDeleteBuffers},
460 {"core", "glDeleteFramebuffers", (void **) &qglDeleteFramebuffers},
461 {"core", "glDeleteProgram", (void **) &qglDeleteProgram},
462 {"core", "glDeleteQueries", (void **) &qglDeleteQueries},
463 {"core", "glDeleteRenderbuffers", (void **) &qglDeleteRenderbuffers},
464 {"core", "glDeleteShader", (void **) &qglDeleteShader},
465 {"core", "glDeleteTextures", (void **) &qglDeleteTextures},
466 {"core", "glDeleteVertexArrays", (void **)&qglDeleteVertexArrays},
467 {"core", "glDepthFunc", (void **) &qglDepthFunc},
468 {"core", "glDepthMask", (void **) &qglDepthMask},
469 {"core", "glDepthRange", (void **) &qglDepthRange},
470 {"core", "glDepthRangef", (void **) &qglDepthRangef},
471 {"core", "glDetachShader", (void **) &qglDetachShader},
472 {"core", "glDisable", (void **) &qglDisable},
473 {"core", "glDisableVertexAttribArray", (void **) &qglDisableVertexAttribArray},
474 {"core", "glDrawArrays", (void **) &qglDrawArrays},
475 {"core", "glDrawBuffer", (void **) &qglDrawBuffer},
476 {"core", "glDrawBuffers", (void **) &qglDrawBuffers},
477 {"core", "glDrawElements", (void **) &qglDrawElements},
478 {"core", "glEnable", (void **) &qglEnable},
479 {"core", "glEnableVertexAttribArray", (void **) &qglEnableVertexAttribArray},
480 {"core", "glEndQuery", (void **) &qglEndQuery},
481 {"core", "glFinish", (void **) &qglFinish},
482 {"core", "glFlush", (void **) &qglFlush},
483 {"core", "glFramebufferRenderbuffer", (void **) &qglFramebufferRenderbuffer},
484 {"core", "glFramebufferTexture1D", (void **) &qglFramebufferTexture1D},
485 {"core", "glFramebufferTexture2D", (void **) &qglFramebufferTexture2D},
486 {"core", "glFramebufferTexture3D", (void **) &qglFramebufferTexture3D},
487 {"core", "glFramebufferTextureLayer", (void **) &qglFramebufferTextureLayer},
488 {"core", "glGenBuffers", (void **) &qglGenBuffers},
489 {"core", "glGenFramebuffers", (void **) &qglGenFramebuffers},
490 {"core", "glGenQueries", (void **) &qglGenQueries},
491 {"core", "glGenRenderbuffers", (void **) &qglGenRenderbuffers},
492 {"core", "glGenTextures", (void **) &qglGenTextures},
493 {"core", "glGenVertexArrays", (void **)&qglGenVertexArrays},
494 {"core", "glGenerateMipmap", (void **) &qglGenerateMipmap},
495 {"core", "glGetActiveAttrib", (void **) &qglGetActiveAttrib},
496 {"core", "glGetActiveUniform", (void **) &qglGetActiveUniform},
497 {"core", "glGetActiveUniformBlockName", (void **) &qglGetActiveUniformBlockName},
498 {"core", "glGetActiveUniformBlockiv", (void **) &qglGetActiveUniformBlockiv},
499 {"core", "glGetActiveUniformName", (void **) &qglGetActiveUniformName},
500 {"core", "glGetActiveUniformsiv", (void **) &qglGetActiveUniformsiv},
501 {"core", "glGetAttachedShaders", (void **) &qglGetAttachedShaders},
502 {"core", "glGetAttribLocation", (void **) &qglGetAttribLocation},
503 {"core", "glGetBooleanv", (void **) &qglGetBooleanv},
504 {"core", "glGetCompressedTexImage", (void **) &qglGetCompressedTexImage},
505 {"core", "glGetDoublev", (void **) &qglGetDoublev},
506 {"core", "glGetError", (void **) &qglGetError},
507 {"core", "glGetFloatv", (void **) &qglGetFloatv},
508 {"core", "glGetFramebufferAttachmentParameteriv", (void **) &qglGetFramebufferAttachmentParameteriv},
509 {"core", "glGetIntegeri_v", (void **) &qglGetIntegeri_v},
510 {"core", "glGetIntegerv", (void **) &qglGetIntegerv},
511 {"core", "glGetProgramInfoLog", (void **) &qglGetProgramInfoLog},
512 {"core", "glGetProgramiv", (void **) &qglGetProgramiv},
513 {"core", "glGetQueryObjectiv", (void **) &qglGetQueryObjectiv},
514 {"core", "glGetQueryObjectuiv", (void **) &qglGetQueryObjectuiv},
515 {"core", "glGetQueryiv", (void **) &qglGetQueryiv},
516 {"core", "glGetRenderbufferParameteriv", (void **) &qglGetRenderbufferParameteriv},
517 {"core", "glGetShaderInfoLog", (void **) &qglGetShaderInfoLog},
518 {"core", "glGetShaderSource", (void **) &qglGetShaderSource},
519 {"core", "glGetShaderiv", (void **) &qglGetShaderiv},
520 {"core", "glGetString", (void **) &qglGetString},
521 {"core", "glGetStringi", (void **) &qglGetStringi},
522 {"core", "glGetTexImage", (void **) &qglGetTexImage},
523 {"core", "glGetTexLevelParameterfv", (void **) &qglGetTexLevelParameterfv},
524 {"core", "glGetTexLevelParameteriv", (void **) &qglGetTexLevelParameteriv},
525 {"core", "glGetTexParameterfv", (void **) &qglGetTexParameterfv},
526 {"core", "glGetTexParameteriv", (void **) &qglGetTexParameteriv},
527 {"core", "glGetUniformBlockIndex", (void **) &qglGetUniformBlockIndex},
528 {"core", "glGetUniformIndices", (void **) &qglGetUniformIndices},
529 {"core", "glGetUniformLocation", (void **) &qglGetUniformLocation},
530 {"core", "glGetUniformfv", (void **) &qglGetUniformfv},
531 {"core", "glGetUniformiv", (void **) &qglGetUniformiv},
532 {"core", "glGetVertexAttribPointerv", (void **) &qglGetVertexAttribPointerv},
533 {"core", "glGetVertexAttribdv", (void **) &qglGetVertexAttribdv},
534 {"core", "glGetVertexAttribfv", (void **) &qglGetVertexAttribfv},
535 {"core", "glGetVertexAttribiv", (void **) &qglGetVertexAttribiv},
536 {"core", "glHint", (void **) &qglHint},
537 {"core", "glIsBuffer", (void **) &qglIsBuffer},
538 {"core", "glIsEnabled", (void **) &qglIsEnabled},
539 {"core", "glIsFramebuffer", (void **) &qglIsFramebuffer},
540 {"core", "glIsQuery", (void **) &qglIsQuery},
541 {"core", "glIsRenderbuffer", (void **) &qglIsRenderbuffer},
542 {"core", "glLinkProgram", (void **) &qglLinkProgram},
543 {"core", "glMapBuffer", (void **) &qglMapBuffer},
544 {"core", "glPixelStorei", (void **) &qglPixelStorei},
545 {"core", "glPointSize", (void **) &qglPointSize},
546 {"core", "glPolygonMode", (void **) &qglPolygonMode},
547 {"core", "glPolygonOffset", (void **) &qglPolygonOffset},
548 {"core", "glReadBuffer", (void **) &qglReadBuffer},
549 {"core", "glReadPixels", (void **) &qglReadPixels},
550 {"core", "glRenderbufferStorage", (void **) &qglRenderbufferStorage},
551 {"core", "glRenderbufferStorageMultisample", (void **) &qglRenderbufferStorageMultisample},
552 {"core", "glSampleCoverage", (void **) &qglSampleCoverage},
553 {"core", "glScissor", (void **) &qglScissor},
554 {"core", "glShaderSource", (void **) &qglShaderSource},
555 {"core", "glStencilFunc", (void **) &qglStencilFunc},
556 {"core", "glStencilMask", (void **) &qglStencilMask},
557 {"core", "glStencilOp", (void **) &qglStencilOp},
558 {"core", "glTexImage2D", (void **) &qglTexImage2D},
559 {"core", "glTexImage3D", (void **) &qglTexImage3D},
560 {"core", "glTexParameterf", (void **) &qglTexParameterf},
561 {"core", "glTexParameterfv", (void **) &qglTexParameterfv},
562 {"core", "glTexParameteri", (void **) &qglTexParameteri},
563 {"core", "glTexSubImage2D", (void **) &qglTexSubImage2D},
564 {"core", "glTexSubImage3D", (void **) &qglTexSubImage3D},
565 {"core", "glUniform1f", (void **) &qglUniform1f},
566 {"core", "glUniform1fv", (void **) &qglUniform1fv},
567 {"core", "glUniform1i", (void **) &qglUniform1i},
568 {"core", "glUniform1iv", (void **) &qglUniform1iv},
569 {"core", "glUniform2f", (void **) &qglUniform2f},
570 {"core", "glUniform2fv", (void **) &qglUniform2fv},
571 {"core", "glUniform2i", (void **) &qglUniform2i},
572 {"core", "glUniform2iv", (void **) &qglUniform2iv},
573 {"core", "glUniform3f", (void **) &qglUniform3f},
574 {"core", "glUniform3fv", (void **) &qglUniform3fv},
575 {"core", "glUniform3i", (void **) &qglUniform3i},
576 {"core", "glUniform3iv", (void **) &qglUniform3iv},
577 {"core", "glUniform4f", (void **) &qglUniform4f},
578 {"core", "glUniform4fv", (void **) &qglUniform4fv},
579 {"core", "glUniform4i", (void **) &qglUniform4i},
580 {"core", "glUniform4iv", (void **) &qglUniform4iv},
581 {"core", "glUniformBlockBinding", (void **) &qglUniformBlockBinding},
582 {"core", "glUniformMatrix2fv", (void **) &qglUniformMatrix2fv},
583 {"core", "glUniformMatrix3fv", (void **) &qglUniformMatrix3fv},
584 {"core", "glUniformMatrix4fv", (void **) &qglUniformMatrix4fv},
585 {"core", "glUnmapBuffer", (void **) &qglUnmapBuffer},
586 {"core", "glUseProgram", (void **) &qglUseProgram},
587 {"core", "glValidateProgram", (void **) &qglValidateProgram},
588 {"core", "glVertexAttrib1d", (void **) &qglVertexAttrib1d},
589 {"core", "glVertexAttrib1dv", (void **) &qglVertexAttrib1dv},
590 {"core", "glVertexAttrib1f", (void **) &qglVertexAttrib1f},
591 {"core", "glVertexAttrib1fv", (void **) &qglVertexAttrib1fv},
592 {"core", "glVertexAttrib1s", (void **) &qglVertexAttrib1s},
593 {"core", "glVertexAttrib1sv", (void **) &qglVertexAttrib1sv},
594 {"core", "glVertexAttrib2d", (void **) &qglVertexAttrib2d},
595 {"core", "glVertexAttrib2dv", (void **) &qglVertexAttrib2dv},
596 {"core", "glVertexAttrib2f", (void **) &qglVertexAttrib2f},
597 {"core", "glVertexAttrib2fv", (void **) &qglVertexAttrib2fv},
598 {"core", "glVertexAttrib2s", (void **) &qglVertexAttrib2s},
599 {"core", "glVertexAttrib2sv", (void **) &qglVertexAttrib2sv},
600 {"core", "glVertexAttrib3d", (void **) &qglVertexAttrib3d},
601 {"core", "glVertexAttrib3dv", (void **) &qglVertexAttrib3dv},
602 {"core", "glVertexAttrib3f", (void **) &qglVertexAttrib3f},
603 {"core", "glVertexAttrib3fv", (void **) &qglVertexAttrib3fv},
604 {"core", "glVertexAttrib3s", (void **) &qglVertexAttrib3s},
605 {"core", "glVertexAttrib3sv", (void **) &qglVertexAttrib3sv},
606 {"core", "glVertexAttrib4Nbv", (void **) &qglVertexAttrib4Nbv},
607 {"core", "glVertexAttrib4Niv", (void **) &qglVertexAttrib4Niv},
608 {"core", "glVertexAttrib4Nsv", (void **) &qglVertexAttrib4Nsv},
609 {"core", "glVertexAttrib4Nub", (void **) &qglVertexAttrib4Nub},
610 {"core", "glVertexAttrib4Nubv", (void **) &qglVertexAttrib4Nubv},
611 {"core", "glVertexAttrib4Nuiv", (void **) &qglVertexAttrib4Nuiv},
612 {"core", "glVertexAttrib4Nusv", (void **) &qglVertexAttrib4Nusv},
613 {"core", "glVertexAttrib4bv", (void **) &qglVertexAttrib4bv},
614 {"core", "glVertexAttrib4d", (void **) &qglVertexAttrib4d},
615 {"core", "glVertexAttrib4dv", (void **) &qglVertexAttrib4dv},
616 {"core", "glVertexAttrib4f", (void **) &qglVertexAttrib4f},
617 {"core", "glVertexAttrib4fv", (void **) &qglVertexAttrib4fv},
618 {"core", "glVertexAttrib4iv", (void **) &qglVertexAttrib4iv},
619 {"core", "glVertexAttrib4s", (void **) &qglVertexAttrib4s},
620 {"core", "glVertexAttrib4sv", (void **) &qglVertexAttrib4sv},
621 {"core", "glVertexAttrib4ubv", (void **) &qglVertexAttrib4ubv},
622 {"core", "glVertexAttrib4uiv", (void **) &qglVertexAttrib4uiv},
623 {"core", "glVertexAttrib4usv", (void **) &qglVertexAttrib4usv},
624 {"core", "glVertexAttribPointer", (void **) &qglVertexAttribPointer},
625 {"core", "glViewport", (void **) &qglViewport},
626 {"glBindFragDataLocation", "glBindFragDataLocation", (void **) &qglBindFragDataLocation}, // optional (no preference)
627 {"GL_ARB_debug_output", "glDebugMessageControlARB", (void **)&qglDebugMessageControlARB},
628 {"GL_ARB_debug_output", "glDebugMessageInsertARB", (void **)&qglDebugMessageInsertARB},
629 {"GL_ARB_debug_output", "glDebugMessageCallbackARB", (void **)&qglDebugMessageCallbackARB},
630 {"GL_ARB_debug_output", "glGetDebugMessageLogARB", (void **)&qglGetDebugMessageLogARB},
631 {"GL_ARB_debug_output", "glGetPointerv", (void **)&qglGetPointerv},
636 qboolean GL_CheckExtension(const char *name, const char *disableparm, int silent)
639 const glfunction_t *func;
640 char extstr[MAX_INPUTLINE];
642 Con_DPrintf("checking for %s... ", name);
644 if (disableparm && (COM_CheckParm(disableparm) || COM_CheckParm("-safe")))
646 Con_DPrint("disabled by commandline\n");
650 if (!GL_ExtensionSupported(name))
652 Con_DPrint("not detected\n");
656 for (func = openglfuncs; func && func->name != NULL; func++)
658 if (!*func->funcvariable && !strcmp(name, func->extension))
661 Con_DPrintf("%s is missing function \"%s\" - broken driver!\n", name, func->name);
665 // delay the return so it prints all missing functions
668 // VorteX: add to found extension list
669 dpsnprintf(extstr, sizeof(extstr), "%s %s ", gl_info_extensions.string, name);
670 Cvar_SetQuick(&gl_info_extensions, extstr);
672 Con_DPrint("enabled\n");
676 void VID_ClearExtensions(void)
678 // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
679 Cvar_SetQuick(&gl_info_extensions, "");
681 // clear the extension flags
682 memset(&vid.support, 0, sizeof(vid.support));
688 const glfunction_t *func;
689 qboolean missingrequiredfuncs = false;
690 static char missingfuncs[16384];
693 // first fetch the function pointers for everything - after this we can begin making GL calls.
694 for (func = openglfuncs; func->name != NULL; func++)
695 *func->funcvariable = (void *)GL_GetProcAddress(func->name);
698 gl_renderer = (const char *)qglGetString(GL_RENDERER);
699 gl_vendor = (const char *)qglGetString(GL_VENDOR);
700 gl_version = (const char *)qglGetString(GL_VERSION);
702 Con_Printf("GL_VENDOR: %s\n", gl_vendor);
703 Con_Printf("GL_RENDERER: %s\n", gl_renderer);
704 Con_Printf("GL_VERSION: %s\n", gl_version);
706 if (developer.integer)
709 GLint numextensions = 0;
710 qglGetIntegerv(GL_NUM_EXTENSIONS, &numextensions);
711 Con_DPrint("GL_EXTENSIONS:");
712 for (j = 0; j < numextensions; j++)
714 const char *ext = (const char *)qglGetStringi(GL_EXTENSIONS, j);
715 Con_DPrintf(" %s", ext);
722 for (func = openglfuncs; func && func->name != NULL; func++)
724 if (!*func->funcvariable && !strcmp(func->extension, "core"))
726 Con_DPrintf("GL context is missing required function \"%s\"!\n", func->name);
727 missingrequiredfuncs = true;
728 strlcat(missingfuncs, " ", sizeof(missingfuncs));
729 strlcat(missingfuncs, func->name, sizeof(missingfuncs));
733 if (missingrequiredfuncs)
734 Sys_Error("OpenGL driver/hardware lacks required features:\n%s", missingfuncs);
737 Con_DPrint("Checking OpenGL extensions...\n");
739 // detect what GLSL version is available, to enable features like higher quality reliefmapping
740 vid.support.glshaderversion = 100;
741 s = (char *) qglGetString(GL_SHADING_LANGUAGE_VERSION);
743 vid.support.glshaderversion = (int)(atof(s) * 100.0f + 0.5f);
744 if (vid.support.glshaderversion < 100)
745 vid.support.glshaderversion = 100;
746 Con_DPrintf("Detected GLSL #version %i\n", vid.support.glshaderversion);
749 // GLES devices in general do not like GL_BGRA, so use GL_RGBA
750 vid.forcetextype = TEXTYPE_RGBA;
752 // GL drivers generally prefer GL_BGRA
753 vid.forcetextype = GL_BGRA;
756 vid.support.amd_texture_texture4 = GL_CheckExtension("GL_AMD_texture_texture4", "-notexture4", false);
757 vid.support.arb_texture_gather = GL_CheckExtension("GL_ARB_texture_gather", "-notexturegather", false);
758 vid.support.ext_texture_compression_s3tc = GL_CheckExtension("GL_EXT_texture_compression_s3tc", "-nos3tc", false);
759 vid.support.ext_texture_filter_anisotropic = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", "-noanisotropy", false);
761 vid.support.ext_texture_srgb = true; // GL3 core, but not GLES2
763 vid.support.arb_debug_output = GL_CheckExtension("GL_ARB_debug_output", "-nogldebugoutput", false);
764 vid.allowalphatocoverage = false;
766 // COMMANDLINEOPTION: GL: -noanisotropy disables GL_EXT_texture_filter_anisotropic (allows higher quality texturing)
767 // COMMANDLINEOPTION: GL: -nos3tc disables GL_EXT_texture_compression_s3tc (which allows use of .dds texture caching)
768 // COMMANDLINEOPTION: GL: -notexture4 disables GL_AMD_texture_texture4 (which provides fetch4 sampling)
769 // COMMANDLINEOPTION: GL: -notexturegather disables GL_ARB_texture_gather (which provides fetch4 sampling)
770 // COMMANDLINEOPTION: GL: -nogldebugoutput disables GL_ARB_debug_output (which provides the gl_debug feature, if enabled)
772 #ifdef GL_MAX_DRAW_BUFFERS
773 qglGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint*)&vid.maxdrawbuffers);
776 qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
778 #ifdef GL_MAX_CUBE_MAP_TEXTURE_SIZE
780 if (GL_CheckExtension("GL_ARB_texture_cube_map", "-nocubemap", false))
783 qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_cubemap);
784 Con_DPrintf("GL_MAX_CUBE_MAP_TEXTURE_SIZE = %i\n", vid.maxtexturesize_cubemap);
788 #ifdef GL_MAX_3D_TEXTURE_SIZE
790 if (GL_CheckExtension("GL_EXT_texture3D", "-notexture3d", false)
791 || GL_CheckExtension("GL_OES_texture3D", "-notexture3d", false))
794 qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
795 Con_DPrintf("GL_MAX_3D_TEXTURE_SIZE = %i\n", vid.maxtexturesize_3d);
801 Con_DPrint("Using GLES2 rendering path\n");
802 vid.renderpath = RENDERPATH_GLES2;
803 vid.sRGBcapable2D = false;
804 vid.sRGBcapable3D = false;
806 Con_DPrint("Using GL32 rendering path\n");
807 vid.renderpath = RENDERPATH_GL32;
808 vid.sRGBcapable2D = false;
809 vid.sRGBcapable3D = true;
810 // enable multisample antialiasing if possible
811 vid.allowalphatocoverage = true; // but see below, it may get turned to false again if GL_SAMPLES is <= 1
814 qglGetIntegerv(GL_SAMPLES, &samples);
815 vid.samples = samples;
817 qglEnable(GL_MULTISAMPLE);
819 vid.allowalphatocoverage = false;
824 #ifdef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
825 if (vid.support.ext_texture_filter_anisotropic)
826 qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
831 float VID_JoyState_GetAxis(const vid_joystate_t *joystate, int axis, float fsensitivity, float deadzone)
834 value = (axis >= 0 && axis < MAXJOYAXIS) ? joystate->axis[axis] : 0.0f;
835 value = value > deadzone ? (value - deadzone) : (value < -deadzone ? (value + deadzone) : 0.0f);
836 value *= deadzone > 0 ? (1.0f / (1.0f - deadzone)) : 1.0f;
837 value = bound(-1, value, 1);
838 return value * fsensitivity;
841 qboolean VID_JoyBlockEmulatedKeys(int keycode)
844 vid_joystate_t joystate;
846 if (!joy_axiskeyevents.integer)
848 if (vid_joystate.is360)
850 if (keycode != K_UPARROW && keycode != K_DOWNARROW && keycode != K_RIGHTARROW && keycode != K_LEFTARROW)
853 // block system-generated key events for arrow keys if we're emulating the arrow keys ourselves
854 VID_BuildJoyState(&joystate);
855 for (j = 32;j < 36;j++)
856 if (vid_joystate.button[j] || joystate.button[j])
862 void VID_Shared_BuildJoyState_Begin(vid_joystate_t *joystate)
865 xinput_state_t xinputstate;
867 memset(joystate, 0, sizeof(*joystate));
869 if (vid_xinputindex >= 0 && qXInputGetState && qXInputGetState(vid_xinputindex, &xinputstate) == S_OK)
871 joystate->is360 = true;
872 joystate->button[ 0] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) != 0;
873 joystate->button[ 1] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) != 0;
874 joystate->button[ 2] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) != 0;
875 joystate->button[ 3] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) != 0;
876 joystate->button[ 4] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_START) != 0;
877 joystate->button[ 5] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) != 0;
878 joystate->button[ 6] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0;
879 joystate->button[ 7] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0;
880 joystate->button[ 8] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) != 0;
881 joystate->button[ 9] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) != 0;
882 joystate->button[10] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0;
883 joystate->button[11] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0;
884 joystate->button[12] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0;
885 joystate->button[13] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0;
886 joystate->button[14] = xinputstate.Gamepad.bLeftTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
887 joystate->button[15] = xinputstate.Gamepad.bRightTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
888 joystate->button[16] = xinputstate.Gamepad.sThumbLY < -16384;
889 joystate->button[17] = xinputstate.Gamepad.sThumbLY > 16384;
890 joystate->button[18] = xinputstate.Gamepad.sThumbLX < -16384;
891 joystate->button[19] = xinputstate.Gamepad.sThumbLX > 16384;
892 joystate->button[20] = xinputstate.Gamepad.sThumbRY < -16384;
893 joystate->button[21] = xinputstate.Gamepad.sThumbRY > 16384;
894 joystate->button[22] = xinputstate.Gamepad.sThumbRX < -16384;
895 joystate->button[23] = xinputstate.Gamepad.sThumbRX > 16384;
896 joystate->axis[ 4] = xinputstate.Gamepad.bLeftTrigger * (1.0f / 255.0f);
897 joystate->axis[ 5] = xinputstate.Gamepad.bRightTrigger * (1.0f / 255.0f);
898 joystate->axis[ 0] = xinputstate.Gamepad.sThumbLX * (1.0f / 32767.0f);
899 joystate->axis[ 1] = xinputstate.Gamepad.sThumbLY * (1.0f / 32767.0f);
900 joystate->axis[ 2] = xinputstate.Gamepad.sThumbRX * (1.0f / 32767.0f);
901 joystate->axis[ 3] = xinputstate.Gamepad.sThumbRY * (1.0f / 32767.0f);
906 void VID_Shared_BuildJoyState_Finish(vid_joystate_t *joystate)
911 // emulate key events for thumbstick
912 f = VID_JoyState_GetAxis(joystate, joy_axisforward.integer, 1, joy_axiskeyevents_deadzone.value) * joy_sensitivityforward.value;
913 r = VID_JoyState_GetAxis(joystate, joy_axisside.integer , 1, joy_axiskeyevents_deadzone.value) * joy_sensitivityside.value;
914 #if MAXJOYBUTTON != 36
915 #error this code must be updated if MAXJOYBUTTON changes!
917 joystate->button[32] = f > 0.0f;
918 joystate->button[33] = f < 0.0f;
919 joystate->button[34] = r > 0.0f;
920 joystate->button[35] = r < 0.0f;
923 static void VID_KeyEventForButton(qboolean oldbutton, qboolean newbutton, int key, double *timer)
929 if (realtime >= *timer)
931 Key_Event(key, 0, true);
932 *timer = realtime + 0.1;
937 Key_Event(key, 0, false);
945 Key_Event(key, 0, true);
946 *timer = realtime + 0.5;
951 #if MAXJOYBUTTON != 36
952 #error this code must be updated if MAXJOYBUTTON changes!
954 static int joybuttonkey[MAXJOYBUTTON][2] =
956 {K_JOY1, K_ENTER}, {K_JOY2, K_ESCAPE}, {K_JOY3, 0}, {K_JOY4, 0}, {K_JOY5, 0}, {K_JOY6, 0}, {K_JOY7, 0}, {K_JOY8, 0}, {K_JOY9, 0}, {K_JOY10, 0}, {K_JOY11, 0}, {K_JOY12, 0}, {K_JOY13, 0}, {K_JOY14, 0}, {K_JOY15, 0}, {K_JOY16, 0},
957 {K_AUX1, 0}, {K_AUX2, 0}, {K_AUX3, 0}, {K_AUX4, 0}, {K_AUX5, 0}, {K_AUX6, 0}, {K_AUX7, 0}, {K_AUX8, 0}, {K_AUX9, 0}, {K_AUX10, 0}, {K_AUX11, 0}, {K_AUX12, 0}, {K_AUX13, 0}, {K_AUX14, 0}, {K_AUX15, 0}, {K_AUX16, 0},
958 {K_JOY_UP, K_UPARROW}, {K_JOY_DOWN, K_DOWNARROW}, {K_JOY_RIGHT, K_RIGHTARROW}, {K_JOY_LEFT, K_LEFTARROW},
961 static int joybuttonkey360[][2] =
963 {K_X360_DPAD_UP, K_UPARROW},
964 {K_X360_DPAD_DOWN, K_DOWNARROW},
965 {K_X360_DPAD_LEFT, K_LEFTARROW},
966 {K_X360_DPAD_RIGHT, K_RIGHTARROW},
967 {K_X360_START, K_ESCAPE},
968 {K_X360_BACK, K_ESCAPE},
969 {K_X360_LEFT_THUMB, 0},
970 {K_X360_RIGHT_THUMB, 0},
971 {K_X360_LEFT_SHOULDER, 0},
972 {K_X360_RIGHT_SHOULDER, 0},
974 {K_X360_B, K_ESCAPE},
977 {K_X360_LEFT_TRIGGER, 0},
978 {K_X360_RIGHT_TRIGGER, 0},
979 {K_X360_LEFT_THUMB_DOWN, K_DOWNARROW},
980 {K_X360_LEFT_THUMB_UP, K_UPARROW},
981 {K_X360_LEFT_THUMB_LEFT, K_LEFTARROW},
982 {K_X360_LEFT_THUMB_RIGHT, K_RIGHTARROW},
983 {K_X360_RIGHT_THUMB_DOWN, 0},
984 {K_X360_RIGHT_THUMB_UP, 0},
985 {K_X360_RIGHT_THUMB_LEFT, 0},
986 {K_X360_RIGHT_THUMB_RIGHT, 0},
989 double vid_joybuttontimer[MAXJOYBUTTON];
990 void VID_ApplyJoyState(vid_joystate_t *joystate)
993 int c = joy_axiskeyevents.integer != 0;
997 // keystrokes (chatpad)
998 // DOES NOT WORK - no driver support in xinput1_3.dll :(
999 xinput_keystroke_t keystroke;
1000 while (qXInputGetKeystroke && qXInputGetKeystroke(XUSER_INDEX_ANY, 0, &keystroke) == S_OK)
1001 Con_Printf("XInput KeyStroke: VirtualKey %i, Unicode %i, Flags %x, UserIndex %i, HidCode %i\n", keystroke.VirtualKey, keystroke.Unicode, keystroke.Flags, keystroke.UserIndex, keystroke.HidCode);
1004 // emit key events for buttons
1005 for (j = 0;j < (int)(sizeof(joybuttonkey360)/sizeof(joybuttonkey360[0]));j++)
1006 VID_KeyEventForButton(vid_joystate.button[j] != 0, joystate->button[j] != 0, joybuttonkey360[j][c], &vid_joybuttontimer[j]);
1009 cl.cmd.forwardmove += VID_JoyState_GetAxis(joystate, joy_x360_axisforward.integer, joy_x360_sensitivityforward.value, joy_x360_deadzoneforward.value) * cl_forwardspeed.value;
1010 cl.cmd.sidemove += VID_JoyState_GetAxis(joystate, joy_x360_axisside.integer, joy_x360_sensitivityside.value, joy_x360_deadzoneside.value) * cl_sidespeed.value;
1011 cl.cmd.upmove += VID_JoyState_GetAxis(joystate, joy_x360_axisup.integer, joy_x360_sensitivityup.value, joy_x360_deadzoneup.value) * cl_upspeed.value;
1012 cl.viewangles[0] += VID_JoyState_GetAxis(joystate, joy_x360_axispitch.integer, joy_x360_sensitivitypitch.value, joy_x360_deadzonepitch.value) * cl.realframetime * cl_pitchspeed.value;
1013 cl.viewangles[1] += VID_JoyState_GetAxis(joystate, joy_x360_axisyaw.integer, joy_x360_sensitivityyaw.value, joy_x360_deadzoneyaw.value) * cl.realframetime * cl_yawspeed.value;
1014 //cl.viewangles[2] += VID_JoyState_GetAxis(joystate, joy_x360_axisroll.integer, joy_x360_sensitivityroll.value, joy_x360_deadzoneroll.value) * cl.realframetime * cl_rollspeed.value;
1018 // emit key events for buttons
1019 for (j = 0;j < MAXJOYBUTTON;j++)
1020 VID_KeyEventForButton(vid_joystate.button[j] != 0, joystate->button[j] != 0, joybuttonkey[j][c], &vid_joybuttontimer[j]);
1023 cl.cmd.forwardmove += VID_JoyState_GetAxis(joystate, joy_axisforward.integer, joy_sensitivityforward.value, joy_deadzoneforward.value) * cl_forwardspeed.value;
1024 cl.cmd.sidemove += VID_JoyState_GetAxis(joystate, joy_axisside.integer, joy_sensitivityside.value, joy_deadzoneside.value) * cl_sidespeed.value;
1025 cl.cmd.upmove += VID_JoyState_GetAxis(joystate, joy_axisup.integer, joy_sensitivityup.value, joy_deadzoneup.value) * cl_upspeed.value;
1026 cl.viewangles[0] += VID_JoyState_GetAxis(joystate, joy_axispitch.integer, joy_sensitivitypitch.value, joy_deadzonepitch.value) * cl.realframetime * cl_pitchspeed.value;
1027 cl.viewangles[1] += VID_JoyState_GetAxis(joystate, joy_axisyaw.integer, joy_sensitivityyaw.value, joy_deadzoneyaw.value) * cl.realframetime * cl_yawspeed.value;
1028 //cl.viewangles[2] += VID_JoyState_GetAxis(joystate, joy_axisroll.integer, joy_sensitivityroll.value, joy_deadzoneroll.value) * cl.realframetime * cl_rollspeed.value;
1031 vid_joystate = *joystate;
1034 int VID_Shared_SetJoystick(int index)
1038 int xinputcount = 0;
1039 int xinputindex = -1;
1040 int xinputavailable = 0;
1041 xinput_state_t state;
1042 // detect available XInput controllers
1043 for (i = 0;i < 4;i++)
1045 if (qXInputGetState && qXInputGetState(i, &state) == S_OK)
1047 xinputavailable |= 1<<i;
1048 if (index == xinputcount)
1053 if (joy_xinputavailable.integer != xinputavailable)
1054 Cvar_SetValueQuick(&joy_xinputavailable, xinputavailable);
1055 if (vid_xinputindex != xinputindex)
1057 vid_xinputindex = xinputindex;
1058 if (xinputindex >= 0)
1059 Con_Printf("Joystick %i opened (XInput Device %i)\n", index, xinputindex);
1068 static void Force_CenterView_f (void)
1070 cl.viewangles[PITCH] = 0;
1073 static int gamma_forcenextframe = false;
1074 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost;
1075 static int cachecolorenable;
1077 void VID_ApplyGammaToColor(const float *rgb, float *out)
1080 if (cachecolorenable)
1082 for (i = 0; i < 3; i++)
1083 out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / invpow(0.5, 1 - cachegrey[i])) * cachewhite[i] + cacheblack[i];
1087 for (i = 0; i < 3; i++)
1088 out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / cachegamma) * cachecontrast + cachebrightness;
1092 unsigned int vid_gammatables_serial = 0; // so other subsystems can poll if gamma parameters have changed
1093 qboolean vid_gammatables_trivial = true;
1094 void VID_BuildGammaTables(unsigned short *ramps, int rampsize)
1096 if (cachecolorenable)
1098 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, ramps, rampsize);
1099 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, ramps + rampsize, rampsize);
1100 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, ramps + rampsize*2, rampsize);
1104 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps, rampsize);
1105 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize, rampsize);
1106 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize*2, rampsize);
1109 if(vid.sRGB2D || vid.sRGB3D)
1112 for(i = 0; i < 3*rampsize; ++i)
1113 ramps[i] = (int)floor(bound(0.0f, Image_sRGBFloatFromLinearFloat(ramps[i] / 65535.0f), 1.0f) * 65535.0f + 0.5f);
1116 // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
1117 // immensely butchered it to work with variable framerates and fit in with
1118 // the rest of darkplaces.
1120 // R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667
1121 if (v_psycho.integer)
1125 static float n[3], nd[3], nt[3];
1126 static int init = true;
1127 unsigned short *ramp;
1128 gamma_forcenextframe = true;
1132 for (x = 0;x < 3;x++)
1134 n[x] = lhrandom(0, 1);
1135 nd[x] = (rand()&1)?-0.25:0.25;
1136 nt[x] = lhrandom(1, 8.2);
1140 for (x = 0;x < 3;x++)
1142 nt[x] -= cl.realframetime;
1146 nt[x] += lhrandom(1, 8.2);
1148 n[x] += nd[x] * cl.realframetime;
1149 n[x] -= floor(n[x]);
1152 for (x = 0, ramp = ramps;x < 3;x++)
1153 for (y = 0, t = n[x] - 0.75f;y < rampsize;y++, t += 0.75f * (2.0f / rampsize))
1154 *ramp++ = (unsigned short)(cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f);
1158 void VID_UpdateGamma(void)
1162 qboolean gamma_changed = false;
1164 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
1165 BOUNDCVAR(v_gamma, 0.1, 5);
1166 BOUNDCVAR(v_contrast, 0.2, 5);
1167 BOUNDCVAR(v_brightness, -v_contrast.value * 0.8, 0.8);
1168 //BOUNDCVAR(v_contrastboost, 0.0625, 16);
1169 BOUNDCVAR(v_color_black_r, 0, 0.8);
1170 BOUNDCVAR(v_color_black_g, 0, 0.8);
1171 BOUNDCVAR(v_color_black_b, 0, 0.8);
1172 BOUNDCVAR(v_color_grey_r, 0, 0.95);
1173 BOUNDCVAR(v_color_grey_g, 0, 0.95);
1174 BOUNDCVAR(v_color_grey_b, 0, 0.95);
1175 BOUNDCVAR(v_color_white_r, 1, 5);
1176 BOUNDCVAR(v_color_white_g, 1, 5);
1177 BOUNDCVAR(v_color_white_b, 1, 5);
1180 // set vid_gammatables_trivial to true if the current settings would generate the identity gamma table
1181 vid_gammatables_trivial = false;
1182 if(v_psycho.integer == 0)
1183 if(v_contrastboost.value == 1)
1187 if(v_color_enable.integer)
1189 if(v_color_black_r.value == 0)
1190 if(v_color_black_g.value == 0)
1191 if(v_color_black_b.value == 0)
1192 if(fabs(v_color_grey_r.value - 0.5) < 1e-6)
1193 if(fabs(v_color_grey_g.value - 0.5) < 1e-6)
1194 if(fabs(v_color_grey_b.value - 0.5) < 1e-6)
1195 if(v_color_white_r.value == 1)
1196 if(v_color_white_g.value == 1)
1197 if(v_color_white_b.value == 1)
1198 vid_gammatables_trivial = true;
1202 if(v_gamma.value == 1)
1203 if(v_contrast.value == 1)
1204 if(v_brightness.value == 0)
1205 vid_gammatables_trivial = true;
1209 // if any gamma settings were changed, bump vid_gammatables_serial so we regenerate the gamma ramp texture
1210 #define GAMMACHECK(cache, value) if (cache != (value)) gamma_changed = true;cache = (value)
1211 if(v_psycho.integer)
1212 gamma_changed = true;
1213 GAMMACHECK(cachegamma , v_gamma.value);
1214 GAMMACHECK(cachecontrast , v_contrast.value);
1215 GAMMACHECK(cachebrightness , v_brightness.value);
1216 GAMMACHECK(cachecontrastboost, v_contrastboost.value);
1217 GAMMACHECK(cachecolorenable, v_color_enable.integer);
1218 GAMMACHECK(cacheblack[0] , v_color_black_r.value);
1219 GAMMACHECK(cacheblack[1] , v_color_black_g.value);
1220 GAMMACHECK(cacheblack[2] , v_color_black_b.value);
1221 GAMMACHECK(cachegrey[0] , v_color_grey_r.value);
1222 GAMMACHECK(cachegrey[1] , v_color_grey_g.value);
1223 GAMMACHECK(cachegrey[2] , v_color_grey_b.value);
1224 GAMMACHECK(cachewhite[0] , v_color_white_r.value);
1225 GAMMACHECK(cachewhite[1] , v_color_white_g.value);
1226 GAMMACHECK(cachewhite[2] , v_color_white_b.value);
1229 ++vid_gammatables_serial;
1234 static dllfunction_t xinputdllfuncs[] =
1236 {"XInputGetState", (void **) &qXInputGetState},
1237 {"XInputGetKeystroke", (void **) &qXInputGetKeystroke},
1240 static const char* xinputdllnames [] =
1247 static dllhandle_t xinputdll_dll = NULL;
1250 void VID_Shared_Init(void)
1252 Cvar_RegisterVariable(&gl_info_vendor);
1253 Cvar_RegisterVariable(&gl_info_renderer);
1254 Cvar_RegisterVariable(&gl_info_version);
1255 Cvar_RegisterVariable(&gl_info_extensions);
1256 Cvar_RegisterVariable(&gl_info_platform);
1257 Cvar_RegisterVariable(&gl_info_driver);
1258 Cvar_RegisterVariable(&v_gamma);
1259 Cvar_RegisterVariable(&v_brightness);
1260 Cvar_RegisterVariable(&v_contrastboost);
1261 Cvar_RegisterVariable(&v_contrast);
1263 Cvar_RegisterVariable(&v_color_enable);
1264 Cvar_RegisterVariable(&v_color_black_r);
1265 Cvar_RegisterVariable(&v_color_black_g);
1266 Cvar_RegisterVariable(&v_color_black_b);
1267 Cvar_RegisterVariable(&v_color_grey_r);
1268 Cvar_RegisterVariable(&v_color_grey_g);
1269 Cvar_RegisterVariable(&v_color_grey_b);
1270 Cvar_RegisterVariable(&v_color_white_r);
1271 Cvar_RegisterVariable(&v_color_white_g);
1272 Cvar_RegisterVariable(&v_color_white_b);
1274 Cvar_RegisterVariable(&v_glslgamma_2d);
1276 Cvar_RegisterVariable(&v_psycho);
1278 Cvar_RegisterVariable(&vid_fullscreen);
1279 Cvar_RegisterVariable(&vid_width);
1280 Cvar_RegisterVariable(&vid_height);
1281 Cvar_RegisterVariable(&vid_bitsperpixel);
1282 Cvar_RegisterVariable(&vid_samples);
1283 Cvar_RegisterVariable(&vid_refreshrate);
1284 Cvar_RegisterVariable(&vid_userefreshrate);
1285 Cvar_RegisterVariable(&vid_stereobuffer);
1286 Cvar_RegisterVariable(&vid_touchscreen_density);
1287 Cvar_RegisterVariable(&vid_touchscreen_xdpi);
1288 Cvar_RegisterVariable(&vid_touchscreen_ydpi);
1289 Cvar_RegisterVariable(&vid_vsync);
1290 Cvar_RegisterVariable(&vid_mouse);
1291 Cvar_RegisterVariable(&vid_grabkeyboard);
1292 Cvar_RegisterVariable(&vid_touchscreen);
1293 Cvar_RegisterVariable(&vid_touchscreen_showkeyboard);
1294 Cvar_RegisterVariable(&vid_touchscreen_supportshowkeyboard);
1295 Cvar_RegisterVariable(&vid_stick_mouse);
1296 Cvar_RegisterVariable(&vid_resizable);
1297 Cvar_RegisterVariable(&vid_desktopfullscreen);
1298 Cvar_RegisterVariable(&vid_minwidth);
1299 Cvar_RegisterVariable(&vid_minheight);
1300 Cvar_RegisterVariable(&gl_finish);
1301 Cvar_RegisterVariable(&vid_sRGB);
1302 Cvar_RegisterVariable(&vid_sRGB_fallback);
1304 Cvar_RegisterVariable(&joy_active);
1306 Cvar_RegisterVariable(&joy_xinputavailable);
1308 Cvar_RegisterVariable(&joy_detected);
1309 Cvar_RegisterVariable(&joy_enable);
1310 Cvar_RegisterVariable(&joy_index);
1311 Cvar_RegisterVariable(&joy_axisforward);
1312 Cvar_RegisterVariable(&joy_axisside);
1313 Cvar_RegisterVariable(&joy_axisup);
1314 Cvar_RegisterVariable(&joy_axispitch);
1315 Cvar_RegisterVariable(&joy_axisyaw);
1316 //Cvar_RegisterVariable(&joy_axisroll);
1317 Cvar_RegisterVariable(&joy_deadzoneforward);
1318 Cvar_RegisterVariable(&joy_deadzoneside);
1319 Cvar_RegisterVariable(&joy_deadzoneup);
1320 Cvar_RegisterVariable(&joy_deadzonepitch);
1321 Cvar_RegisterVariable(&joy_deadzoneyaw);
1322 //Cvar_RegisterVariable(&joy_deadzoneroll);
1323 Cvar_RegisterVariable(&joy_sensitivityforward);
1324 Cvar_RegisterVariable(&joy_sensitivityside);
1325 Cvar_RegisterVariable(&joy_sensitivityup);
1326 Cvar_RegisterVariable(&joy_sensitivitypitch);
1327 Cvar_RegisterVariable(&joy_sensitivityyaw);
1328 //Cvar_RegisterVariable(&joy_sensitivityroll);
1329 Cvar_RegisterVariable(&joy_axiskeyevents);
1330 Cvar_RegisterVariable(&joy_axiskeyevents_deadzone);
1331 Cvar_RegisterVariable(&joy_x360_axisforward);
1332 Cvar_RegisterVariable(&joy_x360_axisside);
1333 Cvar_RegisterVariable(&joy_x360_axisup);
1334 Cvar_RegisterVariable(&joy_x360_axispitch);
1335 Cvar_RegisterVariable(&joy_x360_axisyaw);
1336 //Cvar_RegisterVariable(&joy_x360_axisroll);
1337 Cvar_RegisterVariable(&joy_x360_deadzoneforward);
1338 Cvar_RegisterVariable(&joy_x360_deadzoneside);
1339 Cvar_RegisterVariable(&joy_x360_deadzoneup);
1340 Cvar_RegisterVariable(&joy_x360_deadzonepitch);
1341 Cvar_RegisterVariable(&joy_x360_deadzoneyaw);
1342 //Cvar_RegisterVariable(&joy_x360_deadzoneroll);
1343 Cvar_RegisterVariable(&joy_x360_sensitivityforward);
1344 Cvar_RegisterVariable(&joy_x360_sensitivityside);
1345 Cvar_RegisterVariable(&joy_x360_sensitivityup);
1346 Cvar_RegisterVariable(&joy_x360_sensitivitypitch);
1347 Cvar_RegisterVariable(&joy_x360_sensitivityyaw);
1348 //Cvar_RegisterVariable(&joy_x360_sensitivityroll);
1351 Sys_LoadLibrary(xinputdllnames, &xinputdll_dll, xinputdllfuncs);
1354 Cmd_AddCommand("force_centerview", Force_CenterView_f, "recenters view (stops looking up/down)");
1355 Cmd_AddCommand("vid_restart", VID_Restart_f, "restarts video system (closes and reopens the window, restarts renderer)");
1358 static int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate, int stereobuffer, int samples)
1363 memset(&mode, 0, sizeof(mode));
1364 mode.fullscreen = fullscreen != 0;
1366 mode.height = height;
1367 mode.bitsperpixel = bpp;
1368 mode.refreshrate = vid_userefreshrate.integer ? max(1, refreshrate) : 0;
1369 mode.userefreshrate = vid_userefreshrate.integer != 0;
1370 mode.stereobuffer = stereobuffer != 0;
1371 mode.samples = samples;
1372 cl_ignoremousemoves = 2;
1373 VID_ClearExtensions();
1375 vid.samples = vid.mode.samples;
1376 if (VID_InitMode(&mode))
1378 // accept the (possibly modified) mode
1380 vid.fullscreen = vid.mode.fullscreen;
1381 vid.width = vid.mode.width;
1382 vid.height = vid.mode.height;
1383 vid.bitsperpixel = vid.mode.bitsperpixel;
1384 vid.refreshrate = vid.mode.refreshrate;
1385 vid.userefreshrate = vid.mode.userefreshrate;
1386 vid.stereobuffer = vid.mode.stereobuffer;
1387 vid.stencil = vid.mode.bitsperpixel > 16;
1388 vid.sRGB2D = vid_sRGB.integer >= 1 && vid.sRGBcapable2D;
1389 vid.sRGB3D = vid_sRGB.integer >= 1 && vid.sRGBcapable3D;
1391 switch(vid.renderpath)
1393 case RENDERPATH_GL32:
1397 qglGetBooleanv(GL_STEREO, &stereo);
1398 vid.stereobuffer = stereo != 0;
1402 case RENDERPATH_GLES2:
1404 vid.stereobuffer = false;
1409 (vid_sRGB_fallback.integer >= 3) // force fallback
1411 (vid_sRGB_fallback.integer >= 2 && // fallback if framebuffer is 8bit
1412 r_viewfbo.integer < 2)
1414 vid.sRGB2D = vid.sRGB3D = false;
1416 if(vid.samples != vid.mode.samples)
1417 Con_Printf("NOTE: requested %dx AA, got %dx AA\n", vid.mode.samples, vid.samples);
1419 Con_Printf("Video Mode: %s %dx%dx%dx%.2fhz%s%s\n", mode.fullscreen ? "fullscreen" : "window", mode.width, mode.height, mode.bitsperpixel, mode.refreshrate, mode.stereobuffer ? " stereo" : "", mode.samples > 1 ? va(vabuf, sizeof(vabuf), " (%ix AA)", mode.samples) : "");
1421 Cvar_SetValueQuick(&vid_fullscreen, vid.mode.fullscreen);
1422 Cvar_SetValueQuick(&vid_width, vid.mode.width);
1423 Cvar_SetValueQuick(&vid_height, vid.mode.height);
1424 Cvar_SetValueQuick(&vid_bitsperpixel, vid.mode.bitsperpixel);
1425 Cvar_SetValueQuick(&vid_samples, vid.mode.samples);
1426 if(vid_userefreshrate.integer)
1427 Cvar_SetValueQuick(&vid_refreshrate, vid.mode.refreshrate);
1428 Cvar_SetValueQuick(&vid_stereobuffer, vid.stereobuffer ? 1 : 0);
1430 if (vid_touchscreen.integer)
1432 in_windowmouse_x = vid_width.value / 2.f;
1433 in_windowmouse_y = vid_height.value / 2.f;
1442 static void VID_OpenSystems(void)
1449 static void VID_CloseSystems(void)
1452 R_Modules_Shutdown();
1456 qboolean vid_commandlinecheck = true;
1457 extern qboolean vid_opened;
1459 void VID_Restart_f(void)
1463 // don't crash if video hasn't started yet
1464 if (vid_commandlinecheck)
1469 SCR_BeginLoadingPlaque(false);
1473 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp%s%s, to %s %dx%dx%dbpp%s%s.\n",
1474 vid.mode.fullscreen ? "fullscreen" : "window", vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.fullscreen && vid.mode.userefreshrate ? va(vabuf, sizeof(vabuf), "x%.2fhz", vid.mode.refreshrate) : "", vid.mode.samples > 1 ? va(vabuf2, sizeof(vabuf2), " (%ix AA)", vid.mode.samples) : "",
1475 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_fullscreen.integer && vid_userefreshrate.integer ? va(vabuf, sizeof(vabuf), "x%.2fhz", vid_refreshrate.value) : "", vid_samples.integer > 1 ? va(vabuf2, sizeof(vabuf2), " (%ix AA)", vid_samples.integer) : "");
1478 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer))
1480 Con_Print("Video mode change failed\n");
1481 if (!VID_Mode(vid.mode.fullscreen, vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.refreshrate, vid.mode.stereobuffer, vid.mode.samples))
1482 Sys_Error("Unable to restore to last working video mode");
1487 const char *vidfallbacks[][2] =
1489 {"vid_stereobuffer", "0"},
1490 {"vid_samples", "1"},
1491 {"vid_userefreshrate", "0"},
1492 {"vid_width", "640"},
1493 {"vid_height", "480"},
1494 {"vid_bitsperpixel", "32"},
1498 // this is only called once by Host_StartVideo and again on each FS_GameDir_f
1499 void VID_Start(void)
1501 int i, width, height, success;
1502 if (vid_commandlinecheck)
1504 // interpret command-line parameters
1505 vid_commandlinecheck = false;
1506 // COMMANDLINEOPTION: Video: -window performs +vid_fullscreen 0
1507 if (COM_CheckParm("-window") || COM_CheckParm("-safe"))
1508 Cvar_SetValueQuick(&vid_fullscreen, false);
1509 // COMMANDLINEOPTION: Video: -fullscreen performs +vid_fullscreen 1
1510 if (COM_CheckParm("-fullscreen"))
1511 Cvar_SetValueQuick(&vid_fullscreen, true);
1514 // COMMANDLINEOPTION: Video: -width <pixels> performs +vid_width <pixels> and also +vid_height <pixels*3/4> if only -width is specified (example: -width 1024 sets 1024x768 mode)
1515 if ((i = COM_CheckParm("-width")) != 0)
1516 width = atoi(com_argv[i+1]);
1517 // COMMANDLINEOPTION: Video: -height <pixels> performs +vid_height <pixels> and also +vid_width <pixels*4/3> if only -height is specified (example: -height 768 sets 1024x768 mode)
1518 if ((i = COM_CheckParm("-height")) != 0)
1519 height = atoi(com_argv[i+1]);
1521 width = height * 4 / 3;
1523 height = width * 3 / 4;
1525 Cvar_SetValueQuick(&vid_width, width);
1527 Cvar_SetValueQuick(&vid_height, height);
1528 // COMMANDLINEOPTION: Video: -density <multiplier> performs +vid_touchscreen_density <multiplier> (example -density 1 or -density 1.5)
1529 if ((i = COM_CheckParm("-density")) != 0)
1530 Cvar_SetQuick(&vid_touchscreen_density, com_argv[i+1]);
1531 // COMMANDLINEOPTION: Video: -xdpi <dpi> performs +vid_touchscreen_xdpi <dpi> (example -xdpi 160 or -xdpi 320)
1532 if ((i = COM_CheckParm("-touchscreen_xdpi")) != 0)
1533 Cvar_SetQuick(&vid_touchscreen_xdpi, com_argv[i+1]);
1534 // COMMANDLINEOPTION: Video: -ydpi <dpi> performs +vid_touchscreen_ydpi <dpi> (example -ydpi 160 or -ydpi 320)
1535 if ((i = COM_CheckParm("-touchscreen_ydpi")) != 0)
1536 Cvar_SetQuick(&vid_touchscreen_ydpi, com_argv[i+1]);
1539 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
1542 Con_Print("Desired video mode fail, trying fallbacks...\n");
1543 for (i = 0;!success && vidfallbacks[i][0] != NULL;i++)
1545 Cvar_Set(vidfallbacks[i][0], vidfallbacks[i][1]);
1546 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
1549 Sys_Error("Video modes failed");
1560 static int VID_SortModes_Compare(const void *a_, const void *b_)
1562 vid_mode_t *a = (vid_mode_t *) a_;
1563 vid_mode_t *b = (vid_mode_t *) b_;
1564 if(a->width > b->width)
1566 if(a->width < b->width)
1568 if(a->height > b->height)
1570 if(a->height < b->height)
1572 if(a->refreshrate > b->refreshrate)
1574 if(a->refreshrate < b->refreshrate)
1580 if(a->pixelheight_num * b->pixelheight_denom > a->pixelheight_denom * b->pixelheight_num)
1582 if(a->pixelheight_num * b->pixelheight_denom < a->pixelheight_denom * b->pixelheight_num)
1586 size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean userefreshrate, qboolean useaspect)
1592 qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
1593 // 2. remove duplicates
1594 for(i = 0; i < count; ++i)
1596 if(modes[i].width && modes[i].height)
1600 if(modes[i].width != modes[i-1].width)
1602 if(modes[i].height != modes[i-1].height)
1605 if(modes[i].refreshrate != modes[i-1].refreshrate)
1608 if(modes[i].bpp != modes[i-1].bpp)
1611 if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
1614 // a dupe, or a bogus mode!
1616 memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i));
1617 --i; // check this index again, as mode i+1 is now here