summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp52
1 files changed, 44 insertions, 8 deletions
diff --git a/c2.cpp b/c2.cpp
index ac9e7d4..94e2e38 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -24,6 +24,8 @@ extern "C" {
#define scene_arena_size (1024 * 4)
#define per_frame_memory_size (1024 * 1024)
+#define MSAA_SAMPLES 4
+
static float verts[] = {
0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
@@ -653,7 +655,7 @@ struct C2 : public App {
Tonemap tonemap;
Buffer_Id vbo, cbuf;
Sampler_Id clamped_linear;
- Texture_Id hdr_target;
+ Texture_Id hdr_target, hdr_resolved, ms_depth;
Texture_Id ui_texture;
Buffer_Id ui_buffer;
Line_Renderer lr;
@@ -876,7 +878,7 @@ struct C2 : public App {
pb.begin_rp();
pb.rp_target(hdr_target, Clear_Mode::restore);
- pb.rp_depth_target(dev->get_depth_target(), Clear_Mode::restore);
+ pb.rp_depth_target(ms_depth, Clear_Mode::restore);
Render_Pass& sky_pass = pb.build_rp();
pb.begin_rp();
@@ -903,6 +905,7 @@ struct C2 : public App {
dev,
&frame_arena,
hdr_target,
+ ms_depth,
&lighting
);
ctx.debug_pop();
@@ -919,6 +922,8 @@ struct C2 : public App {
);
ctx.debug_pop();
+ ctx.resolve(hdr_resolved, hdr_target);
+
tonemap.update(dev, 0.2f);
ctx.debug_push("TONEMAP");
@@ -927,7 +932,7 @@ struct C2 : public App {
&frame_arena,
quad,
tonemap_pass,
- hdr_target,
+ hdr_resolved,
clamped_linear
);
ctx.debug_pop();
@@ -1014,6 +1019,8 @@ struct C2 : public App {
assets.destroy();
dev->destroy_texture(default_texture);
dev->destroy_texture(hdr_target);
+ dev->destroy_texture(hdr_resolved);
+ dev->destroy_texture(ms_depth);
dev->destroy_texture(ui_texture);
dev->destroy_buffer(ui_buffer);
dev->destroy_sampler(clamped_linear);
@@ -1025,7 +1032,9 @@ struct C2 : public App {
void on_resize() override {
ui->layout(w, h);
dev->on_resize();
+ dev->destroy_texture(ms_depth);
dev->destroy_texture(hdr_target);
+ dev->destroy_texture(hdr_resolved);
dev->destroy_texture(ui_texture);
dev->destroy_buffer(ui_buffer);
make_hdr_target();
@@ -1033,16 +1042,43 @@ struct C2 : public App {
}
void make_hdr_target() {
+ int sw = dev->swap_w();
+ int sh = dev->swap_h();
hdr_target = dev->create_texture(
- "HDR target",
+ "MS HDR target",
texture_format_rgba16f,
- Texture_Flags::sampleable | Texture_Flags::colour_target,
- dev->swap_w(),
- dev->swap_h(),
+ Texture_Flags::copy_src | Texture_Flags::colour_target,
+ sw,
+ sh,
1,
1,
1,
- Buffer_Id(0)
+ Buffer_Id(0),
+ MSAA_SAMPLES
+ );
+ hdr_resolved = dev->create_texture(
+ "Resolved HDR",
+ texture_format_rgba16f,
+ Texture_Flags::sampleable | Texture_Flags::copy_dst,
+ sw,
+ sh,
+ 1,
+ 1,
+ 1,
+ Buffer_Id(0),
+ 1
+ );
+ ms_depth = dev->create_texture(
+ "MS depth",
+ texture_format_d24s8,
+ Texture_Flags::sampleable | Texture_Flags::depth_stencil_target,
+ sw,
+ sh,
+ 1,
+ 1,
+ 1,
+ 0,
+ MSAA_SAMPLES
);
}