Nameless Engine
Loading...
Searching...
No Matches
ne::ShadowMapManager Class Reference

#include <ShadowMapManager.h>

Classes

struct  InternalResources
 
struct  ShadowMapHandleResources
 

Public Member Functions

 ShadowMapManager (const ShadowMapManager &)=delete
 
ShadowMapManageroperator= (const ShadowMapManager &)=delete
 
 ~ShadowMapManager ()
 
std::variant< std::unique_ptr< ShadowMapHandle >, ErrorcreateShadowMap (const std::string &sResourceName, ShadowMapType type, const std::function< void(unsigned int)> &onArrayIndexChanged)
 
std::pair< std::recursive_mutex, InternalResources > * getInternalResources ()
 
RenderergetRenderer () const
 

Static Public Member Functions

static int getShadowPassDepthBias ()
 
static float getShadowPassDepthSlopeFactor ()
 
static constexpr const char * getDirectionalShadowMapsShaderResourceName ()
 
static constexpr const char * getSpotShadowMapsShaderResourceName ()
 
static constexpr const char * getPointShadowMapsShaderResourceName ()
 
static constexpr float getVisibleDistanceToNearClipPlaneRatio ()
 
static std::variant< std::unique_ptr< ShadowMapManager >, Errorcreate (GpuResourceManager *pResourceManager)
 

Private Member Functions

 ShadowMapManager (GpuResourceManager *pResourceManager, std::array< std::unique_ptr< ShadowMapArrayIndexManager >, static_cast< size_t >(ShadowMapType::SIZE)> vShadowMapArrayIndexManagers)
 
std::optional< ErrorbindShadowMapsToPipeline (Pipeline *pPipeline)
 
std::optional< ErrorbindShadowMapsToAllPipelines ()
 
void onShadowMapHandleBeingDestroyed (ShadowMapHandle *pHandleToResourceDestroy)
 
std::optional< ErrorrecreateShadowMaps ()
 
unsigned int correctShadowMapResolutionForType (unsigned int iRenderSettingsShadowMapSize, ShadowMapType type)
 
ShadowMapArrayIndexManagergetArrayIndexManagerBasedOnShadowMapType (ShadowMapType type)
 

Private Attributes

std::pair< std::recursive_mutex, InternalResourcesmtxInternalResources
 
GpuResourceManagerpResourceManager = nullptr
 

Static Private Attributes

static constexpr float visibleDistanceToNearClipPlaneRatio = 0.004F
 
static constexpr auto pDirectionalShadowMapsShaderResourceName = "directionalShadowMaps"
 
static constexpr auto pSpotShadowMapsShaderResourceName = "spotShadowMaps"
 
static constexpr auto pPointShadowMapsShaderResourceName = "pointShadowMaps"
 

Friends

class ShadowMapHandle
 
class Renderer
 
class PipelineManager
 

Detailed Description

Stores all shadow maps.

Remarks
Although shadow maps are textures they are not managed by the texture manager because shadow maps are special (specific) textures and they need special treatment/management logic that texture manager should not care about.

Constructor & Destructor Documentation

◆ ~ShadowMapManager()

ne::ShadowMapManager::~ShadowMapManager ( )

Makes sure that no resource exists.

◆ ShadowMapManager()

ne::ShadowMapManager::ShadowMapManager ( GpuResourceManager pResourceManager,
std::array< std::unique_ptr< ShadowMapArrayIndexManager >, static_cast< size_t >(ShadowMapType::SIZE)>  vShadowMapArrayIndexManagers 
)
private

Initializes the manager.

Parameters
pResourceManagerResource manager that owns this object.
vShadowMapArrayIndexManagersArray index managers for various light source types

Member Function Documentation

◆ bindShadowMapsToAllPipelines()

std::optional< Error > ne::ShadowMapManager::bindShadowMapsToAllPipelines ( )
private

Goes through all graphics pipelines ad binds shadow maps to pipelines that use them.

Returns
Error if something went wrong.

◆ bindShadowMapsToPipeline()

std::optional< Error > ne::ShadowMapManager::bindShadowMapsToPipeline ( Pipeline pPipeline)
private

Looks if the specified pipeline uses shadow maps and if uses binds shadow maps to the pipeline.

Parameters
pPipelinePipeline to bind shadow maps to.
Returns
Error if something went wrong.

◆ correctShadowMapResolutionForType()

unsigned int ne::ShadowMapManager::correctShadowMapResolutionForType ( unsigned int  iRenderSettingsShadowMapSize,
ShadowMapType  type 
)
private

Returns shadow map texture size (in pixels) that should be used for the specified shadow map type. (the specified value might be corrected for the specified shadow map type).

Parameters
iRenderSettingsShadowMapSizeShadow map size from render settings.
typeShadow map size.
Returns
Shadow map size to use for this shadow map type.

◆ create()

std::variant< std::unique_ptr< ShadowMapManager >, Error > ne::ShadowMapManager::create ( GpuResourceManager pResourceManager)
static

Creates a new shadow map manager.

Parameters
pResourceManagerResource manager that owns this object.
Returns
Error if something went wrong, otherwise created shadow map manager.

◆ createShadowMap()

std::variant< std::unique_ptr< ShadowMapHandle >, Error > ne::ShadowMapManager::createShadowMap ( const std::string &  sResourceName,
ShadowMapType  type,
const std::function< void(unsigned int)> &  onArrayIndexChanged 
)

Creates a shadow map.

