From bd91c664a68cc401185709a0fc4023044e0852e5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 7 Jul 2025 17:27:57 +0200 Subject: [PATCH] Proper debug context setup --- include/egl.h | 7 ++----- src/egl.c | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/egl.h b/include/egl.h index e11557e..38047e8 100644 --- a/include/egl.h +++ b/include/egl.h @@ -52,6 +52,7 @@ typedef void(*__GLXextFuncPtr)(void); #define EGL_OPENGL_ES3_BIT 0x00000040 #define EGL_NONE 0x3038 #define EGL_CONTEXT_CLIENT_VERSION 0x3098 +#define EGL_CONTEXT_OPENGL_DEBUG 0x31B0 #define EGL_BACK_BUFFER 0x3084 #define EGL_GL_TEXTURE_2D 0x30B1 #define EGL_TRUE 1 @@ -85,10 +86,6 @@ typedef void(*__GLXextFuncPtr)(void); #define EGL_ALPHA_SIZE 0x3021 #define EGL_BLUE_SIZE 0x3022 #define EGL_GREEN_SIZE 0x3023 -#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 -#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 -#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 -#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 #define EGL_DEVICE_EXT 0x322C #define EGL_DRM_DEVICE_FILE_EXT 0x3233 @@ -133,7 +130,7 @@ typedef void(*__GLXextFuncPtr)(void); #define GL_BLEND 0x0BE2 #define GL_SRC_ALPHA 0x0302 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 #define GL_SCISSOR_TEST 0x0C11 #define GL_PACK_ALIGNMENT 0x0D05 #define GL_UNPACK_ALIGNMENT 0x0CF5 diff --git a/src/egl.c b/src/egl.c index bcb1663..faba18d 100644 --- a/src/egl.c +++ b/src/egl.c @@ -29,7 +29,7 @@ #define GLX_RGBA_TYPE 0x8014 // TODO: Create egl context without surface (in other words, x11/wayland agnostic, doesn't require x11/wayland dependency) -static bool gsr_egl_create_window(gsr_egl *self) { +static bool gsr_egl_create_window(gsr_egl *self, bool enable_debug) { EGLConfig ecfg; int32_t num_config = 0; @@ -39,11 +39,16 @@ static bool gsr_egl_create_window(gsr_egl *self) { EGL_NONE, EGL_NONE }; - const int32_t ctxattr[] = { + int32_t ctxattr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE, EGL_NONE + EGL_NONE, EGL_NONE, EGL_NONE }; + if(enable_debug) { + ctxattr[2] = EGL_CONTEXT_OPENGL_DEBUG; + ctxattr[3] = EGL_TRUE; + } + self->eglBindAPI(EGL_OPENGL_ES_API); self->egl_display = self->eglGetDisplay((EGLNativeDisplayType)gsr_window_get_display(self->window)); @@ -87,6 +92,7 @@ static bool gsr_egl_create_window(gsr_egl *self) { } static GLXFBConfig glx_fb_config_choose(gsr_egl *self, Display *display) { + // TODO: OpenGL debug context? const int glx_visual_attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, @@ -423,7 +429,7 @@ bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bo if(!gsr_egl_proc_load_egl(self)) goto fail; - if(!gsr_egl_create_window(self)) + if(!gsr_egl_create_window(self, enable_debug)) goto fail; if(!gl_get_gpu_info(self, &self->gpu_info)) @@ -443,16 +449,16 @@ bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bo goto fail; } + if(enable_debug) { + self->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + self->glDebugMessageCallback(debug_callback, NULL); + } + self->glEnable(GL_BLEND); self->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); self->glPixelStorei(GL_PACK_ALIGNMENT, 1); self->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if(enable_debug) { - self->glEnable(GL_DEBUG_OUTPUT); - self->glDebugMessageCallback(debug_callback, NULL); - } - gsr_egl_disable_vsync(self); if(self->gpu_info.vendor == GSR_GPU_VENDOR_NVIDIA) {