MAGE  v0.171.0
Matthias Advanced Game Engine
mage::rendering::ResourceManager Class Reference

#include <rendering_resource_manager.hpp>

Classes

struct  ResourceRecord
 
struct  ResourceRecord< ResourceT, typename std::enable_if_t< !is_shader_v< ResourceT > > >
 
struct  ResourceRecord< ResourceT, typename std::enable_if_t< is_shader_v< ResourceT > > >
 

Public Types

template<typename ResourceT >
using pool_type = typename ResourceRecord< ResourceT >::pool_type
 
template<typename ResourceT >
using key_type = typename pool_type< ResourceT >::key_type
 
template<typename ResourceT >
using value_type = typename pool_type< ResourceT >::value_type
 

Public Member Functions

 ResourceManager (ID3D11Device &device)
 
 ResourceManager (const ResourceManager &manager)=delete
 
 ResourceManager (ResourceManager &&manager) noexcept
 
 ~ResourceManager ()
 
ResourceManageroperator= (const ResourceManager &manager)=delete
 
ResourceManageroperator= (ResourceManager &&manager)=delete
 
template<typename ResourceT >
bool Contains (const typename key_type< ResourceT > &guid) noexcept
 
template<typename ResourceT >
SharedPtr< typename value_type< ResourceT > > Get (const typename key_type< ResourceT > &guid) noexcept
 
template<typename ResourceT , typename VertexT , typename IndexT >
std::enable_if_t< std::is_same_v< ModelDescriptor, ResourceT >, ModelDescriptorPtrGetOrCreate (const std::wstring &fname, const MeshDescriptor< VertexT, IndexT > &desc=MeshDescriptor< VertexT, IndexT >(), bool export_as_MDL=false)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< VertexShader, ResourceT >, VertexShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader, gsl::span< const D3D11_INPUT_ELEMENT_DESC > input_element_descs)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< HullShader, ResourceT >, HullShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< DomainShader, ResourceT >, DomainShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< GeometryShader, ResourceT >, GeometryShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< PixelShader, ResourceT >, PixelShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< ComputeShader, ResourceT >, ComputeShaderPtrGetOrCreate (const std::wstring &guid, const CompiledShader &compiled_shader)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< SpriteFont, ResourceT >, SpriteFontPtrGetOrCreate (const std::wstring &fname, const SpriteFontDescriptor &desc=SpriteFontDescriptor())
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< Texture, ResourceT >, TexturePtrGetOrCreate (const std::wstring &fname)
 
template<typename ResourceT >
std::enable_if_t< std::is_same_v< Texture, ResourceT >, TexturePtrGetOrCreate (const std::wstring &guid, const D3D11_TEXTURE2D_DESC &desc, const D3D11_SUBRESOURCE_DATA &initial_data)
 

Private Member Functions

template<typename ResourceT >
pool_type< ResourceT > & GetPool () noexcept
 
template<typename ResourceT >
const pool_type< ResourceT > & GetPool () const noexcept
 

Private Attributes

ID3D11Device & m_device
 
pool_type< ModelDescriptorm_model_descriptor_pool
 
pool_type< VertexShaderm_vs_pool
 
pool_type< HullShaderm_hs_pool
 
pool_type< DomainShaderm_ds_pool
 
pool_type< GeometryShaderm_gs_pool
 
pool_type< PixelShaderm_ps_pool
 
pool_type< ComputeShaderm_cs_pool
 
pool_type< SpriteFontm_sprite_font_pool
 
pool_type< Texturem_texture_pool
 

Detailed Description

A class of resource managers.

Member Typedef Documentation

◆ key_type

template<typename ResourceT >
using mage::rendering::ResourceManager::key_type = typename pool_type< ResourceT >::key_type

The key type of resource pools containing resources of the given type.

Template Parameters
ResourceTThe resource type.

◆ pool_type

template<typename ResourceT >
using mage::rendering::ResourceManager::pool_type = typename ResourceRecord< ResourceT >::pool_type

The pool type of resource pools containing resources of the given type.

Template Parameters
ResourceTThe resource type.

◆ value_type

template<typename ResourceT >
using mage::rendering::ResourceManager::value_type = typename pool_type< ResourceT >::value_type

The value type of resource pools containing resources of the given type.

Template Parameters
ResourceTThe resource type.

