Antkeeper  0.0.1
pipeline.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_PIPELINE_HPP
21 #define ANTKEEPER_GL_PIPELINE_HPP
22 
34 #include <engine/gl/clear-bits.hpp>
36 #include <array>
37 #include <cstdint>
38 #include <span>
39 
40 namespace app { class sdl_window_manager; }
41 
42 namespace gl {
43 
47 class pipeline
48 {
49 public:
53  pipeline();
54 
57 
64  // void set_vertex_input(std::span<const vertex_input_binding> vertex_bindings, std::span<const vertex_input_attribute> vertex_attributes);
65 
68 
75 
84  void bind_vertex_buffers(std::uint32_t first_binding, std::span<const vertex_buffer* const> buffers, std::span<const std::size_t> offsets, std::span<const std::size_t> strides);
85 
87 
90 
97 
103  void set_primitive_restart_enabled(bool enabled);
104 
106 
109 
120  void set_viewport(std::uint32_t first_viewport, std::span<const viewport> viewports);
121 
132  void set_scissor(std::uint32_t first_scissor, std::span<const scissor_region> scissors);
133 
135 
138 
144  void set_rasterizer_discard_enabled(bool enabled);
145 
151  void set_fill_mode(fill_mode mode);
152 
158  void set_cull_mode(cull_mode mode);
159 
165  void set_front_face(front_face face);
166 
172  void set_depth_bias_enabled(bool enabled);
173 
180  void set_depth_bias_factors(float constant_factor, float slope_factor);
181 
187  void set_depth_clamp_enabled(bool enabled);
188 
194  void set_scissor_test_enabled(bool enabled);
195 
202 
208  void set_point_size(float size);
209 
215  void set_line_width(float width);
216 
218 
221 
227  void set_depth_test_enabled(bool enabled);
228 
236  void set_depth_write_enabled(bool enabled);
237 
244 
250  void set_stencil_test_enabled(bool enabled);
251 
261  void set_stencil_op(std::uint8_t face_mask, stencil_op fail_op, stencil_op pass_op, stencil_op depth_fail_op, gl::compare_op compare_op);
262 
269  void set_stencil_compare_mask(std::uint8_t face_mask, std::uint32_t compare_mask);
270 
277  void set_stencil_reference(std::uint8_t face_mask, std::uint32_t reference);
278 
285  void set_stencil_write_mask(std::uint8_t face_mask, std::uint32_t write_mask);
286 
288 
291 
297  void set_logic_op_enabled(bool enabled);
298 
305 
311  void set_color_blend_enabled(bool enabled);
312 
318  void set_color_blend_equation(const color_blend_equation& equation);
319 
325  void set_color_write_mask(std::uint8_t mask);
326 
332  void set_blend_constants(const std::array<float, 4>& blend_constants);
333 
335 
338 
349  void draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance);
350 
362  void draw_indexed(std::uint32_t index_count, std::uint32_t instance_count, std::uint32_t first_index, std::int32_t vertex_offset, std::uint32_t first_instance);
363 
365 
368 
375  void clear_attachments(std::uint8_t mask, const clear_value& value);
376 
378 
381 
383  [[nodiscard]] inline constexpr const std::array<std::uint32_t, 2>& get_default_framebuffer_dimensions() const noexcept
384  {
385  return m_default_framebuffer_dimensions;
386  }
387 
389  [[nodiscard]] inline constexpr std::uint32_t get_max_viewports() const noexcept
390  {
391  return m_max_viewports;
392  }
393 
395  [[nodiscard]] inline constexpr float get_max_sampler_anisotropy() const noexcept
396  {
397  return m_max_sampler_anisotropy;
398  }
399 
401 
402 private:
404 
406  void defaut_framebuffer_resized(std::uint32_t width, std::uint32_t height) noexcept;
407 
408  void fetch_vertex_input_state();
409  void fetch_input_assembly_state();
410  void fetch_viewport_state();
411  void fetch_rasterization_state();
412  void fetch_depth_stencil_state();
413  void fetch_color_blend_state();
414  void fetch_clear_value();
415 
416  std::uint32_t m_max_viewports{1};
417  float m_max_sampler_anisotropy{0.0f};
418  std::array<std::uint32_t, 2> m_default_framebuffer_dimensions{0, 0};
419 
420  pipeline_vertex_input_state m_vertex_input_state;
421  pipeline_input_assembly_state m_input_assembly_state;
422  pipeline_viewport_state m_viewport_state;
423  pipeline_rasterization_state m_rasterization_state;
424  pipeline_depth_stencil_state m_depth_stencil_state;
425  pipeline_color_blend_state m_color_blend_state;
426  clear_value m_clear_value;
427 
428  const framebuffer* m_framebuffer{};
429  const shader_program* m_shader_program{};
430  const vertex_array* m_vertex_array{};
431 };
432 
433 } // namespace gl
434 
435 #endif // ANTKEEPER_GL_PIPELINE_HPP
Graphics pipeline interface.
Definition: pipeline.hpp:48
void set_stencil_op(std::uint8_t face_mask, stencil_op fail_op, stencil_op pass_op, stencil_op depth_fail_op, gl::compare_op compare_op)
Sets the stencil operations.
Definition: pipeline.cpp:702
void set_primitive_topology(primitive_topology topology)
Sets the primitive topology to use for drawing.
Definition: pipeline.cpp:356
void clear_attachments(std::uint8_t mask, const clear_value &value)
Clears the color, depth, or stencil buffers of current attachments.
Definition: pipeline.cpp:1053
void set_fill_mode(fill_mode mode)
Sets the polygon rasterization mode.
Definition: pipeline.cpp:477
void bind_shader_program(const gl::shader_program *shader_program)
Sets the vertex input.
Definition: pipeline.cpp:292
void set_color_write_mask(std::uint8_t mask)
Sets the color write mask.
Definition: pipeline.cpp:1003
void set_blend_constants(const std::array< float, 4 > &blend_constants)
Sets the values of the blend constants.
Definition: pipeline.cpp:1019
void bind_framebuffer(const gl::framebuffer *framebuffer)
Sets the vertex input.
Definition: pipeline.cpp:275
constexpr float get_max_sampler_anisotropy() const noexcept
Returns the maximum supported degree of sampler anisotropy.
Definition: pipeline.hpp:395
void set_primitive_restart_enabled(bool enabled)
Controls whether a special vertex index value is treated as restarting the assembly of primitives.
Definition: pipeline.cpp:364
void set_stencil_write_mask(std::uint8_t face_mask, std::uint32_t write_mask)
Sets the stencil write mask.
Definition: pipeline.cpp:896
void set_depth_clamp_enabled(bool enabled)
Controls whether depth clamping is enabled.
Definition: pipeline.cpp:585
void set_depth_bias_factors(float constant_factor, float slope_factor)
Sets depth bias factors.
Definition: pipeline.cpp:572
void set_color_blend_enabled(bool enabled)
Controls whether blending is enabled for the corresponding color attachment.
Definition: pipeline.cpp:953
void set_scissor_test_enabled(bool enabled)
Enables or disables scissor testing.
Definition: pipeline.cpp:602
void set_point_size(float size)
Sets the the diameter of rasterized points.
Definition: pipeline.cpp:629
constexpr std::uint32_t get_max_viewports() const noexcept
Returns the maximum number of supported viewports.
Definition: pipeline.hpp:389
void set_cull_mode(cull_mode mode)
Sets the triangle culling mode.
Definition: pipeline.cpp:503
void set_front_face(front_face face)
Sets the front-facing triangle orientation.
Definition: pipeline.cpp:541
void set_stencil_test_enabled(bool enabled)
Controls whether stencil testing is enabled.
Definition: pipeline.cpp:685
void set_viewport(std::uint32_t first_viewport, std::span< const viewport > viewports)
Sets one or more viewports.
Definition: pipeline.cpp:381
void set_provoking_vertex_mode(provoking_vertex_mode mode)
Sets the vertex to be used as the source of data for flat-shaded varyings.
Definition: pipeline.cpp:619
void draw_indexed(std::uint32_t index_count, std::uint32_t instance_count, std::uint32_t first_index, std::int32_t vertex_offset, std::uint32_t first_instance)
Draws primitives with indexed vertices.
Definition: pipeline.cpp:1040
void set_depth_bias_enabled(bool enabled)
Controls whether to bias fragment depth values.
Definition: pipeline.cpp:551
void set_depth_write_enabled(bool enabled)
Controls whether depth writes are enabled.
Definition: pipeline.cpp:666
void set_logic_op(gl::logic_op logic_op)
Selects which logical operation to apply.
Definition: pipeline.cpp:942
void set_scissor(std::uint32_t first_scissor, std::span< const scissor_region > scissors)
Sets one or more scissor regions.
Definition: pipeline.cpp:424
void set_stencil_reference(std::uint8_t face_mask, std::uint32_t reference)
Sets the stencil reference value.
Definition: pipeline.cpp:841
void bind_vertex_buffers(std::uint32_t first_binding, std::span< const vertex_buffer *const > buffers, std::span< const std::size_t > offsets, std::span< const std::size_t > strides)
Binds vertex buffers.
Definition: pipeline.cpp:326
pipeline()
Constructs a pipeline.
Definition: pipeline.cpp:229
void set_color_blend_equation(const color_blend_equation &equation)
Sets the color blend factors and operations.
Definition: pipeline.cpp:970
void set_logic_op_enabled(bool enabled)
Controls whether whether logical operations are enabled.
Definition: pipeline.cpp:925
void set_depth_compare_op(gl::compare_op compare_op)
Sets the depth comparison operator.
Definition: pipeline.cpp:675
void draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance)
Draws primitives.
Definition: pipeline.cpp:1028
constexpr const std::array< std::uint32_t, 2 > & get_default_framebuffer_dimensions() const noexcept
Returns the dimensions of the default framebuffer.
Definition: pipeline.hpp:383
void set_depth_test_enabled(bool enabled)
Controls whether depth testing is enabled.
Definition: pipeline.cpp:649
void bind_vertex_array(const vertex_array *array)
Binds a vertex array.
Definition: pipeline.cpp:309
void set_rasterizer_discard_enabled(bool enabled)
Controls whether primitives are discarded before the rasterization stage.
Definition: pipeline.cpp:460
void set_line_width(float width)
Sets the width of rasterized lines.
Definition: pipeline.cpp:639
void set_stencil_compare_mask(std::uint8_t face_mask, std::uint32_t compare_mask)
Sets the stencil compare mask.
Definition: pipeline.cpp:786
Shader program which can be linked to shader objects and executed.
Vertex arrays describes how vertex input attributes are stored in vertex buffers.
Graphics library interface.
Definition: window.hpp:28
cull_mode
Triangle culling mode.
Definition: cull-mode.hpp:29
@ array
Image array view.
front_face
Polygon front-facing orientation.
Definition: front-face.hpp:29
provoking_vertex_mode
Vertex to be used as the source of data for flat-shaded varyings.
stencil_op
Stencil comparison functions.
Definition: stencil-op.hpp:29
primitive_topology
Primitive topologies.
logic_op
Framebuffer logical operations.
Definition: logic-op.hpp:29
fill_mode
Polygon rasterization mode.
Definition: fill-mode.hpp:29
compare_op
Comparison operators.
Definition: compare-op.hpp:29
Clear value.
Definition: clear-value.hpp:33
Color blend factors and operations.