Browse code

Add implementation

Robert Cranston authored on 10/01/2022 00:25:45
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,85 @@
1
+/// Includes
2
+
3
+
4
+#include "globject.hpp"
5
+
6
+#include <algorithm>
7
+#include <cstddef>
8
+
9
+#include <glbase.hpp>
10
+
11
+#include <str.hpp>
12
+
13
+
14
+/// Object
15
+
16
+
17
+std::string GLObject<0>::label_(
18
+    GLenum object_type,
19
+    GLuint object
20
+)
21
+{
22
+    if (!supported({4, 3}, "GL_KHR_debug"))
23
+        return {};
24
+    auto length = GLint{};
25
+    glGetObjectLabel(
26
+        object_type,
27
+        object,
28
+        0,
29
+        &length,
30
+        nullptr
31
+    );
32
+    auto label = std::string((std::size_t)length, char{});
33
+    glGetObjectLabel(
34
+        object_type,
35
+        object,
36
+        length+1,
37
+        nullptr,
38
+        &label[0]
39
+    );
40
+    check_error_(glGetError());
41
+    return label;
42
+}
43
+
44
+
45
+void GLObject<0>::label_(
46
+    GLenum              object_type,
47
+    GLuint              object,
48
+    std::string const & label
49
+)
50
+{
51
+    if (!supported({4, 3}, "GL_KHR_debug"))
52
+        return;
53
+    auto thread_local label_length_max = integer(GL_MAX_LABEL_LENGTH);
54
+    auto label_length = std::min(
55
+        (GLsizei)label_length_max,
56
+        (GLsizei)label.length()
57
+    );
58
+    glObjectLabel(
59
+        object_type,
60
+        object,
61
+        label_length,
62
+        label.c_str()
63
+    );
64
+}
65
+
66
+
67
+/// Name
68
+
69
+
70
+std::string GLObject<0>::name_(
71
+    GLenum              object_type,
72
+    GLuint              object,
73
+    std::string const & label
74
+)
75
+{
76
+    return STR_JOIN(" ", it, it, {
77
+        str_object_type_(object_type),
78
+        object
79
+            ? STR(object)
80
+            : "",
81
+        !label.empty()
82
+            ? label
83
+            : label_(object_type, object),
84
+    });
85
+}