[gl] Move error check support into a better place

This makes it a little easier to spam checks everywhere and thus narrow
down the location of the error.
This commit is contained in:
Bill Currie 2022-03-15 12:33:25 +09:00
parent 1d93bcfc34
commit fb4fd979ec
3 changed files with 92 additions and 84 deletions

View file

@ -31,4 +31,6 @@ void gl_Fog_DisableGFog (void);
void gl_Fog_StartAdditive (void);
void gl_Fog_StopAdditive (void);
void gl_errors (const char *msg);
#endif//__vid_gl_h

View file

@ -79,86 +79,6 @@ float gl_r_world_matrix[16];
//vec3_t gl_shadecolor; // Ender (Extend) Colormod
float gl_modelalpha; // Ender (Extend) Alpha
/* Unknown renamed to GLErr_Unknown to solve conflict with winioctl.h */
static unsigned int GLErr_InvalidEnum;
static unsigned int GLErr_InvalidValue;
static unsigned int GLErr_InvalidOperation;
static unsigned int GLErr_OutOfMemory;
static unsigned int GLErr_StackOverflow;
static unsigned int GLErr_StackUnderflow;
static unsigned int GLErr_Unknown;
static unsigned int
R_TestErrors (unsigned int numerous)
{
switch (qfglGetError ()) {
case GL_NO_ERROR:
return numerous;
break;
case GL_INVALID_ENUM:
GLErr_InvalidEnum++;
R_TestErrors (numerous++);
break;
case GL_INVALID_VALUE:
GLErr_InvalidValue++;
R_TestErrors (numerous++);
break;
case GL_INVALID_OPERATION:
GLErr_InvalidOperation++;
R_TestErrors (numerous++);
break;
case GL_STACK_OVERFLOW:
GLErr_StackOverflow++;
R_TestErrors (numerous++);
break;
case GL_STACK_UNDERFLOW:
GLErr_StackUnderflow++;
R_TestErrors (numerous++);
break;
case GL_OUT_OF_MEMORY:
GLErr_OutOfMemory++;
R_TestErrors (numerous++);
break;
default:
GLErr_Unknown++;
R_TestErrors (numerous++);
break;
}
return numerous;
}
static void
R_DisplayErrors (void)
{
if (GLErr_InvalidEnum)
printf ("%d OpenGL errors: Invalid Enum!\n", GLErr_InvalidEnum);
if (GLErr_InvalidValue)
printf ("%d OpenGL errors: Invalid Value!\n", GLErr_InvalidValue);
if (GLErr_InvalidOperation)
printf ("%d OpenGL errors: Invalid Operation!\n", GLErr_InvalidOperation);
if (GLErr_StackOverflow)
printf ("%d OpenGL errors: Stack Overflow!\n", GLErr_StackOverflow);
if (GLErr_StackUnderflow)
printf ("%d OpenGL errors: Stack Underflow\n!", GLErr_StackUnderflow);
if (GLErr_OutOfMemory)
printf ("%d OpenGL errors: Out Of Memory!\n", GLErr_OutOfMemory);
if (GLErr_Unknown)
printf ("%d Unknown OpenGL errors!\n", GLErr_Unknown);
}
static void
R_ClearErrors (void)
{
GLErr_InvalidEnum = 0;
GLErr_InvalidValue = 0;
GLErr_InvalidOperation = 0;
GLErr_OutOfMemory = 0;
GLErr_StackOverflow = 0;
GLErr_StackUnderflow = 0;
GLErr_Unknown = 0;
}
void
glrmain_init (void)
{
@ -431,10 +351,6 @@ R_RenderScene (void)
gl_R_DrawParticles ();
gl_Fog_DisableGFog ();
if (R_TestErrors (0))
R_DisplayErrors ();
R_ClearErrors ();
}
/*

View file

@ -47,6 +47,96 @@
gl_ctx_t *gl_ctx;
/* Unknown renamed to GLErr_Unknown to solve conflict with winioctl.h */
static unsigned int GLErr_InvalidEnum;
static unsigned int GLErr_InvalidValue;
static unsigned int GLErr_InvalidOperation;
static unsigned int GLErr_OutOfMemory;
static unsigned int GLErr_StackOverflow;
static unsigned int GLErr_StackUnderflow;
static unsigned int GLErr_Unknown;
static unsigned int
R_TestErrors (unsigned int numerous)
{
switch (qfglGetError ()) {
case GL_NO_ERROR:
return numerous;
break;
case GL_INVALID_ENUM:
GLErr_InvalidEnum++;
R_TestErrors (numerous++);
break;
case GL_INVALID_VALUE:
GLErr_InvalidValue++;
R_TestErrors (numerous++);
break;
case GL_INVALID_OPERATION:
GLErr_InvalidOperation++;
R_TestErrors (numerous++);
break;
case GL_STACK_OVERFLOW:
GLErr_StackOverflow++;
R_TestErrors (numerous++);
break;
case GL_STACK_UNDERFLOW:
GLErr_StackUnderflow++;
R_TestErrors (numerous++);
break;
case GL_OUT_OF_MEMORY:
GLErr_OutOfMemory++;
R_TestErrors (numerous++);
break;
default:
GLErr_Unknown++;
R_TestErrors (numerous++);
break;
}
return numerous;
}
static void
R_DisplayErrors (void)
{
if (GLErr_InvalidEnum)
printf ("%d OpenGL errors: Invalid Enum!\n", GLErr_InvalidEnum);
if (GLErr_InvalidValue)
printf ("%d OpenGL errors: Invalid Value!\n", GLErr_InvalidValue);
if (GLErr_InvalidOperation)
printf ("%d OpenGL errors: Invalid Operation!\n", GLErr_InvalidOperation);
if (GLErr_StackOverflow)
printf ("%d OpenGL errors: Stack Overflow!\n", GLErr_StackOverflow);
if (GLErr_StackUnderflow)
printf ("%d OpenGL errors: Stack Underflow\n!", GLErr_StackUnderflow);
if (GLErr_OutOfMemory)
printf ("%d OpenGL errors: Out Of Memory!\n", GLErr_OutOfMemory);
if (GLErr_Unknown)
printf ("%d Unknown OpenGL errors!\n", GLErr_Unknown);
}
static void
R_ClearErrors (void)
{
GLErr_InvalidEnum = 0;
GLErr_InvalidValue = 0;
GLErr_InvalidOperation = 0;
GLErr_OutOfMemory = 0;
GLErr_StackOverflow = 0;
GLErr_StackUnderflow = 0;
GLErr_Unknown = 0;
}
void
gl_errors (const char *msg)
{
if (R_TestErrors (0)) {
printf ("gl_errors: %s\n", msg);
R_DisplayErrors ();
}
R_ClearErrors ();
}
static void
gl_vid_render_choose_visual (void *data)
{