summaryrefslogtreecommitdiff
path: root/gfx/gl/gldebug.h
blob: 5cfd099f3e23e9794f43137e609d311cc6bc4c0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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