39 pass(pipeline, framebuffer)
42 m_vertex_array = std::make_unique<gl::vertex_array>();
46 m_shader_program = shader_template->build();
47 if (!m_shader_program->linked())
49 debug::log_error(
"Failed to final pass shader program: {}", m_shader_program->info());
58 m_resolution = {
static_cast<float>(viewport_dimensions[0]),
static_cast<float>(viewport_dimensions[1])};
64 for (
const auto&
command: m_command_buffer)
75 m_color_texture = texture;
76 rebuild_command_buffer();
81 m_bloom_texture = texture;
82 rebuild_command_buffer();
87 m_bloom_weight = weight;
92 m_blue_noise_texture = texture;
93 m_blue_noise_scale = 1.0f /
static_cast<float>(texture->get_image_view()->get_image()->get_dimensions()[0]);
94 rebuild_command_buffer();
97 void final_pass::rebuild_command_buffer()
99 m_command_buffer.clear();
101 m_command_buffer.emplace_back
105 const gl::viewport viewport[1] = {{0.0f, 0.0f, m_resolution.
x(), m_resolution.
y()}};
120 if (
const auto var = m_shader_program->variable(
"color_texture"))
122 m_command_buffer.emplace_back([&, var](){var->update(*m_color_texture);});
127 if (
const auto var = m_shader_program->variable(
"bloom_texture"))
129 m_command_buffer.emplace_back([&, var](){var->update(*m_bloom_texture);});
132 if (m_blue_noise_texture)
134 if (
const auto var = m_shader_program->variable(
"blue_noise_texture"))
136 m_command_buffer.emplace_back([&, var](){var->update(*m_blue_noise_texture);});
140 if (
const auto var = m_shader_program->variable(
"bloom_weight"))
142 m_command_buffer.emplace_back([&, var](){var->update(m_bloom_weight);});
144 if (
const auto var = m_shader_program->variable(
"blue_noise_scale"))
146 m_command_buffer.emplace_back([&, var](){var->update(m_blue_noise_scale);});
148 if (
const auto var = m_shader_program->variable(
"resolution"))
150 m_command_buffer.emplace_back([&, var](){var->update(m_resolution);});
152 if (
const auto var = m_shader_program->variable(
"time"))
154 m_command_buffer.emplace_back([&, var](){var->update(m_time);});
156 if (
const auto frame_var = m_shader_program->variable(
"frame"))
158 m_command_buffer.emplace_back([&, frame_var](){frame_var->update(m_frame);});
161 m_command_buffer.emplace_back
constexpr const std::array< std::uint32_t, 2 > & dimensions() const noexcept
Returns the dimensions of the framebuffer.
Graphics pipeline interface.
void set_primitive_topology(primitive_topology topology)
Sets the primitive topology to use for drawing.
void bind_shader_program(const gl::shader_program *shader_program)
Sets the vertex input.
void bind_framebuffer(const gl::framebuffer *framebuffer)
Sets the vertex input.
void set_color_blend_enabled(bool enabled)
Controls whether blending is enabled for the corresponding color attachment.
void set_cull_mode(cull_mode mode)
Sets the triangle culling mode.
void set_viewport(std::uint32_t first_viewport, std::span< const viewport > viewports)
Sets one or more viewports.
void draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance)
Draws primitives.
constexpr const std::array< std::uint32_t, 2 > & get_default_framebuffer_dimensions() const noexcept
Returns the dimensions of the default framebuffer.
void set_depth_test_enabled(bool enabled)
Controls whether depth testing is enabled.
void bind_vertex_array(const vertex_array *array)
Binds a vertex array.
Template used to for generating one or more shader variants from a single source.
void set_color_texture(std::shared_ptr< gl::texture_2d > texture)
void render(render::context &ctx) override
void set_blue_noise_texture(std::shared_ptr< gl::texture_2d > texture)
void set_bloom_weight(float weight) noexcept
void set_bloom_texture(std::shared_ptr< gl::texture_2d > texture) noexcept
final_pass(gl::pipeline *pipeline, const gl::framebuffer *framebuffer, resource_manager *resource_manager)
gl::pipeline * m_pipeline
const gl::framebuffer * m_framebuffer
Manages the loading, caching, and saving of resources.
std::shared_ptr< T > load(const std::filesystem::path &path)
Loads and caches a resource.
Commands which operate on entity::id components.
log_message< log_message_severity::warning, Args... > log_warning
Formats and logs a warning message.
log_message< log_message_severity::error, Args... > log_error
Formats and logs an error message.
@ back
Back-facing triangles are discarded.
@ vertex
Vertex shader stage.
@ triangle_list
Separate triangle primitives.
Viewport position, dimensions, and depth range.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.
float t
Current time, in seconds.