Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
VulkanApp.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "FlingTypes.h"
4 #include "FlingVulkan.h"
5 #include "Singleton.hpp"
6 
7 #include <entt/entity/registry.hpp>
8 #include <vector>
9 
10 namespace Fling
11 {
14  {
15  DEFERRED = (1u << 0),
16  REFLECTIONS = (1u << 1),
17  IMGUI = (1u << 2),
18  CUBEMAP = (1u << 3),
19  DEBUG = (1u << 4),
20  ALL = 0xff
21  };
22 
23  class Instance;
24  class LogicalDevice;
25  class PhysicalDevice;
26  class Swapchain;
27  class FlingWindow;
28  class RenderPipeline;
29  class CommandBuffer;
30  class FirstPersonCamera;
31  class DepthBuffer;
32  class BaseEditor;
33 
38  class VulkanApp : public Singleton<VulkanApp>
39  {
40  public:
41 
42  void Init(PipelineFlags t_Conf, entt::registry& t_Reg, std::shared_ptr<Fling::BaseEditor> t_Editor);
43  void Shutdown(entt::registry& t_Reg);
44 
49  VulkanApp() = default;
50  ~VulkanApp() = default;
51 
55  void Update(float DeltaTime, entt::registry& t_Reg);
56 
57  inline FlingWindow* GetCurrentWindow() const { return m_CurrentWindow; }
58  inline LogicalDevice* GetLogicalDevice() const { return m_LogicalDevice; }
60  inline const VkCommandPool GetCommandPool() const { return m_CommandPool; }
61  inline FirstPersonCamera* GetCamera() const { return m_Camera; }
62 
63  private:
64 
69  void Prepare();
70 
76 
80  void CreateGameWindow(const UINT32 t_width, const UINT32 t_height);
81 
83  VkExtent2D ChooseSwapExtent();
84 
86  void BuildRenderPipelines(PipelineFlags t_Conf, entt::registry& t_Reg, std::shared_ptr<Fling::BaseEditor> t_Editor);
87 
93 
94  void BuildGlobalRenderPass();
95 
97 
99  Instance* m_Instance = nullptr;
103 
104  // Swap chain related stuff ---------------------------------------------------------------------
105  Swapchain* m_SwapChain = nullptr;
106  // Depth buffer acts as a container for our swap chain depth attachment
108  // Global render pass for frame buffer usage
109  VkRenderPass m_RenderPass = VK_NULL_HANDLE;
110  // List of available frame buffers (same as number of swap chain images)
111  std::vector<VkFramebuffer> m_SwapChainFrameBuffers;
113  std::vector<VkClearValue> m_SwapChainClearVals = std::vector<VkClearValue>(2);
114 
115  // Stages that the swap chain needs to wait on in order to present
116  VkPipelineStageFlags m_WaitStages = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
117 
119  std::vector<CommandBuffer*> m_DrawCmdBuffers;
120 
122  std::vector<VkSemaphore> m_PresentCompleteSemaphores;
123  std::vector<VkSemaphore> m_RenderFinishedSemaphores;
124  std::vector<VkFence> m_InFlightFences;
125 
127  VkSurfaceKHR m_Surface = VK_NULL_HANDLE;
128 
131  size_t CurrentFrameIndex = 0;
132 
133  // Command Buffer pool
134  VkCommandPool m_CommandPool = VK_NULL_HANDLE;
135 
136  std::vector<RenderPipeline*> m_RenderPipelines;
137 
140 
141  // #TODO VMA Allocator
142  };
143 } // namespace Fling
Definition: VulkanApp.h:16
const VkCommandPool GetCommandPool() const
Definition: VulkanApp.h:60
FlingWindow * m_CurrentWindow
Definition: VulkanApp.h:102
LogicalDevice * m_LogicalDevice
Definition: VulkanApp.h:100
Definition: VulkanApp.h:17
VkExtent2D ChooseSwapExtent()
Returns the current extents needed to render based on the physical device and surface.
Definition: VulkanApp.cpp:478
virtual FLING_API void Init()
Definition: Singleton.hpp:20
Definition: VulkanApp.h:20
std::vector< VkFence > m_InFlightFences
Definition: VulkanApp.h:124
Base class that represents a window to the Fling Engine.
Definition: FlingWindow.h:27
A simple first person camera.
Definition: FirstPersonCamera.h:9
PhysicalDevice * m_PhysicalDevice
Definition: VulkanApp.h:101
LogicalDevice * GetLogicalDevice() const
Definition: VulkanApp.h:58
The BaseEditor of the Fling Engine.
Definition: BaseEditor.h:13
void BuildSwapChainResources()
Build the frame buffers for each swap chain image along with the render pass for it to use...
Definition: VulkanApp.cpp:67
Swapchain * m_SwapChain
Definition: VulkanApp.h:105
A physical device represents the Vulkan physical device (the GPU) that we are currently using...
Definition: PhyscialDevice.h:11
std::vector< CommandBuffer * > m_DrawCmdBuffers
Keep a vector of command buffers that we want to use so that we can have one for each active frame...
Definition: VulkanApp.h:119
Encapsulates functionality of a Vulkan Command buffer.
Definition: CommandBuffer.h:17
size_t CurrentFrameIndex
The index of the current frame in flight.
Definition: VulkanApp.h:131
void CreateGameWindow(const UINT32 t_width, const UINT32 t_height)
Creates a window and preps the VkSurfaceKHR.
Definition: VulkanApp.cpp:201
Class that can have only one instance.
Definition: Singleton.hpp:11
A logical device represents the application view of the device.
Definition: LogicalDevice.h:13
VkRenderPass m_RenderPass
Definition: VulkanApp.h:109
Definition: VulkanApp.h:18
The instance is a representation of this application graphics instance in Vulkan. ...
Definition: Instance.h:11
FirstPersonCamera * GetCamera() const
Definition: VulkanApp.h:61
void CreateFrameSyncResources()
Create semaphores for available swap chain images and fences for the current frame in flight ...
Definition: VulkanApp.cpp:178
Definition: VulkanApp.h:15
FirstPersonCamera * m_Camera
The Vulkan app will specify the current camera and be limited to one for now.
Definition: VulkanApp.h:139
std::vector< VkClearValue > m_SwapChainClearVals
The clear values that will be used when building the command buffer to run this subpass.
Definition: VulkanApp.h:113
Core rendering functionality of the Fling Engine.
Definition: VulkanApp.h:38
VkCommandPool m_CommandPool
Definition: VulkanApp.h:134
Represents a swap chain that can be used throughout the program.
Definition: SwapChain.h:21
VulkanApp()=default
Specify default constructible so that we have more explicit control with Init and Shutdown...
DepthBuffer * m_DepthBuffer
Definition: VulkanApp.h:107
PhysicalDevice * GetPhysicalDevice() const
Definition: VulkanApp.h:59
void BuildRenderPipelines(PipelineFlags t_Conf, entt::registry &t_Reg, std::shared_ptr< Fling::BaseEditor > t_Editor)
Builds any render pipelines with their specific set of sub passes and shaders.
Definition: VulkanApp.cpp:238
std::vector< VkFramebuffer > m_SwapChainFrameBuffers
Definition: VulkanApp.h:111
virtual FLING_API void Shutdown()
Definition: Singleton.hpp:22
VkPipelineStageFlags m_WaitStages
Definition: VulkanApp.h:116
void BuildSwapChainFrameBuffer()
Definition: VulkanApp.cpp:148
void Update(float DeltaTime, entt::registry &t_Reg)
Updates all rendering buffers and sends commands to draw a frame.
Definition: VulkanApp.cpp:311
FlingWindow * GetCurrentWindow() const
Definition: VulkanApp.h:57
std::vector< RenderPipeline * > m_RenderPipelines
Definition: VulkanApp.h:136
void BuildGlobalRenderPass()
Definition: VulkanApp.cpp:88
A render pipeline encapsulates the functionality of a.
Definition: RenderPipeline.h:19
void Prepare()
Prepare logical, physical and swap chain devices.
Definition: VulkanApp.cpp:34
std::vector< VkSemaphore > m_PresentCompleteSemaphores
Synchronization primitives for drawing the frame.
Definition: VulkanApp.h:122
PipelineFlags
Configuration that can determine what render pipelines will be added to this application.
Definition: VulkanApp.h:13
uint32_t UINT32
Definition: FlingTypes.h:13
Definition: Engine.h:29
Instance * m_Instance
Vulkan Devices that need to get created.
Definition: VulkanApp.h:99
~VulkanApp()=default
Definition: VulkanApp.h:19
VkSurfaceKHR m_Surface
Handle to the surface extension used to interact with the windows system.
Definition: VulkanApp.h:127
std::vector< VkSemaphore > m_RenderFinishedSemaphores
Definition: VulkanApp.h:123
Definition: DepthBuffer.h:9