Browse code

Add implementation

Robert Cranston authored on 29/12/2021 16:30:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,96 @@
1
+#include <gltexturend.hpp>
2
+
3
+#include <functional>
4
+#include <numeric>
5
+#include <utility>
6
+
7
+#include <globject.hpp>
8
+#include <gltexture.hpp>
9
+
10
+// NOLINTNEXTLINE
11
+#define STR_EXCEPTION GLObject<>::Exception
12
+#include <str.hpp>
13
+
14
+
15
+/// Special member functions
16
+
17
+
18
+template<std::size_t N>
19
+inline GLTextureND<N>::GLTextureND(
20
+    // NOLINTNEXTLINE
21
+    std::string object_label,
22
+    GLenum      target,
23
+    GLenum      binding,
24
+    GLenum      size_max_name,
25
+    Size        size,
26
+    GLenum      internal_format,
27
+    GLenum      wrap,
28
+    GLenum      min_filter,
29
+    GLenum      mag_filter
30
+)
31
+:
32
+    GLTexture(
33
+        STR_JOIN(" ", it, it, {
34
+            str_size_(size),
35
+            std::move(object_label)
36
+        }),
37
+        target,
38
+        binding,
39
+        internal_format,
40
+        wrap,
41
+        min_filter,
42
+        mag_filter
43
+    ),
44
+    size_{size}
45
+{
46
+    check_size_max_(size_max_name);
47
+}
48
+
49
+
50
+/// Core
51
+
52
+
53
+template<std::size_t N>
54
+std::size_t GLTextureND<N>::data_size_() const
55
+{
56
+    return std::accumulate(
57
+        size_.begin(),
58
+        size_.end(),
59
+        std::size_t{1},
60
+        std::multiplies<std::size_t>{}
61
+    );
62
+}
63
+
64
+
65
+/// Check
66
+
67
+
68
+template<std::size_t N>
69
+void GLTextureND<N>::check_size_max_(GLenum size_max_name)
70
+{
71
+    auto static const size_max = integer(size_max_name);
72
+    for (auto size : size_)
73
+        if (size > size_max)
74
+            STR_THROW(
75
+                "Expected max size " << size_max         << ", " <<
76
+                "got "               << str_size_(size_) << "."
77
+            );
78
+}
79
+
80
+
81
+/// String
82
+
83
+
84
+template<std::size_t N>
85
+std::string GLTextureND<N>::str_size_(Size size)
86
+{
87
+    return STR("{" << STR_JOIN(", ", it, it, size) << "}");
88
+}
89
+
90
+
91
+/// Explicit template instantiation
92
+
93
+
94
+template class GLTextureND<1>;
95
+template class GLTextureND<2>;
96
+template class GLTextureND<3>;