summaryrefslogtreecommitdiff
path: root/lib/glVertexArrays.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glVertexArrays.h')
-rw-r--r--lib/glVertexArrays.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/glVertexArrays.h b/lib/glVertexArrays.h
new file mode 100644
index 0000000..ab31751
--- /dev/null
+++ b/lib/glVertexArrays.h
@@ -0,0 +1,48 @@
+#ifndef GLVERTEXARRAYS_H
+#define GLVERTEXARRAYS_H
+
+#include <GL/glew.h>
+#include <array>
+#include <cstddef>
+#include <special_members.hpp>
+
+class glVertexArraysBase {
+protected:
+ static void gen(GLsizei, GLuint *);
+ static void del(GLsizei, const GLuint *);
+};
+
+template<size_t N> class glVertexArrays : glVertexArraysBase {
+public:
+ glVertexArrays()
+ {
+ gen(N, ids.data());
+ }
+
+ ~glVertexArrays()
+ {
+ del(N, ids.data());
+ }
+
+ NO_COPY(glVertexArrays);
+ NO_MOVE(glVertexArrays);
+
+ // NOLINTNEXTLINE(hicpp-explicit-conversions)
+ operator GLuint() const
+ {
+ static_assert(N == 1, "Implicit cast only if N == 1");
+ return ids.front();
+ }
+
+ auto
+ operator[](size_t n) const
+ {
+ return ids[n];
+ }
+
+private:
+ std::array<GLuint, N> ids {};
+};
+using glVertexArray = glVertexArrays<1>;
+
+#endif