Nameless Engine
Loading...
Searching...
No Matches
ShadowMapHandle.h
1#pragma once
2
3// Standard.
4#include <functional>
5#include <mutex>
6
7// Custom.
8#include "ShadowMapType.hpp"
9
10// External.
11#include "vulkan/vulkan_core.h"
12
13namespace ne {
14 class ShadowMapManager;
15 class GpuResource;
16
24 // Only manager can create and update objects of this class.
25 friend class ShadowMapManager;
26
27 // Index manager updates array index.
28 friend class ShadowMapArrayIndexManager;
29
30 public:
33 InternalResources() = default;
34
37
43
51 std::vector<VkFramebuffer> vShadowMappingFramebuffers;
52 };
53
54 ShadowMapHandle() = delete;
55
56 ShadowMapHandle(const ShadowMapHandle&) = delete;
57 ShadowMapHandle& operator=(const ShadowMapHandle&) = delete;
58
59 // Intentionally disallow `move` because manager wraps handles to `std::unique_ptr`
60 // to store raw pointer to shadow map handle and we need to make sure nobody will
61 // accidentally `move` the handle which will cause the manager's raw pointer to be invalid.
62 ShadowMapHandle(ShadowMapHandle&& other) noexcept = delete;
63 ShadowMapHandle& operator=(ShadowMapHandle&& other) noexcept = delete;
64
66
76 inline std::pair<std::recursive_mutex, InternalResources>* getResources() { return &mtxResources; }
77
83 inline ShadowMapType getShadowMapType() const { return shadowMapType; }
84
90 inline size_t getShadowMapSize() const { return iShadowMapSize; }
91
92 private:
107 GpuResource* pDepthTexture,
108 ShadowMapType type,
109 size_t iTextureSize,
110 const std::function<void(unsigned int)>& onArrayIndexChanged,
111 GpuResource* pColorTexture = nullptr);
112
118 void changeArrayIndex(unsigned int iNewArrayIndex);
119
130 GpuResource* pDepthTexture, size_t iShadowMapSize, GpuResource* pColorTexture = nullptr);
131
134
137
139 std::pair<std::recursive_mutex, InternalResources> mtxResources;
140
142 size_t iShadowMapSize = 0;
143
148 const std::function<void(unsigned int)> onArrayIndexChanged;
149
151 const ShadowMapType shadowMapType = ShadowMapType::DIRECTIONAL;
152 };
153}
Definition: GpuResource.h:16
Definition: ShadowMapArrayIndexManager.h:25
Definition: ShadowMapHandle.h:23
std::pair< std::recursive_mutex, InternalResources > * getResources()
Definition: ShadowMapHandle.h:76
void recreateFramebuffers()
Definition: ShadowMapHandle.cpp:98
std::pair< std::recursive_mutex, InternalResources > mtxResources
Definition: ShadowMapHandle.h:139
const std::function< void(unsigned int)> onArrayIndexChanged
Definition: ShadowMapHandle.h:148
const ShadowMapType shadowMapType
Definition: ShadowMapHandle.h:151
size_t iShadowMapSize
Definition: ShadowMapHandle.h:142
void changeArrayIndex(unsigned int iNewArrayIndex)
Definition: ShadowMapHandle.cpp:81
ShadowMapManager * pManager
Definition: ShadowMapHandle.h:136
ShadowMapType getShadowMapType() const
Definition: ShadowMapHandle.h:83
void setUpdatedResources(GpuResource *pDepthTexture, size_t iShadowMapSize, GpuResource *pColorTexture=nullptr)
Definition: ShadowMapHandle.cpp:85
size_t getShadowMapSize() const
Definition: ShadowMapHandle.h:90
Definition: ShadowMapManager.h:29
Definition: ShadowMapHandle.h:32
GpuResource * pColorTexture
Definition: ShadowMapHandle.h:42
std::vector< VkFramebuffer > vShadowMappingFramebuffers
Definition: ShadowMapHandle.h:51
GpuResource * pDepthTexture
Definition: ShadowMapHandle.h:36