Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Fling::Renderer Class Reference

Core renderer for the application More...

#include <Renderer.h>

Inherits Fling::Singleton< Renderer >.

Public Member Functions

virtual void Init () override
 
virtual void Shutdown () override
 
void CreateGameWindow (const UINT32 t_width, const UINT32 t_height)
 Init GLFW and create the game window More...
 
FlingWindowGetCurrentWindow () const
 
void Tick ()
 Happens before draw frame. More...
 
void DrawFrame ()
 Draw the frame! More...
 
void PrepShutdown ()
 Prepare for shutdown of the rendering pipeline, close any open semaphores. More...
 
const VkDevice & GetLogicalVkDevice () const
 Get the logical graphics Device object. More...
 
LogicalDeviceGetLogicalDevice () const
 
const VkPhysicalDevice & GetPhysicalVkDevice () const
 Get the Physical Device object used by this renderer. More...
 
PhysicalDeviceGetPhysicalDevice () const
 
const VkCommandPool & GetCommandPool () const
 
const VkQueue & GetGraphicsQueue () const
 
void SetFrameBufferHasBeenResized (bool t_Setting)
 
const VkSurfaceKHR & GetVkSurface () const
 
SwapchainGetSwapChain () const
 

Private Member Functions

void InitGraphics ()
 Init the current graphics API More...
 
void CreateDescriptorLayout ()
 Create a Descriptor Layout object. More...
 
void CreateGraphicsPipeline ()
 Create the graphics pipeline (IA, VS, FS, etc) More...
 
void CreateRenderPass ()
 Create the frame buffer that will be used by the graphics pipeline. More...
 
void CreateFrameBuffers ()
 Create the frame buffers for use by the swap chain. More...
 
void CreateCommandPool ()
 Create the command pool to be sent every frame. More...
 
void CreateCommandBuffers ()
 
void CreateSyncObjects ()
 Create semaphores and fence objects. More...
 
void CleanupFrameResources ()
 
void RecreateFrameResources ()
 Re-create the image views, render passes, and command buffers. More...
 
void CreateUniformBuffers ()
 
void CreateDescriptorPool ()
 
void CreateDescriptorSets ()
 
SwapChainSupportDetails QuerySwapChainSupport (VkPhysicalDevice t_Device)
 Check the swap chain support of a given device. More...
 
VkSurfaceFormatKHR ChooseSwapChainSurfaceFormat (const std::vector< VkSurfaceFormatKHR > &t_AvailableFormats)
 Choose a swap chain format based on the available formats. More...
 
VkPresentModeKHR ChooseSwapChainPresentMode (const std::vector< VkPresentModeKHR > &t_AvialableFormats)
 Choose a present mode for the swap chain based on the given formats. More...
 
VkExtent2D ChooseSwapExtent ()
 Determine the best match extents based on our window width and height. More...
 
void UpdateUniformBuffer (UINT32 t_CurrentImage)
 Update the uniform buffer data. More...
 
VkShaderModule CreateShaderModule (std::shared_ptr< File > t_ShaderCode)
 Create a shader module based on the given shader code. More...
 

Private Attributes

std::unique_ptr< FirstPersonCameram_camera
 Camera Instance. More...
 
FlingWindowm_CurrentWindow = nullptr
 
Instancem_Instance = nullptr
 
LogicalDevicem_LogicalDevice = nullptr
 
PhysicalDevicem_PhysicalDevice = nullptr
 
VkSurfaceKHR m_Surface = VK_NULL_HANDLE
 Handle to the surface extension used to interact with the windows system. More...
 
Swapchainm_SwapChain = nullptr
 
VkRenderPass m_RenderPass
 
VkDescriptorSetLayout m_DescriptorSetLayout
 Pipeline layout stores uniforms (global shader vars) More...
 
VkPipelineLayout m_PipelineLayout
 
VkPipeline m_GraphicsPipeline
 
VkCommandPool m_CommandPool
 
VkDescriptorPool m_DescriptorPool
 
DepthBufferm_DepthBuffer = nullptr
 
size_t CurrentFrameIndex = 0
 
bool m_FrameBufferResized = false
 Used to determine if the frame buffer has been resized or not. More...
 
std::vector< Buffer * > m_UniformBuffers
 Uniform buffers. More...
 
std::vector< VkDescriptorSet > m_DescriptorSets
 
std::vector< VkFramebuffer > m_SwapChainFramebuffers
 The frame buffers for the swap chain. More...
 
std::vector< VkCommandBuffer > m_CommandBuffers
 Command buffers. More...
 
std::vector< VkSemaphore > m_ImageAvailableSemaphores
 
std::vector< VkSemaphore > m_RenderFinishedSemaphores
 
std::vector< VkFence > m_InFlightFences
 
std::shared_ptr< class Imagem_TestImage
 
std::shared_ptr< Modelm_TestModel
 

Static Private Attributes

