summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp62
1 files changed, 32 insertions, 30 deletions
diff --git a/c2.cpp b/c2.cpp
index 73bbbb6..39a57c4 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -110,7 +110,9 @@ extern "C" int entrypoint() {
Texture* texture;
Texture* texture2;
Texture_Id default_texture;
- Model* monkey;
+ Model_Instance* monkey, * monkey2;
+ Model_Scene scene;
+ Camera camera;
Buffer_Id vbo, cbuf;
Sampler_Id clamped_linear;
C2* app = App::create<C2>("c2");
@@ -140,7 +142,6 @@ extern "C" int entrypoint() {
mat_loader.init(&assets, default_texture);
register_asset_loader("MODL", &model_loader);
register_asset_loader("MTRL", &mat_loader);
- monkey = (Model*)assets.load("monkey.mdl");
app->dev = dev;
shader = (Shader*)assets.load("triangle.csh");
ui_shader = (Shader*)assets.load("ui.csh");
@@ -166,6 +167,20 @@ extern "C" int entrypoint() {
vbo = upload_verts(dev);
ui->layout(app->w, app->h);
auto fps_label = ui->create_element<UI::Label>(ui->root, "");
+ scene.init(app->arena, 32, clamped_linear);
+ monkey = scene.instantiate(
+ dev,
+ (Model*)assets.load("monkey.mdl")
+ );
+ monkey2 = scene.instantiate(
+ dev,
+ (Model*)assets.load("monkey.mdl")
+ );
+ camera.init(
+ 90.0f,
+ v3f(0.0f, 0.0f, 1.0f),
+ v3f(0.0f, 0.0f, 0.0f)
+ );
while (app->running) {
Arena frame_arena;
init_arena(&frame_arena, per_frame, per_frame_memory_size);
@@ -239,13 +254,7 @@ extern "C" int entrypoint() {
Render_Pass& pass2 = pb.build_rp();
Texture& bb = dev->get_texture(dev->get_backbuffer());
- m4f projection = m4f::pers(
- 70.0f,
- (float)bb.w / (float)bb.h,
- 0.01f,
- 100.0f
- );
- m4f transform = (m4f::translate(
+ monkey->transform = (m4f::translate(
m4f::identity(),
v3f(0.0f, 0.0f, -5.0f)
) * m4f::rotate(
@@ -253,27 +262,19 @@ extern "C" int entrypoint() {
rot,
raxis
));
- monkey->update_transforms();
- monkey->update_cbuffers(
- dev,
- transform,
- projection
- );
- ctx.debug_push("depth prepass");
- monkey->render(
- dev,
- &frame_arena,
- depth_prepass,
- clamped_linear
- );
- ctx.debug_pop();
- ctx.debug_push("forward");
- monkey->render(
- dev,
- &frame_arena,
- pass2,
- clamped_linear
- );
+ monkey2->transform = (m4f::translate(
+ m4f::identity(),
+ v3f(2.0f, 0.0f, -7.0f)
+ ) * m4f::rotate(
+ m4f::identity(),
+ rot * 2.0f,
+ v3f(1.0f, 0.0f, 0.0f)
+ ));
+ camera.asp = (float)bb.w / (float)bb.h;
+ scene.update(camera, dev);
+ ctx.debug_push("scene");
+ scene.render(dev, &frame_arena, depth_prepass, clamped_linear);
+ scene.render(dev, &frame_arena, pass2, clamped_linear);
ctx.debug_pop();
ctx.debug_push("ui");
@@ -286,6 +287,7 @@ extern "C" int entrypoint() {
dev->present();
app->end();
}
+ scene.destroy(dev);
ui->destroy();
assets.destroy();
dev->destroy_texture(default_texture);