summaryrefslogtreecommitdiff
path: root/lib/glBuffers.h
blob: e91293c8a989a66ddadf1993e1b7f4eb69303f46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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