From ab6cad081f5355eaeaa8615979056b10088a8cea Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 13:17:00 -0500 Subject: [PATCH 1/6] implemented glFlush and glFinish --- Source/Glitch64/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index 27055002a..5ce238aa4 100644 --- a/Source/Glitch64/main.cpp +++ b/Source/Glitch64/main.cpp @@ -2572,13 +2572,13 @@ grErrorSetCallback( GrErrorCallbackFnc_t /*fnc*/ ) FX_ENTRY void FX_CALL grFinish(void) { - display_warning("grFinish"); + glFinish(); } FX_ENTRY void FX_CALL grFlush(void) { - display_warning("grFlush"); + glFlush(); } FX_ENTRY void FX_CALL From 30ecec315eb0224216f33eaf95809e3ebb74341f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 13:40:34 -0500 Subject: [PATCH 2/6] In Debug builds, force flushing of all GL commands each buffer swap. --- Source/Glitch64/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index 5ce238aa4..a3bfaa9ef 100644 --- a/Source/Glitch64/main.cpp +++ b/Source/Glitch64/main.cpp @@ -2115,6 +2115,10 @@ grBufferSwap( FxU32 swap_interval ) for (i = 0; i < nb_fb; i++) fbs[i].buff_clear = 1; +#ifdef _DEBUG + grFinish(); +#endif + // VP debugging #ifdef VPDEBUG dump_stop(); From c2d08d61dccd4bf23099c47354cf8bcb84090bed Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 15:23:26 -0500 Subject: [PATCH 3/6] new function for debugging OpenGL state machine faults in Glitch64 --- Source/Glide64/Debugger.cpp | 58 +++++++++++++++++++++++++++++++++++++ Source/Glide64/Debugger.h | 2 ++ 2 files changed, 60 insertions(+) diff --git a/Source/Glide64/Debugger.cpp b/Source/Glide64/Debugger.cpp index c0ac22f38..35dbc5924 100644 --- a/Source/Glide64/Debugger.cpp +++ b/Source/Glide64/Debugger.cpp @@ -41,6 +41,15 @@ #include "Util.h" #include "Debugger.h" +/* + * required to include OpenGL library without errors + * Dependency on OpenGL in this module is limited to just `glGetError`. + */ +#ifdef _WIN32 +#include +#endif +#include + GLIDE64_DEBUGGER _debugger; #define SX(x) ((x)*rdp.scale_1024) @@ -1018,3 +1027,52 @@ void output (float x, float y, int scale, const char *fmt, ...) x+=8; } } + +static const char * GL_errors[7 + 1] = { + "GL_NO_ERROR", /* "There is no current error." */ + "GL_INVALID_ENUM", /* "Invalid parameter." */ + "GL_INVALID_VALUE", /* "Invalid enum parameter value." */ + "GL_INVALID_OPERATION", /* "Illegal call." */ + "GL_STACK_OVERFLOW", + "GL_STACK_UNDERFLOW", + "GL_OUT_OF_MEMORY", /* "Unable to allocate memory." */ + + "GL_UNKNOWN_ERROR" /* ??? */ +}; + +int grDisplayGLError(const char* message) +{ + GLenum status; + unsigned int error_index; + int failure; + + status = glGetError(); + failure = 1; + + if (status == GL_NO_ERROR) + error_index = failure = 0; + else + error_index = + (status < GL_INVALID_ENUM) /* to avoid underflow when subtracting */ + ? ( 7 ) /* our own, made-up "GL_UNKNOWN_ERROR" error */ + : (status - GL_INVALID_ENUM) + 1; + + if (error_index > 7) + error_index = 7; + +#if !0 +/* + * In most cases, we don't want to spam the screen to repeatedly say that + * there were no OpenGL errors yet, though sometimes one may need verbosity. + */ + if (failure == 0) + return (failure); +#endif + +#ifdef _WIN32 + MessageBoxA(NULL, message, GL_errors[error_index], MB_ICONERROR); +#else + fprintf(stderr, "%s\n%s\n\n", GL_errors[index], text); +#endif + return (failure); +} diff --git a/Source/Glide64/Debugger.h b/Source/Glide64/Debugger.h index cc6b7444c..f304d4eea 100644 --- a/Source/Glide64/Debugger.h +++ b/Source/Glide64/Debugger.h @@ -135,3 +135,5 @@ void debug_cacheviewer (); void debug_mouse (); void debug_keys (); void output (float x, float y, int scale, const char *fmt, ...); + +extern int grDisplayGLError( const char * message ); From fc16d515250f5e3cdc1a417411ccb4ddc6ddc4b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 15:25:00 -0500 Subject: [PATCH 4/6] Propose to always check for GL errors before each vertical interrupt. --- Source/Glide64/Main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Glide64/Main.cpp b/Source/Glide64/Main.cpp index 45a388391..48d3fd369 100644 --- a/Source/Glide64/Main.cpp +++ b/Source/Glide64/Main.cpp @@ -1878,6 +1878,10 @@ void CALL UpdateScreen (void) if (fullscreen && (*gfx.VI_ORIGIN_REG > width)) update_screen_count++; +#if defined(_DEBUG) || 0 + grDisplayGLError("UpdateScreen"); +#endif + #ifdef FPS // vertical interrupt has occurred, increment counter vi_count ++; From a015fdc089776715dc8aaeffda0d3110b87d7fc1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 15:48:35 -0500 Subject: [PATCH 5/6] fixed legacy function input names if not compiling on Windows --- Source/Glide64/Debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Glide64/Debugger.cpp b/Source/Glide64/Debugger.cpp index 35dbc5924..f6501caa6 100644 --- a/Source/Glide64/Debugger.cpp +++ b/Source/Glide64/Debugger.cpp @@ -1072,7 +1072,7 @@ int grDisplayGLError(const char* message) #ifdef _WIN32 MessageBoxA(NULL, message, GL_errors[error_index], MB_ICONERROR); #else - fprintf(stderr, "%s\n%s\n\n", GL_errors[index], text); + fprintf(stderr, "%s\n%s\n\n", GL_errors[index], message); #endif return (failure); } From cd2f90f35fcb79ebf0039032d462c3d88039a923 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 15:58:08 -0500 Subject: [PATCH 6/6] forgot to hit Ctrl+S to save latter half of the previous commit --- Source/Glide64/Debugger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Glide64/Debugger.cpp b/Source/Glide64/Debugger.cpp index f6501caa6..8775524d4 100644 --- a/Source/Glide64/Debugger.cpp +++ b/Source/Glide64/Debugger.cpp @@ -1072,7 +1072,7 @@ int grDisplayGLError(const char* message) #ifdef _WIN32 MessageBoxA(NULL, message, GL_errors[error_index], MB_ICONERROR); #else - fprintf(stderr, "%s\n%s\n\n", GL_errors[index], message); + fprintf(stderr, "%s\n%s\n\n", GL_errors[error_index], message); #endif return (failure); }