summaryrefslogtreecommitdiff
path: root/model.hpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-02 14:55:23 +1100
committerquou <quou@disroot.org>2025-01-02 14:55:23 +1100
commit6d4b56258b89ba12bec5e329b81de62284c47ce1 (patch)
tree4888c607aac9ea542c8413988f6ce4f66641607b /model.hpp
parentcb111c1a73fa0b2168b2003120a002bc207bdeed (diff)
model instance system
Diffstat (limited to 'model.hpp')
-rw-r--r--model.hpp54
1 files changed, 45 insertions, 9 deletions
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