Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
OffscreenSubpass.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Subpass.h"
4 
5 namespace Fling
6 {
7  class CommandBuffer;
8  class LogicalDevice;
9  class FrameBuffer;
10  class MeshRenderer;
11  class Swapchain;
12  class FirstPersonCamera;
13 
15  struct alignas(16) OffscreenUBO
16  {
17  glm::mat4 Projection;
18  glm::mat4 Model;
19  glm::mat4 View;
20  glm::vec3 ObjPos;
21  };
22 
23  // Uses the MRT shaders (mulitple render targets)
24  class OffscreenSubpass : public Subpass
25  {
26  public:
28  const LogicalDevice* t_Dev,
29  const Swapchain* t_Swap,
30  entt::registry& t_reg,
31  FirstPersonCamera* t_Cam,
32  std::shared_ptr<Fling::Shader> t_Vert,
33  std::shared_ptr<Fling::Shader> t_Frag
34  );
35 
36  virtual ~OffscreenSubpass();
37 
38  FrameBuffer* GetOffscreenFrameBuffer() const { return m_OffscreenFrameBuf; }
39 
40  void Draw(CommandBuffer& t_CmdBuf, VkFramebuffer t_PresentFrameBuf, UINT32 t_ActiveSwapImage, entt::registry& t_reg, float DeltaTime) override;
41 
42  void CreateDescriptorSets(VkDescriptorPool t_Pool, entt::registry& t_reg) override;
43 
44  void PrepareAttachments() override;
45 
46  void CreateGraphicsPipeline() override;
47 
48  void GatherPresentDependencies(
49  std::vector<CommandBuffer*>& t_CmdBuffs,
50  std::vector<VkSemaphore>& t_Deps,
51  UINT32 t_ActiveFrameIndex,
52  UINT32 t_CurrentFrameInFlight) override;
53 
54  void CleanUp(entt::registry& t_reg) override;
55 
56  private:
57 
58  void OnMeshRendererAdded(entt::entity t_Ent, entt::registry& t_Reg, MeshRenderer& t_MeshRend);
59 
60  void CreateMeshDescriptorSet(MeshRenderer& t_MeshRend, VkDescriptorPool t_Pool, FrameBuffer& t_FrameBuf);
61 
62  void BuildOffscreenCommandBuffer(entt::registry& t_reg, UINT32 t_ActiveFrameInFlight);
63 
64  // We need an offscreen semaphore for each possible frame in flight because the swap chain
65  // presentation will depend on this command buffer being complete
66  std::vector<VkSemaphore> m_OffscreenSemaphores;
67 
68  VkCommandPool m_CommandPool = VK_NULL_HANDLE;
69 
70  // Offscreen command buffers for populating the GBuffer
71  std::vector<CommandBuffer*> m_OffscreenCmdBufs;
72 
73  FrameBuffer* m_OffscreenFrameBuf = nullptr;
74 
76 
77  VkDescriptorPool m_DescriptorPool = VK_NULL_HANDLE;
78  };
79 } // namespace Fling
A subpass represents one part of a RenderPipeline.
Definition: Subpass.h:25
UBO for mesh data.
Definition: OffscreenSubpass.h:15
Definition: OffscreenSubpass.h:24
A simple first person camera.
Definition: FirstPersonCamera.h:9
Encapsulates functionality of a Vulkan Command buffer.
Definition: CommandBuffer.h:17
A logical device represents the application view of the device.
Definition: LogicalDevice.h:13
Represents a swap chain that can be used throughout the program.
Definition: SwapChain.h:21
glm::mat4 View
Definition: OffscreenSubpass.h:19
std::vector< VkSemaphore > m_OffscreenSemaphores
Definition: OffscreenSubpass.h:66
glm::vec3 ObjPos
Definition: OffscreenSubpass.h:20
Definition: FrameBuffer.h:67
const FirstPersonCamera * m_Camera
Definition: OffscreenSubpass.h:75
std::vector< CommandBuffer * > m_OffscreenCmdBufs
Definition: OffscreenSubpass.h:71
uint32_t UINT32
Definition: FlingTypes.h:13
Definition: Engine.h:29
FrameBuffer * GetOffscreenFrameBuffer() const
Definition: OffscreenSubpass.h:38
void CreateDescriptorSets(MeshRenderer &t_MeshRend, Lighting &t_Lighting, VkDescriptorSetLayout t_DescriptorLayout)
Definition: ShaderProgramReflections.cpp:4
Definition: MeshRenderer.h:12
glm::mat4 Model
Definition: OffscreenSubpass.h:18
glm::mat4 Projection
Definition: OffscreenSubpass.h:17