Ver código fonte

chore: report opengl errors through synchronous glDebugMessageCallback

Almamu 9 meses atrás
pai
commit
363fc2c722

+ 12 - 0
src/WallpaperEngine/Render/Drivers/GLFWOpenGLDriver.cpp

@@ -17,6 +17,16 @@ void CustomGLFWErrorHandler (int errorCode, const char* reason) {
     sLog.error ("GLFW error ", errorCode, ": ", reason);
 }
 
+void CustomGLErrorCallback(GLenum source,
+            GLenum type,
+            GLuint id,
+            GLenum severity,
+            GLsizei length,
+            const GLchar *message,
+            const void *userParam) {
+    sLog.error("OpenGL error: ", message, ", type: ", type, ", id: ", id);
+}
+
 GLFWOpenGLDriver::GLFWOpenGLDriver (
     const char* windowTitle, ApplicationContext& context, WallpaperApplication& app
 ) :
@@ -48,6 +58,8 @@ GLFWOpenGLDriver::GLFWOpenGLDriver (
 
 #if !NDEBUG
     glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
+    glDebugMessageCallback(CustomGLErrorCallback, nullptr);
+    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
 #endif /* DEBUG */
 
     // create window, size doesn't matter as long as we don't show it

+ 13 - 0
src/WallpaperEngine/Render/Drivers/WaylandOpenGLDriver.cpp

@@ -20,6 +20,16 @@ extern "C" {
 
 using namespace WallpaperEngine::Render::Drivers;
 
+void CustomGLEWErrorCallback(GLenum source,
+            GLenum type,
+            GLuint id,
+            GLenum severity,
+            GLsizei length,
+            const GLchar *message,
+            const void *userParam) {
+    sLog.error("OpenGL error: ", message, ", type: ", type, ", id: ", id);
+}
+
 static void handlePointerEnter (void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface,
                                 wl_fixed_t surface_x, wl_fixed_t surface_y) {
     const auto driver = static_cast<WaylandOpenGLDriver*> (data);
@@ -287,6 +297,9 @@ WaylandOpenGLDriver::WaylandOpenGLDriver (ApplicationContext& context, Wallpaper
 
     if (const GLenum result = glewInit (); result != GLEW_OK)
         sLog.error ("Failed to initialize GLEW: ", glewGetErrorString (result));
+
+    glDebugMessageCallback(CustomGLEWErrorCallback, nullptr);
+    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
 }
 
 WaylandOpenGLDriver::~WaylandOpenGLDriver () {