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

#include <ShaderTextureResourceBindingManager.h>

Public Member Functions

 ShaderTextureResourceBindingManager (const ShaderTextureResourceBindingManager &)=delete
 
ShaderTextureResourceBindingManageroperator= (const ShaderTextureResourceBindingManager &)=delete
 
 ~ShaderTextureResourceBindingManager ()
 
std::variant< ShaderTextureResourceBindingUniquePtr, ErrorcreateShaderTextureResource (const std::string &sShaderResourceName, const std::string &sResourceAdditionalInfo, const std::unordered_set< Pipeline * > &pipelinesToUse, std::unique_ptr< TextureHandle > pTextureToUse)
 
std::pair< std::recursive_mutex, std::unordered_map< ShaderTextureResourceBinding *, std::unique_ptr< ShaderTextureResourceBinding > > > * getResources ()
 

Private Member Functions

 ShaderTextureResourceBindingManager (Renderer *pRenderer)
 
std::variant< ShaderTextureResourceBindingUniquePtr, ErrorhandleResourceCreation (std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Error > result)
 
void destroyResource (ShaderTextureResourceBinding *pResourceToDestroy)
 

Private Attributes

RendererpRenderer = nullptr
 
std::pair< std::recursive_mutex, std::unordered_map< ShaderTextureResourceBinding *, std::unique_ptr< ShaderTextureResourceBinding > > > mtxShaderTextureResources
 

Friends

class Renderer
 
class ShaderTextureResourceBindingUniquePtr
 

Detailed Description

Owns all shader resources that references texture resource.

Remarks
This manager does not really do anything but it provides a single and thread-safe way to interact with all shader resources. Initial motivation for this manager was to have a safe way to notify all texture resources using ShaderResourceBase::onAfterAllPipelinesRefreshedResources from pipeline manager (to avoid running this function on not fully initialized shader resources or shader resources that are being destroyed because this could happen if instead of this manager we just had some notifications on ShaderResourceBase constructor/destructor).

Constructor & Destructor Documentation

◆ ~ShaderTextureResourceBindingManager()

ne::ShaderTextureResourceBindingManager::~ShaderTextureResourceBindingManager ( )

Makes sure that no resource exists.

◆ ShaderTextureResourceBindingManager()

ne::ShaderTextureResourceBindingManager::ShaderTextureResourceBindingManager ( Renderer pRenderer)
private

Initializes manager.

Parameters
pRenderer

Member Function Documentation

◆ createShaderTextureResource()

std::variant< ShaderTextureResourceBindingUniquePtr, Error > ne::ShaderTextureResourceBindingManager::createShaderTextureResource ( const std::string &  sShaderResourceName,
const std::string &  sResourceAdditionalInfo,
const std::unordered_set< Pipeline * > &  pipelinesToUse,
std::unique_ptr< TextureHandle pTextureToUse 
)

Creates a new render-specific shader resource.

Parameters
sShaderResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
sResourceAdditionalInfoAdditional text that we will append to created resource name (used for logging).
pipelinesToUsePipelines that use shader/parameters we are referencing.
pTextureToUseTexture that should be binded to a descriptor.
Returns
Error if something went wrong, otherwise created shader resource.

◆ destroyResource()

void ne::ShaderTextureResourceBindingManager::destroyResource ( ShaderTextureResourceBinding pResourceToDestroy)
private

Called by shader texture resource unique pointers to destroy the specified resource because it will no longer be used.

Parameters
pResourceToDestroyResource to destroy.

◆ getResources()

std::pair< std::recursive_mutex, std::unordered_map< ShaderTextureResourceBinding *, std::unique_ptr< ShaderTextureResourceBinding > > > * ne::ShaderTextureResourceBindingManager::getResources ( )

Returns all shader resources that reference textures.

Remarks
Do not free (delete) or modify unique pointers or returned map.
Returns
Internal resources.

◆ handleResourceCreation()

std::variant< ShaderTextureResourceBindingUniquePtr, Error > ne::ShaderTextureResourceBindingManager::handleResourceCreation ( std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Error result)
private

Processes resource creation.

Parameters
resultResult of resource creation function.
Returns
Result of resource creation.

Member Data Documentation

◆ mtxShaderTextureResources

std::pair< std::recursive_mutex, std::unordered_map<ShaderTextureResourceBinding*, std::unique_ptr<ShaderTextureResourceBinding> > > ne::ShaderTextureResourceBindingManager::mtxShaderTextureResources
private

Shader texture resources.

Remarks
Storing pairs of "raw pointer" - "unique pointer" to quickly find needed resources when need to destroy some resource given a raw pointer.

◆ pRenderer

Renderer* ne::ShaderTextureResourceBindingManager::pRenderer = nullptr
private

Renderer that owns this manager.


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