Nameless Engine
Loading...
Searching...
No Matches
ShadowMapManager.h
1#pragma once
2
3// Standard.
4#include <memory>
5#include <variant>
6#include <optional>
7#include <mutex>
8#include <functional>
9#include <unordered_map>
10#include <array>
11
12// Custom.
13#include "misc/Error.h"
14#include "render/general/resource/shadow/ShadowMapArrayIndexManager.h"
15#include "ShadowMapType.hpp"
16
17namespace ne {
18 class GpuResource;
19 class GpuResourceManager;
20 class ShadowMapHandle;
21
30 // Unique pointers will notify the manager before destruction.
31 friend class ShadowMapHandle;
32
33 // Renderer will notify us when shadow quality setting is changed.
34 friend class Renderer;
35
36 // Pipeline manager notifies us about new pipelines or re-created pipelines to re-bind descriptors.
37 friend class PipelineManager;
38
39 public:
43 std::unique_ptr<GpuResource> pDepthTexture;
44
49 std::unique_ptr<GpuResource> pColorTexture;
50 };
51
55 std::unordered_map<ShadowMapHandle*, ShadowMapHandleResources> shadowMaps;
56
62 std::array<std::unique_ptr<ShadowMapArrayIndexManager>, static_cast<size_t>(ShadowMapType::SIZE)>
64 };
65
66 ShadowMapManager() = delete;
67 ShadowMapManager(const ShadowMapManager&) = delete;
68 ShadowMapManager& operator=(const ShadowMapManager&) = delete;
69
72
79 static int getShadowPassDepthBias();
80
87 static float getShadowPassDepthSlopeFactor();
88
95 static constexpr const char* getDirectionalShadowMapsShaderResourceName() {
97 }
98
104 static constexpr const char* getSpotShadowMapsShaderResourceName() {
106 }
107
113 static constexpr const char* getPointShadowMapsShaderResourceName() {
115 }
116
123 static constexpr float getVisibleDistanceToNearClipPlaneRatio() {
125 }
126
134 static std::variant<std::unique_ptr<ShadowMapManager>, Error>
136
151 std::variant<std::unique_ptr<ShadowMapHandle>, Error> createShadowMap(
152 const std::string& sResourceName,
153 ShadowMapType type,
154 const std::function<void(unsigned int)>& onArrayIndexChanged);
155
163 inline std::pair<std::recursive_mutex, InternalResources>* getInternalResources() {
164 return &mtxInternalResources;
165 }
166
172 Renderer* getRenderer() const;
173
174 private:
183 std::array<std::unique_ptr<ShadowMapArrayIndexManager>, static_cast<size_t>(ShadowMapType::SIZE)>
184 vShadowMapArrayIndexManagers);
185
193 [[nodiscard]] std::optional<Error> bindShadowMapsToPipeline(Pipeline* pPipeline);
194
200 [[nodiscard]] std::optional<Error> bindShadowMapsToAllPipelines();
201
208 void onShadowMapHandleBeingDestroyed(ShadowMapHandle* pHandleToResourceDestroy);
209
216 [[nodiscard]] std::optional<Error> recreateShadowMaps();
217
227 unsigned int
228 correctShadowMapResolutionForType(unsigned int iRenderSettingsShadowMapSize, ShadowMapType type);
229
243
253 std::pair<std::recursive_mutex, InternalResources> mtxInternalResources;
254
257
259 static constexpr float visibleDistanceToNearClipPlaneRatio = 0.004F; // NOLINT
260
262 static constexpr auto pDirectionalShadowMapsShaderResourceName = "directionalShadowMaps";
263
265 static constexpr auto pSpotShadowMapsShaderResourceName = "spotShadowMaps";
266
268 static constexpr auto pPointShadowMapsShaderResourceName = "pointShadowMaps";
269 };
270}
Definition: Error.h:27
Definition: GpuResourceManager.h:43
Definition: PipelineManager.h:54
Definition: Pipeline.h:20
Definition: Renderer.h:43
Definition: ShadowMapArrayIndexManager.h:25
Definition: ShadowMapHandle.h:23
Definition: ShadowMapManager.h:29
static constexpr auto pSpotShadowMapsShaderResourceName
Definition: ShadowMapManager.h:265
static constexpr auto pPointShadowMapsShaderResourceName
Definition: ShadowMapManager.h:268
Renderer * getRenderer() const
Definition: ShadowMapManager.cpp:125
std::pair< std::recursive_mutex, InternalResources > * getInternalResources()
Definition: ShadowMapManager.h:163
unsigned int correctShadowMapResolutionForType(unsigned int iRenderSettingsShadowMapSize, ShadowMapType type)
Definition: ShadowMapManager.cpp:258
void onShadowMapHandleBeingDestroyed(ShadowMapHandle *pHandleToResourceDestroy)
Definition: ShadowMapManager.cpp:142
static constexpr float visibleDistanceToNearClipPlaneRatio
Definition: ShadowMapManager.h:259
static constexpr const char * getSpotShadowMapsShaderResourceName()
Definition: ShadowMapManager.h:104
static constexpr const char * getPointShadowMapsShaderResourceName()
Definition: ShadowMapManager.h:113
static float getShadowPassDepthSlopeFactor()
Definition: ShadowMapManager.cpp:317
static constexpr auto pDirectionalShadowMapsShaderResourceName
Definition: ShadowMapManager.h:262
static int getShadowPassDepthBias()
Definition: ShadowMapManager.cpp:313
ShadowMapArrayIndexManager * getArrayIndexManagerBasedOnShadowMapType(ShadowMapType type)
Definition: ShadowMapManager.cpp:128
static constexpr float getVisibleDistanceToNearClipPlaneRatio()
Definition: ShadowMapManager.h:123
std::optional< Error > bindShadowMapsToAllPipelines()
Definition: ShadowMapManager.cpp:39
std::optional< Error > recreateShadowMaps()
Definition: ShadowMapManager.cpp:178
std::variant< std::unique_ptr< ShadowMapHandle >, Error > createShadowMap(const std::string &sResourceName, ShadowMapType type, const std::function< void(unsigned int)> &onArrayIndexChanged)
Definition: ShadowMapManager.cpp:54
GpuResourceManager * pResourceManager
Definition: ShadowMapManager.h:256
std::optional< Error > bindShadowMapsToPipeline(Pipeline *pPipeline)
Definition: ShadowMapManager.cpp:24
static constexpr const char * getDirectionalShadowMapsShaderResourceName()
Definition: ShadowMapManager.h:95
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: ShadowMapManager.h:253
~ShadowMapManager()
Definition: ShadowMapManager.cpp:280
static std::variant< std::unique_ptr< ShadowMapManager >, Error > create(GpuResourceManager *pResourceManager)
Definition: ShadowMapManager.cpp:322
Definition: ShadowMapManager.h:53
std::array< std::unique_ptr< ShadowMapArrayIndexManager >, static_cast< size_t >(ShadowMapType::SIZE)> vShadowMapArrayIndexManagers
Definition: ShadowMapManager.h:63
std::unordered_map< ShadowMapHandle *, ShadowMapHandleResources > shadowMaps
Definition: ShadowMapManager.h:55
Definition: ShadowMapManager.h:41
std::unique_ptr< GpuResource > pDepthTexture
Definition: ShadowMapManager.h:43
std::unique_ptr< GpuResource > pColorTexture
Definition: ShadowMapManager.h:49