8 #define XINPUT_GAMEPAD_DPAD_UP 0x0001
9 #define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
10 #define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
11 #define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
12 #define XINPUT_GAMEPAD_START 0x0010
13 #define XINPUT_GAMEPAD_BACK 0x0020
14 #define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
15 #define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
16 #define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
17 #define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
18 #define XINPUT_GAMEPAD_A 0x1000
19 #define XINPUT_GAMEPAD_B 0x2000
20 #define XINPUT_GAMEPAD_X 0x4000
21 #define XINPUT_GAMEPAD_Y 0x8000
22 #define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
23 #define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
24 #define XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30
25 #define XUSER_INDEX_ANY 0x000000FF
27 typedef struct xinput_gamepad_s
39 typedef struct xinput_state_s
42 xinput_gamepad_t Gamepad;
46 typedef struct xinput_keystroke_s
56 DWORD (WINAPI *qXInputGetState)(DWORD index, xinput_state_t *state);
57 DWORD (WINAPI *qXInputGetKeystroke)(DWORD index, DWORD reserved, xinput_keystroke_t *keystroke);
59 qbool vid_xinputinitialized = false;
60 int vid_xinputindex = -1;
66 // AK FIXME -> input_dest
67 qbool in_client_mouse = true;
69 // AK where should it be placed ?
70 float in_mouse_x, in_mouse_y;
71 float in_windowmouse_x, in_windowmouse_y;
73 // LadyHavoc: if window is hidden, don't update screen
74 qbool vid_hidden = true;
75 // LadyHavoc: if window is not the active window, don't hog as much CPU time,
76 // let go of the mouse, turn off sound, and restore system gamma ramps...
77 qbool vid_activewindow = true;
79 vid_joystate_t vid_joystate;
82 cvar_t joy_xinputavailable = {CF_CLIENT | CF_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)"};
84 cvar_t joy_active = {CF_CLIENT | CF_READONLY, "joy_active", "0", "indicates that a joystick is active (detected and enabled)"};
85 cvar_t joy_detected = {CF_CLIENT | CF_READONLY, "joy_detected", "0", "number of joysticks detected by engine"};
86 cvar_t joy_enable = {CF_CLIENT | CF_ARCHIVE, "joy_enable", "0", "enables joystick support"};
87 cvar_t joy_index = {CF_CLIENT, "joy_index", "0", "selects which joystick to use if you have multiple (0 uses the first controller, 1 uses the second, ...)"};
88 cvar_t joy_axisforward = {CF_CLIENT, "joy_axisforward", "1", "which joystick axis to query for forward/backward movement"};
89 cvar_t joy_axisside = {CF_CLIENT, "joy_axisside", "0", "which joystick axis to query for right/left movement"};
90 cvar_t joy_axisup = {CF_CLIENT, "joy_axisup", "-1", "which joystick axis to query for up/down movement"};
91 cvar_t joy_axispitch = {CF_CLIENT, "joy_axispitch", "3", "which joystick axis to query for looking up/down"};
92 cvar_t joy_axisyaw = {CF_CLIENT, "joy_axisyaw", "2", "which joystick axis to query for looking right/left"};
93 cvar_t joy_axisroll = {CF_CLIENT, "joy_axisroll", "-1", "which joystick axis to query for tilting head right/left"};
94 cvar_t joy_deadzoneforward = {CF_CLIENT, "joy_deadzoneforward", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
95 cvar_t joy_deadzoneside = {CF_CLIENT, "joy_deadzoneside", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
96 cvar_t joy_deadzoneup = {CF_CLIENT, "joy_deadzoneup", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
97 cvar_t joy_deadzonepitch = {CF_CLIENT, "joy_deadzonepitch", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
98 cvar_t joy_deadzoneyaw = {CF_CLIENT, "joy_deadzoneyaw", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
99 cvar_t joy_deadzoneroll = {CF_CLIENT, "joy_deadzoneroll", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
100 cvar_t joy_sensitivityforward = {CF_CLIENT, "joy_sensitivityforward", "-1", "movement multiplier"};
101 cvar_t joy_sensitivityside = {CF_CLIENT, "joy_sensitivityside", "1", "movement multiplier"};
102 cvar_t joy_sensitivityup = {CF_CLIENT, "joy_sensitivityup", "1", "movement multiplier"};
103 cvar_t joy_sensitivitypitch = {CF_CLIENT, "joy_sensitivitypitch", "1", "movement multiplier"};
104 cvar_t joy_sensitivityyaw = {CF_CLIENT, "joy_sensitivityyaw", "-1", "movement multiplier"};
105 cvar_t joy_sensitivityroll = {CF_CLIENT, "joy_sensitivityroll", "1", "movement multiplier"};
106 cvar_t joy_axiskeyevents = {CF_CLIENT | CF_ARCHIVE, "joy_axiskeyevents", "0", "generate uparrow/leftarrow etc. keyevents for joystick axes, use if your joystick driver is not generating them"};
107 cvar_t joy_axiskeyevents_deadzone = {CF_CLIENT | CF_ARCHIVE, "joy_axiskeyevents_deadzone", "0.5", "deadzone value for axes"};
108 cvar_t joy_x360_axisforward = {CF_CLIENT, "joy_x360_axisforward", "1", "which joystick axis to query for forward/backward movement"};
109 cvar_t joy_x360_axisside = {CF_CLIENT, "joy_x360_axisside", "0", "which joystick axis to query for right/left movement"};
110 cvar_t joy_x360_axisup = {CF_CLIENT, "joy_x360_axisup", "-1", "which joystick axis to query for up/down movement"};
111 cvar_t joy_x360_axispitch = {CF_CLIENT, "joy_x360_axispitch", "3", "which joystick axis to query for looking up/down"};
112 cvar_t joy_x360_axisyaw = {CF_CLIENT, "joy_x360_axisyaw", "2", "which joystick axis to query for looking right/left"};
113 cvar_t joy_x360_axisroll = {CF_CLIENT, "joy_x360_axisroll", "-1", "which joystick axis to query for tilting head right/left"};
114 cvar_t joy_x360_deadzoneforward = {CF_CLIENT, "joy_x360_deadzoneforward", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
115 cvar_t joy_x360_deadzoneside = {CF_CLIENT, "joy_x360_deadzoneside", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
116 cvar_t joy_x360_deadzoneup = {CF_CLIENT, "joy_x360_deadzoneup", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
117 cvar_t joy_x360_deadzonepitch = {CF_CLIENT, "joy_x360_deadzonepitch", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
118 cvar_t joy_x360_deadzoneyaw = {CF_CLIENT, "joy_x360_deadzoneyaw", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
119 cvar_t joy_x360_deadzoneroll = {CF_CLIENT, "joy_x360_deadzoneroll", "0.266", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
120 cvar_t joy_x360_sensitivityforward = {CF_CLIENT, "joy_x360_sensitivityforward", "1", "movement multiplier"};
121 cvar_t joy_x360_sensitivityside = {CF_CLIENT, "joy_x360_sensitivityside", "1", "movement multiplier"};
122 cvar_t joy_x360_sensitivityup = {CF_CLIENT, "joy_x360_sensitivityup", "1", "movement multiplier"};
123 cvar_t joy_x360_sensitivitypitch = {CF_CLIENT, "joy_x360_sensitivitypitch", "-1", "movement multiplier"};
124 cvar_t joy_x360_sensitivityyaw = {CF_CLIENT, "joy_x360_sensitivityyaw", "-1", "movement multiplier"};
125 cvar_t joy_x360_sensitivityroll = {CF_CLIENT, "joy_x360_sensitivityroll", "1", "movement multiplier"};
127 // VorteX: more info cvars, mostly set in VID_CheckExtensions
128 cvar_t gl_info_vendor = {CF_CLIENT | CF_READONLY, "gl_info_vendor", "", "indicates brand of graphics chip"};
129 cvar_t gl_info_renderer = {CF_CLIENT | CF_READONLY, "gl_info_renderer", "", "indicates graphics chip model and other information"};
130 cvar_t gl_info_version = {CF_CLIENT | CF_READONLY, "gl_info_version", "", "indicates version of current renderer. begins with 1.0.0, 1.1.0, 1.2.0, 1.3.1 etc."};
131 cvar_t gl_info_extensions = {CF_CLIENT | CF_READONLY, "gl_info_extensions", "", "indicates extension list found by engine, space separated."};
132 cvar_t gl_info_driver = {CF_CLIENT | CF_READONLY, "gl_info_driver", "", "name of driver library (opengl32.dll, libGL.so.1, or whatever)."};
134 cvar_t vid_fullscreen = {CF_CLIENT | CF_ARCHIVE, "vid_fullscreen", "1", "use fullscreen (1) or windowed (0)"};
135 cvar_t vid_borderless = {CF_CLIENT | CF_ARCHIVE, "vid_borderless", "0", "make the window borderless by removing all window decorations. has no effect in fullscreen mode"};
136 cvar_t vid_width = {CF_CLIENT | CF_ARCHIVE, "vid_width", "640", "resolution"};
137 cvar_t vid_height = {CF_CLIENT | CF_ARCHIVE, "vid_height", "480", "resolution"};
138 cvar_t vid_bitsperpixel = {CF_CLIENT | CF_READONLY, "vid_bitsperpixel", "32", "how many bits per pixel to render at (this is not currently configurable)"};
139 cvar_t vid_samples = {CF_CLIENT | CF_ARCHIVE, "vid_samples", "1", "how many anti-aliasing samples per pixel to request from the graphics driver (4 is recommended, 1 is faster)"};
140 cvar_t vid_refreshrate = {CF_CLIENT | CF_ARCHIVE, "vid_refreshrate", "0", "refresh rate to use, in hz (higher values feel smoother, if supported by your monitor), 0 uses the default"};
141 cvar_t vid_stereobuffer = {CF_CLIENT | CF_ARCHIVE, "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"};
142 // the density cvars are completely optional, set and use when something needs to have a density-independent size.
143 // 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.
144 // values for the Samsung Galaxy SIII, Snapdragon version: 2.000000 density, 304.799988 xdpi, 303.850464 ydpi
145 cvar_t vid_touchscreen_density = {CF_CLIENT, "vid_touchscreen_density", "2.0", "Standard quantized screen density multiplier (see Android documentation for DisplayMetrics), similar values are given on iPhoneOS"};
146 cvar_t vid_touchscreen_xdpi = {CF_CLIENT, "vid_touchscreen_xdpi", "300", "Horizontal DPI of the screen (only valid on Android currently)"};
147 cvar_t vid_touchscreen_ydpi = {CF_CLIENT, "vid_touchscreen_ydpi", "300", "Vertical DPI of the screen (only valid on Android currently)"};
149 cvar_t vid_vsync = {CF_CLIENT | CF_ARCHIVE, "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) at the cost of latency, 1 always syncs and -1 is adaptive (stops syncing if the framerate drops, unsupported by some platforms), automatically disabled when doing timedemo benchmarks"};
150 cvar_t vid_mouse = {CF_CLIENT | CF_ARCHIVE, "vid_mouse", "1", "whether to use the mouse in windowed mode (fullscreen always does)"};
151 cvar_t vid_mouse_clickthrough = {CF_CLIENT | CF_ARCHIVE, "vid_mouse_clickthrough", "0", "mouse behavior in windowed mode: 0 = click to focus, 1 = allow interaction even if the window is not focused (click-through behaviour, can be useful when using third-party game overlays)"};
152 cvar_t vid_minimize_on_focus_loss = {CF_CLIENT | CF_ARCHIVE, "vid_minimize_on_focus_loss", "0", "whether to minimize the fullscreen window if it loses focus (such as by alt+tab)"};
153 cvar_t vid_grabkeyboard = {CF_CLIENT | CF_ARCHIVE, "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)"};
154 cvar_t vid_minwidth = {CF_CLIENT, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"};
155 cvar_t vid_minheight = {CF_CLIENT, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"};
156 cvar_t gl_finish = {CF_CLIENT | CF_CLIENT, "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)"};
157 cvar_t vid_sRGB = {CF_CLIENT | CF_ARCHIVE, "vid_sRGB", "0", "if hardware is capable, modify rendering to be gamma corrected for the sRGB color standard (computer monitors, TVs), recommended"};
158 cvar_t vid_sRGB_fallback = {CF_CLIENT | CF_ARCHIVE, "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)"};
160 cvar_t vid_touchscreen = {CF_CLIENT, "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"};
161 cvar_t vid_touchscreen_showkeyboard = {CF_CLIENT, "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"};
162 cvar_t vid_touchscreen_supportshowkeyboard = {CF_CLIENT | CF_READONLY, "vid_touchscreen_supportshowkeyboard", "0", "indicates if the platform supports a virtual keyboard"};
163 cvar_t vid_stick_mouse = {CF_CLIENT | CF_ARCHIVE, "vid_stick_mouse", "0", "have the mouse stuck in the center of the screen" };
164 cvar_t vid_resizable = {CF_CLIENT | CF_ARCHIVE, "vid_resizable", "1", "0: window not resizable, 1: resizable, 2: window can be resized but the framebuffer isn't adjusted" };
165 cvar_t vid_desktopfullscreen = {CF_CLIENT | CF_ARCHIVE, "vid_desktopfullscreen", "1", "force desktop resolution and refresh rate (disable modesetting), also use some OS-dependent tricks for better fullscreen integration; disabling may reveal OS/driver/SDL bugs with multi-monitor configurations"};
166 cvar_t vid_display = {CF_CLIENT | CF_ARCHIVE, "vid_display", "0", "which monitor to render on, numbered from 0 (system default)" };
167 cvar_t vid_info_displaycount = {CF_CLIENT | CF_READONLY, "vid_info_displaycount", "1", "how many monitors are currently available, updated by hotplug events" };
169 cvar_t vid_ignore_taskbar = {CF_CLIENT | CF_ARCHIVE, "vid_ignore_taskbar", "1", "in windowed mode, prevent the Windows taskbar and window borders from affecting the size and placement of the window. it will be aligned centered and uses the unaltered vid_width/vid_height values"};
172 cvar_t v_gamma = {CF_CLIENT | CF_ARCHIVE, "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"};
173 cvar_t v_contrast = {CF_CLIENT | CF_ARCHIVE, "v_contrast", "1", "brightness of white (values above 1 give a brighter image with increased color saturation, unlike v_gamma)"};
174 cvar_t v_brightness = {CF_CLIENT | CF_ARCHIVE, "v_brightness", "0", "brightness of black, useful for monitors that are too dark"};
175 cvar_t v_contrastboost = {CF_CLIENT | CF_ARCHIVE, "v_contrastboost", "1", "by how much to multiply the contrast in dark areas (1 is no change)"};
176 cvar_t v_color_enable = {CF_CLIENT | CF_ARCHIVE, "v_color_enable", "0", "enables black-grey-white color correction curve controls"};
177 cvar_t v_color_black_r = {CF_CLIENT | CF_ARCHIVE, "v_color_black_r", "0", "desired color of black"};
178 cvar_t v_color_black_g = {CF_CLIENT | CF_ARCHIVE, "v_color_black_g", "0", "desired color of black"};
179 cvar_t v_color_black_b = {CF_CLIENT | CF_ARCHIVE, "v_color_black_b", "0", "desired color of black"};
180 cvar_t v_color_grey_r = {CF_CLIENT | CF_ARCHIVE, "v_color_grey_r", "0.5", "desired color of grey"};
181 cvar_t v_color_grey_g = {CF_CLIENT | CF_ARCHIVE, "v_color_grey_g", "0.5", "desired color of grey"};
182 cvar_t v_color_grey_b = {CF_CLIENT | CF_ARCHIVE, "v_color_grey_b", "0.5", "desired color of grey"};
183 cvar_t v_color_white_r = {CF_CLIENT | CF_ARCHIVE, "v_color_white_r", "1", "desired color of white"};
184 cvar_t v_color_white_g = {CF_CLIENT | CF_ARCHIVE, "v_color_white_g", "1", "desired color of white"};
185 cvar_t v_color_white_b = {CF_CLIENT | CF_ARCHIVE, "v_color_white_b", "1", "desired color of white"};
186 cvar_t v_glslgamma_2d = {CF_CLIENT | CF_ARCHIVE, "v_glslgamma_2d", "1", "applies GLSL gamma to 2d pictures (HUD, fonts)"};
187 cvar_t v_psycho = {CF_CLIENT, "v_psycho", "0", "easter egg - R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667"};
189 // brand of graphics chip
190 const char *gl_vendor;
191 // graphics chip model and other information
192 const char *gl_renderer;
193 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
194 const char *gl_version;
197 GLboolean (GLAPIENTRY *qglIsBuffer) (GLuint buffer);
198 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
199 GLboolean (GLAPIENTRY *qglIsFramebuffer)(GLuint framebuffer);
200 GLboolean (GLAPIENTRY *qglIsQuery)(GLuint qid);
201 GLboolean (GLAPIENTRY *qglIsRenderbuffer)(GLuint renderbuffer);
202 GLboolean (GLAPIENTRY *qglUnmapBuffer) (GLenum target);
203 GLenum (GLAPIENTRY *qglCheckFramebufferStatus)(GLenum target);
204 GLenum (GLAPIENTRY *qglGetError)(void);
205 GLint (GLAPIENTRY *qglGetAttribLocation)(GLuint programObj, const GLchar *name);
206 GLint (GLAPIENTRY *qglGetUniformLocation)(GLuint programObj, const GLchar *name);
207 GLuint (GLAPIENTRY *qglCreateProgram)(void);
208 GLuint (GLAPIENTRY *qglCreateShader)(GLenum shaderType);
209 GLuint (GLAPIENTRY *qglGetDebugMessageLogARB)(GLuint count, GLsizei bufSize, GLenum* sources, GLenum* types, GLuint* ids, GLenum* severities, GLsizei* lengths, GLchar* messageLog);
210 GLuint (GLAPIENTRY *qglGetUniformBlockIndex)(GLuint program, const char* uniformBlockName);
211 GLvoid (GLAPIENTRY *qglBindFramebuffer)(GLenum target, GLuint framebuffer);
212 GLvoid (GLAPIENTRY *qglBindRenderbuffer)(GLenum target, GLuint renderbuffer);
213 GLvoid (GLAPIENTRY *qglBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
214 GLvoid (GLAPIENTRY *qglDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers);
215 GLvoid (GLAPIENTRY *qglDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers);
216 GLvoid (GLAPIENTRY *qglFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
217 GLvoid (GLAPIENTRY *qglFramebufferTexture1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
218 GLvoid (GLAPIENTRY *qglFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
219 GLvoid (GLAPIENTRY *qglFramebufferTexture3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer);
220 GLvoid (GLAPIENTRY *qglFramebufferTextureLayer)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
221 GLvoid (GLAPIENTRY *qglGenFramebuffers)(GLsizei n, GLuint *framebuffers);
222 GLvoid (GLAPIENTRY *qglGenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
223 GLvoid (GLAPIENTRY *qglGenerateMipmap)(GLenum target);
224 GLvoid (GLAPIENTRY *qglGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
225 GLvoid (GLAPIENTRY *qglGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params);
226 GLvoid (GLAPIENTRY *qglRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
227 GLvoid (GLAPIENTRY *qglRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
228 GLvoid* (GLAPIENTRY *qglMapBuffer) (GLenum target, GLenum access);
229 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
230 const GLubyte* (GLAPIENTRY *qglGetStringi)(GLenum name, GLuint index);
231 void (GLAPIENTRY *qglActiveTexture)(GLenum texture);
232 void (GLAPIENTRY *qglAttachShader)(GLuint containerObj, GLuint obj);
233 void (GLAPIENTRY *qglBeginQuery)(GLenum target, GLuint qid);
234 void (GLAPIENTRY *qglBindAttribLocation)(GLuint programObj, GLuint index, const GLchar *name);
235 void (GLAPIENTRY *qglBindBuffer) (GLenum target, GLuint buffer);
236 void (GLAPIENTRY *qglBindBufferBase)(GLenum target, GLuint index, GLuint buffer);
237 void (GLAPIENTRY *qglBindBufferRange)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
238 void (GLAPIENTRY *qglBindFragDataLocation)(GLuint programObj, GLuint index, const GLchar *name);
239 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
240 void (GLAPIENTRY *qglBindVertexArray)(GLuint array);
241 void (GLAPIENTRY *qglBlendEquation)(GLenum); // also supplied by GL_blend_subtract
242 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
243 void (GLAPIENTRY *qglBlendFuncSeparate)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
244 void (GLAPIENTRY *qglBufferData) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
245 void (GLAPIENTRY *qglBufferSubData) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
246 void (GLAPIENTRY *qglClear)(GLbitfield mask);
247 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
248 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
249 void (GLAPIENTRY *qglClearStencil)(GLint s);
250 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
251 void (GLAPIENTRY *qglCompileShader)(GLuint shaderObj);
252 void (GLAPIENTRY *qglCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
253 void (GLAPIENTRY *qglCompressedTexImage3D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
254 void (GLAPIENTRY *qglCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
255 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);
256 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
257 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
258 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
259 void (GLAPIENTRY *qglCullFace)(GLenum mode);
260 void (GLAPIENTRY *qglDebugMessageCallbackARB)(GLDEBUGPROCARB callback, const GLvoid* userParam);
261 void (GLAPIENTRY *qglDebugMessageControlARB)(GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, GLboolean enabled);
262 void (GLAPIENTRY *qglDebugMessageInsertARB)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf);
263 void (GLAPIENTRY *qglDeleteBuffers) (GLsizei n, const GLuint *buffers);
264 void (GLAPIENTRY *qglDeleteProgram)(GLuint obj);
265 void (GLAPIENTRY *qglDeleteQueries)(GLsizei n, const GLuint *ids);
266 void (GLAPIENTRY *qglDeleteShader)(GLuint obj);
267 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
268 void (GLAPIENTRY *qglDeleteVertexArrays)(GLsizei n, const GLuint *arrays);
269 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
270 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
271 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
272 void (GLAPIENTRY *qglDepthRangef)(GLclampf near_val, GLclampf far_val);
273 void (GLAPIENTRY *qglDetachShader)(GLuint containerObj, GLuint attachedObj);
274 void (GLAPIENTRY *qglDisable)(GLenum cap);
275 void (GLAPIENTRY *qglDisableVertexAttribArray)(GLuint index);
276 void (GLAPIENTRY *qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
277 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
278 void (GLAPIENTRY *qglDrawBuffers)(GLsizei n, const GLenum *bufs);
279 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
280 void (GLAPIENTRY *qglEnable)(GLenum cap);
281 void (GLAPIENTRY *qglEnableVertexAttribArray)(GLuint index);
282 void (GLAPIENTRY *qglEndQuery)(GLenum target);
283 void (GLAPIENTRY *qglFinish)(void);
284 void (GLAPIENTRY *qglFlush)(void);
285 void (GLAPIENTRY *qglGenBuffers) (GLsizei n, GLuint *buffers);
286 void (GLAPIENTRY *qglGenQueries)(GLsizei n, GLuint *ids);
287 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
288 void (GLAPIENTRY *qglGenVertexArrays)(GLsizei n, GLuint *arrays);
289 void (GLAPIENTRY *qglGetActiveAttrib)(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
290 void (GLAPIENTRY *qglGetActiveUniform)(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
291 void (GLAPIENTRY *qglGetActiveUniformBlockName)(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, char* uniformBlockName);
292 void (GLAPIENTRY *qglGetActiveUniformBlockiv)(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params);
293 void (GLAPIENTRY *qglGetActiveUniformName)(GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei* length, char* uniformName);
294 void (GLAPIENTRY *qglGetActiveUniformsiv)(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params);
295 void (GLAPIENTRY *qglGetAttachedShaders)(GLuint containerObj, GLsizei maxCount, GLsizei *count, GLuint *obj);
296 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
297 void (GLAPIENTRY *qglGetCompressedTexImage)(GLenum target, GLint lod, void *img);
298 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
299 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
300 void (GLAPIENTRY *qglGetIntegeri_v)(GLenum target, GLuint index, GLint* data);
301 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
302 void (GLAPIENTRY *qglGetPointerv)(GLenum pname, GLvoid** params);
303 void (GLAPIENTRY *qglGetProgramInfoLog)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
304 void (GLAPIENTRY *qglGetProgramiv)(GLuint obj, GLenum pname, GLint *params);
305 void (GLAPIENTRY *qglGetQueryObjectiv)(GLuint qid, GLenum pname, GLint *params);
306 void (GLAPIENTRY *qglGetQueryObjectuiv)(GLuint qid, GLenum pname, GLuint *params);
307 void (GLAPIENTRY *qglGetQueryiv)(GLenum target, GLenum pname, GLint *params);
308 void (GLAPIENTRY *qglGetShaderInfoLog)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
309 void (GLAPIENTRY *qglGetShaderSource)(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *source);
310 void (GLAPIENTRY *qglGetShaderiv)(GLuint obj, GLenum pname, GLint *params);
311 void (GLAPIENTRY *qglGetTexImage)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
312 void (GLAPIENTRY *qglGetTexLevelParameterfv)(GLenum target, GLint level, GLenum pname, GLfloat *params);
313 void (GLAPIENTRY *qglGetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint *params);
314 void (GLAPIENTRY *qglGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
315 void (GLAPIENTRY *qglGetTexParameteriv)(GLenum target, GLenum pname, GLint *params);
316 void (GLAPIENTRY *qglGetUniformIndices)(GLuint program, GLsizei uniformCount, const char** uniformNames, GLuint* uniformIndices);
317 void (GLAPIENTRY *qglGetUniformfv)(GLuint programObj, GLint location, GLfloat *params);
318 void (GLAPIENTRY *qglGetUniformiv)(GLuint programObj, GLint location, GLint *params);
319 void (GLAPIENTRY *qglGetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid **pointer);
320 void (GLAPIENTRY *qglGetVertexAttribdv)(GLuint index, GLenum pname, GLdouble *params);
321 void (GLAPIENTRY *qglGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat *params);
322 void (GLAPIENTRY *qglGetVertexAttribiv)(GLuint index, GLenum pname, GLint *params);
323 void (GLAPIENTRY *qglHint)(GLenum target, GLenum mode);
324 void (GLAPIENTRY *qglLinkProgram)(GLuint programObj);
325 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
326 void (GLAPIENTRY *qglPointSize)(GLfloat size);
327 void (GLAPIENTRY *qglPolygonMode)(GLenum face, GLenum mode);
328 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
329 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
330 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
331 void (GLAPIENTRY *qglSampleCoverage)(GLclampf value, GLboolean invert);
332 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
333 void (GLAPIENTRY *qglShaderSource)(GLuint shaderObj, GLsizei count, const GLchar **string, const GLint *length);
334 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
335 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
336 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
337 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
338 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
339 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
340 void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
341 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
342 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
343 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);
344 void (GLAPIENTRY *qglUniform1f)(GLint location, GLfloat v0);
345 void (GLAPIENTRY *qglUniform1fv)(GLint location, GLsizei count, const GLfloat *value);
346 void (GLAPIENTRY *qglUniform1i)(GLint location, GLint v0);
347 void (GLAPIENTRY *qglUniform1iv)(GLint location, GLsizei count, const GLint *value);
348 void (GLAPIENTRY *qglUniform2f)(GLint location, GLfloat v0, GLfloat v1);
349 void (GLAPIENTRY *qglUniform2fv)(GLint location, GLsizei count, const GLfloat *value);
350 void (GLAPIENTRY *qglUniform2i)(GLint location, GLint v0, GLint v1);
351 void (GLAPIENTRY *qglUniform2iv)(GLint location, GLsizei count, const GLint *value);
352 void (GLAPIENTRY *qglUniform3f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
353 void (GLAPIENTRY *qglUniform3fv)(GLint location, GLsizei count, const GLfloat *value);
354 void (GLAPIENTRY *qglUniform3i)(GLint location, GLint v0, GLint v1, GLint v2);
355 void (GLAPIENTRY *qglUniform3iv)(GLint location, GLsizei count, const GLint *value);
356 void (GLAPIENTRY *qglUniform4f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
357 void (GLAPIENTRY *qglUniform4fv)(GLint location, GLsizei count, const GLfloat *value);
358 void (GLAPIENTRY *qglUniform4i)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
359 void (GLAPIENTRY *qglUniform4iv)(GLint location, GLsizei count, const GLint *value);
360 void (GLAPIENTRY *qglUniformBlockBinding)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
361 void (GLAPIENTRY *qglUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
362 void (GLAPIENTRY *qglUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
363 void (GLAPIENTRY *qglUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
364 void (GLAPIENTRY *qglUseProgram)(GLuint programObj);
365 void (GLAPIENTRY *qglValidateProgram)(GLuint programObj);
366 void (GLAPIENTRY *qglVertexAttrib1d)(GLuint index, GLdouble v0);
367 void (GLAPIENTRY *qglVertexAttrib1dv)(GLuint index, const GLdouble *v);
368 void (GLAPIENTRY *qglVertexAttrib1f)(GLuint index, GLfloat v0);
369 void (GLAPIENTRY *qglVertexAttrib1fv)(GLuint index, const GLfloat *v);
370 void (GLAPIENTRY *qglVertexAttrib1s)(GLuint index, GLshort v0);
371 void (GLAPIENTRY *qglVertexAttrib1sv)(GLuint index, const GLshort *v);
372 void (GLAPIENTRY *qglVertexAttrib2d)(GLuint index, GLdouble v0, GLdouble v1);
373 void (GLAPIENTRY *qglVertexAttrib2dv)(GLuint index, const GLdouble *v);
374 void (GLAPIENTRY *qglVertexAttrib2f)(GLuint index, GLfloat v0, GLfloat v1);
375 void (GLAPIENTRY *qglVertexAttrib2fv)(GLuint index, const GLfloat *v);
376 void (GLAPIENTRY *qglVertexAttrib2s)(GLuint index, GLshort v0, GLshort v1);
377 void (GLAPIENTRY *qglVertexAttrib2sv)(GLuint index, const GLshort *v);
378 void (GLAPIENTRY *qglVertexAttrib3d)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2);
379 void (GLAPIENTRY *qglVertexAttrib3dv)(GLuint index, const GLdouble *v);
380 void (GLAPIENTRY *qglVertexAttrib3f)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2);
381 void (GLAPIENTRY *qglVertexAttrib3fv)(GLuint index, const GLfloat *v);
382 void (GLAPIENTRY *qglVertexAttrib3s)(GLuint index, GLshort v0, GLshort v1, GLshort v2);
383 void (GLAPIENTRY *qglVertexAttrib3sv)(GLuint index, const GLshort *v);
384 void (GLAPIENTRY *qglVertexAttrib4Nbv)(GLuint index, const GLbyte *v);
385 void (GLAPIENTRY *qglVertexAttrib4Niv)(GLuint index, const GLint *v);
386 void (GLAPIENTRY *qglVertexAttrib4Nsv)(GLuint index, const GLshort *v);
387 void (GLAPIENTRY *qglVertexAttrib4Nub)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
388 void (GLAPIENTRY *qglVertexAttrib4Nubv)(GLuint index, const GLubyte *v);
389 void (GLAPIENTRY *qglVertexAttrib4Nuiv)(GLuint index, const GLuint *v);
390 void (GLAPIENTRY *qglVertexAttrib4Nusv)(GLuint index, const GLushort *v);
391 void (GLAPIENTRY *qglVertexAttrib4bv)(GLuint index, const GLbyte *v);
392 void (GLAPIENTRY *qglVertexAttrib4d)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
393 void (GLAPIENTRY *qglVertexAttrib4dv)(GLuint index, const GLdouble *v);
394 void (GLAPIENTRY *qglVertexAttrib4f)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
395 void (GLAPIENTRY *qglVertexAttrib4fv)(GLuint index, const GLfloat *v);
396 void (GLAPIENTRY *qglVertexAttrib4iv)(GLuint index, const GLint *v);
397 void (GLAPIENTRY *qglVertexAttrib4s)(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3);
398 void (GLAPIENTRY *qglVertexAttrib4sv)(GLuint index, const GLshort *v);
399 void (GLAPIENTRY *qglVertexAttrib4ubv)(GLuint index, const GLubyte *v);
400 void (GLAPIENTRY *qglVertexAttrib4uiv)(GLuint index, const GLuint *v);
401 void (GLAPIENTRY *qglVertexAttrib4usv)(GLuint index, const GLushort *v);
402 void (GLAPIENTRY *qglVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
403 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
407 #define sscanf sscanf_s
410 typedef struct glfunction_s
412 const char *extension;
419 // functions we look for - both core and extensions - it's okay if some of these are NULL for unsupported extensions.
420 static glfunction_t openglfuncs[] =
422 {"core", "glActiveTexture", (void **) &qglActiveTexture},
423 {"core", "glAttachShader", (void **) &qglAttachShader},
424 {"core", "glBeginQuery", (void **) &qglBeginQuery},
425 {"core", "glBindAttribLocation", (void **) &qglBindAttribLocation},
426 {"core", "glBindBuffer", (void **) &qglBindBuffer},
427 {"core", "glBindBufferBase", (void **) &qglBindBufferBase},
428 {"core", "glBindBufferRange", (void **) &qglBindBufferRange},
429 {"core", "glBindFramebuffer", (void **) &qglBindFramebuffer},
430 {"core", "glBindRenderbuffer", (void **) &qglBindRenderbuffer},
431 {"core", "glBindTexture", (void **) &qglBindTexture},
432 {"core", "glBindVertexArray", (void **) &qglBindVertexArray},
433 {"core", "glBlendEquation", (void **) &qglBlendEquation},
434 {"core", "glBlendFunc", (void **) &qglBlendFunc},
435 {"core", "glBlendFuncSeparate", (void **) &qglBlendFuncSeparate},
436 {"core", "glBlitFramebuffer", (void **) &qglBlitFramebuffer},
437 {"core", "glBufferData", (void **) &qglBufferData},
438 {"core", "glBufferSubData", (void **) &qglBufferSubData},
439 {"core", "glCheckFramebufferStatus", (void **) &qglCheckFramebufferStatus},
440 {"core", "glClear", (void **) &qglClear},
441 {"core", "glClearColor", (void **) &qglClearColor},
442 {"core", "glClearDepth", (void **) &qglClearDepth},
443 {"core", "glClearStencil", (void **) &qglClearStencil},
444 {"core", "glColorMask", (void **) &qglColorMask},
445 {"core", "glCompileShader", (void **) &qglCompileShader},
446 {"core", "glCompressedTexImage2D", (void **) &qglCompressedTexImage2D},
447 {"core", "glCompressedTexImage3D", (void **) &qglCompressedTexImage3D},
448 {"core", "glCompressedTexSubImage2D", (void **) &qglCompressedTexSubImage2D},
449 {"core", "glCompressedTexSubImage3D", (void **) &qglCompressedTexSubImage3D},
450 {"core", "glCopyTexImage2D", (void **) &qglCopyTexImage2D},
451 {"core", "glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
452 {"core", "glCopyTexSubImage3D", (void **) &qglCopyTexSubImage3D},
453 {"core", "glCreateProgram", (void **) &qglCreateProgram},
454 {"core", "glCreateShader", (void **) &qglCreateShader},
455 {"core", "glCullFace", (void **) &qglCullFace},
456 {"core", "glDeleteBuffers", (void **) &qglDeleteBuffers},
457 {"core", "glDeleteFramebuffers", (void **) &qglDeleteFramebuffers},
458 {"core", "glDeleteProgram", (void **) &qglDeleteProgram},
459 {"core", "glDeleteQueries", (void **) &qglDeleteQueries},
460 {"core", "glDeleteRenderbuffers", (void **) &qglDeleteRenderbuffers},
461 {"core", "glDeleteShader", (void **) &qglDeleteShader},
462 {"core", "glDeleteTextures", (void **) &qglDeleteTextures},
463 {"core", "glDeleteVertexArrays", (void **)&qglDeleteVertexArrays},
464 {"core", "glDepthFunc", (void **) &qglDepthFunc},
465 {"core", "glDepthMask", (void **) &qglDepthMask},
466 {"core", "glDepthRange", (void **) &qglDepthRange},
467 {"core", "glDepthRangef", (void **) &qglDepthRangef},
468 {"core", "glDetachShader", (void **) &qglDetachShader},
469 {"core", "glDisable", (void **) &qglDisable},
470 {"core", "glDisableVertexAttribArray", (void **) &qglDisableVertexAttribArray},
471 {"core", "glDrawArrays", (void **) &qglDrawArrays},
472 {"core", "glDrawBuffer", (void **) &qglDrawBuffer},
473 {"core", "glDrawBuffers", (void **) &qglDrawBuffers},
474 {"core", "glDrawElements", (void **) &qglDrawElements},
475 {"core", "glEnable", (void **) &qglEnable},
476 {"core", "glEnableVertexAttribArray", (void **) &qglEnableVertexAttribArray},
477 {"core", "glEndQuery", (void **) &qglEndQuery},
478 {"core", "glFinish", (void **) &qglFinish},
479 {"core", "glFlush", (void **) &qglFlush},
480 {"core", "glFramebufferRenderbuffer", (void **) &qglFramebufferRenderbuffer},
481 {"core", "glFramebufferTexture1D", (void **) &qglFramebufferTexture1D},
482 {"core", "glFramebufferTexture2D", (void **) &qglFramebufferTexture2D},
483 {"core", "glFramebufferTexture3D", (void **) &qglFramebufferTexture3D},
484 {"core", "glFramebufferTextureLayer", (void **) &qglFramebufferTextureLayer},
485 {"core", "glGenBuffers", (void **) &qglGenBuffers},
486 {"core", "glGenFramebuffers", (void **) &qglGenFramebuffers},
487 {"core", "glGenQueries", (void **) &qglGenQueries},
488 {"core", "glGenRenderbuffers", (void **) &qglGenRenderbuffers},
489 {"core", "glGenTextures", (void **) &qglGenTextures},
490 {"core", "glGenVertexArrays", (void **)&qglGenVertexArrays},
491 {"core", "glGenerateMipmap", (void **) &qglGenerateMipmap},
492 {"core", "glGetActiveAttrib", (void **) &qglGetActiveAttrib},
493 {"core", "glGetActiveUniform", (void **) &qglGetActiveUniform},
494 {"core", "glGetActiveUniformBlockName", (void **) &qglGetActiveUniformBlockName},
495 {"core", "glGetActiveUniformBlockiv", (void **) &qglGetActiveUniformBlockiv},
496 {"core", "glGetActiveUniformName", (void **) &qglGetActiveUniformName},
497 {"core", "glGetActiveUniformsiv", (void **) &qglGetActiveUniformsiv},
498 {"core", "glGetAttachedShaders", (void **) &qglGetAttachedShaders},
499 {"core", "glGetAttribLocation", (void **) &qglGetAttribLocation},
500 {"core", "glGetBooleanv", (void **) &qglGetBooleanv},
501 {"core", "glGetCompressedTexImage", (void **) &qglGetCompressedTexImage},
502 {"core", "glGetDoublev", (void **) &qglGetDoublev},
503 {"core", "glGetError", (void **) &qglGetError},
504 {"core", "glGetFloatv", (void **) &qglGetFloatv},
505 {"core", "glGetFramebufferAttachmentParameteriv", (void **) &qglGetFramebufferAttachmentParameteriv},
506 {"core", "glGetIntegeri_v", (void **) &qglGetIntegeri_v},
507 {"core", "glGetIntegerv", (void **) &qglGetIntegerv},
508 {"core", "glGetProgramInfoLog", (void **) &qglGetProgramInfoLog},
509 {"core", "glGetProgramiv", (void **) &qglGetProgramiv},
510 {"core", "glGetQueryObjectiv", (void **) &qglGetQueryObjectiv},
511 {"core", "glGetQueryObjectuiv", (void **) &qglGetQueryObjectuiv},
512 {"core", "glGetQueryiv", (void **) &qglGetQueryiv},
513 {"core", "glGetRenderbufferParameteriv", (void **) &qglGetRenderbufferParameteriv},
514 {"core", "glGetShaderInfoLog", (void **) &qglGetShaderInfoLog},
515 {"core", "glGetShaderSource", (void **) &qglGetShaderSource},
516 {"core", "glGetShaderiv", (void **) &qglGetShaderiv},
517 {"core", "glGetString", (void **) &qglGetString},
518 {"core", "glGetStringi", (void **) &qglGetStringi},
519 {"core", "glGetTexImage", (void **) &qglGetTexImage},
520 {"core", "glGetTexLevelParameterfv", (void **) &qglGetTexLevelParameterfv},
521 {"core", "glGetTexLevelParameteriv", (void **) &qglGetTexLevelParameteriv},
522 {"core", "glGetTexParameterfv", (void **) &qglGetTexParameterfv},
523 {"core", "glGetTexParameteriv", (void **) &qglGetTexParameteriv},
524 {"core", "glGetUniformBlockIndex", (void **) &qglGetUniformBlockIndex},
525 {"core", "glGetUniformIndices", (void **) &qglGetUniformIndices},
526 {"core", "glGetUniformLocation", (void **) &qglGetUniformLocation},
527 {"core", "glGetUniformfv", (void **) &qglGetUniformfv},
528 {"core", "glGetUniformiv", (void **) &qglGetUniformiv},
529 {"core", "glGetVertexAttribPointerv", (void **) &qglGetVertexAttribPointerv},
530 {"core", "glGetVertexAttribdv", (void **) &qglGetVertexAttribdv},
531 {"core", "glGetVertexAttribfv", (void **) &qglGetVertexAttribfv},
532 {"core", "glGetVertexAttribiv", (void **) &qglGetVertexAttribiv},
533 {"core", "glHint", (void **) &qglHint},
534 {"core", "glIsBuffer", (void **) &qglIsBuffer},
535 {"core", "glIsEnabled", (void **) &qglIsEnabled},
536 {"core", "glIsFramebuffer", (void **) &qglIsFramebuffer},
537 {"core", "glIsQuery", (void **) &qglIsQuery},
538 {"core", "glIsRenderbuffer", (void **) &qglIsRenderbuffer},
539 {"core", "glLinkProgram", (void **) &qglLinkProgram},
540 {"core", "glMapBuffer", (void **) &qglMapBuffer},
541 {"core", "glPixelStorei", (void **) &qglPixelStorei},
542 {"core", "glPointSize", (void **) &qglPointSize},
543 {"core", "glPolygonMode", (void **) &qglPolygonMode},
544 {"core", "glPolygonOffset", (void **) &qglPolygonOffset},
545 {"core", "glReadBuffer", (void **) &qglReadBuffer},
546 {"core", "glReadPixels", (void **) &qglReadPixels},
547 {"core", "glRenderbufferStorage", (void **) &qglRenderbufferStorage},
548 {"core", "glRenderbufferStorageMultisample", (void **) &qglRenderbufferStorageMultisample},
549 {"core", "glSampleCoverage", (void **) &qglSampleCoverage},
550 {"core", "glScissor", (void **) &qglScissor},
551 {"core", "glShaderSource", (void **) &qglShaderSource},
552 {"core", "glStencilFunc", (void **) &qglStencilFunc},
553 {"core", "glStencilMask", (void **) &qglStencilMask},
554 {"core", "glStencilOp", (void **) &qglStencilOp},
555 {"core", "glTexImage2D", (void **) &qglTexImage2D},
556 {"core", "glTexImage3D", (void **) &qglTexImage3D},
557 {"core", "glTexParameterf", (void **) &qglTexParameterf},
558 {"core", "glTexParameterfv", (void **) &qglTexParameterfv},
559 {"core", "glTexParameteri", (void **) &qglTexParameteri},
560 {"core", "glTexSubImage2D", (void **) &qglTexSubImage2D},
561 {"core", "glTexSubImage3D", (void **) &qglTexSubImage3D},
562 {"core", "glUniform1f", (void **) &qglUniform1f},
563 {"core", "glUniform1fv", (void **) &qglUniform1fv},
564 {"core", "glUniform1i", (void **) &qglUniform1i},
565 {"core", "glUniform1iv", (void **) &qglUniform1iv},
566 {"core", "glUniform2f", (void **) &qglUniform2f},
567 {"core", "glUniform2fv", (void **) &qglUniform2fv},
568 {"core", "glUniform2i", (void **) &qglUniform2i},
569 {"core", "glUniform2iv", (void **) &qglUniform2iv},
570 {"core", "glUniform3f", (void **) &qglUniform3f},
571 {"core", "glUniform3fv", (void **) &qglUniform3fv},
572 {"core", "glUniform3i", (void **) &qglUniform3i},
573 {"core", "glUniform3iv", (void **) &qglUniform3iv},
574 {"core", "glUniform4f", (void **) &qglUniform4f},
575 {"core", "glUniform4fv", (void **) &qglUniform4fv},
576 {"core", "glUniform4i", (void **) &qglUniform4i},
577 {"core", "glUniform4iv", (void **) &qglUniform4iv},
578 {"core", "glUniformBlockBinding", (void **) &qglUniformBlockBinding},
579 {"core", "glUniformMatrix2fv", (void **) &qglUniformMatrix2fv},
580 {"core", "glUniformMatrix3fv", (void **) &qglUniformMatrix3fv},
581 {"core", "glUniformMatrix4fv", (void **) &qglUniformMatrix4fv},
582 {"core", "glUnmapBuffer", (void **) &qglUnmapBuffer},
583 {"core", "glUseProgram", (void **) &qglUseProgram},
584 {"core", "glValidateProgram", (void **) &qglValidateProgram},
585 {"core", "glVertexAttrib1d", (void **) &qglVertexAttrib1d},
586 {"core", "glVertexAttrib1dv", (void **) &qglVertexAttrib1dv},
587 {"core", "glVertexAttrib1f", (void **) &qglVertexAttrib1f},
588 {"core", "glVertexAttrib1fv", (void **) &qglVertexAttrib1fv},
589 {"core", "glVertexAttrib1s", (void **) &qglVertexAttrib1s},
590 {"core", "glVertexAttrib1sv", (void **) &qglVertexAttrib1sv},
591 {"core", "glVertexAttrib2d", (void **) &qglVertexAttrib2d},
592 {"core", "glVertexAttrib2dv", (void **) &qglVertexAttrib2dv},
593 {"core", "glVertexAttrib2f", (void **) &qglVertexAttrib2f},
594 {"core", "glVertexAttrib2fv", (void **) &qglVertexAttrib2fv},
595 {"core", "glVertexAttrib2s", (void **) &qglVertexAttrib2s},
596 {"core", "glVertexAttrib2sv", (void **) &qglVertexAttrib2sv},
597 {"core", "glVertexAttrib3d", (void **) &qglVertexAttrib3d},
598 {"core", "glVertexAttrib3dv", (void **) &qglVertexAttrib3dv},
599 {"core", "glVertexAttrib3f", (void **) &qglVertexAttrib3f},
600 {"core", "glVertexAttrib3fv", (void **) &qglVertexAttrib3fv},
601 {"core", "glVertexAttrib3s", (void **) &qglVertexAttrib3s},
602 {"core", "glVertexAttrib3sv", (void **) &qglVertexAttrib3sv},
603 {"core", "glVertexAttrib4Nbv", (void **) &qglVertexAttrib4Nbv},
604 {"core", "glVertexAttrib4Niv", (void **) &qglVertexAttrib4Niv},
605 {"core", "glVertexAttrib4Nsv", (void **) &qglVertexAttrib4Nsv},
606 {"core", "glVertexAttrib4Nub", (void **) &qglVertexAttrib4Nub},
607 {"core", "glVertexAttrib4Nubv", (void **) &qglVertexAttrib4Nubv},
608 {"core", "glVertexAttrib4Nuiv", (void **) &qglVertexAttrib4Nuiv},
609 {"core", "glVertexAttrib4Nusv", (void **) &qglVertexAttrib4Nusv},
610 {"core", "glVertexAttrib4bv", (void **) &qglVertexAttrib4bv},
611 {"core", "glVertexAttrib4d", (void **) &qglVertexAttrib4d},
612 {"core", "glVertexAttrib4dv", (void **) &qglVertexAttrib4dv},
613 {"core", "glVertexAttrib4f", (void **) &qglVertexAttrib4f},
614 {"core", "glVertexAttrib4fv", (void **) &qglVertexAttrib4fv},
615 {"core", "glVertexAttrib4iv", (void **) &qglVertexAttrib4iv},
616 {"core", "glVertexAttrib4s", (void **) &qglVertexAttrib4s},
617 {"core", "glVertexAttrib4sv", (void **) &qglVertexAttrib4sv},
618 {"core", "glVertexAttrib4ubv", (void **) &qglVertexAttrib4ubv},
619 {"core", "glVertexAttrib4uiv", (void **) &qglVertexAttrib4uiv},
620 {"core", "glVertexAttrib4usv", (void **) &qglVertexAttrib4usv},
621 {"core", "glVertexAttribPointer", (void **) &qglVertexAttribPointer},
622 {"core", "glViewport", (void **) &qglViewport},
623 {"glBindFragDataLocation", "glBindFragDataLocation", (void **) &qglBindFragDataLocation}, // optional (no preference)
624 {"GL_ARB_debug_output", "glDebugMessageControlARB", (void **)&qglDebugMessageControlARB},
625 {"GL_ARB_debug_output", "glDebugMessageInsertARB", (void **)&qglDebugMessageInsertARB},
626 {"GL_ARB_debug_output", "glDebugMessageCallbackARB", (void **)&qglDebugMessageCallbackARB},
627 {"GL_ARB_debug_output", "glGetDebugMessageLogARB", (void **)&qglGetDebugMessageLogARB},
628 {"GL_ARB_debug_output", "glGetPointerv", (void **)&qglGetPointerv},
633 qbool GL_CheckExtension(const char *name, const char *disableparm, int silent)
636 const glfunction_t *func;
637 char extstr[MAX_INPUTLINE];
639 Con_DPrintf("checking for %s... ", name);
641 if (disableparm && (Sys_CheckParm(disableparm) || Sys_CheckParm("-safe")))
643 Con_DPrint("disabled by commandline\n");
647 if (!GL_ExtensionSupported(name))
649 Con_DPrint("not detected\n");
654 for (func = openglfuncs; func && func->name != NULL; func++)
656 if (!*func->funcvariable && !strcmp(name, func->extension))
659 Con_DPrintf("%s is missing function \"%s\" - broken driver!\n", name, func->name);
664 // delay the return so it prints all missing functions
667 // VorteX: add to found extension list
668 dpsnprintf(extstr, sizeof(extstr), "%s %s ", gl_info_extensions.string, name);
669 Cvar_SetQuick(&gl_info_extensions, extstr);
671 Con_DPrint("enabled\n");
675 void VID_ClearExtensions(void)
677 // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
678 Cvar_SetQuick(&gl_info_extensions, "");
680 // clear the extension flags
681 memset(&vid.support, 0, sizeof(vid.support));
684 void GL_InitFunctions(void)
687 const glfunction_t *func;
688 qbool missingrequiredfuncs = false;
689 static char missingfuncs[16384];
691 // first fetch the function pointers for everything - after this we can begin making GL calls.
692 for (func = openglfuncs; func->name != NULL; func++)
693 *func->funcvariable = (void *)GL_GetProcAddress(func->name);
696 for (func = openglfuncs; func && func->name != NULL; func++)
698 if (!*func->funcvariable && !strcmp(func->extension, "core"))
700 Con_DPrintf("GL context is missing required function \"%s\"!\n", func->name);
701 missingrequiredfuncs = true;
702 dp_strlcat(missingfuncs, " ", sizeof(missingfuncs));
703 dp_strlcat(missingfuncs, func->name, sizeof(missingfuncs));
707 if (missingrequiredfuncs)
708 Sys_Error("OpenGL driver/hardware lacks required features:\n%s", missingfuncs);
716 GLint numextensions = 0;
719 gl_renderer = (const char *)qglGetString(GL_RENDERER);
720 gl_vendor = (const char *)qglGetString(GL_VENDOR);
721 gl_version = (const char *)qglGetString(GL_VERSION);
723 Con_Printf("GL_VENDOR: %s\n", gl_vendor);
724 Con_Printf("GL_RENDERER: %s\n", gl_renderer);
725 Con_Printf("GL_VERSION: %s\n", gl_version);
728 qglGetIntegerv(GL_MAJOR_VERSION, &majorv);
729 qglGetIntegerv(GL_MINOR_VERSION, &minorv);
730 vid.support.glversion = 10 * majorv + minorv;
731 if (vid.support.glversion < 32)
732 // fallback, should never get here: GL context creation should have failed
733 Sys_Error("OpenGL driver/hardware supports version %i.%i but 3.2 is the minimum\n", majorv, minorv);
735 qglGetIntegerv(GL_NUM_EXTENSIONS, &numextensions);
736 Con_DPrint("GL_EXTENSIONS:\n");
737 for (j = 0; j < numextensions; j++)
739 const char *ext = (const char *)qglGetStringi(GL_EXTENSIONS, j);
740 Con_DPrintf(" %s", ext);
747 Con_DPrint("Checking OpenGL extensions...\n");
749 // detect what GLSL version is available, to enable features like higher quality reliefmapping
750 vid.support.glshaderversion = 100;
751 s = (char *) qglGetString(GL_SHADING_LANGUAGE_VERSION);
753 vid.support.glshaderversion = (int)(atof(s) * 100.0f + 0.5f);
754 if (vid.support.glshaderversion < 100)
755 vid.support.glshaderversion = 100;
756 Con_Printf("Detected GLSL version %i\n", vid.support.glshaderversion);
759 // GLES devices in general do not like GL_BGRA, so use GL_RGBA
760 vid.forcetextype = TEXTYPE_RGBA;
762 // GL drivers generally prefer GL_BGRA
763 vid.forcetextype = GL_BGRA;
766 vid.support.amd_texture_texture4 = GL_CheckExtension("GL_AMD_texture_texture4", "-notexture4", false);
767 vid.support.arb_texture_gather = GL_CheckExtension("GL_ARB_texture_gather", "-notexturegather", false);
768 vid.support.ext_texture_compression_s3tc = GL_CheckExtension("GL_EXT_texture_compression_s3tc", "-nos3tc", false);
769 vid.support.ext_texture_filter_anisotropic = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", "-noanisotropy", false);
771 vid.support.ext_texture_srgb = true; // GL3 core, but not GLES2
773 vid.support.arb_debug_output = GL_CheckExtension("GL_ARB_debug_output", "-nogldebugoutput", false);
774 vid.allowalphatocoverage = false;
776 // COMMANDLINEOPTION: GL: -noanisotropy disables GL_EXT_texture_filter_anisotropic (allows higher quality texturing)
777 // COMMANDLINEOPTION: GL: -nos3tc disables GL_EXT_texture_compression_s3tc (which allows use of .dds texture caching)
778 // COMMANDLINEOPTION: GL: -notexture4 disables GL_AMD_texture_texture4 (which provides fetch4 sampling)
779 // COMMANDLINEOPTION: GL: -notexturegather disables GL_ARB_texture_gather (which provides fetch4 sampling)
780 // COMMANDLINEOPTION: GL: -nogldebugoutput disables GL_ARB_debug_output (which provides the gl_debug feature, if enabled)
783 // gl_texturecompression_color is somehow broken on AMD's Windows driver,
784 // see: https://gitlab.com/xonotic/darkplaces/-/issues/228
785 // HACK: force it off (less bad than adding hacky checks to the renderer)
786 if (strncmp(gl_renderer, "AMD Radeon(TM)", 14) == 0)
788 Cvar_SetQuick(&gl_texturecompression_color, "0");
789 gl_texturecompression_color.flags |= CF_READONLY;
793 #ifdef GL_MAX_DRAW_BUFFERS
794 qglGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint*)&vid.maxdrawbuffers);
797 qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
799 #ifdef GL_MAX_CUBE_MAP_TEXTURE_SIZE
801 if (GL_CheckExtension("GL_ARB_texture_cube_map", "-nocubemap", false))
804 qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_cubemap);
805 Con_DPrintf("GL_MAX_CUBE_MAP_TEXTURE_SIZE = %i\n", vid.maxtexturesize_cubemap);
809 #ifdef GL_MAX_3D_TEXTURE_SIZE
811 if (GL_CheckExtension("GL_EXT_texture3D", "-notexture3d", false)
812 || GL_CheckExtension("GL_OES_texture3D", "-notexture3d", false))
815 qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
816 Con_DPrintf("GL_MAX_3D_TEXTURE_SIZE = %i\n", vid.maxtexturesize_3d);
822 Con_Print("Using GLES2 rendering path\n");
823 vid.renderpath = RENDERPATH_GLES2;
824 vid.sRGBcapable2D = false;
825 vid.sRGBcapable3D = false;
827 Con_Print("Using GL32 rendering path\n");
828 vid.renderpath = RENDERPATH_GL32;
829 vid.sRGBcapable2D = false;
830 vid.sRGBcapable3D = true;
831 // enable multisample antialiasing if possible
832 vid.allowalphatocoverage = true; // but see below, it may get turned to false again if GL_SAMPLES is <= 1
835 qglGetIntegerv(GL_SAMPLES, &samples);
836 vid.mode.samples = samples;
838 qglEnable(GL_MULTISAMPLE);
840 vid.allowalphatocoverage = false;
842 // currently MSAA antialiasing is not implemented for fbo viewports, so we actually have to force this off anyway.
843 vid.allowalphatocoverage = false;
847 #ifdef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
848 if (vid.support.ext_texture_filter_anisotropic)
849 qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
854 float VID_JoyState_GetAxis(const vid_joystate_t *joystate, int axis, float fsensitivity, float deadzone)
857 value = (axis >= 0 && axis < MAXJOYAXIS) ? joystate->axis[axis] : 0.0f;
858 value = value > deadzone ? (value - deadzone) : (value < -deadzone ? (value + deadzone) : 0.0f);
859 value *= deadzone > 0 ? (1.0f / (1.0f - deadzone)) : 1.0f;
860 value = bound(-1, value, 1);
861 return value * fsensitivity;
864 qbool VID_JoyBlockEmulatedKeys(int keycode)
867 vid_joystate_t joystate;
869 if (!joy_axiskeyevents.integer)
871 if (vid_joystate.is360)
873 if (keycode != K_UPARROW && keycode != K_DOWNARROW && keycode != K_RIGHTARROW && keycode != K_LEFTARROW)
876 // block system-generated key events for arrow keys if we're emulating the arrow keys ourselves
877 VID_BuildJoyState(&joystate);
878 for (j = 32;j < 36;j++)
879 if (vid_joystate.button[j] || joystate.button[j])
885 void VID_Shared_BuildJoyState_Begin(vid_joystate_t *joystate)
888 xinput_state_t xinputstate;
890 memset(joystate, 0, sizeof(*joystate));
892 if (vid_xinputindex >= 0 && qXInputGetState && qXInputGetState(vid_xinputindex, &xinputstate) == S_OK)
894 joystate->is360 = true;
895 joystate->button[ 0] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) != 0;
896 joystate->button[ 1] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) != 0;
897 joystate->button[ 2] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) != 0;
898 joystate->button[ 3] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) != 0;
899 joystate->button[ 4] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_START) != 0;
900 joystate->button[ 5] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) != 0;
901 joystate->button[ 6] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0;
902 joystate->button[ 7] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0;
903 joystate->button[ 8] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) != 0;
904 joystate->button[ 9] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) != 0;
905 joystate->button[10] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0;
906 joystate->button[11] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0;
907 joystate->button[12] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0;
908 joystate->button[13] = (xinputstate.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0;
909 joystate->button[14] = xinputstate.Gamepad.bLeftTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
910 joystate->button[15] = xinputstate.Gamepad.bRightTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
911 joystate->button[16] = xinputstate.Gamepad.sThumbLY < -16384;
912 joystate->button[17] = xinputstate.Gamepad.sThumbLY > 16384;
913 joystate->button[18] = xinputstate.Gamepad.sThumbLX < -16384;
914 joystate->button[19] = xinputstate.Gamepad.sThumbLX > 16384;
915 joystate->button[20] = xinputstate.Gamepad.sThumbRY < -16384;
916 joystate->button[21] = xinputstate.Gamepad.sThumbRY > 16384;
917 joystate->button[22] = xinputstate.Gamepad.sThumbRX < -16384;
918 joystate->button[23] = xinputstate.Gamepad.sThumbRX > 16384;
919 joystate->axis[ 4] = xinputstate.Gamepad.bLeftTrigger * (1.0f / 255.0f);
920 joystate->axis[ 5] = xinputstate.Gamepad.bRightTrigger * (1.0f / 255.0f);
921 joystate->axis[ 0] = xinputstate.Gamepad.sThumbLX * (1.0f / 32767.0f);
922 joystate->axis[ 1] = xinputstate.Gamepad.sThumbLY * (1.0f / 32767.0f);
923 joystate->axis[ 2] = xinputstate.Gamepad.sThumbRX * (1.0f / 32767.0f);
924 joystate->axis[ 3] = xinputstate.Gamepad.sThumbRY * (1.0f / 32767.0f);
929 void VID_Shared_BuildJoyState_Finish(vid_joystate_t *joystate)
934 // emulate key events for thumbstick
935 f = VID_JoyState_GetAxis(joystate, joy_axisforward.integer, 1, joy_axiskeyevents_deadzone.value) * joy_sensitivityforward.value;
936 r = VID_JoyState_GetAxis(joystate, joy_axisside.integer , 1, joy_axiskeyevents_deadzone.value) * joy_sensitivityside.value;
937 #if MAXJOYBUTTON != 36
938 #error this code must be updated if MAXJOYBUTTON changes!
940 joystate->button[32] = f > 0.0f;
941 joystate->button[33] = f < 0.0f;
942 joystate->button[34] = r > 0.0f;
943 joystate->button[35] = r < 0.0f;
946 static void VID_KeyEventForButton(qbool oldbutton, qbool newbutton, int key, double *timer)
952 if (host.realtime >= *timer)
954 Key_Event(key, 0, true);
955 *timer = host.realtime + 0.1;
960 Key_Event(key, 0, false);
968 Key_Event(key, 0, true);
969 *timer = host.realtime + 0.5;
974 #if MAXJOYBUTTON != 36
975 #error this code must be updated if MAXJOYBUTTON changes!
977 static int joybuttonkey[MAXJOYBUTTON][2] =
979 {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},
980 {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},
981 {K_JOY_UP, K_UPARROW}, {K_JOY_DOWN, K_DOWNARROW}, {K_JOY_RIGHT, K_RIGHTARROW}, {K_JOY_LEFT, K_LEFTARROW},
984 static int joybuttonkey360[][2] =
986 {K_X360_DPAD_UP, K_UPARROW},
987 {K_X360_DPAD_DOWN, K_DOWNARROW},
988 {K_X360_DPAD_LEFT, K_LEFTARROW},
989 {K_X360_DPAD_RIGHT, K_RIGHTARROW},
990 {K_X360_START, K_ESCAPE},
991 {K_X360_BACK, K_ESCAPE},
992 {K_X360_LEFT_THUMB, 0},
993 {K_X360_RIGHT_THUMB, 0},
994 {K_X360_LEFT_SHOULDER, 0},
995 {K_X360_RIGHT_SHOULDER, 0},
997 {K_X360_B, K_ESCAPE},
1000 {K_X360_LEFT_TRIGGER, 0},
1001 {K_X360_RIGHT_TRIGGER, 0},
1002 {K_X360_LEFT_THUMB_DOWN, K_DOWNARROW},
1003 {K_X360_LEFT_THUMB_UP, K_UPARROW},
1004 {K_X360_LEFT_THUMB_LEFT, K_LEFTARROW},
1005 {K_X360_LEFT_THUMB_RIGHT, K_RIGHTARROW},
1006 {K_X360_RIGHT_THUMB_DOWN, 0},
1007 {K_X360_RIGHT_THUMB_UP, 0},
1008 {K_X360_RIGHT_THUMB_LEFT, 0},
1009 {K_X360_RIGHT_THUMB_RIGHT, 0},
1012 double vid_joybuttontimer[MAXJOYBUTTON];
1013 void VID_ApplyJoyState(vid_joystate_t *joystate)
1016 int c = joy_axiskeyevents.integer != 0;
1017 if (joystate->is360)
1020 // keystrokes (chatpad)
1021 // DOES NOT WORK - no driver support in xinput1_3.dll :(
1022 xinput_keystroke_t keystroke;
1023 while (qXInputGetKeystroke && qXInputGetKeystroke(XUSER_INDEX_ANY, 0, &keystroke) == S_OK)
1024 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);
1027 // emit key events for buttons
1028 for (j = 0;j < (int)(sizeof(joybuttonkey360)/sizeof(joybuttonkey360[0]));j++)
1029 VID_KeyEventForButton(vid_joystate.button[j] != 0, joystate->button[j] != 0, joybuttonkey360[j][c], &vid_joybuttontimer[j]);
1032 cl.cmd.forwardmove += VID_JoyState_GetAxis(joystate, joy_x360_axisforward.integer, joy_x360_sensitivityforward.value, joy_x360_deadzoneforward.value) * cl_forwardspeed.value;
1033 cl.cmd.sidemove += VID_JoyState_GetAxis(joystate, joy_x360_axisside.integer, joy_x360_sensitivityside.value, joy_x360_deadzoneside.value) * cl_sidespeed.value;
1034 cl.cmd.upmove += VID_JoyState_GetAxis(joystate, joy_x360_axisup.integer, joy_x360_sensitivityup.value, joy_x360_deadzoneup.value) * cl_upspeed.value;
1035 cl.viewangles[0] += VID_JoyState_GetAxis(joystate, joy_x360_axispitch.integer, joy_x360_sensitivitypitch.value, joy_x360_deadzonepitch.value) * cl.realframetime * cl_pitchspeed.value;
1036 cl.viewangles[1] += VID_JoyState_GetAxis(joystate, joy_x360_axisyaw.integer, joy_x360_sensitivityyaw.value, joy_x360_deadzoneyaw.value) * cl.realframetime * cl_yawspeed.value;
1037 //cl.viewangles[2] += VID_JoyState_GetAxis(joystate, joy_x360_axisroll.integer, joy_x360_sensitivityroll.value, joy_x360_deadzoneroll.value) * cl.realframetime * cl_rollspeed.value;
1041 // emit key events for buttons
1042 for (j = 0;j < MAXJOYBUTTON;j++)
1043 VID_KeyEventForButton(vid_joystate.button[j] != 0, joystate->button[j] != 0, joybuttonkey[j][c], &vid_joybuttontimer[j]);
1046 cl.cmd.forwardmove += VID_JoyState_GetAxis(joystate, joy_axisforward.integer, joy_sensitivityforward.value, joy_deadzoneforward.value) * cl_forwardspeed.value;
1047 cl.cmd.sidemove += VID_JoyState_GetAxis(joystate, joy_axisside.integer, joy_sensitivityside.value, joy_deadzoneside.value) * cl_sidespeed.value;
1048 cl.cmd.upmove += VID_JoyState_GetAxis(joystate, joy_axisup.integer, joy_sensitivityup.value, joy_deadzoneup.value) * cl_upspeed.value;
1049 cl.viewangles[0] += VID_JoyState_GetAxis(joystate, joy_axispitch.integer, joy_sensitivitypitch.value, joy_deadzonepitch.value) * cl.realframetime * cl_pitchspeed.value;
1050 cl.viewangles[1] += VID_JoyState_GetAxis(joystate, joy_axisyaw.integer, joy_sensitivityyaw.value, joy_deadzoneyaw.value) * cl.realframetime * cl_yawspeed.value;
1051 //cl.viewangles[2] += VID_JoyState_GetAxis(joystate, joy_axisroll.integer, joy_sensitivityroll.value, joy_deadzoneroll.value) * cl.realframetime * cl_rollspeed.value;
1054 vid_joystate = *joystate;
1057 int VID_Shared_SetJoystick(int index)
1061 int xinputcount = 0;
1062 int xinputindex = -1;
1063 int xinputavailable = 0;
1064 xinput_state_t state;
1065 // detect available XInput controllers
1066 for (i = 0;i < 4;i++)
1068 if (qXInputGetState && qXInputGetState(i, &state) == S_OK)
1070 xinputavailable |= 1<<i;
1071 if (index == xinputcount)
1076 if (joy_xinputavailable.integer != xinputavailable)
1077 Cvar_SetValueQuick(&joy_xinputavailable, xinputavailable);
1078 if (vid_xinputindex != xinputindex)
1080 vid_xinputindex = xinputindex;
1081 if (xinputindex >= 0)
1082 Con_Printf("Joystick %i opened (XInput Device %i)\n", index, xinputindex);
1091 static void Force_CenterView_f(cmd_state_t *cmd)
1093 cl.viewangles[PITCH] = 0;
1096 static int gamma_forcenextframe = false;
1097 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost;
1098 static int cachecolorenable;
1100 void VID_ApplyGammaToColor(const float *rgb, float *out)
1103 if (cachecolorenable)
1105 for (i = 0; i < 3; i++)
1106 out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / invpow(0.5, 1 - cachegrey[i])) * cachewhite[i] + cacheblack[i];
1110 for (i = 0; i < 3; i++)
1111 out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / cachegamma) * cachecontrast + cachebrightness;
1115 unsigned int vid_gammatables_serial = 0; // so other subsystems can poll if gamma parameters have changed
1116 qbool vid_gammatables_trivial = true;
1117 void VID_BuildGammaTables(unsigned short *ramps, int rampsize)
1119 if (cachecolorenable)
1121 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, ramps, rampsize);
1122 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, ramps + rampsize, rampsize);
1123 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, ramps + rampsize*2, rampsize);
1127 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps, rampsize);
1128 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize, rampsize);
1129 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize*2, rampsize);
1132 if(vid.sRGB2D || vid.sRGB3D)
1135 for(i = 0; i < 3*rampsize; ++i)
1136 ramps[i] = (int)floor(bound(0.0f, Image_sRGBFloatFromLinearFloat(ramps[i] / 65535.0f), 1.0f) * 65535.0f + 0.5f);
1139 // LadyHavoc: this code came from Ben Winslow and Zinx Verituse, I have
1140 // immensely butchered it to work with variable framerates and fit in with
1141 // the rest of darkplaces.
1143 // R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667
1144 if (v_psycho.integer)
1148 static float n[3], nd[3], nt[3];
1149 static int init = true;
1150 unsigned short *ramp;
1151 gamma_forcenextframe = true;
1155 for (x = 0;x < 3;x++)
1157 n[x] = lhrandom(0, 1);
1158 nd[x] = (rand()&1)?-0.25:0.25;
1159 nt[x] = lhrandom(1, 8.2);
1163 for (x = 0;x < 3;x++)
1165 nt[x] -= cl.realframetime;
1169 nt[x] += lhrandom(1, 8.2);
1171 n[x] += nd[x] * cl.realframetime;
1172 n[x] -= floor(n[x]);
1175 for (x = 0, ramp = ramps;x < 3;x++)
1176 for (y = 0, t = n[x] - 0.75f;y < rampsize;y++, t += 0.75f * (2.0f / rampsize))
1177 *ramp++ = (unsigned short)(cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f);
1181 void VID_UpdateGamma(void)
1185 qbool gamma_changed = false;
1187 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
1188 BOUNDCVAR(v_gamma, 0.1, 5);
1189 BOUNDCVAR(v_contrast, 0.2, 5);
1190 BOUNDCVAR(v_brightness, -v_contrast.value * 0.8, 0.8);
1191 //BOUNDCVAR(v_contrastboost, 0.0625, 16);
1192 BOUNDCVAR(v_color_black_r, 0, 0.8);
1193 BOUNDCVAR(v_color_black_g, 0, 0.8);
1194 BOUNDCVAR(v_color_black_b, 0, 0.8);
1195 BOUNDCVAR(v_color_grey_r, 0, 0.95);
1196 BOUNDCVAR(v_color_grey_g, 0, 0.95);
1197 BOUNDCVAR(v_color_grey_b, 0, 0.95);
1198 BOUNDCVAR(v_color_white_r, 1, 5);
1199 BOUNDCVAR(v_color_white_g, 1, 5);
1200 BOUNDCVAR(v_color_white_b, 1, 5);
1203 // set vid_gammatables_trivial to true if the current settings would generate the identity gamma table
1204 vid_gammatables_trivial = false;
1205 if(v_psycho.integer == 0)
1206 if(v_contrastboost.value == 1)
1210 if(v_color_enable.integer)
1212 if(v_color_black_r.value == 0)
1213 if(v_color_black_g.value == 0)
1214 if(v_color_black_b.value == 0)
1215 if(fabs(v_color_grey_r.value - 0.5) < 1e-6)
1216 if(fabs(v_color_grey_g.value - 0.5) < 1e-6)
1217 if(fabs(v_color_grey_b.value - 0.5) < 1e-6)
1218 if(v_color_white_r.value == 1)
1219 if(v_color_white_g.value == 1)
1220 if(v_color_white_b.value == 1)
1221 vid_gammatables_trivial = true;
1225 if(v_gamma.value == 1)
1226 if(v_contrast.value == 1)
1227 if(v_brightness.value == 0)
1228 vid_gammatables_trivial = true;
1232 // if any gamma settings were changed, bump vid_gammatables_serial so we regenerate the gamma ramp texture
1233 #define GAMMACHECK(cache, value) if (cache != (value)) gamma_changed = true;cache = (value)
1234 if(v_psycho.integer)
1235 gamma_changed = true;
1236 GAMMACHECK(cachegamma , v_gamma.value);
1237 GAMMACHECK(cachecontrast , v_contrast.value);
1238 GAMMACHECK(cachebrightness , v_brightness.value);
1239 GAMMACHECK(cachecontrastboost, v_contrastboost.value);
1240 GAMMACHECK(cachecolorenable, v_color_enable.integer);
1241 GAMMACHECK(cacheblack[0] , v_color_black_r.value);
1242 GAMMACHECK(cacheblack[1] , v_color_black_g.value);
1243 GAMMACHECK(cacheblack[2] , v_color_black_b.value);
1244 GAMMACHECK(cachegrey[0] , v_color_grey_r.value);
1245 GAMMACHECK(cachegrey[1] , v_color_grey_g.value);
1246 GAMMACHECK(cachegrey[2] , v_color_grey_b.value);
1247 GAMMACHECK(cachewhite[0] , v_color_white_r.value);
1248 GAMMACHECK(cachewhite[1] , v_color_white_g.value);
1249 GAMMACHECK(cachewhite[2] , v_color_white_b.value);
1252 ++vid_gammatables_serial;
1257 static dllfunction_t xinputdllfuncs[] =
1259 {"XInputGetState", (void **) &qXInputGetState},
1260 {"XInputGetKeystroke", (void **) &qXInputGetKeystroke},
1263 static const char* xinputdllnames [] =
1270 static dllhandle_t xinputdll_dll = NULL;
1273 void VID_Shared_Init(void)
1275 Cvar_RegisterVariable(&gl_info_vendor);
1276 Cvar_RegisterVariable(&gl_info_renderer);
1277 Cvar_RegisterVariable(&gl_info_version);
1278 Cvar_RegisterVariable(&gl_info_extensions);
1279 Cvar_RegisterVariable(&gl_info_driver);
1280 Cvar_RegisterVariable(&v_gamma);
1281 Cvar_RegisterVariable(&v_brightness);
1282 Cvar_RegisterVariable(&v_contrastboost);
1283 Cvar_RegisterVariable(&v_contrast);
1285 Cvar_RegisterVariable(&v_color_enable);
1286 Cvar_RegisterVariable(&v_color_black_r);
1287 Cvar_RegisterVariable(&v_color_black_g);
1288 Cvar_RegisterVariable(&v_color_black_b);
1289 Cvar_RegisterVariable(&v_color_grey_r);
1290 Cvar_RegisterVariable(&v_color_grey_g);
1291 Cvar_RegisterVariable(&v_color_grey_b);
1292 Cvar_RegisterVariable(&v_color_white_r);
1293 Cvar_RegisterVariable(&v_color_white_g);
1294 Cvar_RegisterVariable(&v_color_white_b);
1296 Cvar_RegisterVariable(&v_glslgamma_2d);
1298 Cvar_RegisterVariable(&v_psycho);
1300 Cvar_RegisterVariable(&vid_fullscreen);
1301 Cvar_RegisterVariable(&vid_borderless);
1302 Cvar_RegisterVariable(&vid_width);
1303 Cvar_RegisterVariable(&vid_height);
1304 Cvar_RegisterVariable(&vid_bitsperpixel);
1305 Cvar_RegisterVariable(&vid_samples);
1306 Cvar_RegisterVariable(&vid_refreshrate);
1307 Cvar_RegisterVariable(&vid_stereobuffer);
1308 Cvar_RegisterVariable(&vid_touchscreen_density);
1309 Cvar_RegisterVariable(&vid_touchscreen_xdpi);
1310 Cvar_RegisterVariable(&vid_touchscreen_ydpi);
1311 Cvar_RegisterVariable(&vid_vsync);
1312 Cvar_RegisterVariable(&vid_mouse);
1313 Cvar_RegisterVariable(&vid_mouse_clickthrough);
1314 Cvar_RegisterVariable(&vid_minimize_on_focus_loss);
1315 Cvar_RegisterVariable(&vid_grabkeyboard);
1316 Cvar_RegisterVariable(&vid_touchscreen);
1317 Cvar_RegisterVariable(&vid_touchscreen_showkeyboard);
1318 Cvar_RegisterVariable(&vid_touchscreen_supportshowkeyboard);
1319 Cvar_RegisterVariable(&vid_stick_mouse);
1320 Cvar_RegisterVariable(&vid_resizable);
1321 Cvar_RegisterVariable(&vid_desktopfullscreen);
1322 Cvar_RegisterVariable(&vid_display);
1323 Cvar_RegisterVariable(&vid_info_displaycount);
1325 Cvar_RegisterVariable(&vid_ignore_taskbar);
1327 Cvar_RegisterVariable(&vid_minwidth);
1328 Cvar_RegisterVariable(&vid_minheight);
1329 Cvar_RegisterVariable(&gl_finish);
1330 Cvar_RegisterVariable(&vid_sRGB);
1331 Cvar_RegisterVariable(&vid_sRGB_fallback);
1333 Cvar_RegisterVariable(&joy_active);
1335 Cvar_RegisterVariable(&joy_xinputavailable);
1337 Cvar_RegisterVariable(&joy_detected);
1338 Cvar_RegisterVariable(&joy_enable);
1339 Cvar_RegisterVariable(&joy_index);
1340 Cvar_RegisterVariable(&joy_axisforward);
1341 Cvar_RegisterVariable(&joy_axisside);
1342 Cvar_RegisterVariable(&joy_axisup);
1343 Cvar_RegisterVariable(&joy_axispitch);
1344 Cvar_RegisterVariable(&joy_axisyaw);
1345 //Cvar_RegisterVariable(&joy_axisroll);
1346 Cvar_RegisterVariable(&joy_deadzoneforward);
1347 Cvar_RegisterVariable(&joy_deadzoneside);
1348 Cvar_RegisterVariable(&joy_deadzoneup);
1349 Cvar_RegisterVariable(&joy_deadzonepitch);
1350 Cvar_RegisterVariable(&joy_deadzoneyaw);
1351 //Cvar_RegisterVariable(&joy_deadzoneroll);
1352 Cvar_RegisterVariable(&joy_sensitivityforward);
1353 Cvar_RegisterVariable(&joy_sensitivityside);
1354 Cvar_RegisterVariable(&joy_sensitivityup);
1355 Cvar_RegisterVariable(&joy_sensitivitypitch);
1356 Cvar_RegisterVariable(&joy_sensitivityyaw);
1357 //Cvar_RegisterVariable(&joy_sensitivityroll);
1358 Cvar_RegisterVariable(&joy_axiskeyevents);
1359 Cvar_RegisterVariable(&joy_axiskeyevents_deadzone);
1360 Cvar_RegisterVariable(&joy_x360_axisforward);
1361 Cvar_RegisterVariable(&joy_x360_axisside);
1362 Cvar_RegisterVariable(&joy_x360_axisup);
1363 Cvar_RegisterVariable(&joy_x360_axispitch);
1364 Cvar_RegisterVariable(&joy_x360_axisyaw);
1365 //Cvar_RegisterVariable(&joy_x360_axisroll);
1366 Cvar_RegisterVariable(&joy_x360_deadzoneforward);
1367 Cvar_RegisterVariable(&joy_x360_deadzoneside);
1368 Cvar_RegisterVariable(&joy_x360_deadzoneup);
1369 Cvar_RegisterVariable(&joy_x360_deadzonepitch);
1370 Cvar_RegisterVariable(&joy_x360_deadzoneyaw);
1371 //Cvar_RegisterVariable(&joy_x360_deadzoneroll);
1372 Cvar_RegisterVariable(&joy_x360_sensitivityforward);
1373 Cvar_RegisterVariable(&joy_x360_sensitivityside);
1374 Cvar_RegisterVariable(&joy_x360_sensitivityup);
1375 Cvar_RegisterVariable(&joy_x360_sensitivitypitch);
1376 Cvar_RegisterVariable(&joy_x360_sensitivityyaw);
1377 //Cvar_RegisterVariable(&joy_x360_sensitivityroll);
1380 Sys_LoadDependency(xinputdllnames, &xinputdll_dll, xinputdllfuncs);
1383 Cmd_AddCommand(CF_CLIENT, "force_centerview", Force_CenterView_f, "recenters view (stops looking up/down)");
1384 Cmd_AddCommand(CF_CLIENT, "vid_restart", VID_Restart_f, "restarts video system (closes and reopens the window, restarts renderer)");
1387 /// NULL mode means read it from the cvars
1388 static int VID_Mode(viddef_mode_t *mode)
1391 viddef_mode_t _mode;
1396 memset(mode, 0, sizeof(*mode));
1397 mode->display = vid_display.integer;
1398 mode->fullscreen = vid_fullscreen.integer != 0;
1399 mode->desktopfullscreen = vid_desktopfullscreen.integer != 0;
1400 mode->width = vid_width.integer;
1401 mode->height = vid_height.integer;
1402 mode->bitsperpixel = vid_bitsperpixel.integer;
1403 mode->refreshrate = max(0, vid_refreshrate.integer);
1404 mode->stereobuffer = vid_stereobuffer.integer != 0;
1406 cl_ignoremousemoves = 2;
1407 VID_ClearExtensions();
1409 if (VID_InitMode(mode))
1411 // bones_was_here: we no longer copy the (possibly modified) display mode to `vid` here
1412 // because complete modesetting failure isn't really what happens with SDL2.
1413 // Instead we update the active mode when we successfully apply settings,
1414 // if some can't be applied we still have a viable window.
1415 // Failure is still possible for other (non- display mode) reasons.
1416 vid.sRGB2D = vid_sRGB.integer >= 1 && vid.sRGBcapable2D;
1417 vid.sRGB3D = vid_sRGB.integer >= 1 && vid.sRGBcapable3D;
1419 switch(vid.renderpath)
1421 case RENDERPATH_GL32:
1425 qglGetBooleanv(GL_STEREO, &stereo);
1426 vid.mode.stereobuffer = stereo != 0;
1430 case RENDERPATH_GLES2:
1432 vid.mode.stereobuffer = false;
1437 (vid_sRGB_fallback.integer >= 3) // force fallback
1439 (vid_sRGB_fallback.integer >= 2 && // fallback if framebuffer is 8bit
1440 r_viewfbo.integer < 2)
1442 vid.sRGB2D = vid.sRGB3D = false;
1444 Con_Printf("Video Mode: %s%s %dx%d %dbpp%s%s on display %i\n",
1445 vid.mode.desktopfullscreen ? "desktop " : "",
1446 vid.mode.fullscreen ? "fullscreen" : "window",
1447 vid.mode.width, vid.mode.height, vid.mode.bitsperpixel,
1448 vid.mode.refreshrate ? va(vabuf, sizeof(vabuf), " %.2fhz", vid.mode.refreshrate) : "",
1449 vid.mode.stereobuffer ? " stereo" : "",
1452 if (vid_touchscreen.integer)
1454 in_windowmouse_x = vid_width.value / 2.f;
1455 in_windowmouse_y = vid_height.value / 2.f;
1464 qbool vid_commandlinecheck = true;
1465 extern qbool vid_opened;
1467 void VID_Restart_f(cmd_state_t *cmd)
1470 viddef_mode_t oldmode;
1472 // don't crash if video hasn't started yet
1473 if (vid_commandlinecheck)
1478 Con_Printf("VID_Restart: changing from %s%s %dx%d %dbpp%s%s on display %i, to %s%s %dx%d %dbpp%s%s on display %i.\n",
1479 oldmode.desktopfullscreen ? "desktop " : "",
1480 oldmode.fullscreen ? "fullscreen" : "window",
1481 oldmode.width, oldmode.height, oldmode.bitsperpixel,
1482 oldmode.refreshrate ? va(vabuf, sizeof(vabuf), " %.2fhz", oldmode.refreshrate) : "",
1483 oldmode.stereobuffer ? " stereo" : "",
1485 vid_desktopfullscreen.integer ? "desktop " : "",
1486 vid_fullscreen.integer ? "fullscreen" : "window",
1487 vid_width.integer, vid_height.integer, vid_bitsperpixel.integer,
1488 vid_fullscreen.integer && !vid_desktopfullscreen.integer && vid_refreshrate.integer ? va(vabuf, sizeof(vabuf), " %.2fhz", vid_refreshrate.value) : "",
1489 vid_stereobuffer.integer ? " stereo" : "",
1490 vid_display.integer);
1492 SCR_DeferLoadingPlaque(false);
1493 R_Modules_Shutdown();
1495 if (!VID_Mode(NULL))
1497 Con_Print(CON_ERROR "Video mode change failed\n");
1498 if (!VID_Mode(&oldmode))
1499 Sys_Error("Unable to restore to last working video mode");
1502 Cvar_SetValueQuick(&vid_display, oldmode.display);
1503 Cvar_SetValueQuick(&vid_fullscreen, oldmode.fullscreen);
1504 Cvar_SetValueQuick(&vid_desktopfullscreen, oldmode.desktopfullscreen);
1505 Cvar_SetValueQuick(&vid_width, oldmode.width);
1506 Cvar_SetValueQuick(&vid_height, oldmode.height);
1507 Cvar_SetValueQuick(&vid_bitsperpixel, oldmode.bitsperpixel);
1508 Cvar_SetValueQuick(&vid_refreshrate, oldmode.refreshrate);
1509 Cvar_SetValueQuick(&vid_stereobuffer, oldmode.stereobuffer);
1516 struct vidfallback_s
1519 const char *safevalue;
1521 static struct vidfallback_s vidfallbacks[] =
1523 {&vid_stereobuffer, "0"},
1524 {&vid_samples, "1"},
1525 {&vid_refreshrate, "0"},
1526 {&vid_width, "640"},
1527 {&vid_height, "480"},
1528 {&vid_bitsperpixel, "32"},
1532 // this is only called once by CL_StartVideo and again on each FS_GameDir_f
1533 void VID_Start(void)
1536 int width, height, success;
1537 if (vid_commandlinecheck)
1539 // interpret command-line parameters
1540 vid_commandlinecheck = false;
1541 // COMMANDLINEOPTION: Video: -window performs +vid_fullscreen 0
1542 if (Sys_CheckParm("-window") || Sys_CheckParm("-safe") || ((i = Sys_CheckParm("+vid_fullscreen")) != 0 && atoi(sys.argv[i+1]) == 0))
1543 Cvar_SetValueQuick(&vid_fullscreen, false);
1544 // COMMANDLINEOPTION: Video: -borderless performs +vid_borderless 1
1545 if (Sys_CheckParm("-borderless") || ((i = Sys_CheckParm("+vid_borderless")) != 0 && atoi(sys.argv[i+1]) == 1))
1547 Cvar_SetValueQuick(&vid_borderless, true);
1548 Cvar_SetValueQuick(&vid_fullscreen, false);
1550 // COMMANDLINEOPTION: Video: -fullscreen performs +vid_fullscreen 1
1551 if (Sys_CheckParm("-fullscreen") || ((i = Sys_CheckParm("+vid_fullscreen")) != 0 && atoi(sys.argv[i+1]) == 1))
1552 Cvar_SetValueQuick(&vid_fullscreen, true);
1555 // 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)
1556 if ((i = Sys_CheckParm("-width")) != 0 || ((i = Sys_CheckParm("+vid_width")) != 0))
1557 width = atoi(sys.argv[i+1]);
1558 // 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)
1559 if ((i = Sys_CheckParm("-height")) != 0 || ((i = Sys_CheckParm("+vid_height")) != 0))
1560 height = atoi(sys.argv[i+1]);
1562 width = height * 4 / 3;
1564 height = width * 3 / 4;
1566 Cvar_SetValueQuick(&vid_width, width);
1568 Cvar_SetValueQuick(&vid_height, height);
1569 // COMMANDLINEOPTION: Video: -density <multiplier> performs +vid_touchscreen_density <multiplier> (example -density 1 or -density 1.5)
1570 if ((i = Sys_CheckParm("-density")) != 0)
1571 Cvar_SetQuick(&vid_touchscreen_density, sys.argv[i+1]);
1572 // COMMANDLINEOPTION: Video: -xdpi <dpi> performs +vid_touchscreen_xdpi <dpi> (example -xdpi 160 or -xdpi 320)
1573 if ((i = Sys_CheckParm("-touchscreen_xdpi")) != 0)
1574 Cvar_SetQuick(&vid_touchscreen_xdpi, sys.argv[i+1]);
1575 // COMMANDLINEOPTION: Video: -ydpi <dpi> performs +vid_touchscreen_ydpi <dpi> (example -ydpi 160 or -ydpi 320)
1576 if ((i = Sys_CheckParm("-touchscreen_ydpi")) != 0)
1577 Cvar_SetQuick(&vid_touchscreen_ydpi, sys.argv[i+1]);
1580 success = VID_Mode(NULL);
1583 Con_Print(CON_WARN "Desired video mode fail, trying fallbacks...\n");
1584 for (i = 0; !success && vidfallbacks[i].cvar != NULL; i++)
1586 Cvar_SetQuick(vidfallbacks[i].cvar, vidfallbacks[i].safevalue);
1587 success = VID_Mode(NULL);
1590 Sys_Error("Video modes failed");
1597 static int VID_SortModes_Compare(const void *a_, const void *b_)
1599 vid_mode_t *a = (vid_mode_t *) a_;
1600 vid_mode_t *b = (vid_mode_t *) b_;
1601 if(a->width > b->width)
1603 if(a->width < b->width)
1605 if(a->height > b->height)
1607 if(a->height < b->height)
1609 if(a->refreshrate > b->refreshrate)
1611 if(a->refreshrate < b->refreshrate)
1617 if(a->pixelheight_num * b->pixelheight_denom > a->pixelheight_denom * b->pixelheight_num)
1619 if(a->pixelheight_num * b->pixelheight_denom < a->pixelheight_denom * b->pixelheight_num)
1623 size_t VID_SortModes(vid_mode_t *modes, size_t count, qbool usebpp, qbool userefreshrate, qbool useaspect)
1629 qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
1630 // 2. remove duplicates
1631 for(i = 0; i < count; ++i)
1633 if(modes[i].width && modes[i].height)
1637 if(modes[i].width != modes[i-1].width)
1639 if(modes[i].height != modes[i-1].height)
1642 if(modes[i].refreshrate != modes[i-1].refreshrate)
1645 if(modes[i].bpp != modes[i-1].bpp)
1648 if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
1651 // a dupe, or a bogus mode!
1653 memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i));
1654 --i; // check this index again, as mode i+1 is now here