From 44bb24bbaf13d1ab236e400a096c12b1859e564b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 25 Feb 2024 11:12:10 +0900 Subject: [PATCH] [glsl] Add support for debug callback It's disabled at compile time for now, but everything needed is there. --- include/QF/GLSL/defines.h | 13 ++++++++++ include/QF/GLSL/qf_funcs_list.h | 2 ++ include/QF/GLSL/types.h | 2 ++ libs/video/renderer/glsl/vid_common_glsl.c | 30 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/include/QF/GLSL/defines.h b/include/QF/GLSL/defines.h index b06041469..c866cea43 100644 --- a/include/QF/GLSL/defines.h +++ b/include/QF/GLSL/defines.h @@ -435,4 +435,17 @@ #define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_DEBUG_OUTPUT 0x92E0 + + #endif//__glsl_defines_h diff --git a/include/QF/GLSL/qf_funcs_list.h b/include/QF/GLSL/qf_funcs_list.h index 26adfea69..dca881ed8 100644 --- a/include/QF/GLSL/qf_funcs_list.h +++ b/include/QF/GLSL/qf_funcs_list.h @@ -163,6 +163,8 @@ QFGL_NEED (void, glVertexAttrib4fv, (GLuint indx, const GLfloat* values)) QFGL_NEED (void, glVertexAttribPointer, (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)) QFGL_NEED (void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)) +QFGL_NEED (void, glDebugMessageCallback, (GLDEBUGPROC callback, const void *userParam)) + #ifdef UNDEF_QFGL_DONT_NEED #undef QFGL_DONT_NEED #endif diff --git a/include/QF/GLSL/types.h b/include/QF/GLSL/types.h index 3e0819fa9..65c15a564 100644 --- a/include/QF/GLSL/types.h +++ b/include/QF/GLSL/types.h @@ -44,4 +44,6 @@ typedef ptrdiff_t GLfixed; typedef ptrdiff_t GLintptr; typedef ptrdiff_t GLsizeiptr; +typedef void (GLAPIENTRY *GLDEBUGPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); + #endif//__QF_GLSL_types_h diff --git a/libs/video/renderer/glsl/vid_common_glsl.c b/libs/video/renderer/glsl/vid_common_glsl.c index e03060f68..c386e21ec 100644 --- a/libs/video/renderer/glsl/vid_common_glsl.c +++ b/libs/video/renderer/glsl/vid_common_glsl.c @@ -153,6 +153,31 @@ GLSL_Shutdown_Common (void) GLSL_ShaderShutdown (); } +static void +debug_breakpoint (GLenum type) +{ + exit (1); +} + +static void +MessageCallback (GLenum source, GLenum type, GLuint id, GLenum severity, + GLsizei length, const GLchar *message, const void *uparam) +{ + if (type == GL_DEBUG_TYPE_OTHER + && severity == GL_DEBUG_SEVERITY_NOTIFICATION) { + return; + } + if (type != GL_DEBUG_TYPE_PERFORMANCE) { + fprintf (stderr, + "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", + ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), + type, severity, message ); + } + if (type == GL_DEBUG_TYPE_ERROR) { + debug_breakpoint (type); + } +} + void GLSL_Init_Common (void) { @@ -160,6 +185,11 @@ GLSL_Init_Common (void) GLSL_Common_Init_Cvars (); + if (0) { + qfeglEnable (GL_DEBUG_OUTPUT); + qfeglDebugMessageCallback (MessageCallback, nullptr); + } + GLSL_TextureInit (); if (developer & SYS_glsl) {