12 // LordHavoc: these are only set in wgl
13 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
14 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.
16 // AK FIXME -> input_dest
17 qboolean in_client_mouse = true;
19 // AK where should it be placed ?
20 float in_mouse_x, in_mouse_y;
21 float in_windowmouse_x, in_windowmouse_y;
23 // LordHavoc: if window is hidden, don't update screen
24 qboolean vid_hidden = true;
25 // LordHavoc: if window is not the active window, don't hog as much CPU time,
26 // let go of the mouse, turn off sound, and restore system gamma ramps...
27 qboolean vid_activewindow = true;
29 // we don't know until we try it!
30 cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1", "indicates whether hardware gamma is supported (updated by attempts to set hardware gamma ramps)"};
32 // VorteX: more info cvars, mostly set in VID_CheckExtensions
33 cvar_t gl_info_vendor = {CVAR_READONLY, "gl_info_vendor", "", "indicates brand of graphics chip"};
34 cvar_t gl_info_renderer = {CVAR_READONLY, "gl_info_renderer", "", "indicates graphics chip model and other information"};
35 cvar_t gl_info_version = {CVAR_READONLY, "gl_info_version", "", "indicates version of current renderer. begins with 1.0.0, 1.1.0, 1.2.0, 1.3.1 etc."};
36 cvar_t gl_info_extensions = {CVAR_READONLY, "gl_info_extensions", "", "indicates extension list found by engine, space separated."};
37 cvar_t gl_info_platform = {CVAR_READONLY, "gl_info_platform", "", "indicates GL platform: WGL, GLX, or AGL."};
38 cvar_t gl_info_driver = {CVAR_READONLY, "gl_info_driver", "", "name of driver library (opengl32.dll, libGL.so.1, or whatever)."};
40 // whether hardware gamma ramps are currently in effect
41 qboolean vid_usinghwgamma = false;
43 int vid_gammarampsize = 0;
44 unsigned short *vid_gammaramps = NULL;
45 unsigned short *vid_systemgammaramps = NULL;
47 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1", "use fullscreen (1) or windowed (0)"};
48 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640", "resolution"};
49 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480", "resolution"};
50 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32", "how many bits per pixel to render at (32 or 16, 32 is recommended)"};
51 cvar_t vid_samples = {CVAR_SAVE, "vid_samples", "1", "how many anti-aliasing samples per pixel to request from the graphics driver (4 is recommended, 1 is faster)"};
52 cvar_t vid_refreshrate = {CVAR_SAVE, "vid_refreshrate", "60", "refresh rate to use, in hz (higher values flicker less, if supported by your monitor)"};
53 cvar_t vid_userefreshrate = {CVAR_SAVE, "vid_userefreshrate", "0", "set this to 1 to make vid_refreshrate used, or to 0 to let the engine choose a sane default"};
54 cvar_t vid_stereobuffer = {CVAR_SAVE, "vid_stereobuffer", "0", "enables 'quad-buffered' stereo rendering for stereo shutterglasses, HMD (head mounted display) devices, or polarized stereo LCDs, if supported by your drivers"};
56 cvar_t vid_vsync = {CVAR_SAVE, "vid_vsync", "0", "sync to vertical blank, prevents 'tearing' (seeing part of one frame and part of another on the screen at the same time), automatically disabled when doing timedemo benchmarks"};
57 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1", "whether to use the mouse in windowed mode (fullscreen always does)"};
58 cvar_t vid_grabkeyboard = {CVAR_SAVE, "vid_grabkeyboard", "0", "whether to grab the keyboard when mouse is active (prevents use of volume control keys, music player keys, etc on some keyboards)"};
59 cvar_t vid_minwidth = {0, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"};
60 cvar_t vid_minheight = {0, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"};
61 cvar_t vid_gl13 = {0, "vid_gl13", "1", "enables faster rendering using OpenGL 1.3 features (such as GL_ARB_texture_env_combine extension)"};
62 cvar_t vid_gl20 = {0, "vid_gl20", "1", "enables faster rendering using OpenGL 2.0 features (such as GL_ARB_fragment_shader extension)"};
64 cvar_t vid_cggl = {0, "vid_glcg", "1", "enables faster rendering using the Cg shader library"};
66 cvar_t gl_finish = {0, "gl_finish", "0", "make the cpu wait for the graphics processor at the end of each rendered frame (can help with strange input or video lag problems on some machines)"};
68 cvar_t vid_stick_mouse = {CVAR_SAVE, "vid_stick_mouse", "0", "have the mouse stuck in the center of the screen" };
69 cvar_t vid_resizable = {CVAR_SAVE, "vid_resizable", "0", "0: window not resizable, 1: resizable, 2: window can be resized but the framebuffer isn't adjusted" };
71 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1", "inverse gamma correction value, a brightness effect that does not affect white or black, and tends to make the image grey and dull"};
72 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1", "brightness of white (values above 1 give a brighter image with increased color saturation, unlike v_gamma)"};
73 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0", "brightness of black, useful for monitors that are too dark"};
74 cvar_t v_contrastboost = {CVAR_SAVE, "v_contrastboost", "1", "by how much to multiply the contrast in dark areas (1 is no change)"};
75 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0", "enables black-grey-white color correction curve controls"};
76 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0", "desired color of black"};
77 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0", "desired color of black"};
78 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0", "desired color of black"};
79 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5", "desired color of grey"};
80 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5", "desired color of grey"};
81 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5", "desired color of grey"};
82 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1", "desired color of white"};
83 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1", "desired color of white"};
84 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1", "desired color of white"};
85 cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "1", "enables use of hardware gamma correction ramps if available (note: does not work very well on Windows2000 and above), values are 0 = off, 1 = attempt to use hardware gamma, 2 = use hardware gamma whether it works or not"};
86 cvar_t v_glslgamma = {CVAR_SAVE, "v_glslgamma", "0", "enables use of GLSL to apply gamma correction ramps if available (note: overrides v_hwgamma)"};
87 cvar_t v_psycho = {0, "v_psycho", "0", "easter egg (does not work on Windows2000 or above)"};
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 *qglMultiTexCoord1f) (GLenum, GLfloat);
107 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
108 void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
109 void (GLAPIENTRY *qglMultiTexCoord4f) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
110 void (GLAPIENTRY *qglActiveTexture) (GLenum);
111 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
113 // GL_EXT_compiled_vertex_array
114 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
115 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
117 // general GL functions
119 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
121 void (GLAPIENTRY *qglClear)(GLbitfield mask);
123 void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
124 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
125 void (GLAPIENTRY *qglCullFace)(GLenum mode);
127 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
128 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
129 void (GLAPIENTRY *qglEnable)(GLenum cap);
130 void (GLAPIENTRY *qglDisable)(GLenum cap);
131 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
133 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
134 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
136 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
137 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
138 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
139 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
141 GLenum (GLAPIENTRY *qglGetError)(void);
142 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
143 void (GLAPIENTRY *qglFinish)(void);
144 void (GLAPIENTRY *qglFlush)(void);
146 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
147 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
148 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
149 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
150 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
152 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
153 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
154 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
155 void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
156 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
157 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
158 void (GLAPIENTRY *qglArrayElement)(GLint i);
160 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
161 void (GLAPIENTRY *qglTexCoord1f)(GLfloat s);
162 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
163 void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
164 void (GLAPIENTRY *qglTexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
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);
201 void (GLAPIENTRY *qglHint)(GLenum target, GLenum mode);
203 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
204 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
205 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
206 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
207 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
208 //GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
209 //void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
210 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
212 //void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
213 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
214 //void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
215 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
216 //void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
217 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
218 //void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
219 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
222 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
224 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
226 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
227 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);
228 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
230 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
232 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
233 void (GLAPIENTRY *qglPolygonMode)(GLenum face, GLenum mode);
234 void (GLAPIENTRY *qglPolygonStipple)(const GLubyte *mask);
236 //void (GLAPIENTRY *qglClipPlane)(GLenum plane, const GLdouble *equation);
237 //void (GLAPIENTRY *qglGetClipPlane)(GLenum plane, GLdouble *equation);
239 //[515]: added on 29.07.2005
240 void (GLAPIENTRY *qglLineWidth)(GLfloat width);
241 void (GLAPIENTRY *qglPointSize)(GLfloat size);
243 void (GLAPIENTRY *qglBlendEquationEXT)(GLenum);
245 void (GLAPIENTRY *qglStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum);
246 void (GLAPIENTRY *qglStencilFuncSeparate)(GLenum, GLenum, GLint, GLuint);
247 void (GLAPIENTRY *qglActiveStencilFaceEXT)(GLenum);
249 void (GLAPIENTRY *qglDeleteObjectARB)(GLhandleARB obj);
250 GLhandleARB (GLAPIENTRY *qglGetHandleARB)(GLenum pname);
251 void (GLAPIENTRY *qglDetachObjectARB)(GLhandleARB containerObj, GLhandleARB attachedObj);
252 GLhandleARB (GLAPIENTRY *qglCreateShaderObjectARB)(GLenum shaderType);
253 void (GLAPIENTRY *qglShaderSourceARB)(GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length);
254 void (GLAPIENTRY *qglCompileShaderARB)(GLhandleARB shaderObj);
255 GLhandleARB (GLAPIENTRY *qglCreateProgramObjectARB)(void);
256 void (GLAPIENTRY *qglAttachObjectARB)(GLhandleARB containerObj, GLhandleARB obj);
257 void (GLAPIENTRY *qglLinkProgramARB)(GLhandleARB programObj);
258 void (GLAPIENTRY *qglUseProgramObjectARB)(GLhandleARB programObj);
259 void (GLAPIENTRY *qglValidateProgramARB)(GLhandleARB programObj);
260 void (GLAPIENTRY *qglUniform1fARB)(GLint location, GLfloat v0);
261 void (GLAPIENTRY *qglUniform2fARB)(GLint location, GLfloat v0, GLfloat v1);
262 void (GLAPIENTRY *qglUniform3fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
263 void (GLAPIENTRY *qglUniform4fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
264 void (GLAPIENTRY *qglUniform1iARB)(GLint location, GLint v0);
265 void (GLAPIENTRY *qglUniform2iARB)(GLint location, GLint v0, GLint v1);
266 void (GLAPIENTRY *qglUniform3iARB)(GLint location, GLint v0, GLint v1, GLint v2);
267 void (GLAPIENTRY *qglUniform4iARB)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
268 void (GLAPIENTRY *qglUniform1fvARB)(GLint location, GLsizei count, const GLfloat *value);
269 void (GLAPIENTRY *qglUniform2fvARB)(GLint location, GLsizei count, const GLfloat *value);
270 void (GLAPIENTRY *qglUniform3fvARB)(GLint location, GLsizei count, const GLfloat *value);
271 void (GLAPIENTRY *qglUniform4fvARB)(GLint location, GLsizei count, const GLfloat *value);
272 void (GLAPIENTRY *qglUniform1ivARB)(GLint location, GLsizei count, const GLint *value);
273 void (GLAPIENTRY *qglUniform2ivARB)(GLint location, GLsizei count, const GLint *value);
274 void (GLAPIENTRY *qglUniform3ivARB)(GLint location, GLsizei count, const GLint *value);
275 void (GLAPIENTRY *qglUniform4ivARB)(GLint location, GLsizei count, const GLint *value);
276 void (GLAPIENTRY *qglUniformMatrix2fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
277 void (GLAPIENTRY *qglUniformMatrix3fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
278 void (GLAPIENTRY *qglUniformMatrix4fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
279 void (GLAPIENTRY *qglGetObjectParameterfvARB)(GLhandleARB obj, GLenum pname, GLfloat *params);
280 void (GLAPIENTRY *qglGetObjectParameterivARB)(GLhandleARB obj, GLenum pname, GLint *params);
281 void (GLAPIENTRY *qglGetInfoLogARB)(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
282 void (GLAPIENTRY *qglGetAttachedObjectsARB)(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
283 GLint (GLAPIENTRY *qglGetUniformLocationARB)(GLhandleARB programObj, const GLcharARB *name);
284 void (GLAPIENTRY *qglGetActiveUniformARB)(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
285 void (GLAPIENTRY *qglGetUniformfvARB)(GLhandleARB programObj, GLint location, GLfloat *params);
286 void (GLAPIENTRY *qglGetUniformivARB)(GLhandleARB programObj, GLint location, GLint *params);
287 void (GLAPIENTRY *qglGetShaderSourceARB)(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
289 //void (GLAPIENTRY *qglVertexAttrib1fARB)(GLuint index, GLfloat v0);
290 //void (GLAPIENTRY *qglVertexAttrib1sARB)(GLuint index, GLshort v0);
291 //void (GLAPIENTRY *qglVertexAttrib1dARB)(GLuint index, GLdouble v0);
292 //void (GLAPIENTRY *qglVertexAttrib2fARB)(GLuint index, GLfloat v0, GLfloat v1);
293 //void (GLAPIENTRY *qglVertexAttrib2sARB)(GLuint index, GLshort v0, GLshort v1);
294 //void (GLAPIENTRY *qglVertexAttrib2dARB)(GLuint index, GLdouble v0, GLdouble v1);
295 //void (GLAPIENTRY *qglVertexAttrib3fARB)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2);
296 //void (GLAPIENTRY *qglVertexAttrib3sARB)(GLuint index, GLshort v0, GLshort v1, GLshort v2);
297 //void (GLAPIENTRY *qglVertexAttrib3dARB)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2);
298 //void (GLAPIENTRY *qglVertexAttrib4fARB)(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
299 //void (GLAPIENTRY *qglVertexAttrib4sARB)(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3);
300 //void (GLAPIENTRY *qglVertexAttrib4dARB)(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
301 //void (GLAPIENTRY *qglVertexAttrib4NubARB)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
302 //void (GLAPIENTRY *qglVertexAttrib1fvARB)(GLuint index, const GLfloat *v);
303 //void (GLAPIENTRY *qglVertexAttrib1svARB)(GLuint index, const GLshort *v);
304 //void (GLAPIENTRY *qglVertexAttrib1dvARB)(GLuint index, const GLdouble *v);
305 //void (GLAPIENTRY *qglVertexAttrib2fvARB)(GLuint index, const GLfloat *v);
306 //void (GLAPIENTRY *qglVertexAttrib2svARB)(GLuint index, const GLshort *v);
307 //void (GLAPIENTRY *qglVertexAttrib2dvARB)(GLuint index, const GLdouble *v);
308 //void (GLAPIENTRY *qglVertexAttrib3fvARB)(GLuint index, const GLfloat *v);
309 //void (GLAPIENTRY *qglVertexAttrib3svARB)(GLuint index, const GLshort *v);
310 //void (GLAPIENTRY *qglVertexAttrib3dvARB)(GLuint index, const GLdouble *v);
311 //void (GLAPIENTRY *qglVertexAttrib4fvARB)(GLuint index, const GLfloat *v);
312 //void (GLAPIENTRY *qglVertexAttrib4svARB)(GLuint index, const GLshort *v);
313 //void (GLAPIENTRY *qglVertexAttrib4dvARB)(GLuint index, const GLdouble *v);
314 //void (GLAPIENTRY *qglVertexAttrib4ivARB)(GLuint index, const GLint *v);
315 //void (GLAPIENTRY *qglVertexAttrib4bvARB)(GLuint index, const GLbyte *v);
316 //void (GLAPIENTRY *qglVertexAttrib4ubvARB)(GLuint index, const GLubyte *v);
317 //void (GLAPIENTRY *qglVertexAttrib4usvARB)(GLuint index, const GLushort *v);
318 //void (GLAPIENTRY *qglVertexAttrib4uivARB)(GLuint index, const GLuint *v);
319 //void (GLAPIENTRY *qglVertexAttrib4NbvARB)(GLuint index, const GLbyte *v);
320 //void (GLAPIENTRY *qglVertexAttrib4NsvARB)(GLuint index, const GLshort *v);
321 //void (GLAPIENTRY *qglVertexAttrib4NivARB)(GLuint index, const GLint *v);
322 //void (GLAPIENTRY *qglVertexAttrib4NubvARB)(GLuint index, const GLubyte *v);
323 //void (GLAPIENTRY *qglVertexAttrib4NusvARB)(GLuint index, const GLushort *v);
324 //void (GLAPIENTRY *qglVertexAttrib4NuivARB)(GLuint index, const GLuint *v);
325 void (GLAPIENTRY *qglVertexAttribPointerARB)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
326 void (GLAPIENTRY *qglEnableVertexAttribArrayARB)(GLuint index);
327 void (GLAPIENTRY *qglDisableVertexAttribArrayARB)(GLuint index);
328 void (GLAPIENTRY *qglBindAttribLocationARB)(GLhandleARB programObj, GLuint index, const GLcharARB *name);
329 void (GLAPIENTRY *qglGetActiveAttribARB)(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
330 GLint (GLAPIENTRY *qglGetAttribLocationARB)(GLhandleARB programObj, const GLcharARB *name);
331 //void (GLAPIENTRY *qglGetVertexAttribdvARB)(GLuint index, GLenum pname, GLdouble *params);
332 //void (GLAPIENTRY *qglGetVertexAttribfvARB)(GLuint index, GLenum pname, GLfloat *params);
333 //void (GLAPIENTRY *qglGetVertexAttribivARB)(GLuint index, GLenum pname, GLint *params);
334 //void (GLAPIENTRY *qglGetVertexAttribPointervARB)(GLuint index, GLenum pname, GLvoid **pointer);
336 //GL_ARB_vertex_buffer_object
337 void (GLAPIENTRY *qglBindBufferARB) (GLenum target, GLuint buffer);
338 void (GLAPIENTRY *qglDeleteBuffersARB) (GLsizei n, const GLuint *buffers);
339 void (GLAPIENTRY *qglGenBuffersARB) (GLsizei n, GLuint *buffers);
340 GLboolean (GLAPIENTRY *qglIsBufferARB) (GLuint buffer);
341 GLvoid* (GLAPIENTRY *qglMapBufferARB) (GLenum target, GLenum access);
342 GLboolean (GLAPIENTRY *qglUnmapBufferARB) (GLenum target);
343 void (GLAPIENTRY *qglBufferDataARB) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
344 void (GLAPIENTRY *qglBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data);
346 //GL_EXT_framebuffer_object
347 GLboolean (GLAPIENTRY *qglIsRenderbufferEXT)(GLuint renderbuffer);
348 void (GLAPIENTRY *qglBindRenderbufferEXT)(GLenum target, GLuint renderbuffer);
349 void (GLAPIENTRY *qglDeleteRenderbuffersEXT)(GLsizei n, const GLuint *renderbuffers);
350 void (GLAPIENTRY *qglGenRenderbuffersEXT)(GLsizei n, GLuint *renderbuffers);
351 void (GLAPIENTRY *qglRenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
352 void (GLAPIENTRY *qglGetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint *params);
353 GLboolean (GLAPIENTRY *qglIsFramebufferEXT)(GLuint framebuffer);
354 void (GLAPIENTRY *qglBindFramebufferEXT)(GLenum target, GLuint framebuffer);
355 void (GLAPIENTRY *qglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers);
356 void (GLAPIENTRY *qglGenFramebuffersEXT)(GLsizei n, GLuint *framebuffers);
357 GLenum (GLAPIENTRY *qglCheckFramebufferStatusEXT)(GLenum target);
358 //void (GLAPIENTRY *qglFramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
359 void (GLAPIENTRY *qglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
360 void (GLAPIENTRY *qglFramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
361 void (GLAPIENTRY *qglFramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
362 void (GLAPIENTRY *qglGetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
363 void (GLAPIENTRY *qglGenerateMipmapEXT)(GLenum target);
365 void (GLAPIENTRY *qglDrawBuffersARB)(GLsizei n, const GLenum *bufs);
367 void (GLAPIENTRY *qglCompressedTexImage3DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
368 void (GLAPIENTRY *qglCompressedTexImage2DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
369 //void (GLAPIENTRY *qglCompressedTexImage1DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
370 void (GLAPIENTRY *qglCompressedTexSubImage3DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
371 void (GLAPIENTRY *qglCompressedTexSubImage2DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
372 //void (GLAPIENTRY *qglCompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
373 void (GLAPIENTRY *qglGetCompressedTexImageARB)(GLenum target, GLint lod, void *img);
375 void (GLAPIENTRY *qglGenQueriesARB)(GLsizei n, GLuint *ids);
376 void (GLAPIENTRY *qglDeleteQueriesARB)(GLsizei n, const GLuint *ids);
377 GLboolean (GLAPIENTRY *qglIsQueryARB)(GLuint qid);
378 void (GLAPIENTRY *qglBeginQueryARB)(GLenum target, GLuint qid);
379 void (GLAPIENTRY *qglEndQueryARB)(GLenum target);
380 void (GLAPIENTRY *qglGetQueryivARB)(GLenum target, GLenum pname, GLint *params);
381 void (GLAPIENTRY *qglGetQueryObjectivARB)(GLuint qid, GLenum pname, GLint *params);
382 void (GLAPIENTRY *qglGetQueryObjectuivARB)(GLuint qid, GLenum pname, GLuint *params);
385 #define sscanf sscanf_s
388 int GL_CheckExtension(const char *minglver_or_ext, const dllfunction_t *funcs, const char *disableparm, int silent)
391 const dllfunction_t *func;
392 struct { int major, minor; } min_version, curr_version;
393 char extstr[MAX_INPUTLINE];
396 if(sscanf(minglver_or_ext, "%d.%d", &min_version.major, &min_version.minor) == 2)
397 ext = 0; // opengl version
398 else if(minglver_or_ext[0] != toupper(minglver_or_ext[0]))
399 ext = -1; // pseudo name
401 ext = 1; // extension name
404 Con_DPrintf("checking for %s... ", minglver_or_ext);
406 Con_DPrintf("checking for OpenGL %s core features... ", minglver_or_ext);
408 for (func = funcs;func && func->name;func++)
409 *func->funcvariable = NULL;
411 if (disableparm && (COM_CheckParm(disableparm) || COM_CheckParm("-safe")))
413 Con_DPrint("disabled by commandline\n");
417 if (ext == 1) // opengl extension
419 if (!strstr(gl_extensions ? gl_extensions : "", minglver_or_ext) && !strstr(gl_platformextensions ? gl_platformextensions : "", minglver_or_ext))
421 Con_DPrint("not detected\n");
426 if(ext == 0) // opengl version
428 if (sscanf(gl_version, "%d.%d", &curr_version.major, &curr_version.minor) < 2)
429 curr_version.major = curr_version.minor = 1;
431 if (curr_version.major < min_version.major || (curr_version.major == min_version.major && curr_version.minor < min_version.minor))
433 Con_DPrintf("not detected (OpenGL %d.%d loaded)\n", curr_version.major, curr_version.minor);
438 for (func = funcs;func && func->name != NULL;func++)
440 // Con_DPrintf("\n %s... ", func->name);
442 // functions are cleared before all the extensions are evaluated
443 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
446 Con_DPrintf("%s is missing function \"%s\" - broken driver!\n", minglver_or_ext, func->name);
448 Con_Printf("OpenGL %s core features are missing function \"%s\" - broken driver!\n", minglver_or_ext, func->name);
452 // delay the return so it prints all missing functions
455 // VorteX: add to found extension list
456 dpsnprintf(extstr, sizeof(extstr), "%s %s ", gl_info_extensions.string, minglver_or_ext);
457 Cvar_SetQuick(&gl_info_extensions, extstr);
459 Con_DPrint("enabled\n");
463 static dllfunction_t opengl110funcs[] =
465 {"glClearColor", (void **) &qglClearColor},
466 {"glClear", (void **) &qglClear},
467 {"glAlphaFunc", (void **) &qglAlphaFunc},
468 {"glBlendFunc", (void **) &qglBlendFunc},
469 {"glCullFace", (void **) &qglCullFace},
470 {"glDrawBuffer", (void **) &qglDrawBuffer},
471 {"glReadBuffer", (void **) &qglReadBuffer},
472 {"glEnable", (void **) &qglEnable},
473 {"glDisable", (void **) &qglDisable},
474 {"glIsEnabled", (void **) &qglIsEnabled},
475 {"glEnableClientState", (void **) &qglEnableClientState},
476 {"glDisableClientState", (void **) &qglDisableClientState},
477 {"glGetBooleanv", (void **) &qglGetBooleanv},
478 {"glGetDoublev", (void **) &qglGetDoublev},
479 {"glGetFloatv", (void **) &qglGetFloatv},
480 {"glGetIntegerv", (void **) &qglGetIntegerv},
481 {"glGetError", (void **) &qglGetError},
482 {"glGetString", (void **) &qglGetString},
483 {"glFinish", (void **) &qglFinish},
484 {"glFlush", (void **) &qglFlush},
485 {"glClearDepth", (void **) &qglClearDepth},
486 {"glDepthFunc", (void **) &qglDepthFunc},
487 {"glDepthMask", (void **) &qglDepthMask},
488 {"glDepthRange", (void **) &qglDepthRange},
489 {"glDrawElements", (void **) &qglDrawElements},
490 {"glColorMask", (void **) &qglColorMask},
491 {"glVertexPointer", (void **) &qglVertexPointer},
492 {"glNormalPointer", (void **) &qglNormalPointer},
493 {"glColorPointer", (void **) &qglColorPointer},
494 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
495 {"glArrayElement", (void **) &qglArrayElement},
496 {"glColor4f", (void **) &qglColor4f},
497 {"glTexCoord1f", (void **) &qglTexCoord1f},
498 {"glTexCoord2f", (void **) &qglTexCoord2f},
499 {"glTexCoord3f", (void **) &qglTexCoord3f},
500 {"glTexCoord4f", (void **) &qglTexCoord4f},
501 {"glVertex2f", (void **) &qglVertex2f},
502 {"glVertex3f", (void **) &qglVertex3f},
503 {"glBegin", (void **) &qglBegin},
504 {"glEnd", (void **) &qglEnd},
505 //[515]: added on 29.07.2005
506 {"glLineWidth", (void**) &qglLineWidth},
507 {"glPointSize", (void**) &qglPointSize},
509 {"glMatrixMode", (void **) &qglMatrixMode},
510 // {"glOrtho", (void **) &qglOrtho},
511 // {"glFrustum", (void **) &qglFrustum},
512 {"glViewport", (void **) &qglViewport},
513 // {"glPushMatrix", (void **) &qglPushMatrix},
514 // {"glPopMatrix", (void **) &qglPopMatrix},
515 {"glLoadIdentity", (void **) &qglLoadIdentity},
516 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
517 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
518 // {"glMultMatrixd", (void **) &qglMultMatrixd},
519 // {"glMultMatrixf", (void **) &qglMultMatrixf},
520 // {"glRotated", (void **) &qglRotated},
521 // {"glRotatef", (void **) &qglRotatef},
522 // {"glScaled", (void **) &qglScaled},
523 // {"glScalef", (void **) &qglScalef},
524 // {"glTranslated", (void **) &qglTranslated},
525 // {"glTranslatef", (void **) &qglTranslatef},
526 {"glReadPixels", (void **) &qglReadPixels},
527 {"glStencilFunc", (void **) &qglStencilFunc},
528 {"glStencilMask", (void **) &qglStencilMask},
529 {"glStencilOp", (void **) &qglStencilOp},
530 {"glClearStencil", (void **) &qglClearStencil},
531 {"glTexEnvf", (void **) &qglTexEnvf},
532 {"glTexEnvfv", (void **) &qglTexEnvfv},
533 {"glTexEnvi", (void **) &qglTexEnvi},
534 {"glTexParameterf", (void **) &qglTexParameterf},
535 {"glTexParameterfv", (void **) &qglTexParameterfv},
536 {"glTexParameteri", (void **) &qglTexParameteri},
537 {"glHint", (void **) &qglHint},
538 // {"glPixelStoref", (void **) &qglPixelStoref},
539 {"glPixelStorei", (void **) &qglPixelStorei},
540 {"glGenTextures", (void **) &qglGenTextures},
541 {"glDeleteTextures", (void **) &qglDeleteTextures},
542 {"glBindTexture", (void **) &qglBindTexture},
543 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
544 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
545 // {"glIsTexture", (void **) &qglIsTexture},
546 // {"glTexImage1D", (void **) &qglTexImage1D},
547 {"glTexImage2D", (void **) &qglTexImage2D},
548 // {"glTexSubImage1D", (void **) &qglTexSubImage1D},
549 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
550 // {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
551 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
552 // {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
553 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
554 {"glScissor", (void **) &qglScissor},
555 {"glPolygonOffset", (void **) &qglPolygonOffset},
556 {"glPolygonMode", (void **) &qglPolygonMode},
557 {"glPolygonStipple", (void **) &qglPolygonStipple},
558 // {"glClipPlane", (void **) &qglClipPlane},
559 // {"glGetClipPlane", (void **) &qglGetClipPlane},
563 static dllfunction_t drawrangeelementsfuncs[] =
565 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
569 static dllfunction_t drawrangeelementsextfuncs[] =
571 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
575 static dllfunction_t multitexturefuncs[] =
577 {"glMultiTexCoord1fARB", (void **) &qglMultiTexCoord1f},
578 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
579 {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
580 {"glMultiTexCoord4fARB", (void **) &qglMultiTexCoord4f},
581 {"glActiveTextureARB", (void **) &qglActiveTexture},
582 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
586 static dllfunction_t compiledvertexarrayfuncs[] =
588 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
589 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
593 static dllfunction_t texture3dextfuncs[] =
595 {"glTexImage3DEXT", (void **) &qglTexImage3D},
596 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
597 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
601 static dllfunction_t atiseparatestencilfuncs[] =
603 {"glStencilOpSeparateATI", (void **) &qglStencilOpSeparate},
604 {"glStencilFuncSeparateATI", (void **) &qglStencilFuncSeparate},
608 static dllfunction_t gl2separatestencilfuncs[] =
610 {"glStencilOpSeparate", (void **) &qglStencilOpSeparate},
611 {"glStencilFuncSeparate", (void **) &qglStencilFuncSeparate},
615 static dllfunction_t stenciltwosidefuncs[] =
617 {"glActiveStencilFaceEXT", (void **) &qglActiveStencilFaceEXT},
621 static dllfunction_t blendequationfuncs[] =
623 {"glBlendEquationEXT", (void **) &qglBlendEquationEXT},
627 static dllfunction_t shaderobjectsfuncs[] =
629 {"glDeleteObjectARB", (void **) &qglDeleteObjectARB},
630 {"glGetHandleARB", (void **) &qglGetHandleARB},
631 {"glDetachObjectARB", (void **) &qglDetachObjectARB},
632 {"glCreateShaderObjectARB", (void **) &qglCreateShaderObjectARB},
633 {"glShaderSourceARB", (void **) &qglShaderSourceARB},
634 {"glCompileShaderARB", (void **) &qglCompileShaderARB},
635 {"glCreateProgramObjectARB", (void **) &qglCreateProgramObjectARB},
636 {"glAttachObjectARB", (void **) &qglAttachObjectARB},
637 {"glLinkProgramARB", (void **) &qglLinkProgramARB},
638 {"glUseProgramObjectARB", (void **) &qglUseProgramObjectARB},
639 {"glValidateProgramARB", (void **) &qglValidateProgramARB},
640 {"glUniform1fARB", (void **) &qglUniform1fARB},
641 {"glUniform2fARB", (void **) &qglUniform2fARB},
642 {"glUniform3fARB", (void **) &qglUniform3fARB},
643 {"glUniform4fARB", (void **) &qglUniform4fARB},
644 {"glUniform1iARB", (void **) &qglUniform1iARB},
645 {"glUniform2iARB", (void **) &qglUniform2iARB},
646 {"glUniform3iARB", (void **) &qglUniform3iARB},
647 {"glUniform4iARB", (void **) &qglUniform4iARB},
648 {"glUniform1fvARB", (void **) &qglUniform1fvARB},
649 {"glUniform2fvARB", (void **) &qglUniform2fvARB},
650 {"glUniform3fvARB", (void **) &qglUniform3fvARB},
651 {"glUniform4fvARB", (void **) &qglUniform4fvARB},
652 {"glUniform1ivARB", (void **) &qglUniform1ivARB},
653 {"glUniform2ivARB", (void **) &qglUniform2ivARB},
654 {"glUniform3ivARB", (void **) &qglUniform3ivARB},
655 {"glUniform4ivARB", (void **) &qglUniform4ivARB},
656 {"glUniformMatrix2fvARB", (void **) &qglUniformMatrix2fvARB},
657 {"glUniformMatrix3fvARB", (void **) &qglUniformMatrix3fvARB},
658 {"glUniformMatrix4fvARB", (void **) &qglUniformMatrix4fvARB},
659 {"glGetObjectParameterfvARB", (void **) &qglGetObjectParameterfvARB},
660 {"glGetObjectParameterivARB", (void **) &qglGetObjectParameterivARB},
661 {"glGetInfoLogARB", (void **) &qglGetInfoLogARB},
662 {"glGetAttachedObjectsARB", (void **) &qglGetAttachedObjectsARB},
663 {"glGetUniformLocationARB", (void **) &qglGetUniformLocationARB},
664 {"glGetActiveUniformARB", (void **) &qglGetActiveUniformARB},
665 {"glGetUniformfvARB", (void **) &qglGetUniformfvARB},
666 {"glGetUniformivARB", (void **) &qglGetUniformivARB},
667 {"glGetShaderSourceARB", (void **) &qglGetShaderSourceARB},
671 static dllfunction_t vertexshaderfuncs[] =
673 // {"glVertexAttrib1fARB", (void **) &qglVertexAttrib1fARB},
674 // {"glVertexAttrib1sARB", (void **) &qglVertexAttrib1sARB},
675 // {"glVertexAttrib1dARB", (void **) &qglVertexAttrib1dARB},
676 // {"glVertexAttrib2fARB", (void **) &qglVertexAttrib2fARB},
677 // {"glVertexAttrib2sARB", (void **) &qglVertexAttrib2sARB},
678 // {"glVertexAttrib2dARB", (void **) &qglVertexAttrib2dARB},
679 // {"glVertexAttrib3fARB", (void **) &qglVertexAttrib3fARB},
680 // {"glVertexAttrib3sARB", (void **) &qglVertexAttrib3sARB},
681 // {"glVertexAttrib3dARB", (void **) &qglVertexAttrib3dARB},
682 // {"glVertexAttrib4fARB", (void **) &qglVertexAttrib4fARB},
683 // {"glVertexAttrib4sARB", (void **) &qglVertexAttrib4sARB},
684 // {"glVertexAttrib4dARB", (void **) &qglVertexAttrib4dARB},
685 // {"glVertexAttrib4NubARB", (void **) &qglVertexAttrib4NubARB},
686 // {"glVertexAttrib1fvARB", (void **) &qglVertexAttrib1fvARB},
687 // {"glVertexAttrib1svARB", (void **) &qglVertexAttrib1svARB},
688 // {"glVertexAttrib1dvARB", (void **) &qglVertexAttrib1dvARB},
689 // {"glVertexAttrib2fvARB", (void **) &qglVertexAttrib1fvARB},
690 // {"glVertexAttrib2svARB", (void **) &qglVertexAttrib1svARB},
691 // {"glVertexAttrib2dvARB", (void **) &qglVertexAttrib1dvARB},
692 // {"glVertexAttrib3fvARB", (void **) &qglVertexAttrib1fvARB},
693 // {"glVertexAttrib3svARB", (void **) &qglVertexAttrib1svARB},
694 // {"glVertexAttrib3dvARB", (void **) &qglVertexAttrib1dvARB},
695 // {"glVertexAttrib4fvARB", (void **) &qglVertexAttrib1fvARB},
696 // {"glVertexAttrib4svARB", (void **) &qglVertexAttrib1svARB},
697 // {"glVertexAttrib4dvARB", (void **) &qglVertexAttrib1dvARB},
698 // {"glVertexAttrib4ivARB", (void **) &qglVertexAttrib1ivARB},
699 // {"glVertexAttrib4bvARB", (void **) &qglVertexAttrib1bvARB},
700 // {"glVertexAttrib4ubvARB", (void **) &qglVertexAttrib1ubvARB},
701 // {"glVertexAttrib4usvARB", (void **) &qglVertexAttrib1usvARB},
702 // {"glVertexAttrib4uivARB", (void **) &qglVertexAttrib1uivARB},
703 // {"glVertexAttrib4NbvARB", (void **) &qglVertexAttrib1NbvARB},
704 // {"glVertexAttrib4NsvARB", (void **) &qglVertexAttrib1NsvARB},
705 // {"glVertexAttrib4NivARB", (void **) &qglVertexAttrib1NivARB},
706 // {"glVertexAttrib4NubvARB", (void **) &qglVertexAttrib1NubvARB},
707 // {"glVertexAttrib4NusvARB", (void **) &qglVertexAttrib1NusvARB},
708 // {"glVertexAttrib4NuivARB", (void **) &qglVertexAttrib1NuivARB},
709 {"glVertexAttribPointerARB", (void **) &qglVertexAttribPointerARB},
710 {"glEnableVertexAttribArrayARB", (void **) &qglEnableVertexAttribArrayARB},
711 {"glDisableVertexAttribArrayARB", (void **) &qglDisableVertexAttribArrayARB},
712 {"glBindAttribLocationARB", (void **) &qglBindAttribLocationARB},
713 {"glGetActiveAttribARB", (void **) &qglGetActiveAttribARB},
714 {"glGetAttribLocationARB", (void **) &qglGetAttribLocationARB},
715 // {"glGetVertexAttribdvARB", (void **) &qglGetVertexAttribdvARB},
716 // {"glGetVertexAttribfvARB", (void **) &qglGetVertexAttribfvARB},
717 // {"glGetVertexAttribivARB", (void **) &qglGetVertexAttribivARB},
718 // {"glGetVertexAttribPointervARB", (void **) &qglGetVertexAttribPointervARB},
722 static dllfunction_t vbofuncs[] =
724 {"glBindBufferARB" , (void **) &qglBindBufferARB},
725 {"glDeleteBuffersARB" , (void **) &qglDeleteBuffersARB},
726 {"glGenBuffersARB" , (void **) &qglGenBuffersARB},
727 {"glIsBufferARB" , (void **) &qglIsBufferARB},
728 {"glMapBufferARB" , (void **) &qglMapBufferARB},
729 {"glUnmapBufferARB" , (void **) &qglUnmapBufferARB},
730 {"glBufferDataARB" , (void **) &qglBufferDataARB},
731 {"glBufferSubDataARB" , (void **) &qglBufferSubDataARB},
735 static dllfunction_t fbofuncs[] =
737 {"glIsRenderbufferEXT" , (void **) &qglIsRenderbufferEXT},
738 {"glBindRenderbufferEXT" , (void **) &qglBindRenderbufferEXT},
739 {"glDeleteRenderbuffersEXT" , (void **) &qglDeleteRenderbuffersEXT},
740 {"glGenRenderbuffersEXT" , (void **) &qglGenRenderbuffersEXT},
741 {"glRenderbufferStorageEXT" , (void **) &qglRenderbufferStorageEXT},
742 {"glGetRenderbufferParameterivEXT" , (void **) &qglGetRenderbufferParameterivEXT},
743 {"glIsFramebufferEXT" , (void **) &qglIsFramebufferEXT},
744 {"glBindFramebufferEXT" , (void **) &qglBindFramebufferEXT},
745 {"glDeleteFramebuffersEXT" , (void **) &qglDeleteFramebuffersEXT},
746 {"glGenFramebuffersEXT" , (void **) &qglGenFramebuffersEXT},
747 {"glCheckFramebufferStatusEXT" , (void **) &qglCheckFramebufferStatusEXT},
748 // {"glFramebufferTexture1DEXT" , (void **) &qglFramebufferTexture1DEXT},
749 {"glFramebufferTexture2DEXT" , (void **) &qglFramebufferTexture2DEXT},
750 {"glFramebufferTexture3DEXT" , (void **) &qglFramebufferTexture3DEXT},
751 {"glFramebufferRenderbufferEXT" , (void **) &qglFramebufferRenderbufferEXT},
752 {"glGetFramebufferAttachmentParameterivEXT" , (void **) &qglGetFramebufferAttachmentParameterivEXT},
753 {"glGenerateMipmapEXT" , (void **) &qglGenerateMipmapEXT},
757 static dllfunction_t texturecompressionfuncs[] =
759 {"glCompressedTexImage3DARB", (void **) &qglCompressedTexImage3DARB},
760 {"glCompressedTexImage2DARB", (void **) &qglCompressedTexImage2DARB},
761 // {"glCompressedTexImage1DARB", (void **) &qglCompressedTexImage1DARB},
762 {"glCompressedTexSubImage3DARB", (void **) &qglCompressedTexSubImage3DARB},
763 {"glCompressedTexSubImage2DARB", (void **) &qglCompressedTexSubImage2DARB},
764 // {"glCompressedTexSubImage1DARB", (void **) &qglCompressedTexSubImage1DARB},
765 {"glGetCompressedTexImageARB", (void **) &qglGetCompressedTexImageARB},
769 static dllfunction_t occlusionqueryfuncs[] =
771 {"glGenQueriesARB", (void **) &qglGenQueriesARB},
772 {"glDeleteQueriesARB", (void **) &qglDeleteQueriesARB},
773 {"glIsQueryARB", (void **) &qglIsQueryARB},
774 {"glBeginQueryARB", (void **) &qglBeginQueryARB},
775 {"glEndQueryARB", (void **) &qglEndQueryARB},
776 {"glGetQueryivARB", (void **) &qglGetQueryivARB},
777 {"glGetQueryObjectivARB", (void **) &qglGetQueryObjectivARB},
778 {"glGetQueryObjectuivARB", (void **) &qglGetQueryObjectuivARB},
782 static dllfunction_t drawbuffersfuncs[] =
784 {"glDrawBuffersARB", (void **) &qglDrawBuffersARB},
788 void VID_CheckExtensions(void)
790 // clear the extension flags
791 memset(&vid.support, 0, sizeof(vid.support));
793 // VorteX: reset extensions info cvar, it got filled by GL_CheckExtension
794 Cvar_SetQuick(&gl_info_extensions, "");
795 if (!GL_CheckExtension("1.1", opengl110funcs, NULL, false))
796 Sys_Error("OpenGL 1.1.0 functions not found");
800 Con_DPrint("Checking OpenGL extensions...\n");
802 vid.support.amd_texture_texture4 = GL_CheckExtension("GL_AMD_texture_texture4", NULL, "-notexture4", false);
803 vid.support.arb_depth_texture = GL_CheckExtension("GL_ARB_depth_texture", NULL, "-nodepthtexture", false);
804 vid.support.arb_draw_buffers = GL_CheckExtension("GL_ARB_draw_buffers", drawbuffersfuncs, "-nodrawbuffers", false);
805 vid.support.arb_fragment_shader = GL_CheckExtension("GL_ARB_fragment_shader", NULL, "-nofragmentshader", false);
806 vid.support.arb_multitexture = GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false);
807 vid.support.arb_occlusion_query = GL_CheckExtension("GL_ARB_occlusion_query", occlusionqueryfuncs, "-noocclusionquery", false);
808 vid.support.arb_shader_objects = GL_CheckExtension("GL_ARB_shader_objects", shaderobjectsfuncs, "-noshaderobjects", false);
809 vid.support.arb_shading_language_100 = GL_CheckExtension("GL_ARB_shading_language_100", NULL, "-noshadinglanguage100", false);
810 vid.support.arb_shadow = GL_CheckExtension("GL_ARB_shadow", NULL, "-noshadow", false);
811 vid.support.arb_texture_compression = GL_CheckExtension("GL_ARB_texture_compression", texturecompressionfuncs, "-notexturecompression", false);
812 vid.support.arb_texture_cube_map = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
813 vid.support.arb_texture_env_combine = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
814 vid.support.arb_texture_gather = GL_CheckExtension("GL_ARB_texture_gather", NULL, "-notexturegather", false);
815 vid.support.arb_texture_non_power_of_two = GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false);
816 vid.support.arb_texture_rectangle = GL_CheckExtension("GL_ARB_texture_rectangle", NULL, "-norectangle", false);
817 vid.support.arb_vertex_buffer_object = GL_CheckExtension("GL_ARB_vertex_buffer_object", vbofuncs, "-novbo", false);
818 vid.support.arb_vertex_shader = GL_CheckExtension("GL_ARB_vertex_shader", vertexshaderfuncs, "-novertexshader", false);
819 vid.support.ati_separate_stencil = GL_CheckExtension("2.0", gl2separatestencilfuncs, "-noseparatestencil", true) || GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "-noseparatestencil", false);
820 vid.support.ext_blend_minmax = GL_CheckExtension("GL_EXT_blend_minmax", blendequationfuncs, "-noblendminmax", false);
821 vid.support.ext_blend_subtract = GL_CheckExtension("GL_EXT_blend_subtract", blendequationfuncs, "-noblendsubtract", false);
822 vid.support.ext_compiled_vertex_array = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
823 vid.support.ext_draw_range_elements = GL_CheckExtension("1.2", drawrangeelementsfuncs, "-nodrawrangeelements", true) || GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
824 vid.support.ext_framebuffer_object = GL_CheckExtension("GL_EXT_framebuffer_object", fbofuncs, "-nofbo", false);
825 vid.support.ext_stencil_two_side = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false);
826 vid.support.ext_texture_3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
827 vid.support.ext_texture_edge_clamp = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
828 vid.support.ext_texture_filter_anisotropic = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false);
829 // COMMANDLINEOPTION: GL: -noanisotropy disables GL_EXT_texture_filter_anisotropic (allows higher quality texturing)
830 // COMMANDLINEOPTION: GL: -noblendminmax disables GL_EXT_blend_minmax
831 // COMMANDLINEOPTION: GL: -noblendsubtract disables GL_EXT_blend_subtract
832 // COMMANDLINEOPTION: GL: -nocombine disables GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (required for bumpmapping and faster map rendering)
833 // COMMANDLINEOPTION: GL: -nocubemap disables GL_ARB_texture_cube_map (required for bumpmapping)
834 // COMMANDLINEOPTION: GL: -nocva disables GL_EXT_compiled_vertex_array (renders faster)
835 // COMMANDLINEOPTION: GL: -nodepthtexture disables use of GL_ARB_depth_texture (required for shadowmapping)
836 // COMMANDLINEOPTION: GL: -nodrawbuffers disables use of GL_ARB_draw_buffers (required for r_shadow_deferredprepass)
837 // COMMANDLINEOPTION: GL: -nodrawrangeelements disables GL_EXT_draw_range_elements (renders faster)
838 // COMMANDLINEOPTION: GL: -noedgeclamp disables GL_EXT_texture_edge_clamp or GL_SGIS_texture_edge_clamp (recommended, some cards do not support the other texture clamp method)
839 // COMMANDLINEOPTION: GL: -nofbo disables GL_EXT_framebuffer_object (which accelerates rendering), only used if GL_ARB_fragment_shader is also available
840 // COMMANDLINEOPTION: GL: -nofragmentshader disables GL_ARB_fragment_shader (allows pixel shader effects, can improve per pixel lighting performance and capabilities)
841 // COMMANDLINEOPTION: GL: -nomtex disables GL_ARB_multitexture (required for faster map rendering)
842 // COMMANDLINEOPTION: GL: -noocclusionquery disables GL_ARB_occlusion_query (which allows coronas to fade according to visibility, and potentially used for rendering optimizations)
843 // COMMANDLINEOPTION: GL: -norectangle disables GL_ARB_texture_rectangle (required for bumpmapping)
844 // COMMANDLINEOPTION: GL: -noseparatestencil disables use of OpenGL2.0 glStencilOpSeparate and GL_ATI_separate_stencil extensions (which accelerate shadow rendering)
845 // COMMANDLINEOPTION: GL: -noshaderobjects disables GL_ARB_shader_objects (required for vertex shader and fragment shader)
846 // COMMANDLINEOPTION: GL: -noshadinglanguage100 disables GL_ARB_shading_language_100 (required for vertex shader and fragment shader)
847 // COMMANDLINEOPTION: GL: -noshadow disables use of GL_ARB_shadow (required for hardware shadowmap filtering)
848 // COMMANDLINEOPTION: GL: -nostenciltwoside disables GL_EXT_stencil_two_side (which accelerate shadow rendering)
849 // COMMANDLINEOPTION: GL: -notexture3d disables GL_EXT_texture3D (required for spherical lights, otherwise they render as a column)
850 // COMMANDLINEOPTION: GL: -notexture4 disables GL_AMD_texture_texture4 (which provides fetch4 sampling)
851 // COMMANDLINEOPTION: GL: -notexturecompression disables GL_ARB_texture_compression (which saves video memory if it is supported, but can also degrade image quality, see gl_texturecompression cvar documentation for more information)
852 // COMMANDLINEOPTION: GL: -notexturegather disables GL_ARB_texture_gather (which provides fetch4 sampling)
853 // COMMANDLINEOPTION: GL: -notexturenonpoweroftwo disables GL_ARB_texture_non_power_of_two (which saves video memory if it is supported, but crashes on some buggy drivers)
854 // COMMANDLINEOPTION: GL: -novbo disables GL_ARB_vertex_buffer_object (which accelerates rendering)
855 // COMMANDLINEOPTION: GL: -novertexshader disables GL_ARB_vertex_shader (allows vertex shader effects)
857 vid.maxtexturesize_2d = 0;
858 vid.maxtexturesize_3d = 0;
859 vid.maxtexturesize_cubemap = 0;
861 vid.teximageunits = 1;
862 vid.texarrayunits = 1;
863 vid.max_anisotropy = 1;
864 vid.maxdrawbuffers = 1;
866 if (vid.support.arb_draw_buffers)
867 qglGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, (GLint*)&vid.maxdrawbuffers);
869 // disable non-power-of-two textures on Radeon X1600 and other cards that do not accelerate it with some filtering modes / repeat modes that we use
870 // we detect these cards by checking if the hardware supports vertex texture fetch (Geforce6 does, Radeon X1600 does not, all GL3-class hardware does)
871 if(vid.support.arb_texture_non_power_of_two)
874 if (vid.support.arb_vertex_shader)
875 qglGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &val);CHECKGLERROR
877 vid.support.arb_texture_non_power_of_two = false;
880 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
881 if (qglDrawRangeElements == NULL)
882 qglDrawRangeElements = qglDrawRangeElementsEXT;
884 qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
885 if (vid.support.ext_texture_filter_anisotropic)
886 qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
887 if (vid.support.arb_texture_cube_map)
888 qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&vid.maxtexturesize_cubemap);
889 if (vid.support.arb_texture_rectangle)
890 qglGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, (GLint*)&vid.maxtexturesize_rectangle);
891 if (vid.support.ext_texture_3d)
892 qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
894 // verify that 3d textures are really supported
895 if (vid.support.ext_texture_3d && vid.maxtexturesize_3d < 32)
897 vid.support.ext_texture_3d = false;
898 Con_Printf("GL_EXT_texture3D reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n");
901 vid.texunits = vid.teximageunits = vid.texarrayunits = 1;
902 if (vid.support.arb_multitexture)
903 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&vid.texunits);
904 if (vid_gl20.integer && vid.support.arb_fragment_shader && vid.support.arb_vertex_shader && vid.support.arb_shader_objects)
906 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&vid.texunits);
907 qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (int *)&vid.teximageunits);CHECKGLERROR
908 qglGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, (int *)&vid.texarrayunits);CHECKGLERROR
909 vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
910 vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
911 vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
912 Con_DPrintf("Using GL2.0 rendering path - %i texture matrix, %i texture images, %i texcoords%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.support.ext_framebuffer_object ? ", shadowmapping supported" : "");
913 vid.renderpath = RENDERPATH_GL20;
916 else if (vid_cggl.integer && (vid.cgcontext = cgCreateContext()))
919 vid.teximageunits = 16;
920 vid.texarrayunits = 8;
921 Con_DPrintf("Using NVIDIA Cg rendering path - %i texture matrix, %i texture images, %i texcoords%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.support.ext_framebuffer_object ? ", shadowmapping supported" : "");
922 vid.renderpath = RENDERPATH_CGGL;
925 else if (vid.support.arb_texture_env_combine && vid.texunits >= 2 && vid_gl13.integer)
927 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&vid.texunits);
928 vid.texunits = bound(1, vid.texunits, MAX_TEXTUREUNITS);
929 vid.teximageunits = vid.texunits;
930 vid.texarrayunits = vid.texunits;
931 Con_DPrintf("Using GL1.3 rendering path - %i texture units, single pass rendering\n", vid.texunits);
932 vid.renderpath = RENDERPATH_GL13;
936 vid.texunits = bound(1, vid.texunits, MAX_TEXTUREUNITS);
937 vid.teximageunits = vid.texunits;
938 vid.texarrayunits = vid.texunits;
939 Con_DPrintf("Using GL1.1 rendering path - %i texture units, two pass rendering\n", vid.texunits);
940 vid.renderpath = RENDERPATH_GL11;
943 // VorteX: set other info (maybe place them in VID_InitMode?)
944 Cvar_SetQuick(&gl_info_vendor, gl_vendor);
945 Cvar_SetQuick(&gl_info_renderer, gl_renderer);
946 Cvar_SetQuick(&gl_info_version, gl_version);
947 Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
948 Cvar_SetQuick(&gl_info_driver, gl_driver);
951 void Force_CenterView_f (void)
953 cl.viewangles[PITCH] = 0;
956 static int gamma_forcenextframe = false;
957 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost;
958 static int cachecolorenable, cachehwgamma;
960 unsigned int vid_gammatables_serial = 0; // so other subsystems can poll if gamma parameters have changed
961 qboolean vid_gammatables_trivial = true;
962 void VID_BuildGammaTables(unsigned short *ramps, int rampsize)
964 if (cachecolorenable)
966 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, ramps, rampsize);
967 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, ramps + rampsize, rampsize);
968 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, ramps + rampsize*2, rampsize);
972 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps, rampsize);
973 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize, rampsize);
974 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize*2, rampsize);
977 // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
978 // immensely butchered it to work with variable framerates and fit in with
979 // the rest of darkplaces.
980 if (v_psycho.integer)
984 static float n[3], nd[3], nt[3];
985 static int init = true;
986 unsigned short *ramp;
987 gamma_forcenextframe = true;
991 for (x = 0;x < 3;x++)
993 n[x] = lhrandom(0, 1);
994 nd[x] = (rand()&1)?-0.25:0.25;
995 nt[x] = lhrandom(1, 8.2);
999 for (x = 0;x < 3;x++)
1001 nt[x] -= cl.realframetime;
1005 nt[x] += lhrandom(1, 8.2);
1007 n[x] += nd[x] * cl.realframetime;
1008 n[x] -= floor(n[x]);
1011 for (x = 0, ramp = ramps;x < 3;x++)
1012 for (y = 0, t = n[x] - 0.75f;y < rampsize;y++, t += 0.75f * (2.0f / rampsize))
1013 *ramp++ = (unsigned short)(cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f);
1017 void VID_UpdateGamma(qboolean force, int rampsize)
1022 qboolean gamma_changed = false;
1024 // LordHavoc: don't mess with gamma tables if running dedicated
1025 if (cls.state == ca_dedicated)
1028 wantgamma = v_hwgamma.integer;
1029 switch(vid.renderpath)
1031 case RENDERPATH_GL20:
1032 case RENDERPATH_CGGL:
1033 if (v_glslgamma.integer)
1036 case RENDERPATH_GL13:
1037 case RENDERPATH_GL11:
1040 if(!vid_activewindow)
1042 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
1043 BOUNDCVAR(v_gamma, 0.1, 5);
1044 BOUNDCVAR(v_contrast, 1, 5);
1045 BOUNDCVAR(v_brightness, 0, 0.8);
1046 //BOUNDCVAR(v_contrastboost, 0.0625, 16);
1047 BOUNDCVAR(v_color_black_r, 0, 0.8);
1048 BOUNDCVAR(v_color_black_g, 0, 0.8);
1049 BOUNDCVAR(v_color_black_b, 0, 0.8);
1050 BOUNDCVAR(v_color_grey_r, 0, 0.95);
1051 BOUNDCVAR(v_color_grey_g, 0, 0.95);
1052 BOUNDCVAR(v_color_grey_b, 0, 0.95);
1053 BOUNDCVAR(v_color_white_r, 1, 5);
1054 BOUNDCVAR(v_color_white_g, 1, 5);
1055 BOUNDCVAR(v_color_white_b, 1, 5);
1058 // set vid_gammatables_trivial to true if the current settings would generate the identity gamma table
1059 vid_gammatables_trivial = false;
1060 if(v_psycho.integer == 0)
1061 if(v_contrastboost.value == 1)
1063 if(v_color_enable.integer)
1065 if(v_color_black_r.value == 0)
1066 if(v_color_black_g.value == 0)
1067 if(v_color_black_b.value == 0)
1068 if(fabs(v_color_grey_r.value - 0.5) < 1e-6)
1069 if(fabs(v_color_grey_g.value - 0.5) < 1e-6)
1070 if(fabs(v_color_grey_b.value - 0.5) < 1e-6)
1071 if(v_color_white_r.value == 1)
1072 if(v_color_white_g.value == 1)
1073 if(v_color_white_b.value == 1)
1074 vid_gammatables_trivial = true;
1078 if(v_gamma.value == 1)
1079 if(v_contrast.value == 1)
1080 if(v_brightness.value == 0)
1081 vid_gammatables_trivial = true;
1085 #define GAMMACHECK(cache, value) if (cache != (value)) gamma_changed = true;cache = (value)
1086 if(v_psycho.integer)
1087 gamma_changed = true;
1088 GAMMACHECK(cachegamma , v_gamma.value);
1089 GAMMACHECK(cachecontrast , v_contrast.value);
1090 GAMMACHECK(cachebrightness , v_brightness.value);
1091 GAMMACHECK(cachecontrastboost, v_contrastboost.value);
1092 GAMMACHECK(cachecolorenable, v_color_enable.integer);
1093 GAMMACHECK(cacheblack[0] , v_color_black_r.value);
1094 GAMMACHECK(cacheblack[1] , v_color_black_g.value);
1095 GAMMACHECK(cacheblack[2] , v_color_black_b.value);
1096 GAMMACHECK(cachegrey[0] , v_color_grey_r.value);
1097 GAMMACHECK(cachegrey[1] , v_color_grey_g.value);
1098 GAMMACHECK(cachegrey[2] , v_color_grey_b.value);
1099 GAMMACHECK(cachewhite[0] , v_color_white_r.value);
1100 GAMMACHECK(cachewhite[1] , v_color_white_g.value);
1101 GAMMACHECK(cachewhite[2] , v_color_white_b.value);
1104 ++vid_gammatables_serial;
1106 GAMMACHECK(cachehwgamma , wantgamma);
1109 if (!force && !gamma_forcenextframe && !gamma_changed)
1112 gamma_forcenextframe = false;
1116 if (!vid_usinghwgamma)
1118 vid_usinghwgamma = true;
1119 if (vid_gammarampsize != rampsize || !vid_gammaramps)
1121 vid_gammarampsize = rampsize;
1123 Z_Free(vid_gammaramps);
1124 vid_gammaramps = (unsigned short *)Z_Malloc(6 * vid_gammarampsize * sizeof(unsigned short));
1125 vid_systemgammaramps = vid_gammaramps + 3 * vid_gammarampsize;
1127 VID_GetGamma(vid_systemgammaramps, vid_gammarampsize);
1130 VID_BuildGammaTables(vid_gammaramps, vid_gammarampsize);
1132 // set vid_hardwaregammasupported to true if VID_SetGamma succeeds, OR if vid_hwgamma is >= 2 (forced gamma - ignores driver return value)
1133 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps, vid_gammarampsize) || cachehwgamma >= 2);
1134 // if custom gamma ramps failed (Windows stupidity), restore to system gamma
1135 if(!vid_hardwaregammasupported.integer)
1137 if (vid_usinghwgamma)
1139 vid_usinghwgamma = false;
1140 VID_SetGamma(vid_systemgammaramps, vid_gammarampsize);
1146 if (vid_usinghwgamma)
1148 vid_usinghwgamma = false;
1149 VID_SetGamma(vid_systemgammaramps, vid_gammarampsize);
1154 void VID_RestoreSystemGamma(void)
1156 if (vid_usinghwgamma)
1158 vid_usinghwgamma = false;
1159 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps, vid_gammarampsize));
1160 // force gamma situation to be reexamined next frame
1161 gamma_forcenextframe = true;
1165 void VID_Shared_Init(void)
1167 Cvar_RegisterVariable(&vid_hardwaregammasupported);
1168 Cvar_RegisterVariable(&gl_info_vendor);
1169 Cvar_RegisterVariable(&gl_info_renderer);
1170 Cvar_RegisterVariable(&gl_info_version);
1171 Cvar_RegisterVariable(&gl_info_extensions);
1172 Cvar_RegisterVariable(&gl_info_platform);
1173 Cvar_RegisterVariable(&gl_info_driver);
1174 Cvar_RegisterVariable(&v_gamma);
1175 Cvar_RegisterVariable(&v_brightness);
1176 Cvar_RegisterVariable(&v_contrastboost);
1177 Cvar_RegisterVariable(&v_contrast);
1179 Cvar_RegisterVariable(&v_color_enable);
1180 Cvar_RegisterVariable(&v_color_black_r);
1181 Cvar_RegisterVariable(&v_color_black_g);
1182 Cvar_RegisterVariable(&v_color_black_b);
1183 Cvar_RegisterVariable(&v_color_grey_r);
1184 Cvar_RegisterVariable(&v_color_grey_g);
1185 Cvar_RegisterVariable(&v_color_grey_b);
1186 Cvar_RegisterVariable(&v_color_white_r);
1187 Cvar_RegisterVariable(&v_color_white_g);
1188 Cvar_RegisterVariable(&v_color_white_b);
1190 Cvar_RegisterVariable(&v_hwgamma);
1191 Cvar_RegisterVariable(&v_glslgamma);
1193 Cvar_RegisterVariable(&v_psycho);
1195 Cvar_RegisterVariable(&vid_fullscreen);
1196 Cvar_RegisterVariable(&vid_width);
1197 Cvar_RegisterVariable(&vid_height);
1198 Cvar_RegisterVariable(&vid_bitsperpixel);
1199 Cvar_RegisterVariable(&vid_samples);
1200 Cvar_RegisterVariable(&vid_refreshrate);
1201 Cvar_RegisterVariable(&vid_userefreshrate);
1202 Cvar_RegisterVariable(&vid_stereobuffer);
1203 Cvar_RegisterVariable(&vid_vsync);
1204 Cvar_RegisterVariable(&vid_mouse);
1205 Cvar_RegisterVariable(&vid_grabkeyboard);
1206 Cvar_RegisterVariable(&vid_stick_mouse);
1207 Cvar_RegisterVariable(&vid_resizable);
1208 Cvar_RegisterVariable(&vid_minwidth);
1209 Cvar_RegisterVariable(&vid_minheight);
1210 Cvar_RegisterVariable(&vid_gl13);
1211 Cvar_RegisterVariable(&vid_gl20);
1213 Cvar_RegisterVariable(&vid_cggl);
1215 Cvar_RegisterVariable(&gl_finish);
1216 Cmd_AddCommand("force_centerview", Force_CenterView_f, "recenters view (stops looking up/down)");
1217 Cmd_AddCommand("vid_restart", VID_Restart_f, "restarts video system (closes and reopens the window, restarts renderer)");
1220 int VID_Mode(int fullscreen, int width, int height, int bpp, float refreshrate, int stereobuffer, int samples)
1223 memset(&mode, 0, sizeof(mode));
1224 mode.fullscreen = fullscreen;
1226 mode.height = height;
1227 mode.bitsperpixel = bpp;
1228 mode.refreshrate = vid_userefreshrate.integer ? max(1, refreshrate) : 0;
1229 mode.userefreshrate = vid_userefreshrate.integer;
1230 mode.stereobuffer = stereobuffer;
1231 mode.samples = samples;
1232 cl_ignoremousemoves = 2;
1233 if (VID_InitMode(&mode))
1235 // accept the (possibly modified) mode
1237 vid.fullscreen = vid.mode.fullscreen;
1238 vid.width = vid.mode.width;
1239 vid.height = vid.mode.height;
1240 vid.bitsperpixel = vid.mode.bitsperpixel;
1241 vid.refreshrate = vid.mode.refreshrate;
1242 vid.userefreshrate = vid.mode.userefreshrate;
1243 vid.stereobuffer = vid.mode.stereobuffer;
1244 vid.samples = vid.mode.samples;
1245 vid.stencil = vid.mode.bitsperpixel > 16;
1246 Con_Printf("Video Mode: %s %dx%dx%dx%.2fhz%s%s\n", mode.fullscreen ? "fullscreen" : "window", mode.width, mode.height, mode.bitsperpixel, mode.refreshrate, mode.stereobuffer ? " stereo" : "", mode.samples > 1 ? va(" (%ix AA)", mode.samples) : "");
1248 Cvar_SetValueQuick(&vid_fullscreen, vid.mode.fullscreen);
1249 Cvar_SetValueQuick(&vid_width, vid.mode.width);
1250 Cvar_SetValueQuick(&vid_height, vid.mode.height);
1251 Cvar_SetValueQuick(&vid_bitsperpixel, vid.mode.bitsperpixel);
1252 Cvar_SetValueQuick(&vid_samples, vid.mode.samples);
1253 if(vid_userefreshrate.integer)
1254 Cvar_SetValueQuick(&vid_refreshrate, vid.mode.refreshrate);
1255 Cvar_SetValueQuick(&vid_stereobuffer, vid.mode.stereobuffer);
1263 static void VID_OpenSystems(void)
1269 static void VID_CloseSystems(void)
1272 R_Modules_Shutdown();
1275 qboolean vid_commandlinecheck = true;
1277 void VID_Restart_f(void)
1279 // don't crash if video hasn't started yet
1280 if (vid_commandlinecheck)
1283 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp%s%s, to %s %dx%dx%dbpp%s%s.\n",
1284 vid.mode.fullscreen ? "fullscreen" : "window", vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.fullscreen && vid.mode.userefreshrate ? va("x%.2fhz", vid.mode.refreshrate) : "", vid.mode.samples > 1 ? va(" (%ix AA)", vid.mode.samples) : "",
1285 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_fullscreen.integer && vid_userefreshrate.integer ? va("x%.2fhz", vid_refreshrate.value) : "", vid_samples.integer > 1 ? va(" (%ix AA)", vid_samples.integer) : "");
1288 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer))
1290 Con_Print("Video mode change failed\n");
1291 if (!VID_Mode(vid.mode.fullscreen, vid.mode.width, vid.mode.height, vid.mode.bitsperpixel, vid.mode.refreshrate, vid.mode.stereobuffer, vid.mode.samples))
1292 Sys_Error("Unable to restore to last working video mode");
1297 const char *vidfallbacks[][2] =
1299 {"vid_stereobuffer", "0"},
1300 {"vid_samples", "1"},
1301 {"vid_userefreshrate", "0"},
1302 {"vid_width", "640"},
1303 {"vid_height", "480"},
1304 {"vid_bitsperpixel", "16"},
1308 // this is only called once by Host_StartVideo
1309 void VID_Start(void)
1311 int i, width, height, success;
1312 if (vid_commandlinecheck)
1314 // interpret command-line parameters
1315 vid_commandlinecheck = false;
1316 // COMMANDLINEOPTION: Video: -window performs +vid_fullscreen 0
1317 if (COM_CheckParm("-window") || COM_CheckParm("-safe"))
1318 Cvar_SetValueQuick(&vid_fullscreen, false);
1319 // COMMANDLINEOPTION: Video: -fullscreen performs +vid_fullscreen 1
1320 if (COM_CheckParm("-fullscreen"))
1321 Cvar_SetValueQuick(&vid_fullscreen, true);
1324 // COMMANDLINEOPTION: Video: -width <pixels> performs +vid_width <pixels> and also +vid_height <pixels*3/4> if only -width is specified (example: -width 1024 sets 1024x768 mode)
1325 if ((i = COM_CheckParm("-width")) != 0)
1326 width = atoi(com_argv[i+1]);
1327 // COMMANDLINEOPTION: Video: -height <pixels> performs +vid_height <pixels> and also +vid_width <pixels*4/3> if only -height is specified (example: -height 768 sets 1024x768 mode)
1328 if ((i = COM_CheckParm("-height")) != 0)
1329 height = atoi(com_argv[i+1]);
1331 width = height * 4 / 3;
1333 height = width * 3 / 4;
1335 Cvar_SetValueQuick(&vid_width, width);
1337 Cvar_SetValueQuick(&vid_height, height);
1338 // COMMANDLINEOPTION: Video: -bpp <bits> performs +vid_bitsperpixel <bits> (example -bpp 32 or -bpp 16)
1339 if ((i = COM_CheckParm("-bpp")) != 0)
1340 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
1343 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
1346 Con_Print("Desired video mode fail, trying fallbacks...\n");
1347 for (i = 0;!success && vidfallbacks[i][0] != NULL;i++)
1349 Cvar_Set(vidfallbacks[i][0], vidfallbacks[i][1]);
1350 success = VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_refreshrate.value, vid_stereobuffer.integer, vid_samples.integer);
1353 Sys_Error("Video modes failed");
1358 int VID_SortModes_Compare(const void *a_, const void *b_)
1360 vid_mode_t *a = (vid_mode_t *) a_;
1361 vid_mode_t *b = (vid_mode_t *) b_;
1362 if(a->width > b->width)
1364 if(a->width < b->width)
1366 if(a->height > b->height)
1368 if(a->height < b->height)
1370 if(a->refreshrate > b->refreshrate)
1372 if(a->refreshrate < b->refreshrate)
1378 if(a->pixelheight_num * b->pixelheight_denom > a->pixelheight_denom * b->pixelheight_num)
1380 if(a->pixelheight_num * b->pixelheight_denom < a->pixelheight_denom * b->pixelheight_num)
1384 size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean userefreshrate, qboolean useaspect)
1390 qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
1391 // 2. remove duplicates
1392 for(i = 0; i < count; ++i)
1394 if(modes[i].width && modes[i].height)
1398 if(modes[i].width != modes[i-1].width)
1400 if(modes[i].height != modes[i-1].height)
1403 if(modes[i].refreshrate != modes[i-1].refreshrate)
1406 if(modes[i].bpp != modes[i-1].bpp)
1409 if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
1412 // a dupe, or a bogus mode!
1414 memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i));
1415 --i; // check this index again, as mode i+1 is now here