Parameters
sResourceNameName of the GPU resource that will be created, used for logging.
typeType of a shadow map to create depending on the light source type.
onArrayIndexChangedCalled after the index of the returned shadow map into the descriptor array of shadow maps was initialized/changed.
Returns
Error if something went wrong, otherwise created shadow map. Returning unique ptr although shadow map handle already behaves like unique ptr in order for the manager to be able to store raw pointers to handles without fearing that a raw pointer will point to invalid handle due to moveing the handle.

◆ getArrayIndexManagerBasedOnShadowMapType()

ShadowMapArrayIndexManager * ne::ShadowMapManager::getArrayIndexManagerBasedOnShadowMapType ( ShadowMapType  type)
private

Returns pointer to one of the array index managers from mtxInternalResources depending on the specified shadow map type.

Warning
Do not delete (free) returned pointer.
Remarks
Expects that mtxInternalResources is locked.
Parameters
typeType of the shadow map to determine the manager.
Returns
nullptr if specified not supported shadow map type, otherwise valid pointer.

◆ getDirectionalShadowMapsShaderResourceName()

static constexpr const char * ne::ShadowMapManager::getDirectionalShadowMapsShaderResourceName ( )
inlinestaticconstexpr

Returns name of the shader resource (from shader code) that stores all directional light shadow maps.

Returns
Shader resource name.

◆ getInternalResources()

std::pair< std::recursive_mutex, InternalResources > * ne::ShadowMapManager::getInternalResources ( )
inline

Returns internal resources of this manager.

Warning
Do not delete (free) returned pointer.
Returns
Internal resources.

◆ getPointShadowMapsShaderResourceName()

static constexpr const char * ne::ShadowMapManager::getPointShadowMapsShaderResourceName ( )
inlinestaticconstexpr

Returns name of the shader resource (from shader code) that stores all point light shadow maps.

Returns
Shader resource name.

◆ getRenderer()

Renderer * ne::ShadowMapManager::getRenderer ( ) const

Returns renderer.

Returns
Renderer.

◆ getShadowPassDepthBias()

int ne::ShadowMapManager::getShadowPassDepthBias ( )
static

Constant depth bias (offset) to apply when rendering depth to shadow maps to avoid an effect known as "shadow acne" (stair-stepping).

Returns
Constant depth bias.

◆ getShadowPassDepthSlopeFactor()

float ne::ShadowMapManager::getShadowPassDepthSlopeFactor ( )
static

Constant depth slope bias (multiplier) to apply when rendering depth to shadow maps to avoid an effect known as "shadow acne" (stair-stepping).

Returns
Constant depth slope factor.

◆ getSpotShadowMapsShaderResourceName()

static constexpr const char * ne::ShadowMapManager::getSpotShadowMapsShaderResourceName ( )
inlinestaticconstexpr

Returns name of the shader resource (from shader code) that stores all spot light shadow maps.

Returns
Shader resource name.

◆ getVisibleDistanceToNearClipPlaneRatio()

static constexpr float ne::ShadowMapManager::getVisibleDistanceToNearClipPlaneRatio ( )
inlinestaticconstexpr

Returns constant used to convert visible (non-clipped) distance to near clip plane for shadow mapping.

Returns
Far to near Z ratio.

◆ onShadowMapHandleBeingDestroyed()

void ne::ShadowMapManager::onShadowMapHandleBeingDestroyed ( ShadowMapHandle pHandleToResourceDestroy)
private

Called by destructor of shadow map handle to notify the manager that a resource is no longer used.

Parameters
pHandleToResourceDestroyHandle to resource to destroy.

◆ recreateShadowMaps()

std::optional< Error > ne::ShadowMapManager::recreateShadowMaps ( )
private

Called by the renderer to notify the manager that shadow quality setting was changed and all shadow maps should now be re-created using the new shadow map resolution.

Returns
Error if something went wrong.

Member Data Documentation

◆ mtxInternalResources

std::pair<std::recursive_mutex, InternalResources> ne::ShadowMapManager::mtxInternalResources
private

Allocated shadow maps.

Remarks
Storing pairs of "raw pointer" - "unique pointer" to quickly find needed resources when need to destroy some resource given a raw pointer.
Storing raw pointers here is safe because shadow map handle will notify us before destroying the resource so we will remove the raw pointer and shadow map handle

◆ pDirectionalShadowMapsShaderResourceName

constexpr auto ne::ShadowMapManager::pDirectionalShadowMapsShaderResourceName = "directionalShadowMaps"
staticconstexprprivate

Name of the shader resource (from shader code) that stores all directional shadow maps.

◆ pPointShadowMapsShaderResourceName

constexpr auto ne::ShadowMapManager::pPointShadowMapsShaderResourceName = "pointShadowMaps"
staticconstexprprivate

Name of the shader resource (from shader code) that stores all point shadow maps.

◆ pResourceManager

GpuResourceManager* ne::ShadowMapManager::pResourceManager = nullptr
private

Do not delete (free) this pointer. GPU resource manager that owns this object.

◆ pSpotShadowMapsShaderResourceName

constexpr auto ne::ShadowMapManager::pSpotShadowMapsShaderResourceName = "spotShadowMaps"
staticconstexprprivate

Name of the shader resource (from shader code) that stores all spot shadow maps.

◆ visibleDistanceToNearClipPlaneRatio

constexpr float ne::ShadowMapManager::visibleDistanceToNearClipPlaneRatio = 0.004F
staticconstexprprivate

Constant used to convert visible (non-clipped) distance to near clip plane for shadow mapping.


The documentation for this class was generated from the following files: