diff options
author | quou <quou@disroot.org> | 2025-01-02 14:55:23 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-02 14:55:23 +1100 |
commit | 6d4b56258b89ba12bec5e329b81de62284c47ce1 (patch) | |
tree | 4888c607aac9ea542c8413988f6ce4f66641607b /c2.cpp | |
parent | cb111c1a73fa0b2168b2003120a002bc207bdeed (diff) |
model instance system
Diffstat (limited to 'c2.cpp')
-rw-r--r-- | c2.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
@@ -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); |