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
12#include "krpch.h"
13
15#include "vulkan/vulkan.h"
16
17namespace Karma
18{
20
28 {
29 public:
37
44 virtual ~VulkanRendererAPI();
45
52 virtual void SetClearColor(const glm::vec4& color) override;
53
61 virtual void Clear() override;
62
70 virtual void BeginScene() override;
71
80 virtual void DrawIndexed(std::shared_ptr<VertexArray> vertexArray) override;
81
88 virtual void EndScene() override;
89
99
109 void RecordCommandBuffers(VkCommandBuffer commandBuffer, uint32_t imageIndex);
110
118
124 void CreateSynchronicity();
125
133
140 void RemoveSynchronicity();
141
150
160
161 // Getters. Depending on detailed implementation of other API (such as OpenGL), we may promote the getter to abstract
162 const std::vector<VkCommandBuffer>& GetCommandBuffers() const { return m_commandBuffers; }
163 const int& GetMaxFramesInFlight() const { return MAX_FRAMES_IN_FLIGHT; }
164 const std::vector<VkFence>& GetFences() const { return m_InFlightFences; }
165 const std::vector<VkSemaphore>& GetImageAvailableSemaphores() const { return m_ImageAvailableSemaphores; }
166 const std::vector<VkSemaphore> GetRenderFinishedSemaphore() const { return m_RenderFinishedSemaphores; }
167
168 private:
169 size_t m_CurrentFrame = 0;
170
171 std::vector<VkCommandBuffer> m_commandBuffers;
172 std::vector<std::shared_ptr<VulkanVertexArray>> m_VulkaVertexArrays;
173
174 std::vector<VkSemaphore> m_ImageAvailableSemaphores;
175 std::vector<VkSemaphore> m_RenderFinishedSemaphores;
176 std::vector<VkFence> m_InFlightFences;
177
178 // Number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1
179 // Clearly, MAX_FRAMES_IN_FLIGHT shouldn't exceed m_SwapChainImages.size()
180 const int MAX_FRAMES_IN_FLIGHT = 2;
181
182 bool m_bAllocateCommandBuffers;
183 };
184}
#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:23
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