static const int MAX_FRAMES_IN_FLIGHT = 2
 

Additional Inherited Members

- Static Public Member Functions inherited from Fling::Singleton< Renderer >
static RendererGet ()
 
- Protected Member Functions inherited from Fling::Singleton< Renderer >
 Singleton ()=default
 Every singleton must have a default constructor so that explicit creation and destruction of them is maintained. More...
 

Detailed Description

Core renderer for the application

Member Function Documentation

◆ ChooseSwapChainPresentMode()

VkPresentModeKHR Fling::Renderer::ChooseSwapChainPresentMode ( const std::vector< VkPresentModeKHR > &  t_AvialableFormats)
private

Choose a present mode for the swap chain based on the given formats.

Prefer VK_PRESENT_MODE_MAILBOX_KHR If none are available, than return VK_PRESENT_MODE_FIFO_KHR or VK_PRESENT_MODE_IMMEDIATE_KHR based on support

Parameters
Vectorof available formats
Returns
Preferred present mode from the available formats

◆ ChooseSwapChainSurfaceFormat()

VkSurfaceFormatKHR Fling::Renderer::ChooseSwapChainSurfaceFormat ( const std::vector< VkSurfaceFormatKHR > &  t_AvailableFormats)
private

Choose a swap chain format based on the available formats.

Prefer to format that has VK_FORMAT_B8G8R8A8_UNORM and VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, otherwise get the first available.

Parameters
Availableswap chain formats
Returns
Best swap chain surface formate based on the available ones

◆ ChooseSwapExtent()

VkExtent2D Fling::Renderer::ChooseSwapExtent ( )
private

Determine the best match extents based on our window width and height.

Returns
Extents with the best matching resolution

◆ CleanupFrameResources()

void Fling::Renderer::CleanupFrameResources ( )
private

◆ CreateCommandBuffers()

void Fling::Renderer::CreateCommandBuffers ( )
private

◆ CreateCommandPool()

void Fling::Renderer::CreateCommandPool ( )
private

Create the command pool to be sent every frame.

◆ CreateDescriptorLayout()

void Fling::Renderer::CreateDescriptorLayout ( )
private

Create a Descriptor Layout object.

See also
UniformBufferObject.h

◆ CreateDescriptorPool()

void Fling::Renderer::CreateDescriptorPool ( )
private

◆ CreateDescriptorSets()

void Fling::Renderer::CreateDescriptorSets ( )
private

◆ CreateFrameBuffers()

void Fling::Renderer::CreateFrameBuffers ( )
private

Create the frame buffers for use by the swap chain.

◆ CreateGameWindow()

void Fling::Renderer::CreateGameWindow ( const UINT32  t_width,
const UINT32  t_height 
)

Init GLFW and create the game window

Parameters
t_widthWidth of the window
t_heightHeight of the window

◆ CreateGraphicsPipeline()

void Fling::Renderer::CreateGraphicsPipeline ( )
private

Create the graphics pipeline (IA, VS, FS, etc)

◆ CreateRenderPass()

void Fling::Renderer::CreateRenderPass ( )
private

Create the frame buffer that will be used by the graphics pipeline.

◆ CreateShaderModule()

VkShaderModule Fling::Renderer::CreateShaderModule ( std::shared_ptr< File t_ShaderCode)
private

Create a shader module based on the given shader code.

Parameters
Vectorof the shader code
Returns
Shader module from the given code

◆ CreateSyncObjects()

void Fling::Renderer::CreateSyncObjects ( )
private

Create semaphores and fence objects.

◆ CreateUniformBuffers()

void Fling::Renderer::CreateUniformBuffers ( )
private

◆ DrawFrame()

void Fling::Renderer::DrawFrame ( )

Draw the frame!

◆ GetCommandPool()

const VkCommandPool& Fling::Renderer::GetCommandPool ( ) const
inline

◆ GetCurrentWindow()

FlingWindow* Fling::Renderer::GetCurrentWindow ( ) const
inline

◆ GetGraphicsQueue()

const VkQueue& Fling::Renderer::GetGraphicsQueue ( ) const
inline

◆ GetLogicalDevice()

LogicalDevice* Fling::Renderer::GetLogicalDevice ( ) const
inline

◆ GetLogicalVkDevice()

const VkDevice& Fling::Renderer::GetLogicalVkDevice ( ) const
inline

Get the logical graphics Device object.

Returns
const ref to VkDevice

◆ GetPhysicalDevice()

PhysicalDevice* Fling::Renderer::GetPhysicalDevice ( ) const
inline

◆ GetPhysicalVkDevice()

const VkPhysicalDevice& Fling::Renderer::GetPhysicalVkDevice ( ) const
inline

Get the Physical Device object used by this renderer.

Returns
const VkPhysicalDevice&

◆ GetSwapChain()

Swapchain* Fling::Renderer::GetSwapChain ( ) const
inline

◆ GetVkSurface()

