diff --git a/Makefile b/Makefile index 7e832c6b..b857be6b 100644 --- a/Makefile +++ b/Makefile @@ -144,7 +144,7 @@ endif # Highest supported optimizations are -O2, higher levels # will likely break this crappy code. ifdef DEBUG -CFLAGS ?= -O0 -g -Wall -pipe +CFLAGS ?= -O0 -g -Wall -pipe -DDEBUG ifdef ASAN override CFLAGS += -fsanitize=address -DUSE_SANITIZER endif diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 22b2e808..196667a4 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -559,11 +559,11 @@ R_Upload32Native(unsigned *data, int width, int height, qboolean mipmap) break; } } - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, mipmap); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, mipmap); glTexImage2D(GL_TEXTURE_2D, 0, comp, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, false); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, false); return samples == gl_alpha_format; } diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index e0f3716e..73fc9e66 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -1405,6 +1405,10 @@ RI_Init(void) R_Printf(PRINT_ALL, "Refresh: " REF_VERSION "\n"); R_Printf(PRINT_ALL, "Client: " YQ2VERSION "\n\n"); +#ifdef DEBUG + R_Printf(PRINT_ALL, "ref_gl1::R_Init() - DEBUG mode enabled\n"); +#endif + GetPCXPalette (&colormap, d_8to24table); free(colormap); @@ -1981,3 +1985,32 @@ Com_Printf(const char *msg, ...) ri.Com_VPrintf(PRINT_ALL, msg, argptr); va_end(argptr); } + +#ifdef DEBUG +void +glCheckError_(const char *file, const char *function, int line) +{ + GLenum errorCode; + const char * msg; + +#define MY_ERROR_CASE(X) case X : msg = #X; break; + + while ((errorCode = glGetError()) != GL_NO_ERROR) + { + switch(errorCode) + { + MY_ERROR_CASE(GL_INVALID_ENUM); + MY_ERROR_CASE(GL_INVALID_VALUE); + MY_ERROR_CASE(GL_INVALID_OPERATION); + MY_ERROR_CASE(GL_STACK_OVERFLOW); + MY_ERROR_CASE(GL_STACK_UNDERFLOW); + MY_ERROR_CASE(GL_OUT_OF_MEMORY); + default: msg = "UNKNOWN"; + } + R_Printf(PRINT_ALL, "glError: %s in %s (%s, %d)\n", msg, function, file, line); + } + +#undef MY_ERROR_CASE + +} +#endif diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index ac60f428..5ca9d2a9 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -303,6 +303,55 @@ void R_TextureAlphaMode(char *string); void R_TextureSolidMode(char *string); int Scrap_AllocBlock(int w, int h, int *x, int *y); +#ifdef DEBUG +void glCheckError_(const char *file, const char *function, int line); +// Ideally, the following list should contain all OpenGL calls. +// Either way, errors are caught, since error flags are persisted until the next glGetError() call. +// So they show, even if the location of the error is inaccurate. +#define glDrawArrays(...) glDrawArrays(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexImage2D(...) glTexImage2D(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexSubImage2D(...) glTexSubImage2D(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexEnvf(...) glTexEnvf(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexEnvi(...) glTexEnvi(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glVertexPointer(...) glVertexPointer(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexCoordPointer(...) glTexCoordPointer(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glColorPointer(...) glColorPointer(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTexParameteri(...) glTexParameteri(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glBindTexture(...) glBindTexture(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glFrustum(...) glFrustum(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glTranslatef(...) glTranslatef(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glRotatef(...) glRotatef(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glScalef(...) glScalef(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glScissor(...) glScissor(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glBlendFunc(...) glBlendFunc(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDepthFunc(...) glDepthFunc(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDepthMask(...) glDepthMask(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDepthRange(...) glDepthRange(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glEnable(...) glEnable(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDisable(...) glDisable(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glEnableClientState(...) glEnableClientState(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDisableClientState(...) glDisableClientState(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glPushMatrix(...) glPushMatrix(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glPopMatrix(...) glPopMatrix(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glMatrixMode(...) glMatrixMode(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glOrtho(...) glOrtho(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glColorMask(...) glColorMask(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glStencilOp(...) glStencilOp(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glStencilFunc(...) glStencilFunc(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDrawBuffer(...) glDrawBuffer(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glReadPixels(...) glReadPixels(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glClear(...) glClear(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glClearColor(...) glClearColor(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glClearStencil(...) glClearStencil(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glDeleteTextures(...) glDeleteTextures(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glFinish() glFinish(); glCheckError_(__FILE__, __func__, __LINE__) +#define glAlphaFunc(...) glAlphaFunc(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glHint(...) glHint(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glLoadIdentity() glLoadIdentity(); glCheckError_(__FILE__, __func__, __LINE__) +#define glBegin(...) glBegin(__VA_ARGS__); glCheckError_(__FILE__, __func__, __LINE__) +#define glEnd() glEnd(); glCheckError_(__FILE__, __func__, __LINE__) +#endif + /* GL extension emulation functions */ void R_DrawParticles2(int n, const particle_t particles[],