Nameless Engine
Loading...
Searching...
No Matches
FrameResourceManager.h
1#pragma once
2
3// Standard.
4#include <array>
5#include <memory>
6#include <mutex>
7#include <variant>
8
9// Custom.
10#include "misc/Error.h"
11#include "math/GLMath.hpp"
12#include "shader/VulkanAlignmentConstants.hpp"
13#include "render/general/resource/frame/FrameResource.h"
14
15namespace ne {
16 class UploadBuffer;
17 class Renderer;
18
22 alignas(iVkMat4Alignment) glm::mat4x4 viewMatrix = glm::identity<glm::mat4x4>();
23
25 alignas(iVkMat4Alignment) glm::mat4x4 viewProjectionMatrix = glm::identity<glm::mat4x4>();
26
28 alignas(iVkVec4Alignment) glm::vec4 cameraPosition = glm::vec4(0.0F, 0.0F, 0.0F, 0.0F);
29
31 alignas(iVkScalarAlignment) float timeSincePrevFrameInSec = 0.0F;
32
34 alignas(iVkScalarAlignment) float totalTimeInSec = 0.0F;
35
36 // don't forget to add padding to 4 floats (if needed) for HLSL packing rules
37 };
38
47 // Only renderer is allowed to switch to the next frame resource.
48 friend class Renderer;
49
50 // Vulkan renderer need to cycle frame resources in a very specific case.
51 friend class VulkanRenderer;
52
53 public:
56 CurrentFrameResource() = default;
57
59 size_t iIndex = 0;
60
63 };
64
65 FrameResourceManager() = delete;
67 FrameResourceManager& operator=(const FrameResourceManager&) = delete;
68
74 static constexpr unsigned int getFrameResourceCount() { return iFrameResourceCount; }
75
83 static std::variant<std::unique_ptr<FrameResourceManager>, Error> create(Renderer* pRenderer);
84
91 std::pair<std::recursive_mutex, CurrentFrameResource>* getCurrentFrameResource();
92
102 std::pair<std::recursive_mutex*, std::vector<FrameResource*>> getAllFrameResources();
103
104 private:
106 static constexpr unsigned int iFrameResourceCount = 2; // small to avoid input latency
107
115 static std::array<std::unique_ptr<FrameResource>, iFrameResourceCount>
117
124
135
137 Renderer* pRenderer = nullptr;
138
140 std::pair<std::recursive_mutex, CurrentFrameResource> mtxCurrentFrameResource;
141
143 std::array<std::unique_ptr<FrameResource>, iFrameResourceCount> vFrameResources;
144 };
145} // namespace ne
Definition: Error.h:27
Definition: FrameResourceManager.h:46
void switchToNextFrameResource()
Definition: FrameResourceManager.cpp:103
std::pair< std::recursive_mutex, CurrentFrameResource > mtxCurrentFrameResource
Definition: FrameResourceManager.h:140
std::array< std::unique_ptr< FrameResource >, iFrameResourceCount > vFrameResources
Definition: FrameResourceManager.h:143
static constexpr unsigned int getFrameResourceCount()
Definition: FrameResourceManager.h:74
std::pair< std::recursive_mutex, CurrentFrameResource > * getCurrentFrameResource()
Definition: FrameResourceManager.cpp:99
Renderer * pRenderer
Definition: FrameResourceManager.h:137
std::pair< std::recursive_mutex *, std::vector< FrameResource * > > getAllFrameResources()
Definition: FrameResourceManager.cpp:116
static std::variant< std::unique_ptr< FrameResourceManager >, Error > create(Renderer *pRenderer)
Definition: FrameResourceManager.cpp:58
static std::array< std::unique_ptr< FrameResource >, iFrameResourceCount > createRenderDependentFrameResources(Renderer *pRenderer)
Definition: FrameResourceManager.cpp:21
static constexpr unsigned int iFrameResourceCount
Definition: FrameResourceManager.h:106
Definition: Renderer.h:43
Definition: VulkanRenderer.h:26
Definition: FrameResourceManager.h:20
float timeSincePrevFrameInSec
Definition: FrameResourceManager.h:31
glm::vec4 cameraPosition
Definition: FrameResourceManager.h:28
glm::mat4x4 viewProjectionMatrix
Definition: FrameResourceManager.h:25
glm::mat4x4 viewMatrix
Definition: FrameResourceManager.h:22
float totalTimeInSec
Definition: FrameResourceManager.h:34
Definition: FrameResourceManager.h:55
size_t iIndex
Definition: FrameResourceManager.h:59
FrameResource * pResource
Definition: FrameResourceManager.h:62
Definition: FrameResource.h:15