diff options
Diffstat (limited to 'src/renderer/wrappers.h')
-rw-r--r-- | src/renderer/wrappers.h | 273 |
1 files changed, 273 insertions, 0 deletions
diff --git a/src/renderer/wrappers.h b/src/renderer/wrappers.h new file mode 100644 index 0000000..c6edc11 --- /dev/null +++ b/src/renderer/wrappers.h | |||
@@ -0,0 +1,273 @@ | |||
1 | #ifndef WRAPPERS_H_1EE0965B | ||
2 | #define WRAPPERS_H_1EE0965B | ||
3 | |||
4 | #include "gl.h" | ||
5 | #include <utility> | ||
6 | |||
7 | class GLVertexArray { | ||
8 | public: | ||
9 | |||
10 | GLVertexArray() | ||
11 | { | ||
12 | glGenVertexArrays(1, &id_); | ||
13 | } | ||
14 | |||
15 | GLVertexArray(const GLVertexArray& other) = delete; | ||
16 | GLVertexArray& operator=(const GLVertexArray& other) = delete; | ||
17 | |||
18 | GLVertexArray(GLVertexArray&& other) : GLVertexArray() | ||
19 | { | ||
20 | std::swap(id_, other.id_); | ||
21 | } | ||
22 | |||
23 | GLVertexArray& operator=(GLVertexArray&& other) | ||
24 | { | ||
25 | std::swap(id_, other.id_); | ||
26 | |||
27 | return *this; | ||
28 | } | ||
29 | |||
30 | ~GLVertexArray() | ||
31 | { | ||
32 | glDeleteVertexArrays(1, &id_); | ||
33 | } | ||
34 | |||
35 | inline GLuint getId() const | ||
36 | { | ||
37 | return id_; | ||
38 | } | ||
39 | |||
40 | private: | ||
41 | |||
42 | GLuint id_; | ||
43 | }; | ||
44 | |||
45 | class GLFramebuffer { | ||
46 | public: | ||
47 | |||
48 | GLFramebuffer() | ||
49 | { | ||
50 | glGenFramebuffers(1, &id_); | ||
51 | } | ||
52 | |||
53 | GLFramebuffer(const GLFramebuffer& other) = delete; | ||
54 | GLFramebuffer& operator=(const GLFramebuffer& other) = delete; | ||
55 | |||
56 | GLFramebuffer(GLFramebuffer&& other) : GLFramebuffer() | ||
57 | { | ||
58 | std::swap(id_, other.id_); | ||
59 | } | ||
60 | |||
61 | GLFramebuffer& operator=(GLFramebuffer&& other) | ||
62 | { | ||
63 | std::swap(id_, other.id_); | ||
64 | |||
65 | return *this; | ||
66 | } | ||
67 | |||
68 | ~GLFramebuffer() | ||
69 | { | ||
70 | glDeleteFramebuffers(1, &id_); | ||
71 | } | ||
72 | |||
73 | inline GLuint getId() const | ||
74 | { | ||
75 | return id_; | ||
76 | } | ||
77 | |||
78 | private: | ||
79 | |||
80 | GLuint id_; | ||
81 | }; | ||
82 | |||
83 | class GLRenderbuffer { | ||
84 | public: | ||
85 | |||
86 | GLRenderbuffer() | ||
87 | { | ||
88 | glGenRenderbuffers(1, &id_); | ||
89 | } | ||
90 | |||
91 | GLRenderbuffer(const GLRenderbuffer& other) = delete; | ||
92 | GLRenderbuffer& operator=(const GLRenderbuffer& other) = delete; | ||
93 | |||
94 | GLRenderbuffer(GLRenderbuffer&& other) : GLRenderbuffer() | ||
95 | { | ||
96 | std::swap(id_, other.id_); | ||
97 | } | ||
98 | |||
99 | GLRenderbuffer& operator=(GLRenderbuffer&& other) | ||
100 | { | ||
101 | std::swap(id_, other.id_); | ||
102 | |||
103 | return *this; | ||
104 | } | ||
105 | |||
106 | ~GLRenderbuffer() | ||
107 | { | ||
108 | glDeleteRenderbuffers(1, &id_); | ||
109 | } | ||
110 | |||
111 | inline GLuint getId() const | ||
112 | { | ||
113 | return id_; | ||
114 | } | ||
115 | |||
116 | private: | ||
117 | |||
118 | GLuint id_; | ||
119 | }; | ||
120 | |||
121 | class GLBuffer { | ||
122 | public: | ||
123 | |||
124 | GLBuffer() | ||
125 | { | ||
126 | glGenBuffers(1, &id_); | ||
127 | } | ||
128 | |||
129 | GLBuffer(const GLBuffer& other) = delete; | ||
130 | GLBuffer& operator=(const GLBuffer& other) = delete; | ||
131 | |||
132 | GLBuffer(GLBuffer&& other) : GLBuffer() | ||
133 | { | ||
134 | std::swap(id_, other.id_); | ||
135 | } | ||
136 | |||
137 | GLBuffer& operator=(GLBuffer&& other) | ||
138 | { | ||
139 | std::swap(id_, other.id_); | ||
140 | |||
141 | return *this; | ||
142 | } | ||
143 | |||
144 | ~GLBuffer() | ||
145 | { | ||
146 | glDeleteBuffers(1, &id_); | ||
147 | } | ||
148 | |||
149 | inline GLuint getId() const | ||
150 | { | ||
151 | return id_; | ||
152 | } | ||
153 | |||
154 | private: | ||
155 | |||
156 | GLuint id_; | ||
157 | }; | ||
158 | |||
159 | class GLTexture { | ||
160 | public: | ||
161 | |||
162 | GLTexture() | ||
163 | { | ||
164 | glGenTextures(1, &id_); | ||
165 | } | ||
166 | |||
167 | GLTexture(const GLTexture& other) = delete; | ||
168 | GLTexture& operator=(const GLTexture& other) = delete; | ||
169 | |||
170 | GLTexture(GLTexture&& other) : GLTexture() | ||
171 | { | ||
172 | std::swap(id_, other.id_); | ||
173 | } | ||
174 | |||
175 | GLTexture& operator=(GLTexture&& other) | ||
176 | { | ||
177 | std::swap(id_, other.id_); | ||
178 | |||
179 | return *this; | ||
180 | } | ||
181 | |||
182 | ~GLTexture() | ||
183 | { | ||
184 | glDeleteTextures(1, &id_); | ||
185 | } | ||
186 | |||
187 | inline GLuint getId() const | ||
188 | { | ||
189 | return id_; | ||
190 | } | ||
191 | |||
192 | private: | ||
193 | |||
194 | GLuint id_; | ||
195 | }; | ||
196 | |||
197 | class GLShader { | ||
198 | public: | ||
199 | |||
200 | GLShader(GLenum type) | ||
201 | { | ||
202 | id_ = glCreateShader(type); | ||
203 | } | ||
204 | |||
205 | GLShader(const GLShader& other) = delete; | ||
206 | GLShader& operator=(const GLShader& other) = delete; | ||
207 | |||
208 | GLShader(GLShader&& other) : GLShader(GL_VERTEX_SHADER) | ||
209 | { | ||
210 | std::swap(id_, other.id_); | ||
211 | } | ||
212 | |||
213 | GLShader& operator=(GLShader&& other) | ||
214 | { | ||
215 | std::swap(id_, other.id_); | ||
216 | |||
217 | return *this; | ||
218 | } | ||
219 | |||
220 | ~GLShader() | ||
221 | { | ||
222 | glDeleteShader(id_); | ||
223 | } | ||
224 | |||
225 | inline GLuint getId() const | ||
226 | { | ||
227 | return id_; | ||
228 | } | ||
229 | |||
230 | private: | ||
231 | |||
232 | GLuint id_; | ||
233 | }; | ||
234 | |||
235 | class GLProgram { | ||
236 | public: | ||
237 | |||
238 | GLProgram() | ||
239 | { | ||
240 | id_ = glCreateProgram(); | ||
241 | } | ||
242 | |||
243 | GLProgram(const GLProgram& other) = delete; | ||
244 | GLProgram& operator=(const GLProgram& other) = delete; | ||
245 | |||
246 | GLProgram(GLProgram&& other) : GLProgram() | ||
247 | { | ||
248 | std::swap(id_, other.id_); | ||
249 | } | ||
250 | |||
251 | GLProgram& operator=(GLProgram&& other) | ||
252 | { | ||
253 | std::swap(id_, other.id_); | ||
254 | |||
255 | return *this; | ||
256 | } | ||
257 | |||
258 | ~GLProgram() | ||
259 | { | ||
260 | glDeleteProgram(id_); | ||
261 | } | ||
262 | |||
263 | inline GLuint getId() const | ||
264 | { | ||
265 | return id_; | ||
266 | } | ||
267 | |||
268 | private: | ||
269 | |||
270 | GLuint id_; | ||
271 | }; | ||
272 | |||
273 | #endif /* end of include guard: WRAPPERS_H_1EE0965B */ | ||