Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
VulkanSkeletalMeshRenderer.hpp
Go to the documentation of this file.
1 #pragma once
3 #ifdef USING_VULKAN
4 
5 #include <ThirdParty/Vulkan/Include/vulkan/vulkan.h>
6 
15 #include <ThirdParty/glm/glm/glm.hpp>
16 
17 namespace Engine {
18 
19  class VulkanRenderer;
20 
21  class VulkanSkeletalMeshRenderer
22  {
23  public:
24  VulkanSkeletalMeshRenderer(VulkanRenderer* renderer, VulkanLogicalDevice* device, VulkanDescriptorPool* descriptorPool);
25  ~VulkanSkeletalMeshRenderer();
26 
27  void StartRender(glm::mat4 view, glm::mat4 projection);
28 
29  void RenderMesh(const glm::mat4x4& modelMatrix, VulkanMesh* mesh,
30  VulkanMaterial* material, Skeleton* skeleton,
31  size_t animation,
32  float time, float ticksPerSecond, float duration, bool looping,
33  const glm::vec4& mainColor = glm::vec4(1.f, 1.f, 1.f, 1.f));
34 
35  void FinishRender(size_t threadID, VkCommandPool commandPool, VkCommandBuffer buffer);
36 
37  void RenderShadows(size_t threadID, VkCommandPool commandPool, VkCommandBuffer buffer, uint32_t lightOffset);
38 
39  void Clean() const;
40  void Recreate();
41 
42  const int MAX_INSTANCE_COUNT = 256;
43 
44  protected:
45 
46  eastl::unique_ptr<VulkanPipeline> skeletalMeshPipeline_;
47  eastl::unique_ptr<VulkanPipeline> shadowPipeline_;
48 
49  eastl::unique_ptr<VulkanBuffer> uniformBuffer_;
50 
51  typedef struct {
52  glm::mat4 view;
53  glm::mat4 proj;
54  }Ubo_t;
55 
56  Ubo_t ubo_;
57 
58  eastl::weak_ptr<VulkanTexture> defaultTexture_;
59 
60  VkDescriptorSet oldBones_;
61 
62  eastl::vector<VkDescriptorSet> uboDescriptors_;
63 
64  typedef struct {
65  glm::mat4 model;
66  glm::vec4 color;
67  float time;
68  float ticksPerSecond;
69  float duration;
70  bool looping;
71  }PushConstants_t;
72 
73  struct MeshData {
74  glm::mat4 transform;
75  VulkanMaterial* material;
76  Skeleton* skeleton;
77  VulkanTexture* boneData;
78  VulkanMesh* mesh;
79  glm::vec4 color;
80  size_t animation;
81  float time;
82  float ticksPerSecond;
83  float duration;
84  bool looping;
85  };
86 
87  eastl::vector<MeshData> meshes;
88 
89  VulkanRenderer* renderer_;
90  VulkanLogicalDevice* device_;
91  VulkanDescriptorPool* descriptorPool_;
92  VkCommandPool commandPool_;
93  VmaAllocator allocator_;
94 
95  VkCommandBuffer commandBuffer_;
96  };
97 
98 }
99 
100 #endif // USING_VULKAN