Antkeeper  0.0.1
gl-shader-variables.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_GL_GL_SHADER_VARIABLES_HPP
21 #define ANTKEEPER_GL_GL_SHADER_VARIABLES_HPP
22 
24 #include <glad/gl.h>
25 #include <vector>
26 
27 namespace gl {
28 
33 {
34 public:
35  gl_shader_bool(std::size_t size, GLint gl_uniform_location);
36 
37  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
38  {
40  }
41 
42  void update(bool value) const noexcept override;
43  void update(bool value, std::size_t index) const override;
44  void update(std::span<const bool> values, std::size_t index = 0) const override;
45 
46 private:
47  GLint gl_uniform_location;
48  mutable std::vector<GLint> ivalues;
49 };
50 
55 {
56 public:
57  gl_shader_bvec2(std::size_t size, GLint gl_uniform_location);
58 
59  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
60  {
62  }
63 
64  void update(const math::bvec2& value) const noexcept override;
65  void update(const math::bvec2& value, std::size_t index) const override;
66  void update(std::span<const math::bvec2> values, std::size_t index = 0) const override;
67 
68 private:
69  GLint gl_uniform_location;
70  mutable std::vector<GLint> ivalues;
71 };
72 
77 {
78 public:
79  gl_shader_bvec3(std::size_t size, GLint gl_uniform_location);
80 
81  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
82  {
84  }
85 
86  void update(const math::bvec3& value) const noexcept override;
87  void update(const math::bvec3& value, std::size_t index) const override;
88  void update(std::span<const math::bvec3> values, std::size_t index = 0) const override;
89 
90 private:
91  GLint gl_uniform_location;
92  mutable std::vector<GLint> ivalues;
93 };
94 
99 {
100 public:
101  gl_shader_bvec4(std::size_t size, GLint gl_uniform_location);
102 
103  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
104  {
106  }
107 
108  void update(const math::bvec4& value) const noexcept override;
109  void update(const math::bvec4& value, std::size_t index) const override;
110  void update(std::span<const math::bvec4> values, std::size_t index = 0) const override;
111 
112 private:
113  GLint gl_uniform_location;
114  mutable std::vector<GLint> ivalues;
115 };
116 
121 {
122 public:
123  gl_shader_int(std::size_t size, GLint gl_uniform_location);
124 
125  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
126  {
128  }
129 
130  void update(int value) const noexcept override;
131  void update(int value, std::size_t index) const override;
132  void update(std::span<const int> values, std::size_t index = 0) const override;
133 
134 private:
135  GLint gl_uniform_location;
136 };
137 
142 {
143 public:
144  gl_shader_ivec2(std::size_t size, GLint gl_uniform_location);
145 
146  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
147  {
149  }
150 
151  void update(const math::ivec2& value) const noexcept override;
152  void update(const math::ivec2& value, std::size_t index) const override;
153  void update(std::span<const math::ivec2> values, std::size_t index = 0) const override;
154 
155 private:
156  GLint gl_uniform_location;
157 };
158 
163 {
164 public:
165  gl_shader_ivec3(std::size_t size, GLint gl_uniform_location);
166 
167  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
168  {
170  }
171 
172  void update(const math::ivec3& value) const noexcept override;
173  void update(const math::ivec3& value, std::size_t index) const override;
174  void update(std::span<const math::ivec3> values, std::size_t index = 0) const override;
175 
176 private:
177  GLint gl_uniform_location;
178 };
179 
184 {
185 public:
186  gl_shader_ivec4(std::size_t size, GLint gl_uniform_location);
187 
188  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
189  {
191  }
192 
193  void update(const math::ivec4& value) const noexcept override;
194  void update(const math::ivec4& value, std::size_t index) const override;
195  void update(std::span<const math::ivec4> values, std::size_t index = 0) const override;
196 
197 private:
198  GLint gl_uniform_location;
199 };
200 
205 {
206 public:
207  gl_shader_uint(std::size_t size, GLint gl_uniform_location);
208 
209  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
210  {
212  }
213 
214  void update(unsigned int value) const noexcept override;
215  void update(unsigned int value, std::size_t index) const override;
216  void update(std::span<const unsigned int> values, std::size_t index = 0) const override;
217 
218 private:
219  GLint gl_uniform_location;
220 };
221 
226 {
227 public:
228  gl_shader_uvec2(std::size_t size, GLint gl_uniform_location);
229 
230  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
231  {
233  }
234 
235  void update(const math::uvec2& value) const noexcept override;
236  void update(const math::uvec2& value, std::size_t index) const override;
237  void update(std::span<const math::uvec2> values, std::size_t index = 0) const override;
238 
239 private:
240  GLint gl_uniform_location;
241 };
242 
247 {
248 public:
249  gl_shader_uvec3(std::size_t size, GLint gl_uniform_location);
250 
251  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
252  {
254  }
255 
256  void update(const math::uvec3& value) const noexcept override;
257  void update(const math::uvec3& value, std::size_t index) const override;
258  void update(std::span<const math::uvec3> values, std::size_t index = 0) const override;
259 
260 private:
261  GLint gl_uniform_location;
262 };
263 
268 {
269 public:
270  gl_shader_uvec4(std::size_t size, GLint gl_uniform_location);
271 
272  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
273  {
275  }
276 
277  void update(const math::uvec4& value) const noexcept override;
278  void update(const math::uvec4& value, std::size_t index) const override;
279  void update(std::span<const math::uvec4> values, std::size_t index = 0) const override;
280 
281 private:
282  GLint gl_uniform_location;
283 };
284 
289 {
290 public:
291  gl_shader_float(std::size_t size, GLint gl_uniform_location);
292 
293  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
294  {
296  }
297 
298  void update(float value) const noexcept override;
299  void update(float value, std::size_t index) const override;
300  void update(std::span<const float> values, std::size_t index = 0) const override;
301 
302 private:
303  GLint gl_uniform_location;
304 };
305 
310 {
311 public:
312  gl_shader_fvec2(std::size_t size, GLint gl_uniform_location);
313 
314  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
315  {
317  }
318 
319  void update(const math::fvec2& value) const noexcept override;
320  void update(const math::fvec2& value, std::size_t index) const override;
321  void update(std::span<const math::fvec2> values, std::size_t index = 0) const override;
322 
323 private:
324  GLint gl_uniform_location;
325 };
326 
331 {
332 public:
333  gl_shader_fvec3(std::size_t size, GLint gl_uniform_location);
334 
335  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
336  {
338  }
339 
340  void update(const math::fvec3& value) const noexcept override;
341  void update(const math::fvec3& value, std::size_t index) const override;
342  void update(std::span<const math::fvec3> values, std::size_t index = 0) const override;
343 
344 private:
345  GLint gl_uniform_location;
346 };
347 
352 {
353 public:
354  gl_shader_fvec4(std::size_t size, GLint gl_uniform_location);
355 
356  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
357  {
359  }
360 
361  void update(const math::fvec4& value) const noexcept override;
362  void update(const math::fvec4& value, std::size_t index) const override;
363  void update(std::span<const math::fvec4> values, std::size_t index = 0) const override;
364 
365 private:
366  GLint gl_uniform_location;
367 };
368 
373 {
374 public:
375  gl_shader_fmat2(std::size_t size, GLint gl_uniform_location);
376 
377  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
378  {
380  }
381 
382  void update(const math::fmat2& value) const noexcept override;
383  void update(const math::fmat2& value, std::size_t index) const override;
384  void update(std::span<const math::fmat2> values, std::size_t index = 0) const override;
385 
386 private:
387  GLint gl_uniform_location;
388 };
389 
394 {
395 public:
396  gl_shader_fmat3(std::size_t size, GLint gl_uniform_location);
397 
398  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
399  {
401  }
402 
403  void update(const math::fmat3& value) const noexcept override;
404  void update(const math::fmat3& value, std::size_t index) const override;
405  void update(std::span<const math::fmat3> values, std::size_t index = 0) const override;
406 
407 private:
408  GLint gl_uniform_location;
409 };
410 
415 {
416 public:
417  gl_shader_fmat4(std::size_t size, GLint gl_uniform_location);
418 
419  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
420  {
422  }
423 
424  void update(const math::fmat4& value) const noexcept override;
425  void update(const math::fmat4& value, std::size_t index) const override;
426  void update(std::span<const math::fmat4> values, std::size_t index = 0) const override;
427 
428 private:
429  GLint gl_uniform_location;
430 };
431 
436 {
437 public:
438  gl_shader_texture_1d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index);
439 
440  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
441  {
443  }
444 
445  void update(const texture_1d& value) const noexcept override;
446  void update(const texture_1d& value, std::size_t index) const override;
447  void update(std::span<const texture_1d* const> values, std::size_t index = 0) const override;
448  void update(std::span<const std::shared_ptr<texture_1d>> values, std::size_t index = 0) const override;
449 
450 private:
451  GLint gl_uniform_location;
452  std::vector<GLint> gl_texture_unit_indices;
453 };
454 
459 {
460 public:
461  gl_shader_texture_2d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_unit_index);
462 
463  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
464  {
466  }
467 
468  void update(const texture_2d& value) const noexcept override;
469  void update(const texture_2d& value, std::size_t index) const override;
470  void update(std::span<const texture_2d* const> values, std::size_t index = 0) const override;
471  void update(std::span<const std::shared_ptr<texture_2d>> values, std::size_t index = 0) const override;
472 
473 private:
474  GLint gl_uniform_location;
475  std::vector<GLint> gl_texture_unit_indices;
476 };
477 
482 {
483 public:
484  gl_shader_texture_3d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index);
485 
486  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
487  {
489  }
490 
491  void update(const texture_3d& value) const noexcept override;
492  void update(const texture_3d& value, std::size_t index) const override;
493  void update(std::span<const texture_3d* const> values, std::size_t index = 0) const override;
494  void update(std::span<const std::shared_ptr<texture_3d>> values, std::size_t index = 0) const override;
495 
496 private:
497  GLint gl_uniform_location;
498  std::vector<GLint> gl_texture_unit_indices;
499 };
500 
505 {
506 public:
507  gl_shader_texture_cube(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index);
508 
509  [[nodiscard]] inline constexpr shader_variable_type type() const noexcept override
510  {
512  }
513 
514  void update(const texture_cube& value) const noexcept override;
515  void update(const texture_cube& value, std::size_t index) const override;
516  void update(std::span<const texture_cube* const> values, std::size_t index = 0) const override;
517  void update(std::span<const std::shared_ptr<texture_cube>> values, std::size_t index = 0) const override;
518 
519 private:
520  GLint gl_uniform_location;
521  std::vector<GLint> gl_texture_unit_indices;
522 };
523 
524 } // namespace gl
525 
526 #endif // ANTKEEPER_GL_GL_SHADER_VARIABLES_HPP
Boolean shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(bool value) const noexcept override
Updates the value of the variable.
gl_shader_bool(std::size_t size, GLint gl_uniform_location)
2-dimensional boolean vector shader variable implementation using OpenGL.
gl_shader_bvec2(std::size_t size, GLint gl_uniform_location)
void update(const math::bvec2 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
3-dimensional boolean vector shader variable implementation using OpenGL.
void update(const math::bvec3 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_bvec3(std::size_t size, GLint gl_uniform_location)
4-dimensional boolean vector shader variable implementation using OpenGL.
void update(const math::bvec4 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_bvec4(std::size_t size, GLint gl_uniform_location)
Floating-point shader variable implementation using OpenGL.
gl_shader_float(std::size_t size, GLint gl_uniform_location)
void update(float value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
2x2 floating-point matrix shader variable implementation using OpenGL.
void update(const math::fmat2 &value) const noexcept override
Updates the value of the variable.
gl_shader_fmat2(std::size_t size, GLint gl_uniform_location)
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
3x3 floating-point matrix shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const math::fmat3 &value) const noexcept override
Updates the value of the variable.
gl_shader_fmat3(std::size_t size, GLint gl_uniform_location)
4x4 floating-point matrix shader variable implementation using OpenGL.
void update(const math::fmat4 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_fmat4(std::size_t size, GLint gl_uniform_location)
2-dimensional floating-point vector shader variable implementation using OpenGL.
void update(const math::fvec2 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_fvec2(std::size_t size, GLint gl_uniform_location)
3-dimensional floating-point vector shader variable implementation using OpenGL.
void update(const math::fvec3 &value) const noexcept override
Updates the value of the variable.
gl_shader_fvec3(std::size_t size, GLint gl_uniform_location)
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
4-dimensional floating-point vector shader variable implementation using OpenGL.
gl_shader_fvec4(std::size_t size, GLint gl_uniform_location)
void update(const math::fvec4 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
Signed integer shader variable implementation using OpenGL.
void update(int value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_int(std::size_t size, GLint gl_uniform_location)
2-dimensional signed integer vector shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const math::ivec2 &value) const noexcept override
Updates the value of the variable.
gl_shader_ivec2(std::size_t size, GLint gl_uniform_location)
3-dimensional signed integer vector shader variable implementation using OpenGL.
void update(const math::ivec3 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_ivec3(std::size_t size, GLint gl_uniform_location)
4-dimensional signed integer vector shader variable implementation using OpenGL.
void update(const math::ivec4 &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_ivec4(std::size_t size, GLint gl_uniform_location)
1-dimensional texture shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const texture_1d &value) const noexcept override
Updates the value of the variable.
gl_shader_texture_1d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index)
2-dimensional texture shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_texture_2d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_unit_index)
void update(const texture_2d &value) const noexcept override
Updates the value of the variable.
3-dimensional texture shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const texture_3d &value) const noexcept override
Updates the value of the variable.
gl_shader_texture_3d(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index)
Cube texture shader variable implementation using OpenGL.
gl_shader_texture_cube(std::size_t size, GLint gl_uniform_location, GLint gl_first_texture_index)
void update(const texture_cube &value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
Unsigned integer shader variable implementation using OpenGL.
void update(unsigned int value) const noexcept override
Updates the value of the variable.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
gl_shader_uint(std::size_t size, GLint gl_uniform_location)
2-dimensional unsigned integer vector shader variable implementation using OpenGL.
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const math::uvec2 &value) const noexcept override
Updates the value of the variable.
gl_shader_uvec2(std::size_t size, GLint gl_uniform_location)
3-dimensional unsigned integer vector shader variable implementation using OpenGL.
gl_shader_uvec3(std::size_t size, GLint gl_uniform_location)
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
void update(const math::uvec3 &value) const noexcept override
Updates the value of the variable.
4-dimensional unsigned integer vector shader variable implementation using OpenGL.
void update(const math::uvec4 &value) const noexcept override
Updates the value of the variable.
gl_shader_uvec4(std::size_t size, GLint gl_uniform_location)
constexpr shader_variable_type type() const noexcept override
Returns the shader variable data type.
Shader program variable.
std::size_t size() const noexcept
Returns the number of elements in an array variable, or 1 if the variable is not an array.
1D texture.
Definition: texture.hpp:73
2D texture.
Definition: texture.hpp:141
3D texture.
Definition: texture.hpp:209
Cube texture.
Definition: texture.hpp:243
Graphics library interface.
Definition: window.hpp:28
shader_variable_type
Shader variable data types.
n by m column-major matrix.
Definition: math/matrix.hpp:44
n-dimensional vector.
Definition: vector.hpp:44