7 // LordHavoc: these are only set in wgl
8 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
9 qboolean isRagePro = false; // LordHavoc: the ATI Rage Pro has limitations with per pixel alpha (the color scaler does not apply to per pixel alpha images...), although not as bad as a G200.
11 // AK FIXME -> input_dest
12 qboolean in_client_mouse = true;
14 // AK where should it be placed ?
15 float in_mouse_x, in_mouse_y;
17 // GL_ARB_multitexture
18 int gl_textureunits = 0;
19 // GL_ARB_texture_env_combine or GL_EXT_texture_env_combine
20 int gl_combine_extension = false;
21 // GL_EXT_compiled_vertex_array
22 int gl_supportslockarrays = false;
23 // GLX_SGI_video_sync or WGL_EXT_swap_control
24 int gl_videosyncavailable = false;
26 int gl_stencil = false;
27 // 3D textures available
28 int gl_texture3d = false;
29 // GL_ARB_texture_cubemap
30 int gl_texturecubemap = false;
31 // GL_ARB_texture_env_dot3
32 int gl_dot3arb = false;
33 // GL_SGIS_texture_edge_clamp
34 int gl_support_clamptoedge = false;
35 // GL_NV_vertex_array_range
36 int gl_support_var = false;
37 // GL_NV_vertex_array_range2
38 int gl_support_var2 = false;
39 // GL_EXT_texture_filter_anisotropic
40 int gl_support_anisotropy = false;
41 // GL_NV_texture_shader
42 int gl_textureshader = false;
43 // GL_EXT_stencil_two_side
44 int gl_support_stenciltwoside = false;
46 // LordHavoc: if window is hidden, don't update screen
47 int vid_hidden = true;
48 // LordHavoc: if window is not the active window, don't hog as much CPU time,
49 // let go of the mouse, turn off sound, and restore system gamma ramps...
50 int vid_activewindow = true;
52 // we don't know until we try it!
53 cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1"};
54 // whether hardware gamma ramps are currently in effect
55 int vid_usinghwgamma = false;
57 unsigned short vid_gammaramps[768];
58 unsigned short vid_systemgammaramps[768];
60 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
61 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
62 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
63 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"};
65 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
66 cvar_t gl_combine = {CVAR_SAVE, "gl_combine", "1"};
68 cvar_t in_pitch_min = {0, "in_pitch_min", "-70"};
69 cvar_t in_pitch_max = {0, "in_pitch_max", "80"};
71 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
73 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
74 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"};
75 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"};
76 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0"};
77 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0"};
78 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0"};
79 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0"};
80 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5"};
81 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5"};
82 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5"};
83 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1"};
84 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1"};
85 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1"};
86 cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "1"};
87 cvar_t v_psycho = {0, "v_psycho", "0"};
89 // brand of graphics chip
90 const char *gl_vendor;
91 // graphics chip model and other information
92 const char *gl_renderer;
93 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
94 const char *gl_version;
95 // extensions list, space separated
96 const char *gl_extensions;
98 const char *gl_platform;
99 // another extensions list, containing platform-specific extensions that are
100 // not in the main list
101 const char *gl_platformextensions;
102 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
105 // GL_ARB_multitexture
106 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
107 void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
108 void (GLAPIENTRY *qglActiveTexture) (GLenum);
109 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
111 // GL_EXT_compiled_vertex_array
112 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
113 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
115 //GL_NV_vertex_array_range
116 GLvoid *(GLAPIENTRY *qglAllocateMemoryNV)(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority);
117 GLvoid (GLAPIENTRY *qglFreeMemoryNV)(GLvoid *pointer);
118 GLvoid (GLAPIENTRY *qglVertexArrayRangeNV)(GLsizei length, GLvoid *pointer);
119 GLvoid (GLAPIENTRY *qglFlushVertexArrayRangeNV)(GLvoid);
121 // general GL functions
123 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
125 void (GLAPIENTRY *qglClear)(GLbitfield mask);
127 void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
128 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
129 void (GLAPIENTRY *qglCullFace)(GLenum mode);
131 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
132 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
133 void (GLAPIENTRY *qglEnable)(GLenum cap);
134 void (GLAPIENTRY *qglDisable)(GLenum cap);
135 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
137 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
138 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
140 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
141 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
142 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
143 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
145 GLenum (GLAPIENTRY *qglGetError)(void);
146 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
147 void (GLAPIENTRY *qglFinish)(void);
148 void (GLAPIENTRY *qglFlush)(void);
150 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
151 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
152 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
153 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
154 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
156 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
157 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
158 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
159 void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
160 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
161 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
162 void (GLAPIENTRY *qglArrayElement)(GLint i);
164 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
165 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
166 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
167 void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
168 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
169 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
170 void (GLAPIENTRY *qglBegin)(GLenum mode);
171 void (GLAPIENTRY *qglEnd)(void);
173 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
174 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
175 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
176 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
177 void (GLAPIENTRY *qglPushMatrix)(void);
178 void (GLAPIENTRY *qglPopMatrix)(void);
179 void (GLAPIENTRY *qglLoadIdentity)(void);
180 void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
181 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
182 void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
183 void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
184 void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
185 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
186 void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
187 void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
188 void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
189 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
191 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
193 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
194 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
195 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
196 void (GLAPIENTRY *qglClearStencil)(GLint s);
198 void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
199 void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
200 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
201 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
202 void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
203 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
205 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
206 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
207 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
208 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
209 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
210 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
211 void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
212 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
214 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
215 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
216 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
217 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
218 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
219 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
220 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
221 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
224 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
226 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
228 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
229 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);
230 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
232 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
234 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
236 void (GLAPIENTRY *qglActiveStencilFaceEXT)(GLenum);
238 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
241 const dllfunction_t *func;
243 Con_DPrintf("checking for %s... ", name);
245 for (func = funcs;func && func->name;func++)
246 *func->funcvariable = NULL;
248 if (disableparm && (COM_CheckParm(disableparm) || COM_CheckParm("-safe")))
250 Con_DPrint("disabled by commandline\n");
254 if (strstr(gl_extensions, name) || strstr(gl_platformextensions, name) || (strncmp(name, "GL_", 3) && strncmp(name, "WGL_", 4) && strncmp(name, "GLX_", 4) && strncmp(name, "AGL_", 4)))
256 for (func = funcs;func && func->name != NULL;func++)
258 // functions are cleared before all the extensions are evaluated
259 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
262 Con_Printf("OpenGL extension \"%s\" is missing function \"%s\" - broken driver!\n", name, func->name);
266 // delay the return so it prints all missing functions
269 Con_DPrint("enabled\n");
274 Con_DPrint("not detected\n");
279 static dllfunction_t opengl110funcs[] =
281 {"glClearColor", (void **) &qglClearColor},
282 {"glClear", (void **) &qglClear},
283 {"glAlphaFunc", (void **) &qglAlphaFunc},
284 {"glBlendFunc", (void **) &qglBlendFunc},
285 {"glCullFace", (void **) &qglCullFace},
286 {"glDrawBuffer", (void **) &qglDrawBuffer},
287 {"glReadBuffer", (void **) &qglReadBuffer},
288 {"glEnable", (void **) &qglEnable},
289 {"glDisable", (void **) &qglDisable},
290 {"glIsEnabled", (void **) &qglIsEnabled},
291 {"glEnableClientState", (void **) &qglEnableClientState},
292 {"glDisableClientState", (void **) &qglDisableClientState},
293 {"glGetBooleanv", (void **) &qglGetBooleanv},
294 {"glGetDoublev", (void **) &qglGetDoublev},
295 {"glGetFloatv", (void **) &qglGetFloatv},
296 {"glGetIntegerv", (void **) &qglGetIntegerv},
297 {"glGetError", (void **) &qglGetError},
298 {"glGetString", (void **) &qglGetString},
299 {"glFinish", (void **) &qglFinish},
300 {"glFlush", (void **) &qglFlush},
301 {"glClearDepth", (void **) &qglClearDepth},
302 {"glDepthFunc", (void **) &qglDepthFunc},
303 {"glDepthMask", (void **) &qglDepthMask},
304 {"glDepthRange", (void **) &qglDepthRange},
305 {"glDrawElements", (void **) &qglDrawElements},
306 {"glColorMask", (void **) &qglColorMask},
307 {"glVertexPointer", (void **) &qglVertexPointer},
308 {"glNormalPointer", (void **) &qglNormalPointer},
309 {"glColorPointer", (void **) &qglColorPointer},
310 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
311 {"glArrayElement", (void **) &qglArrayElement},
312 {"glColor4f", (void **) &qglColor4f},
313 {"glTexCoord2f", (void **) &qglTexCoord2f},
314 {"glTexCoord3f", (void **) &qglTexCoord3f},
315 {"glVertex2f", (void **) &qglVertex2f},
316 {"glVertex3f", (void **) &qglVertex3f},
317 {"glBegin", (void **) &qglBegin},
318 {"glEnd", (void **) &qglEnd},
319 {"glMatrixMode", (void **) &qglMatrixMode},
320 {"glOrtho", (void **) &qglOrtho},
321 {"glFrustum", (void **) &qglFrustum},
322 {"glViewport", (void **) &qglViewport},
323 {"glPushMatrix", (void **) &qglPushMatrix},
324 {"glPopMatrix", (void **) &qglPopMatrix},
325 {"glLoadIdentity", (void **) &qglLoadIdentity},
326 {"glLoadMatrixd", (void **) &qglLoadMatrixd},
327 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
328 {"glMultMatrixd", (void **) &qglMultMatrixd},
329 {"glMultMatrixf", (void **) &qglMultMatrixf},
330 {"glRotated", (void **) &qglRotated},
331 {"glRotatef", (void **) &qglRotatef},
332 {"glScaled", (void **) &qglScaled},
333 {"glScalef", (void **) &qglScalef},
334 {"glTranslated", (void **) &qglTranslated},
335 {"glTranslatef", (void **) &qglTranslatef},
336 {"glReadPixels", (void **) &qglReadPixels},
337 {"glStencilFunc", (void **) &qglStencilFunc},
338 {"glStencilMask", (void **) &qglStencilMask},
339 {"glStencilOp", (void **) &qglStencilOp},
340 {"glClearStencil", (void **) &qglClearStencil},
341 {"glTexEnvf", (void **) &qglTexEnvf},
342 {"glTexEnvfv", (void **) &qglTexEnvfv},
343 {"glTexEnvi", (void **) &qglTexEnvi},
344 {"glTexParameterf", (void **) &qglTexParameterf},
345 {"glTexParameterfv", (void **) &qglTexParameterfv},
346 {"glTexParameteri", (void **) &qglTexParameteri},
347 {"glPixelStoref", (void **) &qglPixelStoref},
348 {"glPixelStorei", (void **) &qglPixelStorei},
349 {"glGenTextures", (void **) &qglGenTextures},
350 {"glDeleteTextures", (void **) &qglDeleteTextures},
351 {"glBindTexture", (void **) &qglBindTexture},
352 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
353 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
354 {"glIsTexture", (void **) &qglIsTexture},
355 {"glTexImage1D", (void **) &qglTexImage1D},
356 {"glTexImage2D", (void **) &qglTexImage2D},
357 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
358 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
359 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
360 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
361 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
362 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
363 {"glScissor", (void **) &qglScissor},
364 {"glPolygonOffset", (void **) &qglPolygonOffset},
368 static dllfunction_t drawrangeelementsfuncs[] =
370 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
374 static dllfunction_t drawrangeelementsextfuncs[] =
376 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
380 static dllfunction_t multitexturefuncs[] =
382 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
383 {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
384 {"glActiveTextureARB", (void **) &qglActiveTexture},
385 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
389 static dllfunction_t compiledvertexarrayfuncs[] =
391 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
392 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
396 static dllfunction_t texture3dextfuncs[] =
398 {"glTexImage3DEXT", (void **) &qglTexImage3D},
399 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
400 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
404 static dllfunction_t glxvarfuncs[] =
406 {"glXAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
407 {"glXFreeMemoryNV", (void **) &qglFreeMemoryNV},
408 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
409 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
413 static dllfunction_t wglvarfuncs[] =
415 {"wglAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
416 {"wglFreeMemoryNV", (void **) &qglFreeMemoryNV},
417 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
418 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
422 static dllfunction_t stenciltwosidefuncs[] =
424 {"glActiveStencilFaceEXT", (void **) &qglActiveStencilFaceEXT},
429 void VID_CheckExtensions(void)
431 gl_stencil = vid_bitsperpixel.integer == 32;
432 gl_combine_extension = false;
434 gl_supportslockarrays = false;
436 gl_support_clamptoedge = false;
437 gl_support_var = false;
438 gl_support_var2 = false;
439 gl_support_stenciltwoside = false;
441 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
442 Sys_Error("OpenGL 1.1.0 functions not found\n");
444 Con_DPrintf("GL_VENDOR: %s\n", gl_vendor);
445 Con_DPrintf("GL_RENDERER: %s\n", gl_renderer);
446 Con_DPrintf("GL_VERSION: %s\n", gl_version);
447 Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
448 Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
450 Con_DPrint("Checking OpenGL extensions...\n");
452 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
453 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
455 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
457 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
458 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
459 if (gl_combine_extension)
460 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
463 gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
464 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
465 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
466 gl_support_clamptoedge = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
468 if (!strcmp(gl_platform, "GLX"))
469 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", glxvarfuncs, "-novar", false);
470 else if (!strcmp(gl_platform, "WGL"))
471 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", wglvarfuncs, "-novar", false);
473 gl_support_var2 = GL_CheckExtension("GL_NV_vertex_array_range2", NULL, "-novar2", false);
475 gl_support_anisotropy = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false);
477 gl_textureshader = GL_CheckExtension("GL_NV_texture_shader", NULL, "-notextureshader", false);
479 gl_support_stenciltwoside = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false);
481 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
482 if (qglDrawRangeElements == NULL)
483 qglDrawRangeElements = qglDrawRangeElementsEXT;
486 int vid_vertexarrays_are_var = false;
487 void *VID_AllocVertexArrays(mempool_t *pool, int size, int fast, float readfrequency, float writefrequency, float priority)
490 vid_vertexarrays_are_var = false;
491 if (fast && qglAllocateMemoryNV)
494 m = qglAllocateMemoryNV(size, readfrequency, writefrequency, priority);
498 vid_vertexarrays_are_var = true;
502 return Mem_Alloc(pool, size);
505 void VID_FreeVertexArrays(void *pointer)
507 if (vid_vertexarrays_are_var)
510 qglFreeMemoryNV(pointer);
515 vid_vertexarrays_are_var = false;
518 void Force_CenterView_f (void)
520 cl.viewangles[PITCH] = 0;
523 void IN_PreMove(void)
527 void CL_AdjustAngles(void);
528 void IN_PostMove(void)
530 // clamp after the move as well to prevent messed up rendering angles
539 void IN_ProcessMove(usercmd_t *cmd)
541 // get basic movement from keyboard
544 // OS independent code
547 // allow mice or other external controllers to add to the move
550 // OS independent code
555 void IN_Mouse(usercmd_t *cmd, float mx, float my)
557 int mouselook = (in_mlook.state & 1) || freelook.integer;
558 float mouse_x, mouse_y;
559 static float old_mouse_x = 0, old_mouse_y = 0;
561 if (m_filter.integer)
563 mouse_x = (mx + old_mouse_x) * 0.5;
564 mouse_y = (my + old_mouse_y) * 0.5;
575 in_mouse_x = (float) mouse_x * vid.conwidth / vid.realwidth;
576 in_mouse_y = (float) mouse_y * vid.conheight / vid.realheight;
578 // AK: eveything else is client stuff
579 // BTW, this should be seperated somewhen
583 // LordHavoc: viewzoom affects mouse sensitivity for sniping
584 mouse_x *= sensitivity.value * cl.viewzoom;
585 mouse_y *= sensitivity.value * cl.viewzoom;
587 // Add mouse X/Y movement to cmd
588 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
589 cmd->sidemove += m_side.value * mouse_x;
591 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
596 if (mouselook && !(in_strafe.state & 1))
597 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
600 if ((in_strafe.state & 1) && noclip_anglehack)
601 cmd->upmove -= m_forward.value * mouse_y;
603 cmd->forwardmove -= m_forward.value * mouse_y;
607 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
608 static int cachecolorenable, cachehwgamma;
609 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
610 void VID_UpdateGamma(qboolean force)
614 static int forcenextframe = false;
616 // LordHavoc: don't mess with gamma tables if running dedicated
617 if (cls.state == ca_dedicated)
623 && vid_usinghwgamma == (vid_activewindow && v_hwgamma.integer)
624 && v_gamma.value == cachegamma
625 && v_contrast.value == cachecontrast
626 && v_brightness.value == cachebrightness
627 && cachecolorenable == v_color_enable.integer
628 && cacheblack[0] == v_color_black_r.value
629 && cacheblack[1] == v_color_black_g.value
630 && cacheblack[2] == v_color_black_b.value
631 && cachegrey[0] == v_color_grey_r.value
632 && cachegrey[1] == v_color_grey_g.value
633 && cachegrey[2] == v_color_grey_b.value
634 && cachewhite[0] == v_color_white_r.value
635 && cachewhite[1] == v_color_white_g.value
636 && cachewhite[2] == v_color_white_b.value)
639 forcenextframe = false;
641 if (vid_activewindow && v_hwgamma.integer)
643 if (!vid_usinghwgamma)
645 vid_usinghwgamma = true;
646 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_GetGamma(vid_systemgammaramps));
649 BOUNDCVAR(v_gamma, 0.1, 5);cachegamma = v_gamma.value;
650 BOUNDCVAR(v_contrast, 1, 5);cachecontrast = v_contrast.value;
651 BOUNDCVAR(v_brightness, 0, 0.8);cachebrightness = v_brightness.value;
652 BOUNDCVAR(v_color_black_r, 0, 0.8);cacheblack[0] = v_color_black_r.value;
653 BOUNDCVAR(v_color_black_g, 0, 0.8);cacheblack[1] = v_color_black_g.value;
654 BOUNDCVAR(v_color_black_b, 0, 0.8);cacheblack[2] = v_color_black_b.value;
655 BOUNDCVAR(v_color_grey_r, 0, 0.95);cachegrey[0] = v_color_grey_r.value;
656 BOUNDCVAR(v_color_grey_g, 0, 0.95);cachegrey[1] = v_color_grey_g.value;
657 BOUNDCVAR(v_color_grey_b, 0, 0.95);cachegrey[2] = v_color_grey_b.value;
658 BOUNDCVAR(v_color_white_r, 1, 5);cachewhite[0] = v_color_white_r.value;
659 BOUNDCVAR(v_color_white_g, 1, 5);cachewhite[1] = v_color_white_g.value;
660 BOUNDCVAR(v_color_white_b, 1, 5);cachewhite[2] = v_color_white_b.value;
661 cachecolorenable = v_color_enable.integer;
662 cachehwgamma = v_hwgamma.integer;
664 if (cachecolorenable)
666 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps);
667 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + 256);
668 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + 512);
672 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps);
673 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 256);
674 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 512);
677 // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
678 // immensely butchered it to work with variable framerates and fit in with
679 // the rest of darkplaces.
680 if (v_psycho.integer)
684 static float n[3], nd[3], nt[3];
685 static int init = true;
686 unsigned short *ramp;
687 forcenextframe = true;
691 for (x = 0;x < 3;x++)
693 n[x] = lhrandom(0, 1);
694 nd[x] = (rand()&1)?-0.25:0.25;
695 nt[x] = lhrandom(1, 8.2);
699 for (x = 0;x < 3;x++)
701 nt[x] -= host_realframetime;
705 nt[x] += lhrandom(1, 8.2);
707 n[x] += nd[x] * host_realframetime;
711 for (x = 0, ramp = vid_gammaramps;x < 3;x++)
712 for (y = 0, t = n[x] - 0.75f;y < 256;y++, t += 0.75f * (2.0f / 256.0f))
713 *ramp++ = cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f;
716 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps));
720 if (vid_usinghwgamma)
722 vid_usinghwgamma = false;
723 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps));
728 void VID_RestoreSystemGamma(void)
730 if (vid_usinghwgamma)
732 vid_usinghwgamma = false;
733 VID_SetGamma(vid_systemgammaramps);
737 void VID_Shared_Init(void)
739 Cvar_RegisterVariable(&vid_hardwaregammasupported);
740 Cvar_RegisterVariable(&v_gamma);
741 Cvar_RegisterVariable(&v_brightness);
742 Cvar_RegisterVariable(&v_contrast);
744 Cvar_RegisterVariable(&v_color_enable);
745 Cvar_RegisterVariable(&v_color_black_r);
746 Cvar_RegisterVariable(&v_color_black_g);
747 Cvar_RegisterVariable(&v_color_black_b);
748 Cvar_RegisterVariable(&v_color_grey_r);
749 Cvar_RegisterVariable(&v_color_grey_g);
750 Cvar_RegisterVariable(&v_color_grey_b);
751 Cvar_RegisterVariable(&v_color_white_r);
752 Cvar_RegisterVariable(&v_color_white_g);
753 Cvar_RegisterVariable(&v_color_white_b);
755 Cvar_RegisterVariable(&v_hwgamma);
757 Cvar_RegisterVariable(&v_psycho);
759 Cvar_RegisterVariable(&vid_fullscreen);
760 Cvar_RegisterVariable(&vid_width);
761 Cvar_RegisterVariable(&vid_height);
762 Cvar_RegisterVariable(&vid_bitsperpixel);
763 Cvar_RegisterVariable(&vid_mouse);
764 Cvar_RegisterVariable(&gl_combine);
765 Cvar_RegisterVariable(&in_pitch_min);
766 Cvar_RegisterVariable(&in_pitch_max);
767 Cvar_RegisterVariable(&m_filter);
768 Cmd_AddCommand("force_centerview", Force_CenterView_f);
769 Cmd_AddCommand("vid_restart", VID_Restart_f);
770 if (gamemode == GAME_GOODVSBAD2)
771 Cvar_Set("gl_combine", "0");
774 int current_vid_fullscreen;
775 int current_vid_width;
776 int current_vid_height;
777 int current_vid_bitsperpixel;
778 int VID_Mode(int fullscreen, int width, int height, int bpp)
780 Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp);
781 if (VID_InitMode(fullscreen, width, height, bpp))
783 current_vid_fullscreen = fullscreen;
784 current_vid_width = width;
785 current_vid_height = height;
786 current_vid_bitsperpixel = bpp;
787 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
788 Cvar_SetValueQuick(&vid_width, width);
789 Cvar_SetValueQuick(&vid_height, height);
790 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
797 static void VID_OpenSystems(void)
804 static void VID_CloseSystems(void)
808 R_Modules_Shutdown();
811 int vid_commandlinecheck = true;
813 void VID_Restart_f(void)
815 // don't crash if video hasn't started yet
816 if (vid_commandlinecheck)
819 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n",
820 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel,
821 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
823 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
825 Con_Print("Video mode change failed\n");
826 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel))
827 Sys_Error("Unable to restore to last working video mode\n");
834 int i, width, height, success;
835 if (vid_commandlinecheck)
837 // interpret command-line parameters
838 vid_commandlinecheck = false;
839 if (COM_CheckParm("-window") || COM_CheckParm("-safe"))
840 Cvar_SetValueQuick(&vid_fullscreen, false);
841 if (COM_CheckParm("-fullscreen"))
842 Cvar_SetValueQuick(&vid_fullscreen, true);
845 if ((i = COM_CheckParm("-width")) != 0)
846 width = atoi(com_argv[i+1]);
847 if ((i = COM_CheckParm("-height")) != 0)
848 height = atoi(com_argv[i+1]);
850 width = height * 4 / 3;
852 height = width * 3 / 4;
854 Cvar_SetValueQuick(&vid_width, width);
856 Cvar_SetValueQuick(&vid_height, height);
857 if ((i = COM_CheckParm("-bpp")) != 0)
858 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
861 Con_DPrint("Starting video system\n");
862 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
865 Con_Print("Desired video mode fail, trying fallbacks...\n");
866 if (!success && vid_bitsperpixel.integer > 16)
867 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, 16);
868 if (!success && (vid_width.integer > 640 || vid_height.integer > 480))
869 success = VID_Mode(vid_fullscreen.integer, 640, 480, 16);
870 if (!success && vid_fullscreen.integer)
871 success = VID_Mode(false, 640, 480, 16);
873 Sys_Error("Video modes failed\n");