Constructor & Destructor Documentation

◆ ResourceManager() [1/3]

mage::rendering::ResourceManager::ResourceManager ( ID3D11Device &  device)
explicit

Constructs a resource manager.

Parameters
[in,out]deviceA reference to the device.

◆ ResourceManager() [2/3]

mage::rendering::ResourceManager::ResourceManager ( const ResourceManager manager)
delete

Constructs a resource manager from the given resource manager.

Parameters
[in]managerA reference to the resource manager to copy.

◆ ResourceManager() [3/3]

mage::rendering::ResourceManager::ResourceManager ( ResourceManager &&  manager)
defaultnoexcept

Constructs a resource manager by moving the given resource manager.

Parameters
[in]managerA reference to the resource manager to move.

◆ ~ResourceManager()

mage::rendering::ResourceManager::~ResourceManager ( )
default

Destructs this resource manager.

Member Function Documentation

◆ Contains()

template<typename ResourceT >
bool mage::rendering::ResourceManager::Contains ( const typename key_type< ResourceT > &  guid)
noexcept

Checks whether this resource manager contains a resource of the given type corresponding to the given globally unique identifier.

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidA reference to the globally unique identifier of the resource.
Returns
true if this resource managers contains a resource of the given type corresponding to the given globally unique identifier. false otherwise.

◆ Get()

template<typename ResourceT >
SharedPtr< typename value_type< ResourceT > > mage::rendering::ResourceManager::Get ( const typename key_type< ResourceT > &  guid)
noexcept

Returns the resource of the given type corresponding to the given globally unique identifier of this resource manager.

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidA reference to the globally unique identifier of the model descriptor.
Returns
nullptr, if this resource managers does not contain a resource of the given type corresponding to the given globally unique identifier.
A pointer to the resource.

◆ GetOrCreate() [1/10]

template<typename ResourceT , typename VertexT , typename IndexT >
std::enable_if_t< std::is_same_v< ModelDescriptor, ResourceT >, ModelDescriptorPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  fname,
const MeshDescriptor< VertexT, IndexT > &  desc = MeshDescriptor< VertexT, IndexT >(),
bool  export_as_MDL = false 
)

Creates a model descriptor (if not existing).

Template Parameters
ResourceTThe resource type.
VertexTThe vertex type.
IndexTThe index type.
Parameters
[in]fnameThe filename (the globally unique identifier).
[in]descA reference to the mesh descriptor.
[in]export_as_MDLtrue if the model descriptor needs to be exported as MDL file. false otherwise.
Returns
A pointer to the model descriptor.
Exceptions
ExceptionFailed to create the model descriptor.

◆ GetOrCreate() [2/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< VertexShader, ResourceT >, VertexShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader,
gsl::span< const D3D11_INPUT_ELEMENT_DESC >  input_element_descs 
)

Creates a vertex shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled vertex shader.
[in]input_element_descsThe input element descriptors.
Returns
A pointer to the vertex shader.
Exceptions
ExceptionFailed to create the vertex shader.

◆ GetOrCreate() [3/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< HullShader, ResourceT >, HullShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader 
)

Creates a hull shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled shader.
Returns
A pointer to the hull shader.
Exceptions
ExceptionFailed to create the hull shader.

◆ GetOrCreate() [4/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< DomainShader, ResourceT >, DomainShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader 
)

Creates a domain shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled shader.
Returns
A pointer to the domain shader.
Exceptions
ExceptionFailed to create the domain shader.

◆ GetOrCreate() [5/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< GeometryShader, ResourceT >, GeometryShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader 
)

Creates a geometry shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled shader.
Returns
A pointer to the geometry shader.
Exceptions
ExceptionFailed to create the geometry shader.

◆ GetOrCreate() [6/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< PixelShader, ResourceT >, PixelShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader 
)

Creates a pixel shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled shader.
Returns
A pointer to the pixel shader.
Exceptions
ExceptionFailed to create the pixel shader.

◆ GetOrCreate() [7/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< ComputeShader, ResourceT >, ComputeShaderPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const CompiledShader compiled_shader 
)

Creates a compute shader (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]compiled_shaderA reference to the compiled shader.
Returns
A pointer to the hull shader.
Exceptions
ExceptionFailed to create the compute shader.

