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;
44 // LordHavoc: if window is hidden, don't update screen
45 int vid_hidden = true;
46 // LordHavoc: if window is not the active window, don't hog as much CPU time,
47 // let go of the mouse, turn off sound, and restore system gamma ramps...
48 int vid_activewindow = true;
50 // we don't know until we try it!
51 cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1"};
52 // whether hardware gamma ramps are currently in effect
53 int vid_usinghwgamma = false;
55 unsigned short vid_gammaramps[768];
56 unsigned short vid_systemgammaramps[768];
58 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
59 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
60 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
61 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"};
63 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
64 cvar_t gl_combine = {CVAR_SAVE, "gl_combine", "1"};
66 cvar_t in_pitch_min = {0, "in_pitch_min", "-70"};
67 cvar_t in_pitch_max = {0, "in_pitch_max", "80"};
69 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
71 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
72 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"};
73 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"};
74 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0"};
75 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0"};
76 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0"};
77 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0"};
78 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5"};
79 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5"};
80 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5"};
81 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1"};
82 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1"};
83 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1"};
84 cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "1"};
86 // brand of graphics chip
87 const char *gl_vendor;
88 // graphics chip model and other information
89 const char *gl_renderer;
90 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
91 const char *gl_version;
92 // extensions list, space separated
93 const char *gl_extensions;
95 const char *gl_platform;
96 // another extensions list, containing platform-specific extensions that are
97 // not in the main list
98 const char *gl_platformextensions;
99 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
102 // GL_ARB_multitexture
103 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
104 void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
105 void (GLAPIENTRY *qglActiveTexture) (GLenum);
106 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
108 // GL_EXT_compiled_vertex_array
109 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
110 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
112 //GL_NV_vertex_array_range
113 GLvoid *(GLAPIENTRY *qglAllocateMemoryNV)(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority);
114 GLvoid (GLAPIENTRY *qglFreeMemoryNV)(GLvoid *pointer);
115 GLvoid (GLAPIENTRY *qglVertexArrayRangeNV)(GLsizei length, GLvoid *pointer);
116 GLvoid (GLAPIENTRY *qglFlushVertexArrayRangeNV)(GLvoid);
118 // general GL functions
120 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
122 void (GLAPIENTRY *qglClear)(GLbitfield mask);
124 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
125 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
126 void (GLAPIENTRY *qglCullFace)(GLenum mode);
128 //void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
129 //void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
130 void (GLAPIENTRY *qglEnable)(GLenum cap);
131 void (GLAPIENTRY *qglDisable)(GLenum cap);
132 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
134 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
135 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
137 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
138 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
139 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
140 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
142 GLenum (GLAPIENTRY *qglGetError)(void);
143 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
144 void (GLAPIENTRY *qglFinish)(void);
145 void (GLAPIENTRY *qglFlush)(void);
147 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
148 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
149 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
150 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
151 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
153 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
154 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
155 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
156 void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
157 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
158 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
159 void (GLAPIENTRY *qglArrayElement)(GLint i);
161 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
162 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
163 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
164 void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
165 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
166 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
167 void (GLAPIENTRY *qglBegin)(GLenum mode);
168 void (GLAPIENTRY *qglEnd)(void);
170 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
171 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
172 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
173 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
174 //void (GLAPIENTRY *qglPushMatrix)(void);
175 //void (GLAPIENTRY *qglPopMatrix)(void);
176 void (GLAPIENTRY *qglLoadIdentity)(void);
177 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
178 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
179 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
180 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
181 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
182 //void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
183 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
184 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
185 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
186 //void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
188 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
190 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
191 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
192 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
193 void (GLAPIENTRY *qglClearStencil)(GLint s);
195 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
196 void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
197 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
198 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
199 //void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
200 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
202 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
203 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
204 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
205 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
206 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
207 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
208 //void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
209 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
211 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
212 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
213 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
214 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
215 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
216 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
217 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
218 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
221 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
223 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
225 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
226 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);
227 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
229 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
231 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
233 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
236 const dllfunction_t *func;
238 Con_DPrintf("checking for %s... ", name);
240 for (func = funcs;func && func->name;func++)
241 *func->funcvariable = NULL;
243 if (disableparm && COM_CheckParm(disableparm))
245 Con_DPrintf("disabled by commandline\n");
249 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)))
251 for (func = funcs;func && func->name != NULL;func++)
253 // functions are cleared before all the extensions are evaluated
254 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
257 Con_Printf("OpenGL extension \"%s\" is missing function \"%s\" - broken driver!\n", name, func->name);
261 // delay the return so it prints all missing functions
264 Con_DPrintf("enabled\n");
269 Con_DPrintf("not detected\n");
274 static dllfunction_t opengl110funcs[] =
276 {"glClearColor", (void **) &qglClearColor},
277 {"glClear", (void **) &qglClear},
278 // {"glAlphaFunc", (void **) &qglAlphaFunc},
279 {"glBlendFunc", (void **) &qglBlendFunc},
280 {"glCullFace", (void **) &qglCullFace},
281 // {"glDrawBuffer", (void **) &qglDrawBuffer},
282 // {"glReadBuffer", (void **) &qglReadBuffer},
283 {"glEnable", (void **) &qglEnable},
284 {"glDisable", (void **) &qglDisable},
285 {"glIsEnabled", (void **) &qglIsEnabled},
286 {"glEnableClientState", (void **) &qglEnableClientState},
287 {"glDisableClientState", (void **) &qglDisableClientState},
288 // {"glGetBooleanv", (void **) &qglGetBooleanv},
289 // {"glGetDoublev", (void **) &qglGetDoublev},
290 // {"glGetFloatv", (void **) &qglGetFloatv},
291 {"glGetIntegerv", (void **) &qglGetIntegerv},
292 {"glGetError", (void **) &qglGetError},
293 {"glGetString", (void **) &qglGetString},
294 {"glFinish", (void **) &qglFinish},
295 {"glFlush", (void **) &qglFlush},
296 {"glClearDepth", (void **) &qglClearDepth},
297 {"glDepthFunc", (void **) &qglDepthFunc},
298 {"glDepthMask", (void **) &qglDepthMask},
299 {"glDepthRange", (void **) &qglDepthRange},
300 {"glDrawElements", (void **) &qglDrawElements},
301 {"glColorMask", (void **) &qglColorMask},
302 {"glVertexPointer", (void **) &qglVertexPointer},
303 {"glNormalPointer", (void **) &qglNormalPointer},
304 {"glColorPointer", (void **) &qglColorPointer},
305 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
306 {"glArrayElement", (void **) &qglArrayElement},
307 {"glColor4f", (void **) &qglColor4f},
308 {"glTexCoord2f", (void **) &qglTexCoord2f},
309 {"glTexCoord3f", (void **) &qglTexCoord3f},
310 {"glVertex2f", (void **) &qglVertex2f},
311 {"glVertex3f", (void **) &qglVertex3f},
312 {"glBegin", (void **) &qglBegin},
313 {"glEnd", (void **) &qglEnd},
314 {"glMatrixMode", (void **) &qglMatrixMode},
315 {"glOrtho", (void **) &qglOrtho},
316 {"glFrustum", (void **) &qglFrustum},
317 {"glViewport", (void **) &qglViewport},
318 // {"glPushMatrix", (void **) &qglPushMatrix},
319 // {"glPopMatrix", (void **) &qglPopMatrix},
320 {"glLoadIdentity", (void **) &qglLoadIdentity},
321 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
322 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
323 // {"glMultMatrixd", (void **) &qglMultMatrixd},
324 // {"glMultMatrixf", (void **) &qglMultMatrixf},
325 // {"glRotated", (void **) &qglRotated},
326 // {"glRotatef", (void **) &qglRotatef},
327 // {"glScaled", (void **) &qglScaled},
328 // {"glScalef", (void **) &qglScalef},
329 // {"glTranslated", (void **) &qglTranslated},
330 // {"glTranslatef", (void **) &qglTranslatef},
331 {"glReadPixels", (void **) &qglReadPixels},
332 {"glStencilFunc", (void **) &qglStencilFunc},
333 {"glStencilMask", (void **) &qglStencilMask},
334 {"glStencilOp", (void **) &qglStencilOp},
335 {"glClearStencil", (void **) &qglClearStencil},
336 // {"glTexEnvf", (void **) &qglTexEnvf},
337 {"glTexEnvfv", (void **) &qglTexEnvfv},
338 {"glTexEnvi", (void **) &qglTexEnvi},
339 {"glTexParameterf", (void **) &qglTexParameterf},
340 // {"glTexParameterfv", (void **) &qglTexParameterfv},
341 {"glTexParameteri", (void **) &qglTexParameteri},
342 // {"glPixelStoref", (void **) &qglPixelStoref},
343 {"glPixelStorei", (void **) &qglPixelStorei},
344 {"glGenTextures", (void **) &qglGenTextures},
345 {"glDeleteTextures", (void **) &qglDeleteTextures},
346 {"glBindTexture", (void **) &qglBindTexture},
347 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
348 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
349 {"glIsTexture", (void **) &qglIsTexture},
350 {"glTexImage1D", (void **) &qglTexImage1D},
351 {"glTexImage2D", (void **) &qglTexImage2D},
352 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
353 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
354 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
355 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
356 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
357 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
358 {"glScissor", (void **) &qglScissor},
359 {"glPolygonOffset", (void **) &qglPolygonOffset},
363 static dllfunction_t drawrangeelementsfuncs[] =
365 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
369 static dllfunction_t drawrangeelementsextfuncs[] =
371 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
375 static dllfunction_t multitexturefuncs[] =
377 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
378 {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
379 {"glActiveTextureARB", (void **) &qglActiveTexture},
380 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
384 static dllfunction_t compiledvertexarrayfuncs[] =
386 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
387 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
391 static dllfunction_t texture3dextfuncs[] =
393 {"glTexImage3DEXT", (void **) &qglTexImage3D},
394 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
395 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
399 static dllfunction_t glxvarfuncs[] =
401 {"glXAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
402 {"glXFreeMemoryNV", (void **) &qglFreeMemoryNV},
403 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
404 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
408 static dllfunction_t wglvarfuncs[] =
410 {"wglAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
411 {"wglFreeMemoryNV", (void **) &qglFreeMemoryNV},
412 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
413 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
418 void VID_CheckExtensions(void)
420 gl_stencil = vid_bitsperpixel.integer == 32;
421 gl_combine_extension = false;
423 gl_supportslockarrays = false;
425 gl_support_clamptoedge = false;
426 gl_support_var = false;
427 gl_support_var2 = false;
429 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
430 Sys_Error("OpenGL 1.1.0 functions not found\n");
432 Con_DPrintf ("GL_VENDOR: %s\n", gl_vendor);
433 Con_DPrintf ("GL_RENDERER: %s\n", gl_renderer);
434 Con_DPrintf ("GL_VERSION: %s\n", gl_version);
435 Con_DPrintf ("GL_EXTENSIONS: %s\n", gl_extensions);
436 Con_DPrintf ("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
438 Con_DPrintf("Checking OpenGL extensions...\n");
440 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
441 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
443 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
445 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
446 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
447 if (gl_combine_extension)
448 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
451 gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
452 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
453 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
454 gl_support_clamptoedge = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
456 if (!strcmp(gl_platform, "GLX"))
457 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", glxvarfuncs, "-novar", false);
458 else if (!strcmp(gl_platform, "WGL"))
459 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", wglvarfuncs, "-novar", false);
461 gl_support_var2 = GL_CheckExtension("GL_NV_vertex_array_range2", NULL, "-novar2", false);
463 gl_support_anisotropy = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false);
465 gl_textureshader = GL_CheckExtension("GL_NV_texture_shader", NULL, "-notextureshader", false);
467 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
468 if (qglDrawRangeElements == NULL)
469 qglDrawRangeElements = qglDrawRangeElementsEXT;
472 int vid_vertexarrays_are_var = false;
473 void *VID_AllocVertexArrays(mempool_t *pool, int size, int fast, float readfrequency, float writefrequency, float priority)
476 vid_vertexarrays_are_var = false;
477 if (fast && qglAllocateMemoryNV)
480 m = qglAllocateMemoryNV(size, readfrequency, writefrequency, priority);
484 vid_vertexarrays_are_var = true;
488 return Mem_Alloc(pool, size);
491 void VID_FreeVertexArrays(void *pointer)
493 if (vid_vertexarrays_are_var)
496 qglFreeMemoryNV(pointer);
501 vid_vertexarrays_are_var = false;
504 void Force_CenterView_f (void)
506 cl.viewangles[PITCH] = 0;
509 void IN_PreMove(void)
513 void CL_AdjustAngles(void);
514 void IN_PostMove(void)
516 // clamp after the move as well to prevent messed up rendering angles
525 void IN_ProcessMove(usercmd_t *cmd)
527 // get basic movement from keyboard
530 // OS independent code
533 // allow mice or other external controllers to add to the move
536 // OS independent code
541 void IN_Mouse(usercmd_t *cmd, float mx, float my)
543 int mouselook = (in_mlook.state & 1) || freelook.integer;
544 float mouse_x, mouse_y;
545 static float old_mouse_x = 0, old_mouse_y = 0;
547 if (m_filter.integer)
549 mouse_x = (mx + old_mouse_x) * 0.5;
550 mouse_y = (my + old_mouse_y) * 0.5;
561 in_mouse_x = (float) mouse_x * vid.conwidth / vid.realwidth;
562 in_mouse_y = (float) mouse_y * vid.conheight / vid.realheight;
564 // AK: eveything else is client stuff
565 // BTW, this should be seperated somewhen
569 // LordHavoc: viewzoom affects mouse sensitivity for sniping
570 mouse_x *= sensitivity.value * cl.viewzoom;
571 mouse_y *= sensitivity.value * cl.viewzoom;
573 // Add mouse X/Y movement to cmd
574 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
575 cmd->sidemove += m_side.value * mouse_x;
577 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
582 if (mouselook && !(in_strafe.state & 1))
583 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
586 if ((in_strafe.state & 1) && noclip_anglehack)
587 cmd->upmove -= m_forward.value * mouse_y;
589 cmd->forwardmove -= m_forward.value * mouse_y;
593 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
594 static int cachecolorenable, cachehwgamma;
595 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
596 void VID_UpdateGamma(qboolean force)
601 // LordHavoc: don't mess with gamma tables if running dedicated
602 if (cls.state == ca_dedicated)
606 && vid_usinghwgamma == (vid_activewindow && v_hwgamma.integer)
607 && v_gamma.value == cachegamma
608 && v_contrast.value == cachecontrast
609 && v_brightness.value == cachebrightness
610 && cachecolorenable == v_color_enable.integer
611 && cacheblack[0] == v_color_black_r.value
612 && cacheblack[1] == v_color_black_g.value
613 && cacheblack[2] == v_color_black_b.value
614 && cachegrey[0] == v_color_grey_r.value
615 && cachegrey[1] == v_color_grey_g.value
616 && cachegrey[2] == v_color_grey_b.value
617 && cachewhite[0] == v_color_white_r.value
618 && cachewhite[1] == v_color_white_g.value
619 && cachewhite[2] == v_color_white_b.value)
622 if (vid_activewindow && v_hwgamma.integer)
624 if (!vid_usinghwgamma)
626 vid_usinghwgamma = true;
627 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_GetGamma(vid_systemgammaramps));
630 BOUNDCVAR(v_gamma, 0.1, 5);cachegamma = v_gamma.value;
631 BOUNDCVAR(v_contrast, 1, 5);cachecontrast = v_contrast.value;
632 BOUNDCVAR(v_brightness, 0, 0.8);cachebrightness = v_brightness.value;
633 BOUNDCVAR(v_color_black_r, 0, 0.8);cacheblack[0] = v_color_black_r.value;
634 BOUNDCVAR(v_color_black_g, 0, 0.8);cacheblack[1] = v_color_black_g.value;
635 BOUNDCVAR(v_color_black_b, 0, 0.8);cacheblack[2] = v_color_black_b.value;
636 BOUNDCVAR(v_color_grey_r, 0, 0.95);cachegrey[0] = v_color_grey_r.value;
637 BOUNDCVAR(v_color_grey_g, 0, 0.95);cachegrey[1] = v_color_grey_g.value;
638 BOUNDCVAR(v_color_grey_b, 0, 0.95);cachegrey[2] = v_color_grey_b.value;
639 BOUNDCVAR(v_color_white_r, 1, 5);cachewhite[0] = v_color_white_r.value;
640 BOUNDCVAR(v_color_white_g, 1, 5);cachewhite[1] = v_color_white_g.value;
641 BOUNDCVAR(v_color_white_b, 1, 5);cachewhite[2] = v_color_white_b.value;
642 cachecolorenable = v_color_enable.integer;
643 cachehwgamma = v_hwgamma.integer;
645 if (cachecolorenable)
647 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps);
648 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + 256);
649 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + 512);
653 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps);
654 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 256);
655 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 512);
658 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps));
662 if (vid_usinghwgamma)
664 vid_usinghwgamma = false;
665 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps));
670 void VID_RestoreSystemGamma(void)
672 if (vid_usinghwgamma)
674 vid_usinghwgamma = false;
675 VID_SetGamma(vid_systemgammaramps);
679 void VID_Shared_Init(void)
681 Cvar_RegisterVariable(&vid_hardwaregammasupported);
682 Cvar_RegisterVariable(&v_gamma);
683 Cvar_RegisterVariable(&v_brightness);
684 Cvar_RegisterVariable(&v_contrast);
686 Cvar_RegisterVariable(&v_color_enable);
687 Cvar_RegisterVariable(&v_color_black_r);
688 Cvar_RegisterVariable(&v_color_black_g);
689 Cvar_RegisterVariable(&v_color_black_b);
690 Cvar_RegisterVariable(&v_color_grey_r);
691 Cvar_RegisterVariable(&v_color_grey_g);
692 Cvar_RegisterVariable(&v_color_grey_b);
693 Cvar_RegisterVariable(&v_color_white_r);
694 Cvar_RegisterVariable(&v_color_white_g);
695 Cvar_RegisterVariable(&v_color_white_b);
697 Cvar_RegisterVariable(&v_hwgamma);
699 Cvar_RegisterVariable(&vid_fullscreen);
700 Cvar_RegisterVariable(&vid_width);
701 Cvar_RegisterVariable(&vid_height);
702 Cvar_RegisterVariable(&vid_bitsperpixel);
703 Cvar_RegisterVariable(&vid_mouse);
704 Cvar_RegisterVariable(&gl_combine);
705 Cvar_RegisterVariable(&in_pitch_min);
706 Cvar_RegisterVariable(&in_pitch_max);
707 Cvar_RegisterVariable(&m_filter);
708 Cmd_AddCommand("force_centerview", Force_CenterView_f);
709 Cmd_AddCommand("vid_restart", VID_Restart_f);
710 if (gamemode == GAME_GOODVSBAD2)
711 Cvar_Set("gl_combine", "0");
714 int current_vid_fullscreen;
715 int current_vid_width;
716 int current_vid_height;
717 int current_vid_bitsperpixel;
718 extern int VID_InitMode (int fullscreen, int width, int height, int bpp);
719 int VID_Mode(int fullscreen, int width, int height, int bpp)
721 Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp);
722 if (VID_InitMode(fullscreen, width, height, bpp))
724 current_vid_fullscreen = fullscreen;
725 current_vid_width = width;
726 current_vid_height = height;
727 current_vid_bitsperpixel = bpp;
728 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
729 Cvar_SetValueQuick(&vid_width, width);
730 Cvar_SetValueQuick(&vid_height, height);
731 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
738 static void VID_OpenSystems(void)
745 static void VID_CloseSystems(void)
749 R_Modules_Shutdown();
752 int vid_commandlinecheck = true;
754 void VID_Restart_f(void)
756 // don't crash if video hasn't started yet
757 if (vid_commandlinecheck)
760 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n",
761 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel,
762 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
764 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
766 Con_Printf("Video mode change failed\n");
767 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel))
768 Sys_Error("Unable to restore to last working video mode\n");
775 int i, width, height;
776 if (vid_commandlinecheck)
778 // interpret command-line parameters
779 vid_commandlinecheck = false;
780 if ((i = COM_CheckParm("-window")) != 0)
781 Cvar_SetValueQuick(&vid_fullscreen, false);
782 if ((i = COM_CheckParm("-fullscreen")) != 0)
783 Cvar_SetValueQuick(&vid_fullscreen, true);
786 if ((i = COM_CheckParm("-width")) != 0)
787 width = atoi(com_argv[i+1]);
788 if ((i = COM_CheckParm("-height")) != 0)
789 height = atoi(com_argv[i+1]);
791 width = height * 4 / 3;
793 height = width * 3 / 4;
795 Cvar_SetValueQuick(&vid_width, width);
797 Cvar_SetValueQuick(&vid_height, height);
798 if ((i = COM_CheckParm("-bpp")) != 0)
799 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
802 Con_DPrintf("Starting video system\n");
803 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
805 Con_Printf("Desired video mode fail, trying fallbacks...\n");
806 if (vid_fullscreen.integer)
808 if (!VID_Mode(true, 640, 480, 16))
809 if (!VID_Mode(false, 640, 480, 16))
810 Sys_Error("Video modes failed\n");
813 Sys_Error("Windowed video failed\n");