Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
VulkanMesh.hpp
Go to the documentation of this file.
1 #pragma once
3 #ifdef USING_VULKAN
4 #include "Engine/Mesh/Mesh.hpp"
5 #include <ThirdParty/Vulkan/Include/vulkan/vulkan.h>
6 #include <ThirdParty/assimp/include/assimp/Importer.hpp>
7 #include <ThirdParty/assimp/include/assimp/scene.h>
8 
15 
16 #include <ThirdParty/EASTL-master/include/EASTL/map.h>
17 #include <ThirdParty/EASTL-master/include/EASTL/tuple.h>
18 
19 namespace Engine
20 {
21 
22  class VulkanRenderer;
23 
27  class ENGINE_API VulkanMesh : public Mesh
28  {
29  public:
30  // Should be called from renderer
31  static void InitMeshes(VulkanRenderer* renderer, VulkanLogicalDevice* device, VulkanDescriptorPool* descriptorPool, VkCommandPool commandPool);
32 
36  void SetUpMesh() override;
37 
42  VkBuffer GetVertexBuffer() const;
43 
48  VkBuffer GetIndexBuffer() const;
49 
54  VkBuffer GetShadowIndexBuffer() const;
55 
60  uint32_t GetShadowIndexCount() const;
61 
66  uint32_t GetIndexCount();
67 
72  bool IsAnimated() const;
73 
81  VkDescriptorSet CreateBoneOffsetDescriptorSet(size_t threadID, size_t pipelineID, size_t set, VkDescriptorSetLayout layout);
82 
90  VkDescriptorSet GetBoneOffsetDescriptorSet(size_t threadID, size_t pipelineID, size_t set);
91 
92 
93  private:
94 
95  friend class ResourceManager;
96 
97  VulkanMesh() = delete;
98  VulkanMesh(aiMesh* mesh, eastl::shared_ptr<Skeleton> skeleton, eastl::vector<Vertex> vertices, eastl::vector<unsigned> indices);
99  VulkanMesh(VulkanMesh const &other) = default;
100  public:
101  ~VulkanMesh();
102  private:
103 
104  //eastl::vector<eastl::shared_ptr<Texture>> textures;
105 
106  struct Edge {
107  uint32_t indices[2];
108 
109  Edge(uint32_t index1, uint32_t index2) {
110  if (index1 > index2) {
111  indices[0] = index1;
112  indices[1] = index2;
113  }
114  else {
115  indices[0] = index2;
116  indices[1] = index1;
117  }
118  }
119 
120  bool operator<(const Edge& right) const {
121  return eastl::tie(indices[0], indices[1]) <
122  eastl::tie(right.indices[0], right.indices[1]);
123  }
124 
125  };
126 
127  struct Face {
128  uint32_t indices[3];
129 
130  bool operator==(const Face& other)const {
131  return (indices[0] == other.indices[0] &&
132  indices[1] == other.indices[1] &&
133  indices[2] == other.indices[2]);
134  }
135 
136  uint32_t FindOpposingIndex(Edge edge) {
137  for (int i = 0; i < 3; ++i) {
138  if (indices[i] != edge.indices[0] && indices[i] != edge.indices[1])
139  return indices[i];
140  }
141  return -1;
142  }
143  };
144 
145  eastl::shared_ptr<Skeleton> skeleton;
146 
147  eastl::vector<glm::mat4> boneOffsets;
148 
149  eastl::unique_ptr<VulkanBuffer> vertexBuffer;
150  eastl::unique_ptr<VulkanBuffer> indexBuffer;
151  eastl::unique_ptr<VulkanBuffer> offsetBuffer;
152 
153  eastl::unique_ptr<VulkanBuffer> shadowIndexBuffer;
154 
155  eastl::vector<eastl::vector<eastl::vector<VkDescriptorSet>>> offsetDescriptorSets;
156 
157  eastl::shared_ptr<VulkanTexture> diffuseMissing;
158 
159  const aiScene* scene;
160  aiMesh* mesh;
161 
162  static VulkanRenderer* renderer;
163  static VulkanLogicalDevice* device;
164  static VkCommandPool commandPool;
165  static VmaAllocator allocator;
166  static VulkanDescriptorPool* descriptorPool;
167 
168  bool animated;
169 
170  uint32_t shadowIndicesCount;
171 
172  };
173 
174 } //namespace Engine
175 #endif
#define ENGINE_API
Definition: api.hpp:25