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.
This commit is contained in:
Wunkolo 2023-06-20 00:24:51 -07:00
parent 1251cecc88
commit dbf0597bd8

View file

@ -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;