| 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 {
13 enum PipelineFlags
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; }
59 inline PhysicalDevice* GetPhysicalDevice() const { return m_PhysicalDevice; }
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
75 void CreateFrameSyncResources();
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
92 void BuildSwapChainResources();
93
94 void BuildGlobalRenderPass();
95
96 void BuildSwapChainFrameBuffer();
97
99 Instance* m_Instance = nullptr;
100 LogicalDevice* m_LogicalDevice = nullptr;
101 PhysicalDevice* m_PhysicalDevice = nullptr;
102 FlingWindow* m_CurrentWindow = 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
107 DepthBuffer* m_DepthBuffer = nullptr;
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
139 FirstPersonCamera* m_Camera = nullptr;
140
141 // #TODO VMA Allocator
142 };
143 } // namespace Fling
Fling::REFLECTIONS
Definition: VulkanApp.h:16
Fling::VulkanApp::GetCommandPool
const VkCommandPool GetCommandPool() const
Definition: VulkanApp.h:60
Fling::VulkanApp::m_CurrentWindow
FlingWindow * m_CurrentWindow
Definition: VulkanApp.h:102
Fling::VulkanApp::m_LogicalDevice
LogicalDevice * m_LogicalDevice
Definition: VulkanApp.h:100
FlingVulkan.h
Fling::IMGUI
Definition: VulkanApp.h:17
Fling::VulkanApp::ChooseSwapExtent
VkExtent2D ChooseSwapExtent()
Returns the current extents needed to render based on the physical device and surface.
Definition: VulkanApp.cpp:478
Fling::Singleton< VulkanApp >::Init
virtual FLING_API void Init()
Definition: Singleton.hpp:20
Fling::ALL
Definition: VulkanApp.h:20
Fling::VulkanApp::m_InFlightFences
std::vector< VkFence > m_InFlightFences
Definition: VulkanApp.h:124
Fling::FlingWindow
Base class that represents a window to the Fling Engine.
Definition: FlingWindow.h:27
Fling::FirstPersonCamera
A simple first person camera.
Definition: FirstPersonCamera.h:9
Fling::VulkanApp::m_PhysicalDevice
PhysicalDevice * m_PhysicalDevice
Definition: VulkanApp.h:101
Fling::VulkanApp::GetLogicalDevice
LogicalDevice * GetLogicalDevice() const
Definition: VulkanApp.h:58
Fling::BaseEditor
The BaseEditor of the Fling Engine.
Definition: BaseEditor.h:13
Fling::VulkanApp::BuildSwapChainResources
void BuildSwapChainResources()
Build the frame buffers for each swap chain image along with the render pass for it to use...
Definition: VulkanApp.cpp:67
Fling::VulkanApp::m_SwapChain
Swapchain * m_SwapChain
Definition: VulkanApp.h:105
Fling::PhysicalDevice
A physical device represents the Vulkan physical device (the GPU) that we are currently using...
Definition: PhyscialDevice.h:11
Fling::VulkanApp::m_DrawCmdBuffers
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
Fling::CommandBuffer
Encapsulates functionality of a Vulkan Command buffer.
Definition: CommandBuffer.h:17
Fling::VulkanApp::CurrentFrameIndex
size_t CurrentFrameIndex
The index of the current frame in flight.
Definition: VulkanApp.h:131
Fling::VulkanApp::CreateGameWindow
void CreateGameWindow(const UINT32 t_width, const UINT32 t_height)
Creates a window and preps the VkSurfaceKHR.
Definition: VulkanApp.cpp:201
Fling::Singleton
Class that can have only one instance.
Definition: Singleton.hpp:11
Fling::LogicalDevice
A logical device represents the application view of the device.
Definition: LogicalDevice.h:13
Fling::VulkanApp::m_RenderPass
VkRenderPass m_RenderPass
Definition: VulkanApp.h:109
Fling::CUBEMAP
Definition: VulkanApp.h:18
Fling::Instance
The instance is a representation of this application graphics instance in Vulkan. ...
Definition: Instance.h:11
Fling::VulkanApp::GetCamera
FirstPersonCamera * GetCamera() const
Definition: VulkanApp.h:61
Fling::VulkanApp::CreateFrameSyncResources
void CreateFrameSyncResources()
Create semaphores for available swap chain images and fences for the current frame in flight ...
Definition: VulkanApp.cpp:178
Fling::DEFERRED
Definition: VulkanApp.h:15
Fling::VulkanApp::m_Camera
FirstPersonCamera * m_Camera
The Vulkan app will specify the current camera and be limited to one for now.
Definition: VulkanApp.h:139
Fling::VulkanApp::m_SwapChainClearVals
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
Fling::VulkanApp
Core rendering functionality of the Fling Engine.
Definition: VulkanApp.h:38
Fling::VulkanApp::m_CommandPool
VkCommandPool m_CommandPool
Definition: VulkanApp.h:134
Fling::Swapchain
Represents a swap chain that can be used throughout the program.
Definition: SwapChain.h:21
Fling::VulkanApp::VulkanApp
VulkanApp()=default
Specify default constructible so that we have more explicit control with Init and Shutdown...
Fling::VulkanApp::m_DepthBuffer
DepthBuffer * m_DepthBuffer
Definition: VulkanApp.h:107
Fling::VulkanApp::GetPhysicalDevice
PhysicalDevice * GetPhysicalDevice() const
Definition: VulkanApp.h:59
Fling::VulkanApp::BuildRenderPipelines
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
Fling::VulkanApp::m_SwapChainFrameBuffers
std::vector< VkFramebuffer > m_SwapChainFrameBuffers
Definition: VulkanApp.h:111
Fling::Singleton< VulkanApp >::Shutdown
virtual FLING_API void Shutdown()
Definition: Singleton.hpp:22
Fling::VulkanApp::m_WaitStages
VkPipelineStageFlags m_WaitStages
Definition: VulkanApp.h:116
Fling::VulkanApp::BuildSwapChainFrameBuffer
void BuildSwapChainFrameBuffer()
Definition: VulkanApp.cpp:148
Fling::VulkanApp::Update
void Update(float DeltaTime, entt::registry &t_Reg)
Updates all rendering buffers and sends commands to draw a frame.
Definition: VulkanApp.cpp:311
Fling::VulkanApp::GetCurrentWindow
FlingWindow * GetCurrentWindow() const
Definition: VulkanApp.h:57
Fling::VulkanApp::m_RenderPipelines
std::vector< RenderPipeline * > m_RenderPipelines
Definition: VulkanApp.h:136
Fling::VulkanApp::BuildGlobalRenderPass
void BuildGlobalRenderPass()
Definition: VulkanApp.cpp:88
Fling::RenderPipeline
A render pipeline encapsulates the functionality of a.
Definition: RenderPipeline.h:19
Fling::VulkanApp::Prepare
void Prepare()
Prepare logical, physical and swap chain devices.
Definition: VulkanApp.cpp:34
Fling::VulkanApp::m_PresentCompleteSemaphores
std::vector< VkSemaphore > m_PresentCompleteSemaphores
Synchronization primitives for drawing the frame.
Definition: VulkanApp.h:122
Fling::PipelineFlags
PipelineFlags
Configuration that can determine what render pipelines will be added to this application.
Definition: VulkanApp.h:13
UINT32
uint32_t UINT32
Definition: FlingTypes.h:13
Fling
Definition: Engine.h:29
FlingTypes.h
Fling::VulkanApp::m_Instance
Instance * m_Instance
Vulkan Devices that need to get created.
Definition: VulkanApp.h:99
Fling::VulkanApp::~VulkanApp
~VulkanApp()=default
Fling::DEBUG
Definition: VulkanApp.h:19
Fling::VulkanApp::m_Surface
VkSurfaceKHR m_Surface
Handle to the surface extension used to interact with the windows system.
Definition: VulkanApp.h:127
Fling::VulkanApp::m_RenderFinishedSemaphores
std::vector< VkSemaphore > m_RenderFinishedSemaphores
Definition: VulkanApp.h:123
Singleton.hpp
Fling::DepthBuffer
Definition: DepthBuffer.h:9