const VkSurfaceKHR& Fling::Renderer::GetVkSurface ( ) const
inline

◆ Init()

void Fling::Renderer::Init ( )
overridevirtual

Reimplemented from Fling::Singleton< Renderer >.

◆ InitGraphics()

void Fling::Renderer::InitGraphics ( )
private

Init the current graphics API

◆ PrepShutdown()

void Fling::Renderer::PrepShutdown ( )

Prepare for shutdown of the rendering pipeline, close any open semaphores.

◆ QuerySwapChainSupport()

SwapChainSupportDetails Fling::Renderer::QuerySwapChainSupport ( VkPhysicalDevice  t_Device)
private

Check the swap chain support of a given device.

Parameters
Thedevice to check support on
Returns
Details of the the swap chain support on this device

◆ RecreateFrameResources()

void Fling::Renderer::RecreateFrameResources ( )
private

Re-create the image views, render passes, and command buffers.

◆ SetFrameBufferHasBeenResized()

void Fling::Renderer::SetFrameBufferHasBeenResized ( bool  t_Setting)
inline

◆ Shutdown()

void Fling::Renderer::Shutdown ( )
overridevirtual

Reimplemented from Fling::Singleton< Renderer >.

◆ Tick()

void Fling::Renderer::Tick ( )

Happens before draw frame.

Update the window

◆ UpdateUniformBuffer()

void Fling::Renderer::UpdateUniformBuffer ( UINT32  t_CurrentImage)
private

Update the uniform buffer data.

Called during DrawFrame

Parameters
t_CurrentImageThe current image index that we are using

Field Documentation

◆ CurrentFrameIndex

size_t Fling::Renderer::CurrentFrameIndex = 0
private

◆ m_camera

std::unique_ptr<FirstPersonCamera> Fling::Renderer::m_camera
private

◆ m_CommandBuffers

std::vector<VkCommandBuffer> Fling::Renderer::m_CommandBuffers
private

Command buffers.

See also
m_CommandPool

◆ m_CommandPool

VkCommandPool Fling::Renderer::m_CommandPool
private

◆ m_CurrentWindow

FlingWindow* Fling::Renderer::m_CurrentWindow = nullptr
private

◆ m_DepthBuffer

DepthBuffer* Fling::Renderer::m_DepthBuffer = nullptr
private

◆ m_DescriptorPool

VkDescriptorPool Fling::Renderer::m_DescriptorPool
private

◆ m_DescriptorSetLayout

VkDescriptorSetLayout Fling::Renderer::m_DescriptorSetLayout
private

Pipeline layout stores uniforms (global shader vars)

◆ m_DescriptorSets

std::vector<VkDescriptorSet> Fling::Renderer::m_DescriptorSets
private

◆ m_FrameBufferResized

bool Fling::Renderer::m_FrameBufferResized = false
private

Used to determine if the frame buffer has been resized or not.

◆ m_GraphicsPipeline

VkPipeline Fling::Renderer::m_GraphicsPipeline
private

◆ m_ImageAvailableSemaphores

std::vector<VkSemaphore> Fling::Renderer::m_ImageAvailableSemaphores
private

◆ m_InFlightFences

std::vector<VkFence> Fling::Renderer::m_InFlightFences
private

◆ m_Instance

Instance* Fling::Renderer::m_Instance = nullptr
private

◆ m_LogicalDevice

LogicalDevice* Fling::Renderer::m_LogicalDevice = nullptr
private

◆ m_PhysicalDevice

PhysicalDevice* Fling::Renderer::m_PhysicalDevice = nullptr
private

◆ m_PipelineLayout

VkPipelineLayout Fling::Renderer::m_PipelineLayout
private

◆ m_RenderFinishedSemaphores

std::vector<VkSemaphore> Fling::Renderer::m_RenderFinishedSemaphores
private

◆ m_RenderPass

VkRenderPass Fling::Renderer::m_RenderPass
private

◆ m_Surface

VkSurfaceKHR Fling::Renderer::m_Surface = VK_NULL_HANDLE
private

Handle to the surface extension used to interact with the windows system.

◆ m_SwapChain

Swapchain* Fling::Renderer::m_SwapChain = nullptr
private

◆ m_SwapChainFramebuffers

std::vector<VkFramebuffer> Fling::Renderer::m_SwapChainFramebuffers
private

The frame buffers for the swap chain.

See also
Renderer::CreateFrameBuffers

◆ m_TestImage

std::shared_ptr<class Image> Fling::Renderer::m_TestImage
private

◆ m_TestModel

std::shared_ptr<Model> Fling::Renderer::m_TestModel
private

◆ m_UniformBuffers

std::vector<Buffer*> Fling::Renderer::m_UniformBuffers
private

Uniform buffers.

◆ MAX_FRAMES_IN_FLIGHT

const int Fling::Renderer::MAX_FRAMES_IN_FLIGHT = 2
staticprivate

The documentation for this class was generated from the following files: