summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp111
1 files changed, 65 insertions, 46 deletions
diff --git a/c2.cpp b/c2.cpp
index af843f2..ff4196f 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -155,32 +155,17 @@ struct Orbit_Cam : public Camera {
}
};
-struct Sky {
- Staged_Buffer config;
+struct Fullscreen_Quad {
Buffer_Id vb;
- Texture_Id texture;
- Shader* shader;
- int vert_binding;
- int picture_binding;
- int cfg_binding;
- struct Cbuffer {
- m4f iview;
- m4f iprojection;
- };
-
- void init(Device* d, Asset_Arena* assets) {
- Buffer_Id stage;
- void* mem;
- Context& ctx = d->acquire();
+ void init(Device* d) {
float verts[] = {
-1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 3.0f, 0.0f, 2.0f,
3.0f, -1.0f, 2.0f, 0.0f
};
- Texture* tex = (Texture*)assets->load("sky.tex");
- shader = (Shader*)assets->load("sky.csh");
- texture = tex->id;
+ Buffer_Id stage;
+ void* mem;
stage = d->create_buffer(
"sky vb stage",
sizeof verts,
@@ -191,14 +176,57 @@ struct Sky {
memcpy(mem, verts, sizeof verts);
d->unmap_buffer(stage);
vb = d->create_buffer(
- "sky vb",
+ "fullscreen quad",
sizeof verts,
Buffer_Flags::copy_dst |
Buffer_Flags::vertex_buffer
);
+ Context& ctx = d->acquire();
ctx.copy(vb, stage);
d->submit(ctx);
d->destroy_bufferi(stage);
+ }
+
+ void destroy(Device* d) {
+ d->destroy_buffer(vb);
+ }
+
+ void render(
+ Context& ctx,
+ Pipeline& pip,
+ Render_Pass& pass,
+ int bind
+ ) {
+ Vertex_Buffer_Binding vbb[] = {{
+ .id = vb,
+ .offset = 0,
+ .target = bind
+ }, {}};
+ Draw draw{};
+ draw.verts = vbb;
+ draw.vertex_count = 3;
+ draw.instance_count = 1;
+ ctx.submit(draw, pip, pass);
+ }
+};
+
+struct Sky {
+ Staged_Buffer config;
+ Texture_Id texture;
+ Shader* shader;
+ int vert_binding;
+ int picture_binding;
+ int cfg_binding;
+
+ struct Cbuffer {
+ m4f iview;
+ m4f iprojection;
+ };
+
+ void init(Device* d, Asset_Arena* assets) {
+ Texture* tex = (Texture*)assets->load("sky.tex");
+ shader = (Shader*)assets->load("sky.csh");
+ texture = tex->id;
assert(shader != 0);
vert_binding = shader->binding_index("verts");
assert(vert_binding >= 0);
@@ -215,13 +243,13 @@ struct Sky {
}
void destroy(Device* d) {
- d->destroy_buffer(vb);
config.destroy(d);
}
void render(
Device* d,
Arena* a,
+ Fullscreen_Quad& quad,
Render_Pass& pass,
Sampler_Id sampler,
const Camera& cam
@@ -236,6 +264,7 @@ struct Sky {
render_imp(
d,
a,
+ quad,
pass,
sampler,
config.gpuonly,
@@ -248,6 +277,7 @@ struct Sky {
void render_imp(
Device* d,
Arena* a,
+ Fullscreen_Quad& quad,
Render_Pass& pass,
Sampler_Id sampler,
Buffer_Id cbuffer,
@@ -270,18 +300,7 @@ struct Sky {
pb.cbuffer(cfg_binding, cbuffer, offset, sizeof(Cbuffer));
pb.depth(true, false, Depth_Mode::equal);
Pipeline& pip = pb.build();
-
- Vertex_Buffer_Binding vbb[] = {{
- .id = vb,
- .offset = 0,
- .target = vert_binding
- }, {}};
-
- Draw draw{};
- draw.verts = vbb;
- draw.vertex_count = 3;
- draw.instance_count = 1;
- ctx.submit(draw, pip, pass);
+ quad.render(ctx, pip, pass, vert_binding);
}
};
@@ -462,7 +481,12 @@ struct Env_Probe {
config.update(ctx);
}
- void render(Device* dev, Arena* a, Sky& sky) {
+ void render(
+ Device* dev,
+ Arena* a,
+ Fullscreen_Quad& quad,
+ Sky& sky
+ ) {
int i;
Pipeline_Builder pb(a, dev);
Context& ctx = dev->get_ctx();
@@ -487,6 +511,7 @@ struct Env_Probe {
sky.render_imp(
dev,
a,
+ quad,
pb.build_rp(),
sampler,
config.gpuonly,
@@ -517,17 +542,7 @@ struct Env_Probe {
pb.shader(shader->id);
pb.vertex_format(shader->vf);
Pipeline& pip = pb.build();
-
- Vertex_Buffer_Binding vbb[] = {{
- .id = sky.vb,
- .offset = 0,
- .target = vert_binding
- }, {}};
- Draw draw{};
- draw.verts = vbb;
- draw.vertex_count = 3;
- draw.instance_count = 1;
- ctx.submit(draw, pip, pass);
+ quad.render(ctx, pip, pass, vert_binding);
}
}
}
@@ -559,6 +574,7 @@ struct C2 : public App {
Model_Instance* monkey, * monkey2;
Model_Scene scene;
Orbit_Cam camera;
+ Fullscreen_Quad quad;
Sky sky;
Env_Probe eprobe;
Buffer_Id vbo, cbuf;
@@ -607,6 +623,7 @@ struct C2 : public App {
ui_shader = (Shader*)assets.load("ui.csh");
texture = (Texture*)assets.load("22.tex");
texture2 = (Texture*)assets.load("kita.tex");
+ quad.init(dev);
cbuf = dev->create_buffer(
"config buffer",
sizeof(Config_Buffer),
@@ -717,7 +734,7 @@ struct C2 : public App {
Render_Pass& sky_pass = pb.build_rp();
ctx.debug_push("environment cube");
- eprobe.render(dev, &frame_arena, sky);
+ eprobe.render(dev, &frame_arena, quad, sky);
ctx.debug_pop();
Texture& bb = dev->get_texture(dev->get_backbuffer());
@@ -754,6 +771,7 @@ struct C2 : public App {
sky.render(
dev,
&frame_arena,
+ quad,
sky_pass,
clamped_linear,
camera
@@ -787,6 +805,7 @@ struct C2 : public App {
}
void on_destroy() override {
+ quad.destroy(dev);
scene.destroy(dev);
sky.destroy(dev);
lr.destroy(dev);