Antkeeper  0.0.1
sampler.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_SAMPLER_HPP
21 #define ANTKEEPER_GL_SAMPLER_HPP
22 
26 #include <engine/gl/compare-op.hpp>
27 #include <array>
28 
29 namespace gl {
30 
34 class sampler
35 {
36 public:
54  explicit sampler
55  (
62  float mip_lod_bias = 0.0f,
63  float max_anisotropy = 0.0f,
64  bool compare_enabled = false,
66  float min_lod = -1000.0f,
67  float max_lod = 1000.0f,
68  const std::array<float, 4>& border_color = {0.0f, 0.0f, 0.0f, 0.0f}
69  );
70 
72  ~sampler();
73 
74  sampler(const sampler&) = delete;
75  sampler(sampler&&) = delete;
76  sampler& operator=(const sampler&) = delete;
77  sampler& operator=(sampler&&) = delete;
78 
84  void set_mag_filter(sampler_filter filter);
85 
91  void set_min_filter(sampler_filter filter);
92 
99 
106 
113 
120 
126  void set_mip_lod_bias(float bias);
127 
133  void set_max_anisotropy(float anisotropy);
134 
140  void set_compare_enabled(bool enabled);
141 
148 
154  void set_min_lod(float lod);
155 
161  void set_max_lod(float lod);
162 
168  void set_border_color(const std::array<float, 4>& color);
169 
171  [[nodiscard]] inline constexpr sampler_filter get_mag_filter() const noexcept
172  {
173  return m_mag_filter;
174  }
175 
177  [[nodiscard]] inline constexpr sampler_filter get_min_filter() const noexcept
178  {
179  return m_min_filter;
180  }
181 
183  [[nodiscard]] inline constexpr sampler_mipmap_mode get_mipmap_mode() const noexcept
184  {
185  return m_mipmap_mode;
186  }
187 
189  [[nodiscard]] inline constexpr sampler_address_mode get_address_mode_u() const noexcept
190  {
191  return m_address_mode_u;
192  }
193 
195  [[nodiscard]] inline constexpr sampler_address_mode get_address_mode_v() const noexcept
196  {
197  return m_address_mode_v;
198  }
199 
201  [[nodiscard]] inline constexpr sampler_address_mode get_address_mode_w() const noexcept
202  {
203  return m_address_mode_w;
204  }
205 
207  [[nodiscard]] inline constexpr float get_mip_lod_bias() const noexcept
208  {
209  return m_mip_lod_bias;
210  }
211 
213  [[nodiscard]] inline constexpr float get_max_anisotropy() const noexcept
214  {
215  return m_max_anisotropy;
216  }
217 
219  [[nodiscard]] inline constexpr float get_compare_enabled() const noexcept
220  {
221  return m_compare_enabled;
222  }
223 
225  [[nodiscard]] inline constexpr compare_op get_compare_op() const noexcept
226  {
227  return m_compare_op;
228  }
229 
231  [[nodiscard]] inline constexpr float get_min_lod() const noexcept
232  {
233  return m_min_lod;
234  }
235 
237  [[nodiscard]] inline constexpr float get_max_lod() const noexcept
238  {
239  return m_max_lod;
240  }
241 
243  [[nodiscard]] inline constexpr const std::array<float, 4>& get_border_color() const noexcept
244  {
245  return m_border_color;
246  }
247 
248 private:
249  friend class pipeline;
250  friend class gl_shader_texture_1d;
251  friend class gl_shader_texture_2d;
252  friend class gl_shader_texture_3d;
254 
255  unsigned int m_gl_named_sampler{0};
256 
263  float m_mip_lod_bias{0.0f};
264  float m_max_anisotropy{0.0f};
265  bool m_compare_enabled{false};
266  gl::compare_op m_compare_op{gl::compare_op::less};
267  float m_min_lod{-1000.0f};
268  float m_max_lod{1000.0f};
269  std::array<float, 4> m_border_color{0.0f, 0.0f, 0.0f, 0.0f};
270 };
271 
272 } // namespace gl
273 
274 #endif // ANTKEEPER_GL_SAMPLER_HPP
1-dimensional texture shader variable implementation using OpenGL.
2-dimensional texture shader variable implementation using OpenGL.
3-dimensional texture shader variable implementation using OpenGL.
Cube texture shader variable implementation using OpenGL.
Graphics pipeline interface.
Definition: pipeline.hpp:48
Sampler object.
Definition: sampler.hpp:35
constexpr float get_min_lod() const noexcept
Returns the minimum clamp value of the computed LOD.
Definition: sampler.hpp:231
constexpr const std::array< float, 4 > & get_border_color() const noexcept
Returns the border color used for texture lookups.
Definition: sampler.hpp:243
void set_min_lod(float lod)
Sets the minimum clamp value of the computed LOD.
Definition: sampler.cpp:203
void set_max_anisotropy(float anisotropy)
Sets the anisotropy clamp value.
Definition: sampler.cpp:175
void set_address_mode_w(sampler_address_mode mode)
Sets the addressing mode for W-coordinates outside [0, 1).
Definition: sampler.cpp:156
sampler & operator=(sampler &&)=delete
constexpr float get_max_lod() const noexcept
Returns the maximum clamp value of the computed LOD.
Definition: sampler.hpp:237
sampler(sampler &&)=delete
void set_mipmap_mode(sampler_mipmap_mode mode)
Sets the mipmap filter to apply to lookups.
Definition: sampler.cpp:126
constexpr sampler_address_mode get_address_mode_w() const noexcept
Returns the addressing mode for W-coordinates outside [0, 1).
Definition: sampler.hpp:201
void set_compare_op(gl::compare_op op)
Sets the comparison operator to apply to fetched data, if compare is enabled.
Definition: sampler.cpp:193
constexpr sampler_address_mode get_address_mode_u() const noexcept
Returns the addressing mode for U-coordinates outside [0, 1).
Definition: sampler.hpp:189
constexpr float get_max_anisotropy() const noexcept
Returns the anisotropy clamp value.
Definition: sampler.hpp:213
constexpr sampler_filter get_mag_filter() const noexcept
Returns the magnification filter to apply to lookups.
Definition: sampler.hpp:171
constexpr sampler_mipmap_mode get_mipmap_mode() const noexcept
Returns the mipmap filter to apply to lookups.
Definition: sampler.hpp:183
void set_address_mode_v(sampler_address_mode mode)
Sets the addressing mode for V-coordinates outside [0, 1).
Definition: sampler.cpp:146
void set_min_filter(sampler_filter filter)
Sets the minification filter to apply to lookups.
Definition: sampler.cpp:116
constexpr compare_op get_compare_op() const noexcept
Returns the comparison operator to apply to fetched data, if compare is enabled.
Definition: sampler.hpp:225
constexpr sampler_filter get_min_filter() const noexcept
Returns the minification filter to apply to lookups.
Definition: sampler.hpp:177
void set_mip_lod_bias(float bias)
Sets the bias to be added to mipmap LOD calculation.
Definition: sampler.cpp:166
constexpr sampler_address_mode get_address_mode_v() const noexcept
Returns the addressing mode for V-coordinates outside [0, 1).
Definition: sampler.hpp:195
void set_compare_enabled(bool enabled)
Enables or disables a comparison against a reference value during lookups.
Definition: sampler.cpp:184
sampler(sampler_filter mag_filter=sampler_filter::linear, sampler_filter min_filter=sampler_filter::nearest, sampler_mipmap_mode mipmap_mode=sampler_mipmap_mode::linear, sampler_address_mode address_mode_u=sampler_address_mode::repeat, sampler_address_mode address_mode_v=sampler_address_mode::repeat, sampler_address_mode address_mode_w=sampler_address_mode::repeat, float mip_lod_bias=0.0f, float max_anisotropy=0.0f, bool compare_enabled=false, gl::compare_op compare_op=gl::compare_op::less, float min_lod=-1000.0f, float max_lod=1000.0f, const std::array< float, 4 > &border_color={0.0f, 0.0f, 0.0f, 0.0f})
Constructs a sampler object.
Definition: sampler.cpp:68
void set_max_lod(float lod)
Sets the maximum clamp value of the computed LOD.
Definition: sampler.cpp:212
void set_border_color(const std::array< float, 4 > &color)
Sets the border color used for texture lookups.
Definition: sampler.cpp:221
void set_mag_filter(sampler_filter filter)
Sets the magnification filter to apply to lookups.
Definition: sampler.cpp:106
constexpr float get_mip_lod_bias() const noexcept
Returns the bias to be added to mipmap LOD calculation.
Definition: sampler.hpp:207
sampler & operator=(const sampler &)=delete
sampler(const sampler &)=delete
~sampler()
Destroys a sampler object.
Definition: sampler.cpp:101
constexpr float get_compare_enabled() const noexcept
Returns true if comparison against a reference value during lookups is enabled, false otherwise.
Definition: sampler.hpp:219
void set_address_mode_u(sampler_address_mode mode)
Sets the addressing mode for U-coordinates outside [0, 1).
Definition: sampler.cpp:136
Color science.
Definition: aces.hpp:27
Graphics library interface.
Definition: window.hpp:28
sampler_address_mode
Behaviors of sampling with texture coordinates outside an image.
@ repeat
Repeat wrap mode.
sampler_mipmap_mode
Mipmap modes used for texture lookups.
@ linear
Linear filtering.
sampler_filter
Filters used for texture lookups.
@ linear
Linear filtering.
@ nearest
Nearest filtering.
compare_op
Comparison operators.
Definition: compare-op.hpp:29
@ less
Comparison evaluates reference < test.