Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1#pragma once
2#include "Vertex.h"
3#include "backends/opengl/IB.h"
4#include "backends/opengl/VA.h"
5#include "backends/opengl/VB.h"
6#include "material/Material.h"
7
8namespace hellfire {
9 class Mesh {
10 public:
11 Mesh();
12
13 Mesh(const std::vector<Vertex> &vertices, const std::vector<unsigned int> &indices);
14
15 Mesh(const std::vector<Vertex> &vertices,
16 const std::vector<unsigned int> &indices,
17 bool defer_build);
18
19 void cleanup();
20
21 void bind() const;
22
23 void unbind() const;
24
25 void build();
26 bool is_built() const { return vao_ != nullptr; }
27
28 // mesh data
30 std::vector<unsigned int> indices;
31
32 bool is_wireframe = false;
33
34 void draw() const;
35
36 void draw_instanced(size_t amount) const;
37
38 int get_index_count() const;
39
40 private:
41 std::unique_ptr<VA> vao_ = nullptr;
42 std::unique_ptr<VB> vbo_ = nullptr;
43 std::unique_ptr<IB> ibo_ = nullptr;
44
46
47 void create_mesh();
48 };
49}
std::shared_ptr< Texture > get_texture(AssetID id)
size_t get_loaded_mesh_count() const
std::unordered_map< AssetID, std::shared_ptr< Texture > > texture_cache_
AssetManager(AssetRegistry &registry)
std::shared_ptr< Mesh > get_mesh(AssetID id)
size_t get_loaded_material_count() const
void unload(AssetID id)
AssetRegistry & registry_
std::unordered_map< AssetID, std::shared_ptr< Material > > material_cache_
size_t get_loaded_texture_count() const
std::shared_ptr< Material > get_material(AssetID id)
std::unordered_map< AssetID, std::shared_ptr< Mesh > > mesh_cache_
Registry for storing assets.
const std::filesystem::path & get_project_root()
std::optional< AssetID > get_uuid_by_path(const std::filesystem::path &filepath)
AssetID generate_uuid(const std::filesystem::path &filepath)
void unregister_asset(AssetID uuid)
bool has_asset_changed(AssetID uuid) const
void set_project_root(const std::filesystem::path &project_root)
std::filesystem::path get_absolute_path(AssetID uuid)
std::unordered_map< std::filesystem::path, AssetID > path_to_uuid_
std::filesystem::path registry_file_
AssetID register_asset(const std::filesystem::path &filepath, AssetType type)
std::unordered_map< AssetID, AssetMetadata > assets_
std::filesystem::path to_absolute_path(const std::filesystem::path &relative_path) const
static AssetType get_type_from_extension(const std::filesystem::path &filepath)
std::filesystem::path to_relative_path(const std::filesystem::path &absolute_path) const
AssetID register_asset(const std::filesystem::path &filepath)
std::vector< AssetID > register_directory(const std::filesystem::path &directory_path, bool recursive)
std::vector< AssetMetadata > get_assets_by_type(AssetType type)
std::filesystem::path get_relative_path(AssetID uuid)
bool asset_exists(AssetID uuid) const
size_t get_asset_count() const
std::vector< AssetID > get_modified_assets() const
AssetRegistry(const std::filesystem::path &registry_file, const std::filesystem::path &project_root)
std::optional< AssetMetadata > get_asset(AssetID uuid) const
std::filesystem::path project_root_
std::vector< AssetMetadata > get_all_assets() const
uint64_t get_file_last_modified(const std::filesystem::path &filepath) const
static std::optional< MaterialData > load(const std::filesystem::path &filepath)
static std::shared_ptr< Mesh > load(const std::filesystem::path &filepath)
bool is_wireframe
Definition Mesh.h:32
Mesh(const std::vector< Vertex > &vertices, const std::vector< unsigned int > &indices)
Definition Mesh.cpp:11
int get_index_count() const
Definition Mesh.cpp:96
void bind() const
Definition Mesh.cpp:22
std::unique_ptr< VA > vao_
Definition Mesh.h:41
void build()
Definition Mesh.cpp:30
std::unique_ptr< IB > ibo_
Definition Mesh.h:43
void create_mesh()
Definition Mesh.cpp:34
std::vector< Vertex > vertices
Definition Mesh.h:29
bool is_built() const
Definition Mesh.h:26
void draw() const
Definition Mesh.cpp:83
void unbind() const
Definition Mesh.cpp:26
Mesh(const std::vector< Vertex > &vertices, const std::vector< unsigned int > &indices, bool defer_build)
Definition Mesh.cpp:16
std::unique_ptr< VB > vbo_
Definition Mesh.h:42
std::vector< unsigned int > indices
Definition Mesh.h:30
void draw_instanced(size_t amount) const
Definition Mesh.cpp:89
int index_count_
Definition Mesh.h:45
constexpr AssetID INVALID_ASSET_ID
std::filesystem::path filepath