diff --git a/Source/Glide64/Debugger.cpp b/Source/Glide64/Debugger.cpp index c0ac22f38..8775524d4 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[error_index], message); +#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 ); diff --git a/Source/Glide64/Main.cpp b/Source/Glide64/Main.cpp index 2b3dfc2ed..ea4f83e02 100644 --- a/Source/Glide64/Main.cpp +++ b/Source/Glide64/Main.cpp @@ -1890,6 +1890,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 ++; diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index 27055002a..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(); @@ -2572,13 +2576,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