◆ GetOrCreate() [8/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< SpriteFont, ResourceT >, SpriteFontPtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  fname,
const SpriteFontDescriptor desc = SpriteFontDescriptor() 
)

Creates a sprite font (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]fnameThe filename (the globally unique identifier).
[in]descA reference to the sprite font descriptor.
Returns
A pointer to the sprite font.
Exceptions
ExceptionFailed to create the sprite font.

◆ GetOrCreate() [9/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< Texture, ResourceT >, TexturePtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  fname)

Creates a texture (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]fnameThe filename (the globally unique identifier).
Returns
A pointer to the texture.
Exceptions
ExceptionFailed to create the texture.

◆ GetOrCreate() [10/10]

template<typename ResourceT >
std::enable_if_t< std::is_same_v< Texture, ResourceT >, TexturePtr > mage::rendering::ResourceManager::GetOrCreate ( const std::wstring &  guid,
const D3D11_TEXTURE2D_DESC &  desc,
const D3D11_SUBRESOURCE_DATA &  initial_data 
)

Creates a texture (if not existing).

Template Parameters
ResourceTThe resource type.
Parameters
[in]guidThe globally unique identifier.
[in]descA reference to the texture descriptor.
[in]initial_dataA reference to the initial data.
Returns
A pointer to the texture.
Exceptions
ExceptionFailed to create the texture.

◆ GetPool() [1/2]

template<typename ResourceT >
pool_type< ResourceT >& mage::rendering::ResourceManager::GetPool ( )
privatenoexcept

Returns the resource pool containing resources of the given type of this resource manager.

Template Parameters
ResourceTThe resource type.
Returns
A reference to the the resource pool containing resources of the given type of this resource manager.

◆ GetPool() [2/2]

template<typename ResourceT >
const pool_type< ResourceT >& mage::rendering::ResourceManager::GetPool ( ) const
privatenoexcept

Returns the resource pool containing resources of the given type of this resource manager.

Template Parameters
ResourceTThe resource type.
Returns
A reference to the the resource pool containing resources of the given type of this resource manager.

◆ operator=() [1/2]

ResourceManager& mage::rendering::ResourceManager::operator= ( const ResourceManager manager)
delete

Copies the given resource manager to this resource manager.

Parameters
[in]managerA reference to the resource manager to copy.
Returns
A reference to the copy of the given resource manager (i.e. this resource manager).

◆ operator=() [2/2]

ResourceManager& mage::rendering::ResourceManager::operator= ( ResourceManager &&  manager)
delete

Moves the given resource manager to this resource manager.

Parameters
[in]managerA reference to the resource manager to move.
Returns
A reference to the moved resource manager (i.e. this resource manager).

Member Data Documentation

◆ m_cs_pool

pool_type< ComputeShader > mage::rendering::ResourceManager::m_cs_pool
private

The compute shader resource pool of this resource manager.

◆ m_device

ID3D11Device& mage::rendering::ResourceManager::m_device
private

A reference to the device of this resource manager.

◆ m_ds_pool

pool_type< DomainShader > mage::rendering::ResourceManager::m_ds_pool
private

The domain shader resource pool of this resource manager.

◆ m_gs_pool

pool_type< GeometryShader > mage::rendering::ResourceManager::m_gs_pool
private

The geometry shader resource pool of this resource manager.

◆ m_hs_pool

pool_type< HullShader > mage::rendering::ResourceManager::m_hs_pool
private

The hull shader resource pool of this resource manager.

◆ m_model_descriptor_pool

pool_type< ModelDescriptor > mage::rendering::ResourceManager::m_model_descriptor_pool
private

The model descriptor resource pool of this resource manager.

◆ m_ps_pool

pool_type< PixelShader > mage::rendering::ResourceManager::m_ps_pool
private

The pixel shader resource pool of this resource manager.

◆ m_sprite_font_pool

pool_type< SpriteFont > mage::rendering::ResourceManager::m_sprite_font_pool
private

The sprite font resource pool of this resource manager.

◆ m_texture_pool

pool_type< Texture > mage::rendering::ResourceManager::m_texture_pool
private

The texture resource pool of this resource manager.

◆ m_vs_pool

pool_type< VertexShader > mage::rendering::ResourceManager::m_vs_pool
private

The vertex shader resource pool of this resource manager.