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 = 1;
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 int gl_max_anisotropy = 1;
42 // GL_NV_texture_shader
43 int gl_textureshader = false;
44 // GL_EXT_stencil_two_side
45 int gl_support_stenciltwoside = false;
47 // LordHavoc: if window is hidden, don't update screen
48 int vid_hidden = true;
49 // LordHavoc: if window is not the active window, don't hog as much CPU time,
50 // let go of the mouse, turn off sound, and restore system gamma ramps...
51 int vid_activewindow = true;
53 // we don't know until we try it!
54 cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1"};
55 // whether hardware gamma ramps are currently in effect
56 int vid_usinghwgamma = false;
58 unsigned short vid_gammaramps[768];
59 unsigned short vid_systemgammaramps[768];
61 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
62 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
63 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
64 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"};
66 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
67 cvar_t gl_combine = {CVAR_SAVE, "gl_combine", "1"};
69 cvar_t in_pitch_min = {0, "in_pitch_min", "-70"};
70 cvar_t in_pitch_max = {0, "in_pitch_max", "80"};
72 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
74 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
75 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"};
76 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"};
77 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0"};
78 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0"};
79 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0"};
80 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0"};
81 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5"};
82 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5"};
83 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5"};
84 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1"};
85 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1"};
86 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1"};
87 cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "1"};
88 cvar_t v_psycho = {0, "v_psycho", "0"};
90 // brand of graphics chip
91 const char *gl_vendor;
92 // graphics chip model and other information
93 const char *gl_renderer;
94 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
95 const char *gl_version;
96 // extensions list, space separated
97 const char *gl_extensions;
99 const char *gl_platform;
100 // another extensions list, containing platform-specific extensions that are
101 // not in the main list
102 const char *gl_platformextensions;
103 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
106 // GL_ARB_multitexture
107 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
108 void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
109 void (GLAPIENTRY *qglActiveTexture) (GLenum);
110 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
112 // GL_EXT_compiled_vertex_array
113 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
114 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
116 //GL_NV_vertex_array_range
117 GLvoid *(GLAPIENTRY *qglAllocateMemoryNV)(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority);
118 GLvoid (GLAPIENTRY *qglFreeMemoryNV)(GLvoid *pointer);
119 GLvoid (GLAPIENTRY *qglVertexArrayRangeNV)(GLsizei length, GLvoid *pointer);
120 GLvoid (GLAPIENTRY *qglFlushVertexArrayRangeNV)(GLvoid);
122 // general GL functions
124 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
126 void (GLAPIENTRY *qglClear)(GLbitfield mask);
128 void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
129 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
130 void (GLAPIENTRY *qglCullFace)(GLenum mode);
132 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
133 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
134 void (GLAPIENTRY *qglEnable)(GLenum cap);
135 void (GLAPIENTRY *qglDisable)(GLenum cap);
136 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
138 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
139 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
141 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
142 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
143 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
144 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
146 GLenum (GLAPIENTRY *qglGetError)(void);
147 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
148 void (GLAPIENTRY *qglFinish)(void);
149 void (GLAPIENTRY *qglFlush)(void);
151 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
152 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
153 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
154 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
155 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
157 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
158 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
159 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
160 void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
161 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
162 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
163 void (GLAPIENTRY *qglArrayElement)(GLint i);
165 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
166 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
167 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
168 void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
169 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
170 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
171 void (GLAPIENTRY *qglBegin)(GLenum mode);
172 void (GLAPIENTRY *qglEnd)(void);
174 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
175 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
176 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
177 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
178 void (GLAPIENTRY *qglPushMatrix)(void);
179 void (GLAPIENTRY *qglPopMatrix)(void);
180 void (GLAPIENTRY *qglLoadIdentity)(void);
181 void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
182 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
183 void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
184 void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
185 void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
186 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
187 void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
188 void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
189 void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
190 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
192 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
194 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
195 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
196 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
197 void (GLAPIENTRY *qglClearStencil)(GLint s);
199 void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
200 void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
201 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
202 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
203 void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
204 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
206 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
207 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
208 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
209 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
210 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
211 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
212 void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
213 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
215 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
216 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
217 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
218 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
219 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
220 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
221 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
222 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
225 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
227 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
229 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
230 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);
231 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
233 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
235 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
237 void (GLAPIENTRY *qglActiveStencilFaceEXT)(GLenum);
239 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
242 const dllfunction_t *func;
244 Con_DPrintf("checking for %s... ", name);
246 for (func = funcs;func && func->name;func++)
247 *func->funcvariable = NULL;
249 if (disableparm && (COM_CheckParm(disableparm) || COM_CheckParm("-safe")))
251 Con_DPrint("disabled by commandline\n");
255 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)))
257 for (func = funcs;func && func->name != NULL;func++)
259 // functions are cleared before all the extensions are evaluated
260 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
263 Con_Printf("OpenGL extension \"%s\" is missing function \"%s\" - broken driver!\n", name, func->name);
267 // delay the return so it prints all missing functions
270 Con_DPrint("enabled\n");
275 Con_DPrint("not detected\n");
280 static dllfunction_t opengl110funcs[] =
282 {"glClearColor", (void **) &qglClearColor},
283 {"glClear", (void **) &qglClear},
284 {"glAlphaFunc", (void **) &qglAlphaFunc},
285 {"glBlendFunc", (void **) &qglBlendFunc},
286 {"glCullFace", (void **) &qglCullFace},
287 {"glDrawBuffer", (void **) &qglDrawBuffer},
288 {"glReadBuffer", (void **) &qglReadBuffer},
289 {"glEnable", (void **) &qglEnable},
290 {"glDisable", (void **) &qglDisable},
291 {"glIsEnabled", (void **) &qglIsEnabled},
292 {"glEnableClientState", (void **) &qglEnableClientState},
293 {"glDisableClientState", (void **) &qglDisableClientState},
294 {"glGetBooleanv", (void **) &qglGetBooleanv},
295 {"glGetDoublev", (void **) &qglGetDoublev},
296 {"glGetFloatv", (void **) &qglGetFloatv},
297 {"glGetIntegerv", (void **) &qglGetIntegerv},
298 {"glGetError", (void **) &qglGetError},
299 {"glGetString", (void **) &qglGetString},
300 {"glFinish", (void **) &qglFinish},
301 {"glFlush", (void **) &qglFlush},
302 {"glClearDepth", (void **) &qglClearDepth},
303 {"glDepthFunc", (void **) &qglDepthFunc},
304 {"glDepthMask", (void **) &qglDepthMask},
305 {"glDepthRange", (void **) &qglDepthRange},
306 {"glDrawElements", (void **) &qglDrawElements},
307 {"glColorMask", (void **) &qglColorMask},
308 {"glVertexPointer", (void **) &qglVertexPointer},
309 {"glNormalPointer", (void **) &qglNormalPointer},
310 {"glColorPointer", (void **) &qglColorPointer},
311 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
312 {"glArrayElement", (void **) &qglArrayElement},
313 {"glColor4f", (void **) &qglColor4f},
314 {"glTexCoord2f", (void **) &qglTexCoord2f},
315 {"glTexCoord3f", (void **) &qglTexCoord3f},
316 {"glVertex2f", (void **) &qglVertex2f},
317 {"glVertex3f", (void **) &qglVertex3f},
318 {"glBegin", (void **) &qglBegin},
319 {"glEnd", (void **) &qglEnd},
320 {"glMatrixMode", (void **) &qglMatrixMode},
321 {"glOrtho", (void **) &qglOrtho},
322 {"glFrustum", (void **) &qglFrustum},
323 {"glViewport", (void **) &qglViewport},
324 {"glPushMatrix", (void **) &qglPushMatrix},
325 {"glPopMatrix", (void **) &qglPopMatrix},
326 {"glLoadIdentity", (void **) &qglLoadIdentity},
327 {"glLoadMatrixd", (void **) &qglLoadMatrixd},
328 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
329 {"glMultMatrixd", (void **) &qglMultMatrixd},
330 {"glMultMatrixf", (void **) &qglMultMatrixf},
331 {"glRotated", (void **) &qglRotated},
332 {"glRotatef", (void **) &qglRotatef},
333 {"glScaled", (void **) &qglScaled},
334 {"glScalef", (void **) &qglScalef},
335 {"glTranslated", (void **) &qglTranslated},
336 {"glTranslatef", (void **) &qglTranslatef},
337 {"glReadPixels", (void **) &qglReadPixels},
338 {"glStencilFunc", (void **) &qglStencilFunc},
339 {"glStencilMask", (void **) &qglStencilMask},
340 {"glStencilOp", (void **) &qglStencilOp},
341 {"glClearStencil", (void **) &qglClearStencil},
342 {"glTexEnvf", (void **) &qglTexEnvf},
343 {"glTexEnvfv", (void **) &qglTexEnvfv},
344 {"glTexEnvi", (void **) &qglTexEnvi},
345 {"glTexParameterf", (void **) &qglTexParameterf},
346 {"glTexParameterfv", (void **) &qglTexParameterfv},
347 {"glTexParameteri", (void **) &qglTexParameteri},
348 {"glPixelStoref", (void **) &qglPixelStoref},
349 {"glPixelStorei", (void **) &qglPixelStorei},
350 {"glGenTextures", (void **) &qglGenTextures},
351 {"glDeleteTextures", (void **) &qglDeleteTextures},
352 {"glBindTexture", (void **) &qglBindTexture},
353 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
354 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
355 {"glIsTexture", (void **) &qglIsTexture},
356 {"glTexImage1D", (void **) &qglTexImage1D},
357 {"glTexImage2D", (void **) &qglTexImage2D},
358 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
359 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
360 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
361 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
362 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
363 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
364 {"glScissor", (void **) &qglScissor},
365 {"glPolygonOffset", (void **) &qglPolygonOffset},
369 static dllfunction_t drawrangeelementsfuncs[] =
371 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
375 static dllfunction_t drawrangeelementsextfuncs[] =
377 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
381 static dllfunction_t multitexturefuncs[] =
383 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
384 {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
385 {"glActiveTextureARB", (void **) &qglActiveTexture},
386 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
390 static dllfunction_t compiledvertexarrayfuncs[] =
392 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
393 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
397 static dllfunction_t texture3dextfuncs[] =
399 {"glTexImage3DEXT", (void **) &qglTexImage3D},
400 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
401 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
405 static dllfunction_t glxvarfuncs[] =
407 {"glXAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
408 {"glXFreeMemoryNV", (void **) &qglFreeMemoryNV},
409 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
410 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
414 static dllfunction_t wglvarfuncs[] =
416 {"wglAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
417 {"wglFreeMemoryNV", (void **) &qglFreeMemoryNV},
418 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
419 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
423 static dllfunction_t stenciltwosidefuncs[] =
425 {"glActiveStencilFaceEXT", (void **) &qglActiveStencilFaceEXT},
430 void VID_CheckExtensions(void)
432 gl_stencil = vid_bitsperpixel.integer == 32;
434 // reset all the gl extension variables here
435 // this should match the declarations
437 gl_combine_extension = false;
438 gl_supportslockarrays = false;
439 gl_videosyncavailable = false;
441 gl_texture3d = false;
442 gl_texturecubemap = false;
444 gl_support_clamptoedge = false;
445 gl_support_var = false;
446 gl_support_var2 = false;
447 gl_support_anisotropy = false;
448 gl_max_anisotropy = 1;
449 gl_textureshader = false;
450 gl_support_stenciltwoside = false;
452 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
453 Sys_Error("OpenGL 1.1.0 functions not found\n");
455 Con_DPrintf("GL_VENDOR: %s\n", gl_vendor);
456 Con_DPrintf("GL_RENDERER: %s\n", gl_renderer);
457 Con_DPrintf("GL_VERSION: %s\n", gl_version);
458 Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
459 Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
461 Con_DPrint("Checking OpenGL extensions...\n");
463 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
464 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
466 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
468 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
469 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
470 if (gl_combine_extension)
471 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
474 gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
475 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
476 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
477 gl_support_clamptoedge = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
479 if (!strcmp(gl_platform, "GLX"))
480 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", glxvarfuncs, "-novar", false);
481 else if (!strcmp(gl_platform, "WGL"))
482 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", wglvarfuncs, "-novar", false);
484 gl_support_var2 = GL_CheckExtension("GL_NV_vertex_array_range2", NULL, "-novar2", false);
486 if ((gl_support_anisotropy = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false)))
487 qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max_anisotropy);
489 gl_textureshader = GL_CheckExtension("GL_NV_texture_shader", NULL, "-notextureshader", false);
491 gl_support_stenciltwoside = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false);
493 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
494 if (qglDrawRangeElements == NULL)
495 qglDrawRangeElements = qglDrawRangeElementsEXT;
498 int vid_vertexarrays_are_var = false;
499 void *VID_AllocVertexArrays(mempool_t *pool, int size, int fast, float readfrequency, float writefrequency, float priority)
502 vid_vertexarrays_are_var = false;
503 if (fast && qglAllocateMemoryNV)
506 m = qglAllocateMemoryNV(size, readfrequency, writefrequency, priority);
510 vid_vertexarrays_are_var = true;
514 return Mem_Alloc(pool, size);
517 void VID_FreeVertexArrays(void *pointer)
519 if (vid_vertexarrays_are_var)
522 qglFreeMemoryNV(pointer);
527 vid_vertexarrays_are_var = false;
530 void Force_CenterView_f (void)
532 cl.viewangles[PITCH] = 0;
535 void IN_PreMove(void)
539 void CL_AdjustAngles(void);
540 void IN_PostMove(void)
542 // clamp after the move as well to prevent messed up rendering angles
551 void IN_ProcessMove(usercmd_t *cmd)
553 // get basic movement from keyboard
556 // OS independent code
559 // allow mice or other external controllers to add to the move
562 // OS independent code
567 void IN_Mouse(usercmd_t *cmd, float mx, float my)
569 int mouselook = (in_mlook.state & 1) || freelook.integer;
570 float mouse_x, mouse_y;
571 static float old_mouse_x = 0, old_mouse_y = 0;
573 if (m_filter.integer)
575 mouse_x = (mx + old_mouse_x) * 0.5;
576 mouse_y = (my + old_mouse_y) * 0.5;
587 in_mouse_x = (float) mouse_x * vid.conwidth / vid.realwidth;
588 in_mouse_y = (float) mouse_y * vid.conheight / vid.realheight;
590 // AK: eveything else is client stuff
591 // BTW, this should be seperated somewhen
595 // LordHavoc: viewzoom affects mouse sensitivity for sniping
596 mouse_x *= sensitivity.value * cl.viewzoom;
597 mouse_y *= sensitivity.value * cl.viewzoom;
599 // Add mouse X/Y movement to cmd
600 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
601 cmd->sidemove += m_side.value * mouse_x;
603 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
608 if (mouselook && !(in_strafe.state & 1))
609 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
612 if ((in_strafe.state & 1) && noclip_anglehack)
613 cmd->upmove -= m_forward.value * mouse_y;
615 cmd->forwardmove -= m_forward.value * mouse_y;
619 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
620 static int cachecolorenable, cachehwgamma;
621 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
622 void VID_UpdateGamma(qboolean force)
626 static int forcenextframe = false;
628 // LordHavoc: don't mess with gamma tables if running dedicated
629 if (cls.state == ca_dedicated)
635 && vid_usinghwgamma == (vid_activewindow && v_hwgamma.integer)
636 && v_gamma.value == cachegamma
637 && v_contrast.value == cachecontrast
638 && v_brightness.value == cachebrightness
639 && cachecolorenable == v_color_enable.integer
640 && cacheblack[0] == v_color_black_r.value
641 && cacheblack[1] == v_color_black_g.value
642 && cacheblack[2] == v_color_black_b.value
643 && cachegrey[0] == v_color_grey_r.value
644 && cachegrey[1] == v_color_grey_g.value
645 && cachegrey[2] == v_color_grey_b.value
646 && cachewhite[0] == v_color_white_r.value
647 && cachewhite[1] == v_color_white_g.value
648 && cachewhite[2] == v_color_white_b.value)
651 forcenextframe = false;
653 if (vid_activewindow && v_hwgamma.integer)
655 if (!vid_usinghwgamma)
657 vid_usinghwgamma = true;
658 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_GetGamma(vid_systemgammaramps));
661 BOUNDCVAR(v_gamma, 0.1, 5);cachegamma = v_gamma.value;
662 BOUNDCVAR(v_contrast, 1, 5);cachecontrast = v_contrast.value;
663 BOUNDCVAR(v_brightness, 0, 0.8);cachebrightness = v_brightness.value;
664 BOUNDCVAR(v_color_black_r, 0, 0.8);cacheblack[0] = v_color_black_r.value;
665 BOUNDCVAR(v_color_black_g, 0, 0.8);cacheblack[1] = v_color_black_g.value;
666 BOUNDCVAR(v_color_black_b, 0, 0.8);cacheblack[2] = v_color_black_b.value;
667 BOUNDCVAR(v_color_grey_r, 0, 0.95);cachegrey[0] = v_color_grey_r.value;
668 BOUNDCVAR(v_color_grey_g, 0, 0.95);cachegrey[1] = v_color_grey_g.value;
669 BOUNDCVAR(v_color_grey_b, 0, 0.95);cachegrey[2] = v_color_grey_b.value;
670 BOUNDCVAR(v_color_white_r, 1, 5);cachewhite[0] = v_color_white_r.value;
671 BOUNDCVAR(v_color_white_g, 1, 5);cachewhite[1] = v_color_white_g.value;
672 BOUNDCVAR(v_color_white_b, 1, 5);cachewhite[2] = v_color_white_b.value;
673 cachecolorenable = v_color_enable.integer;
674 cachehwgamma = v_hwgamma.integer;
676 if (cachecolorenable)
678 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps);
679 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + 256);
680 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + 512);
684 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps);
685 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 256);
686 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 512);
689 // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
690 // immensely butchered it to work with variable framerates and fit in with
691 // the rest of darkplaces.
692 if (v_psycho.integer)
696 static float n[3], nd[3], nt[3];
697 static int init = true;
698 unsigned short *ramp;
699 forcenextframe = true;
703 for (x = 0;x < 3;x++)
705 n[x] = lhrandom(0, 1);
706 nd[x] = (rand()&1)?-0.25:0.25;
707 nt[x] = lhrandom(1, 8.2);
711 for (x = 0;x < 3;x++)
713 nt[x] -= host_realframetime;
717 nt[x] += lhrandom(1, 8.2);
719 n[x] += nd[x] * host_realframetime;
723 for (x = 0, ramp = vid_gammaramps;x < 3;x++)
724 for (y = 0, t = n[x] - 0.75f;y < 256;y++, t += 0.75f * (2.0f / 256.0f))
725 *ramp++ = cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f;
728 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps));
732 if (vid_usinghwgamma)
734 vid_usinghwgamma = false;
735 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps));
740 void VID_RestoreSystemGamma(void)
742 if (vid_usinghwgamma)
744 vid_usinghwgamma = false;
745 VID_SetGamma(vid_systemgammaramps);
749 void VID_Shared_Init(void)
751 Cvar_RegisterVariable(&vid_hardwaregammasupported);
752 Cvar_RegisterVariable(&v_gamma);
753 Cvar_RegisterVariable(&v_brightness);
754 Cvar_RegisterVariable(&v_contrast);
756 Cvar_RegisterVariable(&v_color_enable);
757 Cvar_RegisterVariable(&v_color_black_r);
758 Cvar_RegisterVariable(&v_color_black_g);
759 Cvar_RegisterVariable(&v_color_black_b);
760 Cvar_RegisterVariable(&v_color_grey_r);
761 Cvar_RegisterVariable(&v_color_grey_g);
762 Cvar_RegisterVariable(&v_color_grey_b);
763 Cvar_RegisterVariable(&v_color_white_r);
764 Cvar_RegisterVariable(&v_color_white_g);
765 Cvar_RegisterVariable(&v_color_white_b);
767 Cvar_RegisterVariable(&v_hwgamma);
769 Cvar_RegisterVariable(&v_psycho);
771 Cvar_RegisterVariable(&vid_fullscreen);
772 Cvar_RegisterVariable(&vid_width);
773 Cvar_RegisterVariable(&vid_height);
774 Cvar_RegisterVariable(&vid_bitsperpixel);
775 Cvar_RegisterVariable(&vid_mouse);
776 Cvar_RegisterVariable(&gl_combine);
777 Cvar_RegisterVariable(&in_pitch_min);
778 Cvar_RegisterVariable(&in_pitch_max);
779 Cvar_RegisterVariable(&m_filter);
780 Cmd_AddCommand("force_centerview", Force_CenterView_f);
781 Cmd_AddCommand("vid_restart", VID_Restart_f);
782 if (gamemode == GAME_GOODVSBAD2)
783 Cvar_Set("gl_combine", "0");
786 int current_vid_fullscreen;
787 int current_vid_width;
788 int current_vid_height;
789 int current_vid_bitsperpixel;
790 int VID_Mode(int fullscreen, int width, int height, int bpp)
792 Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp);
793 if (VID_InitMode(fullscreen, width, height, bpp))
795 current_vid_fullscreen = fullscreen;
796 current_vid_width = width;
797 current_vid_height = height;
798 current_vid_bitsperpixel = bpp;
799 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
800 Cvar_SetValueQuick(&vid_width, width);
801 Cvar_SetValueQuick(&vid_height, height);
802 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
809 static void VID_OpenSystems(void)
816 static void VID_CloseSystems(void)
820 R_Modules_Shutdown();
823 int vid_commandlinecheck = true;
825 void VID_Restart_f(void)
827 // don't crash if video hasn't started yet
828 if (vid_commandlinecheck)
831 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n",
832 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel,
833 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
835 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
837 Con_Print("Video mode change failed\n");
838 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel))
839 Sys_Error("Unable to restore to last working video mode\n");
846 int i, width, height, success;
847 if (vid_commandlinecheck)
849 // interpret command-line parameters
850 vid_commandlinecheck = false;
851 if (COM_CheckParm("-window") || COM_CheckParm("-safe"))
852 Cvar_SetValueQuick(&vid_fullscreen, false);
853 if (COM_CheckParm("-fullscreen"))
854 Cvar_SetValueQuick(&vid_fullscreen, true);
857 if ((i = COM_CheckParm("-width")) != 0)
858 width = atoi(com_argv[i+1]);
859 if ((i = COM_CheckParm("-height")) != 0)
860 height = atoi(com_argv[i+1]);
862 width = height * 4 / 3;
864 height = width * 3 / 4;
866 Cvar_SetValueQuick(&vid_width, width);
868 Cvar_SetValueQuick(&vid_height, height);
869 if ((i = COM_CheckParm("-bpp")) != 0)
870 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
873 Con_DPrint("Starting video system\n");
874 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
877 Con_Print("Desired video mode fail, trying fallbacks...\n");
878 if (!success && vid_bitsperpixel.integer > 16)
879 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, 16);
880 if (!success && (vid_width.integer > 640 || vid_height.integer > 480))
881 success = VID_Mode(vid_fullscreen.integer, 640, 480, 16);
882 if (!success && vid_fullscreen.integer)
883 success = VID_Mode(false, 640, 480, 16);
885 Sys_Error("Video modes failed\n");