Antkeeper  0.0.1
shader-input.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_SHADER_INPUT_HPP
21 #define ANTKEEPER_GL_SHADER_INPUT_HPP
22 
24 #include <string>
25 
26 namespace gl {
27 
28 class shader_program;
29 class texture_1d;
30 class texture_2d;
31 class texture_3d;
32 class texture_cube;
33 enum class shader_variable_type;
34 
39 {
40 public:
45 
49  bool is_array() const;
50 
54  std::size_t get_element_count() const;
55 
63  bool upload(const bool& value) const;
64  bool upload(const bool2& value) const;
65  bool upload(const bool3& value) const;
66  bool upload(const bool4& value) const;
67  bool upload(const int& value) const;
68  bool upload(const int2& value) const;
69  bool upload(const int3& value) const;
70  bool upload(const int4& value) const;
71  bool upload(const unsigned int& value) const;
72  bool upload(const uint2& value) const;
73  bool upload(const uint3& value) const;
74  bool upload(const uint4& value) const;
75  bool upload(const float& value) const;
76  bool upload(const float2& value) const;
77  bool upload(const float3& value) const;
78  bool upload(const float4& value) const;
79  bool upload(const float2x2& value) const;
80  bool upload(const float3x3& value) const;
81  bool upload(const float4x4& value) const;
82  bool upload(const texture_1d* value) const;
83  bool upload(const texture_2d* value) const;
84  bool upload(const texture_3d* value) const;
85  bool upload(const texture_cube* value) const;
87 
96  bool upload(std::size_t index, const bool& value) const;
97  bool upload(std::size_t index, const bool2& value) const;
98  bool upload(std::size_t index, const bool3& value) const;
99  bool upload(std::size_t index, const bool4& value) const;
100  bool upload(std::size_t index, const int& value) const;
101  bool upload(std::size_t index, const int2& value) const;
102  bool upload(std::size_t index, const int3& value) const;
103  bool upload(std::size_t index, const int4& value) const;
104  bool upload(std::size_t index, const unsigned int& value) const;
105  bool upload(std::size_t index, const uint2& value) const;
106  bool upload(std::size_t index, const uint3& value) const;
107  bool upload(std::size_t index, const uint4& value) const;
108  bool upload(std::size_t index, const float& value) const;
109  bool upload(std::size_t index, const float2& value) const;
110  bool upload(std::size_t index, const float3& value) const;
111  bool upload(std::size_t index, const float4& value) const;
112  bool upload(std::size_t index, const float2x2& value) const;
113  bool upload(std::size_t index, const float3x3& value) const;
114  bool upload(std::size_t index, const float4x4& value) const;
115  bool upload(std::size_t index, const texture_1d* value) const;
116  bool upload(std::size_t index, const texture_2d* value) const;
117  bool upload(std::size_t index, const texture_3d* value) const;
118  bool upload(std::size_t index, const texture_cube* value) const;
120 
130  bool upload(std::size_t index, const bool* values, std::size_t count) const;
131  bool upload(std::size_t index, const bool2* values, std::size_t count) const;
132  bool upload(std::size_t index, const bool3* values, std::size_t count) const;
133  bool upload(std::size_t index, const bool4* values, std::size_t count) const;
134  bool upload(std::size_t index, const int* values, std::size_t count) const;
135  bool upload(std::size_t index, const int2* values, std::size_t count) const;
136  bool upload(std::size_t index, const int3* values, std::size_t count) const;
137  bool upload(std::size_t index, const int4* values, std::size_t count) const;
138  bool upload(std::size_t index, const unsigned int* values, std::size_t count) const;
139  bool upload(std::size_t index, const uint2* values, std::size_t count) const;
140  bool upload(std::size_t index, const uint3* values, std::size_t count) const;
141  bool upload(std::size_t index, const uint4* values, std::size_t count) const;
142  bool upload(std::size_t index, const float* values, std::size_t count) const;
143  bool upload(std::size_t index, const float2* values, std::size_t count) const;
144  bool upload(std::size_t index, const float3* values, std::size_t count) const;
145  bool upload(std::size_t index, const float4* values, std::size_t count) const;
146  bool upload(std::size_t index, const float2x2* values, std::size_t count) const;
147  bool upload(std::size_t index, const float3x3* values, std::size_t count) const;
148  bool upload(std::size_t index, const float4x4* values, std::size_t count) const;
149  bool upload(std::size_t index, const texture_1d** values, std::size_t count) const;
150  bool upload(std::size_t index, const texture_2d** values, std::size_t count) const;
151  bool upload(std::size_t index, const texture_3d** values, std::size_t count) const;
152  bool upload(std::size_t index, const texture_cube** values, std::size_t count) const;
154 
155 private:
156  friend class shader_program;
157 
168  shader_input(shader_program* program, std::size_t input_index, int gl_uniform_location, const std::string& name, shader_variable_type data_type, std::size_t element_count, int texture_unit);
169 
173  ~shader_input();
174 
175  shader_program* program;
176  std::size_t input_index;
177  int gl_uniform_location;
178  std::string name;
179  shader_variable_type data_type;
180  std::size_t element_count;
181  int texture_unit;
182 };
183 
185 {
186  return data_type;
187 }
188 
189 inline bool shader_input::is_array() const
190 {
191  return (element_count > 1);
192 }
193 
194 inline std::size_t shader_input::get_element_count() const
195 {
196  return element_count;
197 }
198 
199 } // namespace gl
200 
201 #endif // ANTKEEPER_GL_SHADER_INPUT_HPP
202 
Port through which data can be uploaded to shader variables.
std::size_t get_element_count() const
Returns the number of elements the array can contain, or 1 if the data is not stored in an array.
shader_variable_type get_data_type() const
Returns the type of data which can be passed through this input.
bool upload(const bool &value) const
Uploads a value to the shader.
bool is_array() const
Returns true if the input data is stored in an array.
Shader program which can be linked to shader objects and executed.
A 1D texture which can be uploaded to shaders via shader inputs.
Definition: texture-1d.hpp:31
A 2D texture which can be uploaded to shaders via shader inputs.
Definition: texture-2d.hpp:31
A 3D texture which can be uploaded to shaders via shader inputs.
Definition: texture-3d.hpp:31
A cube texture which can be uploaded to shaders via shader inputs.
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
Definition: bit-math.hpp:211
Graphics library interface.
@ index
General purpose index (uint)
n by m column-major matrix.
Definition: math/matrix.hpp:44
n-dimensional vector.
Definition: vector.hpp:43