Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Renderer.h
Go to the documentation of this file.
1/**
2 * @file Renderer.h
3 * @brief Per-frame Vulkan command-buffer recording + presentation.
4 *
5 * Skeleton renderer for the preview path. Records a single render pass that
6 * clears the swapchain image to a configurable colour, submits to the
7 * graphics queue, and presents. Two frames in flight (FRAMES_IN_FLIGHT = 2)
8 * with the standard image-available / render-finished semaphore + in-flight
9 * fence triple.
10 */
11
12#pragma once
13
14#include <array>
15
16#include <vulkan/vulkan.h>
17
18namespace mnd::vk
19{
20class Context;
21class Swapchain;
22
24{
25public:
26 static constexpr uint32_t kFramesInFlight = 2;
27
28 Renderer(Context &ctx, Swapchain &swap);
29 ~Renderer();
30
31 Renderer(const Renderer &) = delete;
32 Renderer &operator=(const Renderer &) = delete;
33
34 /// Record + submit + present one frame. Returns false if the swapchain
35 /// went out-of-date and the caller should rebuild it before calling again.
36 bool DrawFrame(float clearR, float clearG, float clearB);
37
38 /// Block until the GPU is idle. Call before destroying anything bound
39 /// to the swapchain or device.
40 void WaitIdle() const;
41
42private:
43 void CreateCommandPool();
44 void AllocateCommandBuffers();
45 void CreateSyncObjects();
46 void RecordCommandBuffer(VkCommandBuffer cb, uint32_t imageIndex,
47 float r, float g, float b);
48
49 Context &m_ctx;
50 Swapchain &m_swap;
51
52 VkCommandPool m_cmdPool = VK_NULL_HANDLE;
53 std::array<VkCommandBuffer, kFramesInFlight> m_cmdBuffers{};
54 std::array<VkSemaphore, kFramesInFlight> m_imageAvailable{};
55 std::array<VkSemaphore, kFramesInFlight> m_renderFinished{};
56 std::array<VkFence, kFramesInFlight> m_inFlight{};
57
58 uint32_t m_currentFrame = 0;
59};
60
61} // namespace mnd::vk
Owns the Vulkan instance, surface (tied to a GLFW window), physical + logical device,...
Definition Context.h:41
Renderer(const Renderer &)=delete
void WaitIdle() const
Definition Renderer.cpp:45
Renderer & operator=(const Renderer &)=delete
bool DrawFrame(float clearR, float clearG, float clearB)
Definition Renderer.cpp:118
static constexpr uint32_t kFramesInFlight
Definition Renderer.h:26