#ifndef model_hpp #define model_hpp #include "asset.hpp" #include "maths.hpp" #include "video.hpp" struct Material : public Asset { float metalness, roughness, ao; v3f albedo; struct { Texture_Id albedo; Texture_Id ao; Texture_Id metal; Texture_Id rough; Texture_Id normal; } tex; void use( Pipeline_Builder& pb, Sampler_Id sampler, Shader& shader ); }; struct Model; struct Mesh { int offset, vbo_offset, count; int parent, mesh_binding, mvp_binding, mat_binding; int env_cube_binding; int mvp_binding_depth; bool world_dirty; m4f world, local; Shader_Id shader, depth_shader; Material* material; const m4f& get_world(Model& m); }; struct Model : public Asset { Buffer_Id vbo; Buffer_Id ibo; int mesh_count; Mesh* get_meshes() { return (Mesh*)&this[1]; } void destroy(Device* dev); void update_transforms(); void update_cbuffers( Device* dev, const m4f& transform, const m4f& view_projection ); }; struct Model_Loader : public Asset_Loader { Device* dev; Asset_Arena* shaders; void init(Device* device, Asset_Arena* shader_arena); Asset* load( Arena* a, Arena* s, const char* filename, Pack_File* f ) override; void unload(Asset* a) override; }; struct Material_Loader : public Asset_Loader { Asset_Arena* textures; Texture_Id default_tex; void init(Asset_Arena* texture_arena, Texture_Id dt); Asset* load( Arena* a, Arena* s, const char* filename, Pack_File* f ) override; 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, Texture_Id env_cubemap, 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, Texture_Id env_cubemap, Sampler_Id sampler ); }; #endif