Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
VulkanStaticMeshRenderer.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 
14 #include <ThirdParty/glm/glm/glm.hpp>
15 #include <ThirdParty/EASTL-master/include/EASTL/map.h>
16 
17 namespace Engine {
18 
19  class VulkanRenderer;
20 
21 
22  class VulkanStaticMeshRenderer
23  {
24  public:
25  VulkanStaticMeshRenderer(VulkanRenderer* renderer, VulkanLogicalDevice* device, VulkanDescriptorPool* descriptorPool);
26  ~VulkanStaticMeshRenderer();
27 
28  void StartRender(glm::mat4 view, glm::mat4 projection);
29 
30  void RenderMesh(const glm::mat4x4& modelMatrix, eastl::shared_ptr<VulkanMesh> mesh,
31  eastl::shared_ptr<VulkanMaterial> material, const glm::vec4& mainColor = glm::vec4(1.f, 1.f, 1.f, 1.f));
32 
33  void FinishRender(size_t threadID, VkCommandPool commandPool, VkCommandBuffer buffer);
34 
35  void RenderShadows(size_t threadID, VkCommandPool commandPool, VkCommandBuffer buffer, uint32_t lightOffset);
36 
37  void Clean() const;
38  void Recreate();
39 
40  const int MAX_INSTANCE_COUNT = 1024;
41 
42  protected:
43 
44  eastl::unique_ptr<VulkanPipeline> staticMeshPipeline_;
45  eastl::unique_ptr<VulkanPipeline> shadowPipeline_;
46 
47  eastl::unique_ptr<VulkanBuffer> uniformBuffer_;
48 
49  typedef struct {
50  glm::mat4 view;
51  glm::mat4 proj;
52  }Ubo_t;
53 
54  Ubo_t ubo_;
55 
56  eastl::shared_ptr<VulkanTexture> defaultTexture_;
57 
58  eastl::vector<VkDescriptorSet> uboDescriptors_;
59 
60  typedef struct {
61  glm::mat4 model;
62  glm::vec4 color;
63  }PushConstants_t;
64 
65  struct MeshData {
66  eastl::vector<glm::mat4> transforms;
67  eastl::unique_ptr<VulkanBuffer> transformBuffer;
68  VkDescriptorSet materialDescriptor;
69  eastl::shared_ptr<VulkanMaterial> material;
70  int meshes;
71  };
72 
73  eastl::multimap<eastl::shared_ptr<VulkanMesh>, MeshData*> meshInstances_;
74 
75  VulkanRenderer* renderer_;
76  VulkanLogicalDevice* device_;
77  VulkanDescriptorPool* descriptorPool_;
78 
79  VmaAllocator allocator_;
80 
81  VkCommandPool commandPool_;
82 
83  VkCommandBuffer commandBuffer_;
84  };
85 
86 }
87 
88 #endif // USING_VULKAN