summaryrefslogtreecommitdiff
path: root/lib/glBuffers.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 14:10:34 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 14:10:34 +0000
commit20646758939562c0fbad4d52774efcfacf7e22fc (patch)
tree9bd582b749640206a5e38389117d6c931dcf1f5f /lib/glBuffers.h
parentInitial commit with some basic UI (diff)
downloadilt-20646758939562c0fbad4d52774efcfacf7e22fc.tar.bz2
ilt-20646758939562c0fbad4d52774efcfacf7e22fc.tar.xz
ilt-20646758939562c0fbad4d52774efcfacf7e22fc.zip
RAII for glVertex and glBuffer
Diffstat (limited to 'lib/glBuffers.h')
-rw-r--r--lib/glBuffers.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/glBuffers.h b/lib/glBuffers.h
new file mode 100644
index 0000000..e91293c
--- /dev/null
+++ b/lib/glBuffers.h
@@ -0,0 +1,48 @@
+#ifndef GLBUFFERS_H
+#define GLBUFFERS_H
+
+#include <GL/glew.h>
+#include <array>
+#include <cstddef>
+#include <special_members.hpp>
+
+class glBuffersBase {
+protected:
+ static void gen(GLsizei, GLuint *);
+ static void del(GLsizei, const GLuint *);
+};
+
+template<size_t N> class glBuffers : glBuffersBase {
+public:
+ glBuffers()
+ {
+ gen(N, ids.data());
+ }
+
+ ~glBuffers()
+ {
+ del(N, ids.data());
+ }
+
+ NO_COPY(glBuffers);
+ NO_MOVE(glBuffers);
+
+ // 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 glBuffer = glBuffers<1>;
+
+#endif