From dbf0597bd82a0b44fc7ec0b11ced537f55096873 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Tue, 20 Jun 2023 00:24:51 -0700 Subject: [PATCH] Add `DebugScope` utility-class for RAII-based OpenGL debug-scopes Simply define this object in a C++ scope like: ```cpp OpenGL::DebugScope glScope("Renderer::display"); ``` and it will associate all functions within the current scope within a named group. Supports `printf` formatting. --- include/opengl.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/opengl.hpp b/include/opengl.hpp index 9ecbc4c6..42167388 100644 --- a/include/opengl.hpp +++ b/include/opengl.hpp @@ -73,6 +73,26 @@ namespace OpenGL { glObjectLabel(identifier, name, length, label); } + class DebugScope { + inline static GLuint scopeDepth = 0; + const GLuint m_scope_depth; + + public: + OPENGL_PRINTF_FORMAT_ATTR(2, 3) + DebugScope(OPENGL_PRINTF_FORMAT const char* format, ...) : m_scope_depth(scopeDepth++) { + GLchar message[256] = {}; + va_list args; + va_start(args, format); + const GLsizei length = vsnprintf(message, std::size(message), format, args); + va_end(args); + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, m_scope_depth, length, message); + } + ~DebugScope() { + glPopDebugGroup(); + scopeDepth--; + } + }; + struct VertexArray { GLuint m_handle = 0;