21 #include <engine/config.hpp>
34 #include <stb/stb_image_write.h>
39 static void reroute_framebuffers(::
game& ctx);
41 static void rebuild_hdr_framebuffer(::
game& ctx)
44 auto hdr_sampler = std::make_shared<gl::sampler>
56 std::make_shared<gl::image_view_2d>
58 std::make_shared<gl::image_2d>
71 std::make_shared<gl::image_view_2d>
73 std::make_shared<gl::image_2d>
100 static void rebuild_ldr_framebuffers(::
game& ctx)
102 auto ldr_sampler = std::make_shared<gl::sampler>
114 std::make_shared<gl::image_view_2d>
116 std::make_shared<gl::image_2d>
140 std::make_shared<gl::image_view_2d>
142 std::make_shared<gl::image_2d>
167 auto shadow_sampler = std::make_shared<gl::sampler>
181 std::array<float, 4>{0.0f, 0.0f, 0.0f, 0.0f}
187 std::make_shared<gl::image_view_2d>
189 std::make_shared<gl::image_2d>
219 rebuild_hdr_framebuffer(ctx);
220 rebuild_ldr_framebuffers(ctx);
253 const auto render_resolution =
math::ivec2{
static_cast<int>(viewport_size.
x() *
scale + 0.5f),
static_cast<int>(viewport_size.
y() *
scale + 0.5f)};
266 rebuild_hdr_framebuffer(ctx);
267 rebuild_ldr_framebuffers(ctx);
281 reroute_framebuffers(ctx);
289 const auto time = std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now());
290 const std::string screenshot_filename =
std::format(
"{0}-{1:%Y%m%d}T{1:%H%M%S}Z.png", config::application_name, time);
293 std::filesystem::path screenshot_filepath = ctx.
screenshots_path / screenshot_filename;
294 std::string screenshot_filepath_string = screenshot_filepath.string();
295 debug::log_debug(
"Saving screenshot to \"{}\"...", screenshot_filepath_string);
298 const auto& viewport_size = ctx.
window->get_viewport_size();
301 std::unique_ptr<std::byte[]> frame = std::make_unique<std::byte[]>(viewport_size.x() * viewport_size.y() * 3);
304 glReadBuffer(GL_BACK);
305 glReadPixels(0, 0, viewport_size.x(), viewport_size.y(), GL_RGB, GL_UNSIGNED_BYTE, frame.get());
310 [frame = std::move(frame), w = viewport_size.x(), h = viewport_size.y(), path = std::move(screenshot_filepath_string)]
312 stbi_flip_vertically_on_write(1);
313 stbi_write_png(path.c_str(), w, h, 3, frame.get(), w * 3);
315 debug::log_debug(
"Saved screenshot to \"{}\"", path);
328 reroute_framebuffers(ctx);
334 reroute_framebuffers(ctx);
342 void reroute_framebuffers(::
game& ctx)
std::shared_ptr< gl::texture_2d > shadow_map_depth_texture
std::shared_ptr< gl::texture_2d > ldr_color_texture_a
std::shared_ptr< gl::texture_2d > hdr_color_texture
std::shared_ptr< gl::framebuffer > hdr_framebuffer
std::shared_ptr< gl::framebuffer > shadow_map_framebuffer
std::unique_ptr< render::material_pass > surface_material_pass
std::shared_ptr< gl::texture_2d > hdr_depth_texture
std::unique_ptr< render::bloom_pass > bloom_pass
std::shared_ptr< gl::texture_2d > ldr_color_texture_b
std::shared_ptr< gl::framebuffer > ldr_framebuffer_a
std::filesystem::path screenshots_path
std::unique_ptr< render::resample_pass > resample_pass
render::anti_aliasing_method anti_aliasing_method
std::unique_ptr< render::sky_pass > sky_pass
std::shared_ptr< app::window > window
std::unique_ptr< render::final_pass > common_final_pass
int shadow_map_resolution
math::ivec2 render_resolution
std::shared_ptr< gl::framebuffer > ldr_framebuffer_b
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
log_message< log_message_severity::debug, Args... > log_debug
Formats and logs a debug message.
format
Image and vertex formats.
@ clamp_to_edge
Clamp to edge wrap mode.
@ clamp_to_border
Clamp to border wrap mode.
@ depth_stencil_attachment_bits
Framebuffer depth/stencil attachment.
@ color_attachment_bit
Framebuffer color attachment.
@ depth_attachment_bit
Framebuffer depth attachment.
@ linear
Linear filtering.
@ linear
Linear filtering.
@ greater
Comparison evaluates reference > test.
void destroy_framebuffers(::game &ctx)
void select_anti_aliasing_method(::game &ctx, render::anti_aliasing_method method)
void save_screenshot(::game &ctx)
void create_framebuffers(::game &ctx)
void change_render_resolution(::game &ctx, float scale)
void rebuild_shadow_framebuffer(::game &ctx)
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
anti_aliasing_method
Anti-aliasing methods.
@ fxaa
Fast approximate anti-aliasing (FXAA).
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.