19 #include "shared/shared.h"
20 #include "common/common.h"
21 #include "client/video.h"
26 #define QGL(x) qgl##x##_t qgl##x
42 #define QGL(x) static qgl##x##_t dll##x
50 #define SIG(x) fprintf(log_fp, "%s\n", x)
51 #define SIGf(...) fprintf(log_fp, __VA_ARGS__)
53 static const char *enumToString(GLenum num)
55 #define E(x) case x: return #x;
72 E(GL_TEXTURE_COORD_ARRAY)
87 E(GL_POLYGON_OFFSET_FILL)
105 E(GL_ONE_MINUS_SRC_ALPHA)
117 E(GL_TEXTURE_ENV_MODE)
121 E(GL_TEXTURE_MAG_FILTER)
122 E(GL_TEXTURE_MIN_FILTER)
126 E(GL_FRAGMENT_PROGRAM_ARB)
129 E(GL_TEXTURE_MAX_ANISOTROPY_EXT)
132 return va(
"%#x", num);
135 static void APIENTRY logAlphaFunc(GLenum func, GLclampf ref)
137 SIGf(
"%s( %s, %f )\n",
"glAlphaFunc", enumToString(func), ref);
138 dllAlphaFunc(func, ref);
141 static void APIENTRY logBindTexture(GLenum target, GLuint texture)
143 SIGf(
"%s( %s, %u )\n",
"glBindTexture", enumToString(target), texture);
144 dllBindTexture(target, texture);
147 static void APIENTRY logBlendFunc(GLenum sfactor, GLenum dfactor)
149 SIGf(
"%s( %s, %s )\n",
"glBlendFunc", enumToString(sfactor), enumToString(dfactor));
150 dllBlendFunc(sfactor, dfactor);
153 static void APIENTRY logClear(GLbitfield mask)
155 SIGf(
"%s( %#x )\n",
"glClear", mask);
159 static void APIENTRY logClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
162 dllClearColor(red, green, blue, alpha);
165 static void APIENTRY logClearDepth(GLclampd depth)
168 dllClearDepth(depth);
171 static void APIENTRY logClearStencil(GLint s)
173 SIG(
"glClearStencil");
177 static void APIENTRY logColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
179 SIGf(
"%s( %f, %f, %f, %f )\n",
"glColor4f", red, green, blue, alpha);
180 dllColor4f(red, green, blue, alpha);
183 static void APIENTRY logColor4fv(
const GLfloat *v)
185 SIGf(
"%s( %f, %f, %f, %f )\n",
"glColor4fv", v[0], v[1], v[2], v[3]);
189 static void APIENTRY logColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
192 dllColorMask(red, green, blue, alpha);
195 static void APIENTRY logColorPointer(GLint size, GLenum type, GLsizei stride,
const void *pointer)
197 SIGf(
"%s( %d, %s, %d, %p )\n",
"glColorPointer", size, enumToString(type), stride, pointer);
198 dllColorPointer(size, type, stride, pointer);
201 static void APIENTRY logCopyTexImage2D(GLenum target, GLint
level, GLenum internalFormat, GLint x, GLint y, GLsizei
width, GLsizei
height, GLint border)
203 SIG(
"glCopyTexImage2D");
204 dllCopyTexImage2D(target,
level, internalFormat, x, y,
width,
height, border);
207 static void APIENTRY logCopyTexSubImage2D(GLenum target, GLint
level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei
width, GLsizei
height)
209 SIG(
"glCopyTexSubImage2D");
213 static void APIENTRY logCullFace(GLenum mode)
215 SIGf(
"%s( %s )\n",
"glCullFace", enumToString(mode));
219 static void APIENTRY logDeleteTextures(GLsizei n,
const GLuint *textures)
221 SIGf(
"%s( %d, %p )\n",
"glDeleteTextures", n, textures);
222 dllDeleteTextures(n, textures);
225 static void APIENTRY logDepthFunc(GLenum func)
227 SIGf(
"%s( %s )\n",
"glDepthFunc", enumToString(func));
231 static void APIENTRY logDepthMask(GLboolean flag)
233 SIGf(
"%s( %s )\n",
"glDepthMask", flag ?
"GL_TRUE" :
"GL_FALSE");
237 static void APIENTRY logDepthRange(GLclampd zNear, GLclampd zFar)
239 SIGf(
"%s( %f, %f )\n",
"glDepthRange", zNear, zFar);
240 dllDepthRange(zNear, zFar);
243 static void APIENTRY logDisable(GLenum cap)
245 SIGf(
"%s( %s )\n",
"glDisable", enumToString(cap));
249 static void APIENTRY logDisableClientState(GLenum array)
251 SIGf(
"%s( %s )\n",
"glDisableClientState", enumToString(array));
252 dllDisableClientState(array);
255 static void APIENTRY logDrawArrays(GLenum mode, GLint first, GLsizei count)
257 SIGf(
"%s( %s, %u, %u )\n",
"glDrawArrays", enumToString(mode), first, count);
258 dllDrawArrays(mode, first, count);
261 static void APIENTRY logDrawElements(GLenum mode, GLsizei count, GLenum type,
const void *indices)
263 SIGf(
"%s( %s, %u, %s, %p )\n",
"glDrawElements", enumToString(mode), count, enumToString(type), indices);
264 dllDrawElements(mode, count, type, indices);
267 static void APIENTRY logEnable(GLenum cap)
269 SIGf(
"%s( %s )\n",
"glEnable", enumToString(cap));
273 static void APIENTRY logEnableClientState(GLenum array)
275 SIGf(
"%s( %s )\n",
"glEnableClientState", enumToString(array));
276 dllEnableClientState(array);
279 static void APIENTRY logFinish(
void)
291 static void APIENTRY logFogf(GLenum pname, GLfloat param)
294 dllFogf(pname, param);
297 static void APIENTRY logFogfv(GLenum pname,
const GLfloat *params)
300 dllFogfv(pname, params);
303 static void APIENTRY logFrontFace(GLenum mode)
305 SIGf(
"%s( %s )\n",
"glFrontFace", enumToString(mode));
309 static void APIENTRY logFrustum(GLdouble left, GLdouble
right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
312 dllFrustum(left,
right, bottom, top, zNear, zFar);
315 static void APIENTRY logGenTextures(GLsizei n, GLuint *textures)
317 SIGf(
"%s( %d, %p )\n",
"glGenTextures", n, textures);
318 dllGenTextures(n, textures);
321 static GLenum
APIENTRY logGetError(
void)
324 return dllGetError();
327 static void APIENTRY logGetFloatv(GLenum pname, GLfloat *params)
330 dllGetFloatv(pname, params);
333 static void APIENTRY logGetIntegerv(GLenum pname, GLint *params)
335 SIG(
"glGetIntegerv");
336 dllGetIntegerv(pname, params);
339 static const GLubyte *
APIENTRY logGetString(GLenum name)
342 return dllGetString(name);
345 static void APIENTRY logHint(GLenum target, GLenum mode)
347 SIGf(
"%s( %#x, %#x )\n",
"glHint", target, mode);
348 dllHint(target, mode);
351 static GLboolean
APIENTRY logIsEnabled(GLenum cap)
354 return dllIsEnabled(cap);
357 static GLboolean
APIENTRY logIsTexture(GLuint texture)
360 return dllIsTexture(texture);
363 static void APIENTRY logLightModelf(GLenum pname, GLfloat param)
365 SIG(
"glLightModelf");
366 dllLightModelf(pname, param);
369 static void APIENTRY logLightModelfv(GLenum pname,
const GLfloat *params)
371 SIG(
"glLightModelfv");
372 dllLightModelfv(pname, params);
375 static void APIENTRY logLightf(GLenum light, GLenum pname, GLfloat param)
378 dllLightf(light, pname, param);
381 static void APIENTRY logLightfv(GLenum light, GLenum pname,
const GLfloat *params)
384 dllLightfv(light, pname, params);
393 static void APIENTRY logLoadIdentity(
void)
395 SIG(
"glLoadIdentity");
399 static void APIENTRY logLoadMatrixf(
const GLfloat *
m)
401 SIGf(
"glLoadMatrixf( %p )\n",
m);
405 static void APIENTRY logLogicOp(GLenum opcode)
411 static void APIENTRY logMaterialf(GLenum face, GLenum pname, GLfloat param)
414 dllMaterialf(face, pname, param);
417 static void APIENTRY logMaterialfv(GLenum face, GLenum pname,
const GLfloat *params)
420 dllMaterialfv(face, pname, params);
423 static void APIENTRY logMatrixMode(GLenum mode)
425 SIGf(
"%s( %s )\n",
"glMatrixMode", enumToString(mode));
429 static void APIENTRY logMultMatrixf(
const GLfloat *
m)
431 SIG(
"glMultMatrixf");
435 static void APIENTRY logNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
438 dllNormal3f(nx, ny, nz);
441 static void APIENTRY logNormal3fv(
const GLfloat *v)
447 static void APIENTRY logNormalPointer(GLenum type, GLsizei stride,
const void *pointer)
449 SIG(
"glNormalPointer");
450 dllNormalPointer(type, stride, pointer);
453 static void APIENTRY logOrtho(GLdouble left, GLdouble
right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
456 dllOrtho(left,
right, bottom, top, zNear, zFar);
459 static void APIENTRY logPixelStorei(GLenum pname, GLint param)
461 SIG(
"glPixelStorei");
462 dllPixelStorei(pname, param);
465 static void APIENTRY logPointSize(GLfloat size)
471 static void APIENTRY logPolygonMode(GLenum face, GLenum mode)
473 SIGf(
"%s( %s, %s )\n",
"glPolygonMode", enumToString(face), enumToString(mode));
474 dllPolygonMode(face, mode);
477 static void APIENTRY logPolygonOffset(GLfloat factor, GLfloat units)
479 SIGf(
"%s( %f, %f )\n",
"glPolygonOffset", factor, units);
480 dllPolygonOffset(factor, units);
483 static void APIENTRY logPopMatrix(
void)
489 static void APIENTRY logPushMatrix(
void)
495 static void APIENTRY logReadPixels(GLint x, GLint y, GLsizei
width, GLsizei
height, GLenum format, GLenum type,
void *pixels)
498 dllReadPixels(x, y,
width,
height, format, type, pixels);
501 static void APIENTRY logRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
504 dllRotatef(angle, x, y, z);
507 static void APIENTRY logScalef(GLfloat x, GLfloat y, GLfloat z)
515 SIGf(
"%s( %d, %d, %d, %d )\n",
"glScissor", x, y,
width,
height);
519 static void APIENTRY logShadeModel(GLenum mode)
521 SIGf(
"%s( %s )\n",
"glShadeModel", enumToString(mode));
525 static void APIENTRY logStencilFunc(GLenum func, GLint ref, GLuint mask)
527 SIG(
"glStencilFunc");
528 dllStencilFunc(func, ref, mask);
531 static void APIENTRY logStencilMask(GLuint mask)
533 SIG(
"glStencilMask");
534 dllStencilMask(mask);
537 static void APIENTRY logStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
540 dllStencilOp(fail, zfail, zpass);
543 static void APIENTRY logTexCoordPointer(GLint size, GLenum type, GLsizei stride,
const void *pointer)
545 SIGf(
"%s( %d, %s, %d, %p )\n",
"glTexCoordPointer", size, enumToString(type), stride, pointer);
546 dllTexCoordPointer(size, type, stride, pointer);
549 static void APIENTRY logTexEnvf(GLenum target, GLenum pname, GLfloat param)
551 SIGf(
"%s( %s, %s, %s )\n",
"glTexEnvf", enumToString(target), enumToString(pname), enumToString(param));
552 dllTexEnvf(target, pname, param);
555 static void APIENTRY logTexEnvfv(GLenum target, GLenum pname,
const GLfloat *params)
558 dllTexEnvfv(target, pname, params);
561 static void APIENTRY logTexImage2D(GLenum target, GLint
level, GLint internalformat, GLsizei
width, GLsizei
height, GLint border, GLenum format, GLenum type,
const void *pixels)
564 dllTexImage2D(target,
level, internalformat,
width,
height, border, format, type, pixels);
567 static void APIENTRY logTexParameterf(GLenum target, GLenum pname, GLfloat param)
569 SIGf(
"%s( %s, %s, %f )\n",
"glTexParameterf", enumToString(target), enumToString(pname), param);
570 dllTexParameterf(target, pname, param);
573 static void APIENTRY logTexParameterfv(GLenum target, GLenum pname,
const GLfloat *params)
575 SIG(
"glTexParameterfv");
576 dllTexParameterfv(target, pname, params);
579 static void APIENTRY logTexSubImage2D(GLenum target, GLint
level, GLint xoffset, GLint yoffset, GLsizei
width, GLsizei
height, GLenum format, GLenum type,
const void *pixels)
581 SIG(
"glTexSubImage2D");
582 dllTexSubImage2D(target,
level, xoffset, yoffset,
width,
height, format, type, pixels);
585 static void APIENTRY logTranslatef(GLfloat x, GLfloat y, GLfloat z)
588 dllTranslatef(x, y, z);
591 static void APIENTRY logVertexPointer(GLint size, GLenum type, GLsizei stride,
const void *pointer)
593 SIGf(
"%s( %d, %s, %d, %p )\n",
"glVertexPointer", size, enumToString(type), stride, pointer);
594 dllVertexPointer(size, type, stride, pointer);
599 SIGf(
"%s( %d, %d, %d, %d )\n",
"glViewport", x, y,
width,
height);
603 static void APIENTRY logActiveTextureARB(GLenum texture)
605 SIGf(
"%s( GL_TEXTURE%d )\n",
"glActiveTextureARB", texture - GL_TEXTURE0);
606 dllActiveTextureARB(texture);
609 static void APIENTRY logClientActiveTextureARB(GLenum texture)
611 SIGf(
"%s( GL_TEXTURE%d )\n",
"glClientActiveTextureARB", texture - GL_TEXTURE0);
612 dllClientActiveTextureARB(texture);
615 static void APIENTRY logLockArraysEXT(GLint first, GLsizei count)
617 SIGf(
"%s( %u, %u )\n",
"glLockArraysEXT", first, count);
618 dllLockArraysEXT(first, count);
621 static void APIENTRY logUnlockArraysEXT(
void)
623 SIG(
"glUnlockArraysEXT");
624 dllUnlockArraysEXT();
634 #define QGL(x) qgl##x = dll##x = NULL
636 #define QGL(x) qgl##x = NULL
667 #define GCA(x) VID_GetCoreAddr("gl"#x)
668 #define GPA(x) VID_GetProcAddr("gl"#x)
673 #define QGL(x) if ((qgl##x = dll##x = GCA(x)) == NULL) return qfalse;
675 #define QGL(x) if ((qgl##x = GCA(x)) == NULL) return qfalse;
686 #define QGL(x) qgl##x = dll##x = GPA(x)
688 #define QGL(x) qgl##x = GPA(x)
715 static const char *
const extnames[] = {
716 "GL_ARB_fragment_program",
717 "GL_ARB_multitexture",
718 "GL_ARB_vertex_buffer_object",
719 "GL_EXT_compiled_vertex_array",
720 "GL_EXT_texture_filter_anisotropic",
724 return Com_ParseExtensionString(s, extnames);
729 void QGL_EnableLogging(
unsigned mask)
735 char buffer[MAX_OSPATH];
741 if (len >=
sizeof(buffer)) {
745 log_fp = fopen(buffer,
"w");
750 newtime = localtime(&aclock);
751 fprintf(log_fp,
"%s\n", asctime(newtime));
754 #define QGL(x) qgl##x = log##x
773 void QGL_DisableLogging(
unsigned mask)
780 #define QGL(x) qgl##x = dll##x
801 void QGL_LogComment(
const char *fmt, ...)
807 vfprintf(log_fp, fmt, ap);