From 6d4b56258b89ba12bec5e329b81de62284c47ce1 Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 2 Jan 2025 14:55:23 +1100 Subject: model instance system --- model.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'model.hpp') diff --git a/model.hpp b/model.hpp index 0dd8c43..53fb0fb 100644 --- a/model.hpp +++ b/model.hpp @@ -27,7 +27,7 @@ struct Mesh { int offset, vbo_offset, count; int parent, mesh_binding, mvp_binding, mat_binding; bool world_dirty; - m4f local, world; + m4f world, local; Shader_Id shader; Material* material; const m4f& get_world(Model& m); @@ -36,8 +36,6 @@ struct Mesh { struct Model : public Asset { Buffer_Id vbo; Buffer_Id ibo; - Buffer_Id mvp; - Buffer_Id mat; int mesh_count; Mesh* get_meshes() { @@ -51,12 +49,6 @@ struct Model : public Asset { const m4f& transform, const m4f& view_projection ); - void render( - Device* dev, - Arena* a, - Render_Pass& pass, - Sampler_Id sampler - ); }; struct Model_Loader : public Asset_Loader { @@ -85,4 +77,48 @@ struct Material_Loader : public Asset_Loader { void unload(Asset* a) override; }; +struct Camera { + float fov, near, far, asp; + v3f forward, position; + void init(float vfov, const v3f& f, const v3f& p); + m4f get_view() const; + m4f get_proj() const; +}; + +struct Model_Instance { + Buffer_Id mvp; + Buffer_Id mat; + m4f transform; + Model* m; + + void init(Device* dev, Model* model); + void destroy(Device* dev); + void update_cbuffers(Device* dev, const Camera& cam); + void render( + Device* dev, + Arena* a, + Render_Pass& pass, + Sampler_Id sampler + ); +}; + +struct Model_Scene { + Model_Instance* instances; + int count, max; + Sampler_Id sampler; + + Model_Instance* instantiate(Device* dev, Model* model); + void uninstantiate(Device* dev, Model_Instance* model); + void destroy(Device* dev); + + void init(Arena* arena, int max_instances, Sampler_Id s); + void update(const Camera& cam, Device* dev); + void render( + Device* dev, + Arena* a, + Render_Pass& pass, + Sampler_Id sampler + ); +}; + #endif -- cgit v1.2.3-54-g00ecf