From 1f750cd7b26348aa799b2ebc9a779f670dba5f4f Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 20:31:51 +0300 Subject: [PATCH] Add debug handler --- source/Irrlicht/CIrrDeviceSDL.cpp | 1 + source/Irrlicht/OpenGL/Driver.cpp | 11 +++++++++++ source/Irrlicht/OpenGL/Driver.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 8a74719e..a5ba6f69 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -393,6 +393,7 @@ bool CIrrDeviceSDL::createWindow() SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); if (CreationParams.Bits == 16) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4); diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 7c13e7c7..671f338a 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -31,6 +31,16 @@ namespace irr namespace video { +void APIENTRY COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +{ + ((COpenGL3Driver *)userParam)->debugCb(source, type, id, severity, length, message); +} + +void COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +{ + printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); +} + COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), @@ -52,6 +62,7 @@ COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IF ExposedData = ContextManager->getContext(); ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); + GL.DebugMessageCallback(debugCb, this); } COpenGL3Driver::~COpenGL3Driver() diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index dd2ad89e..4920fdea 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -397,6 +397,9 @@ private: ECOLOR_FORMAT ColorFormat; IContextManager* ContextManager; + + void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); + static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); }; } // end namespace video