summaryrefslogtreecommitdiff
path: root/gfx/gl/gldebug.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-01-16 02:53:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-01-16 03:18:29 +0000
commit09533ab9379a675a89638132fb6831b420ebb8f4 (patch)
tree984985821bcad18e0d8d93831150407e0d5b1a8e /gfx/gl/gldebug.h
parentTidy thirdparty jam, use -isystem for thirdparty includes (diff)
downloadilt-09533ab9379a675a89638132fb6831b420ebb8f4.tar.bz2
ilt-09533ab9379a675a89638132fb6831b420ebb8f4.tar.xz
ilt-09533ab9379a675a89638132fb6831b420ebb8f4.zip
Add glDebugScope
Wrapper for glPushDebugGroup/glPopDebugGroup which allows neatly grouping OpenGL calls in diagnostic tools.
Diffstat (limited to 'gfx/gl/gldebug.h')
-rw-r--r--gfx/gl/gldebug.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/gfx/gl/gldebug.h b/gfx/gl/gldebug.h
new file mode 100644
index 0000000..5cfd099
--- /dev/null
+++ b/gfx/gl/gldebug.h
@@ -0,0 +1,52 @@
+#pragma once
+#ifndef GLDEBUG
+# define GLDEBUG 0
+#endif
+
+#include "special_members.h"
+#include <glad/gl.h>
+#include <source_location>
+#include <string_view>
+
+class [[nodiscard]] glDebugScope {
+public:
+ explicit glDebugScope(GLuint id, const std::source_location & = std::source_location::current());
+ explicit glDebugScope(
+ GLuint id, std::string_view msg, const std::source_location & = std::source_location::current());
+
+ ~glDebugScope();
+
+ constexpr
+ operator bool() const
+ {
+ return true;
+ }
+
+ NO_MOVE(glDebugScope);
+ NO_COPY(glDebugScope);
+};
+
+#if GLDEBUG > 0
+inline glDebugScope::~glDebugScope()
+{
+ glPopDebugGroup();
+}
+# if GLDEBUG == 1
+// Level 1 is inlined for performance because they're thin wrappers
+inline glDebugScope::glDebugScope(GLuint id, const std::source_location & location) :
+ glDebugScope {id, location.function_name()}
+{
+}
+
+inline glDebugScope::glDebugScope(GLuint id, const std::string_view msg, const std::source_location &)
+{
+ glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, id, static_cast<GLsizei>(msg.length()), msg.data());
+}
+# endif
+#else
+inline glDebugScope::glDebugScope(GLuint, const std::source_location &) { }
+
+inline glDebugScope::glDebugScope(GLuint, const std::string_view, const std::source_location &) { }
+
+inline glDebugScope::~glDebugScope() = default;
+#endif