KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
VulkanRendererAPI.h
Go to the documentation of this file.
1
10#pragma once
11
13#include "vulkan/vulkan.h"
14
15namespace Karma
16{
18
26 {
27 public:
35
42 virtual ~VulkanRendererAPI();
43
50 virtual void SetClearColor(const glm::vec4& color) override;
51
59 virtual void Clear() override;
60
68 virtual void BeginScene() override;
69
78 virtual void DrawIndexed(std::shared_ptr<VertexArray> vertexArray) override;
79
86 virtual void EndScene() override;
87
97
107 void RecordCommandBuffers(VkCommandBuffer commandBuffer, uint32_t imageIndex);
108
116
122 void CreateSynchronicity();
123
131
138 void RemoveSynchronicity();
139
148
158
159 // Getters. Depending on detailed implementation of other API (such as OpenGL), we may promote the getter to abstract
160 const std::vector<VkCommandBuffer>& GetCommandBuffers() const { return m_commandBuffers; }
161 const int& GetMaxFramesInFlight() const { return MAX_FRAMES_IN_FLIGHT; }
162 const std::vector<VkFence>& GetFences() const { return m_InFlightFences; }
163 const std::vector<VkSemaphore>& GetImageAvailableSemaphores() const { return m_ImageAvailableSemaphores; }
164 const std::vector<VkSemaphore> GetRenderFinishedSemaphore() const { return m_RenderFinishedSemaphores; }
165
166 private:
167 size_t m_CurrentFrame = 0;
168
169 std::vector<VkCommandBuffer> m_commandBuffers;
170 std::vector<std::shared_ptr<VulkanVertexArray>> m_VulkaVertexArrays;
171
172 std::vector<VkSemaphore> m_ImageAvailableSemaphores;
173 std::vector<VkSemaphore> m_RenderFinishedSemaphores;
174 std::vector<VkFence> m_InFlightFences;
175
176 // Number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1
177 // Clearly, MAX_FRAMES_IN_FLIGHT shouldn't exceed m_SwapChainImages.size()
178 const int MAX_FRAMES_IN_FLIGHT = 2;
179
180 bool m_bAllocateCommandBuffers;
181 };
182}
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
This file contains the class RendererAPI.
An abstract class for a renderer.
Definition RendererAPI.h:21
void RecreateCommandBuffersPipelineSwapchain()
Recreates command buffers, graphics pipelines, and uniform buffer objects when swapchain is recreated...
Definition VulkanRendererAPI.cpp:238
virtual void DrawIndexed(std::shared_ptr< VertexArray > vertexArray) override
Routine for drawing primitives.
Definition VulkanRendererAPI.cpp:262
virtual void Clear() override
Clear the rendering screen. Not much use in Vulkan as such since we record commands in command buffer...
Definition VulkanRendererAPI.cpp:32
void RecreateCommandBuffersAndSwapChain()
Recreates command buffers and swapchain when swapchain is recreated (like on window resize when acqui...
Definition VulkanRendererAPI.cpp:228
void RecordCommandBuffers(VkCommandBuffer commandBuffer, uint32_t imageIndex)
Records the command buffers with rendering commands for a particular image in the swapchain.
Definition VulkanRendererAPI.cpp:62
virtual void SetClearColor(const glm::vec4 &color) override
Sets the color to be used for clear (rendering) screen.
Definition VulkanRendererAPI.cpp:27
void ClearVulkanRendererAPI()
Clears up VulkanRendererAPI specific resources like command buffers and synchronization objects.
Definition VulkanRendererAPI.cpp:16
void CreateSynchronicity()
Creates synchronization objects like semaphores and fences for coordinating rendering operations.
Definition VulkanRendererAPI.cpp:122
void RemoveSynchronicity()
Removes synchronization objects like semaphores and fences.
Definition VulkanRendererAPI.cpp:150
virtual void EndScene() override
Instructions for end of the scene.
Definition VulkanRendererAPI.cpp:112
VulkanRendererAPI()
A constructor.
Definition VulkanRendererAPI.cpp:8
void AllocateCommandBuffers()
Allocates resources for command buffers.
Definition VulkanRendererAPI.cpp:46
virtual void BeginScene() override
Setting up resources for rendering of a scene which includes allocating command buffers if not alread...
Definition VulkanRendererAPI.cpp:36
void SubmitCommandBuffers()
Submits the recorded command buffers to the graphics queue for execution.
Definition VulkanRendererAPI.cpp:162
Vulkan specific implementation of VertexArray class.
Definition VulkanVertexArray.h:34