vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
Renderer.hpp
Go to the documentation of this file.
1///
2/// @file Renderer.hpp
3/// @brief This file contains the Renderer class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <cassert>
10#include <array>
11
13
14namespace ven {
15
16 static constexpr VkClearColorValue DEFAULT_CLEAR_COLOR = {{0.0F, 0.0F, 0.0F, 1.0F}};
17 static constexpr VkClearDepthStencilValue DEFAULT_CLEAR_DEPTH = {1.0F, 0};
18
19 ///
20 /// @class Renderer
21 /// @brief Class for renderer
22 /// @namespace ven
23 ///
24 class Renderer {
25
26 public:
27
28 Renderer(Window &window, Device &device) : m_window{window}, m_device{device} { recreateSwapChain(); createCommandBuffers(); }
30
31 Renderer(const Renderer &) = delete;
32 Renderer& operator=(const Renderer &) = delete;
33 Renderer(Renderer &&) = delete;
35
36 [[nodiscard]] VkRenderPass getSwapChainRenderPass() const { return m_swapChain->getRenderPass(); }
37 [[nodiscard]] float getAspectRatio() const { return m_swapChain->extentAspectRatio(); }
38 [[nodiscard]] bool isFrameInProgress() const { return m_isFrameStarted; }
39 [[nodiscard]] VkCommandBuffer getCurrentCommandBuffer() const { assert(isFrameInProgress() && "cannot get command m_buffer when frame not in progress"); return m_commandBuffers[static_cast<unsigned long>(m_currentFrameIndex)]; }
40
41 [[nodiscard]] unsigned long getFrameIndex() const { assert(isFrameInProgress() && "cannot get frame index when frame not in progress"); return m_currentFrameIndex; }
42 [[nodiscard]] std::array<float, 4> getClearColor() const { return {
43 m_clearValues[0].color.float32[0],
44 m_clearValues[0].color.float32[1],
45 m_clearValues[0].color.float32[2],
46 m_clearValues[0].color.float32[3]
47 };}
48
49 [[nodiscard]] Window& getWindow() const { return m_window; }
50
51 void setClearValue(const VkClearColorValue clearColorValue = DEFAULT_CLEAR_COLOR, const VkClearDepthStencilValue clearDepthValue = DEFAULT_CLEAR_DEPTH) { m_clearValues[0].color = clearColorValue; m_clearValues[1].depthStencil = clearDepthValue; }
52 VkCommandBuffer beginFrame();
53 void endFrame();
54 void beginSwapChainRenderPass(VkCommandBuffer commandBuffer) const;
55 void endSwapChainRenderPass(VkCommandBuffer commandBuffer) const;
56
57 private:
58
60 void freeCommandBuffers();
61 void recreateSwapChain();
62
65 std::unique_ptr<SwapChain> m_swapChain;
66 std::vector<VkCommandBuffer> m_commandBuffers;
67 std::array<VkClearValue, 2> m_clearValues{DEFAULT_CLEAR_COLOR, 1.0F, 0.F};
68
70 unsigned long m_currentFrameIndex{0};
71 bool m_isFrameStarted{false};
72
73 }; // class Renderer
74
75} // namespace ven
This file contains the Shader class.
Class for device.
Definition Device.hpp:35
Class for renderer.
Definition Renderer.hpp:24
VkCommandBuffer beginFrame()
Definition renderer.cpp:43
Renderer & operator=(const Renderer &)=delete
Window & getWindow() const
Definition Renderer.hpp:49
bool m_isFrameStarted
Definition Renderer.hpp:71
std::array< float, 4 > getClearColor() const
Definition Renderer.hpp:42
std::unique_ptr< SwapChain > m_swapChain
Definition Renderer.hpp:65
VkRenderPass getSwapChainRenderPass() const
Definition Renderer.hpp:36
float getAspectRatio() const
Definition Renderer.hpp:37
Window & m_window
Definition Renderer.hpp:63
void endSwapChainRenderPass(VkCommandBuffer commandBuffer) const
Definition renderer.cpp:119
Renderer & operator=(Renderer &&)=delete
Device & m_device
Definition Renderer.hpp:64
void createCommandBuffers()
Definition renderer.cpp:3
void beginSwapChainRenderPass(VkCommandBuffer commandBuffer) const
Definition renderer.cpp:89
Renderer(Renderer &&)=delete
void freeCommandBuffers()
Definition renderer.cpp:17
unsigned long m_currentFrameIndex
Definition Renderer.hpp:70
void setClearValue(const VkClearColorValue clearColorValue=DEFAULT_CLEAR_COLOR, const VkClearDepthStencilValue clearDepthValue=DEFAULT_CLEAR_DEPTH)
Definition Renderer.hpp:51
Renderer(const Renderer &)=delete
void recreateSwapChain()
Definition renderer.cpp:23
std::array< VkClearValue, 2 > m_clearValues
Definition Renderer.hpp:67
std::vector< VkCommandBuffer > m_commandBuffers
Definition Renderer.hpp:66
VkCommandBuffer getCurrentCommandBuffer() const
Definition Renderer.hpp:39
void endFrame()
Definition renderer.cpp:69
uint32_t m_currentImageIndex
Definition Renderer.hpp:69
unsigned long getFrameIndex() const
Definition Renderer.hpp:41
bool isFrameInProgress() const
Definition Renderer.hpp:38
Renderer(Window &window, Device &device)
Definition Renderer.hpp:28
Class for window.
Definition Window.hpp:26
static constexpr VkClearColorValue DEFAULT_CLEAR_COLOR
Definition Renderer.hpp:16
static constexpr VkClearDepthStencilValue DEFAULT_CLEAR_DEPTH
Definition Renderer.hpp:17