| Fling Engine 0.00.1 Fling Engine is a game engine written in Vulkan

MeshRenderer.h
Go to the documentation of this file.
1 #pragma once
2
3 #include "Serilization.h"
4 #include "Material.h"
5 #include "Model.h"
6 #include "Buffer.h"
7
8 #include <entt/entity/registry.hpp>
9
10 namespace Fling
11 {
12 class MeshRenderer
13 {
14 friend class Renderer;
15 public:
17 MeshRenderer() = default;
18
20 MeshRenderer(const std::string& t_MeshPath);
21
22 MeshRenderer(const std::string& t_MeshPath, const std::string& t_MaterialPath);
23
24 MeshRenderer(Model* t_Model, Material* t_Mat = nullptr);
25
26 ~MeshRenderer();
27
29 Model* m_Model = nullptr;
30
32 Material* m_Material = nullptr;
33
35 Buffer* m_UniformBuffer = nullptr;
36
37 VkDescriptorSet m_DescriptorSet = VK_NULL_HANDLE;
38
39 void Release();
40
41 bool operator==(const MeshRenderer& other) const;
42 bool operator!=(const MeshRenderer& other) const;
43
44 template<class Archive>
45 void save(Archive& t_Archive) const;
46
47 template<class Archive>
48 void load(Archive& t_Archive);
49
50 void LoadModelFromPath(const std::string t_MeshPath);
51
52 void LoadMaterialFromPath(const std::string t_MatPath);
53 };
54
56 template<class Archive>
57 inline void MeshRenderer::save(Archive& t_Archive) const
58 {
59 std::string modelPath = m_Model->GetGuidString();
60 std::string MaterialPath = m_Material->GetGuidString();
61
62 t_Archive(
63 cereal::make_nvp("MESH_NAME", modelPath),
64 cereal::make_nvp("MATERIAL_NAME", MaterialPath)
65 );
66 }
67
68 template<class Archive>
69 inline void MeshRenderer::load(Archive& t_Archive)
70 {
71 std::string MeshPath = "";
72 std::string MaterialPath = "";
73
74 t_Archive(
75 cereal::make_nvp("MESH_NAME", MeshPath),
76 cereal::make_nvp("MATERIAL_NAME", MaterialPath)
77 );
78
79 LoadModelFromPath(MeshPath);
80 LoadMaterialFromPath(MaterialPath);
81 }
82 } // namespace Fling
83
Fling::MeshRenderer::Renderer
friend class Renderer
Definition: MeshRenderer.h:14
Fling::MeshRenderer::m_Material
Material * m_Material
Pointer to the material that this mesh renderer uses.
Definition: MeshRenderer.h:32
Fling::MeshRenderer::save
void save(Archive &t_Archive) const
Serialization to an Archive.
Definition: MeshRenderer.h:57
Material.h
Fling::MeshRenderer::load
void load(Archive &t_Archive)
Definition: MeshRenderer.h:69
Model.h
Fling::MeshRenderer::m_UniformBuffer
Buffer * m_UniformBuffer
We need a uniform buffer per-swap chain image.
Definition: MeshRenderer.h:35
Fling::MeshRenderer::operator==
bool operator==(const MeshRenderer &other) const
Definition: MeshRenderer.cpp:44
Fling::MeshRenderer::Release
void Release()
Definition: MeshRenderer.cpp:35
Fling::MeshRenderer::MeshRenderer
MeshRenderer()=default
Fling::Model
A model represents a 3D model (.obj files for now) with vertices and indecies.
Definition: Model.h:15
Serilization.h
Fling::MeshRenderer::LoadMaterialFromPath
void LoadMaterialFromPath(const std::string t_MatPath)
Definition: MeshRenderer.cpp:61
Fling::Material
A material represents what properties should be given to a set of shaders.
Definition: Material.h:25
Fling::MeshRenderer::m_Model
Model * m_Model
Pointer to the actual model.
Definition: MeshRenderer.h:29
Fling::MeshRenderer::~MeshRenderer
~MeshRenderer()
Definition: MeshRenderer.cpp:30
Fling::MeshRenderer::LoadModelFromPath
void LoadModelFromPath(const std::string t_MeshPath)
Definition: MeshRenderer.cpp:54
Fling::Buffer
A Buffer represents a Vulkan buffer with a size, buffer pointer, and buffer memory.
Definition: Buffer.h:11
Fling::MeshRenderer::operator!=
bool operator!=(const MeshRenderer &other) const
Definition: MeshRenderer.cpp:49
Fling::Resource::GetGuidString
const std::string & GetGuidString() const
Get the human-readable string representation of this GUID.
Definition: Resource.h:37
Buffer.h
Fling
Definition: Engine.h:29
Fling::MeshRenderer::m_DescriptorSet
VkDescriptorSet m_DescriptorSet
Definition: MeshRenderer.h:37
Fling::MeshRenderer
Definition: MeshRenderer.h:12