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

#include <ShaderUser.h>

Inheritance diagram for ne::ShaderUser:
ne::Pipeline ne::DirectXPso ne::VulkanPipeline

Public Member Functions

 ShaderUser (const ShaderUser &)=delete
 
ShaderUseroperator= (const ShaderUser &)=delete
 

Protected Member Functions

 ShaderUser (ShaderManager *pShaderManager)
 
virtual ~ShaderUser ()
 
bool addShader (const std::string &sShaderName)
 
ShaderPackfindShader (ShaderType shaderType)
 

Private Member Functions

void releaseShader (const std::string &sShaderName) const
 

Private Attributes

std::pair< std::mutex, std::unordered_map< ShaderType, std::shared_ptr< ShaderPack > > > mtxAssignedShaders
 
ShaderManagerpShaderManager
 

Detailed Description

The only class that is allowed to store shaders (not counting ShaderManager).

Other classes should inherit from this class in order to work with shaders.

Allows storing one shader per shader type.

Constructor & Destructor Documentation

◆ ShaderUser()

ne::ShaderUser::ShaderUser ( ShaderManager pShaderManager)
protected

Constructor.

Parameters
pShaderManagerShader manager to use.

◆ ~ShaderUser()

ne::ShaderUser::~ShaderUser ( )
protectedvirtual

Destructor.

Member Function Documentation

◆ addShader()

bool ne::ShaderUser::addShader ( const std::string &  sShaderName)
protected

Adds a shader to be stored (for usage).

Warning
If a shader of this type was already added it will be replaced with the new one.
Remarks
Adding the same shader that was already added is safe as this will do nothing.
Parameters
sShaderNameName of the compiled shader (see ShaderManager::compileShaders).
Returns
false if shader was added successfully, true if it was not found in ShaderManager.

◆ findShader()

ShaderPack * ne::ShaderUser::findShader ( ShaderType  shaderType)
protected

Looks for a previously added shader (see addShader) for the specified type.

Warning
Do not delete returned pointer. Returned shader will not be destroyed until this ShaderUser object is not destroyed. Once this ShaderUser object is destroyed there is no guarantee that the shader will be valid.
Parameters
shaderTypeType of the shader to query.
Returns
nullptr if a shader of this type was not added before, valid pointer otherwise.

◆ releaseShader()

void ne::ShaderUser::releaseShader ( const std::string &  sShaderName) const
private

Uses ShaderManager to release shader bytecode if needed and removes shader if it was marked as "to remove".

Parameters
sShaderNameName of the shader to release.

Member Data Documentation

◆ mtxAssignedShaders

std::pair<std::mutex, std::unordered_map<ShaderType, std::shared_ptr<ShaderPack> > > ne::ShaderUser::mtxAssignedShaders
private

Assigned shaders (see addShader). Must be used with mutex.

◆ pShaderManager

ShaderManager* ne::ShaderUser::pShaderManager
private

Shader manager to work with shaders.


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