summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-31 12:31:13 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-31 12:31:13 +0000
commit7c6ad616ae0d8c2bb83c9ad6473b5581a6bd7526 (patch)
tree4e05d57497b2c2bd8f339bb6aa966a38ccc4d13f /lib
parentRemove unnecessary initialiser (diff)
downloadilt-7c6ad616ae0d8c2bb83c9ad6473b5581a6bd7526.tar.bz2
ilt-7c6ad616ae0d8c2bb83c9ad6473b5581a6bd7526.tar.xz
ilt-7c6ad616ae0d8c2bb83c9ad6473b5581a6bd7526.zip
Allow glBuffers and glVertexArrays to be moved
Diffstat (limited to 'lib')
-rw-r--r--lib/glBuffers.h18
-rw-r--r--lib/glVertexArrays.h18
-rw-r--r--lib/special_members.hpp4
3 files changed, 38 insertions, 2 deletions
diff --git a/lib/glBuffers.h b/lib/glBuffers.h
index e91293c..e2c09df 100644
--- a/lib/glBuffers.h
+++ b/lib/glBuffers.h
@@ -2,6 +2,7 @@
#define GLBUFFERS_H
#include <GL/glew.h>
+#include <algorithm> // IWYU pragma: keep
#include <array>
#include <cstddef>
#include <special_members.hpp>
@@ -25,7 +26,7 @@ public:
}
NO_COPY(glBuffers);
- NO_MOVE(glBuffers);
+ CUSTOM_MOVE(glBuffers);
// NOLINTNEXTLINE(hicpp-explicit-conversions)
operator GLuint() const
@@ -43,6 +44,21 @@ public:
private:
std::array<GLuint, N> ids {};
};
+
+template<size_t N> glBuffers<N>::glBuffers(glBuffers<N> && src) noexcept : ids {src.ids}
+{
+ std::fill(src.ids.begin(), src.ids.end(), -1);
+}
+
+template<size_t N>
+glBuffers<N> &
+glBuffers<N>::operator=(glBuffers<N> && src) noexcept
+{
+ ids = src.ids;
+ std::fill(src.ids.begin(), src.ids.end(), -1);
+ return *this;
+}
+
using glBuffer = glBuffers<1>;
#endif
diff --git a/lib/glVertexArrays.h b/lib/glVertexArrays.h
index ab31751..803206a 100644
--- a/lib/glVertexArrays.h
+++ b/lib/glVertexArrays.h
@@ -2,6 +2,7 @@
#define GLVERTEXARRAYS_H
#include <GL/glew.h>
+#include <algorithm> // IWYU pragma: keep
#include <array>
#include <cstddef>
#include <special_members.hpp>
@@ -25,7 +26,7 @@ public:
}
NO_COPY(glVertexArrays);
- NO_MOVE(glVertexArrays);
+ CUSTOM_MOVE(glVertexArrays);
// NOLINTNEXTLINE(hicpp-explicit-conversions)
operator GLuint() const
@@ -43,6 +44,21 @@ public:
private:
std::array<GLuint, N> ids {};
};
+
+template<size_t N> glVertexArrays<N>::glVertexArrays(glVertexArrays<N> && src) noexcept : ids {src.ids}
+{
+ std::fill(src.ids.begin(), src.ids.end(), -1);
+}
+
+template<size_t N>
+glVertexArrays<N> &
+glVertexArrays<N>::operator=(glVertexArrays<N> && src) noexcept
+{
+ ids = src.ids;
+ std::fill(src.ids.begin(), src.ids.end(), -1);
+ return *this;
+}
+
using glVertexArray = glVertexArrays<1>;
#endif
diff --git a/lib/special_members.hpp b/lib/special_members.hpp
index d1dca99..4b85884 100644
--- a/lib/special_members.hpp
+++ b/lib/special_members.hpp
@@ -25,4 +25,8 @@
DEFAULT_MOVE(TYPE); \
NO_COPY(TYPE)
+#define CUSTOM_MOVE(TYPE) \
+ TYPE(TYPE &&) noexcept; \
+ TYPE & operator=(TYPE &&) noexcept
+
#endif