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

#include <ShaderPack.h>

Classes

struct  InternalResources
 

Public Member Functions

 ShaderPack (const ShaderPack &)=delete
 
ShaderPackoperator= (const ShaderPack &)=delete
 
bool releaseShaderPackDataFromMemoryIfLoaded ()
 
std::shared_ptr< ShadergetShader (const std::set< ShaderMacro > &shaderConfiguration)
 
std::string getShaderName () const
 
ShaderType getShaderType ()
 
std::pair< std::mutex, InternalResources > * getInternalResources ()
 

Static Public Member Functions

static std::variant< std::shared_ptr< ShaderPack >, std::string, ErrorcompileShaderPack (Renderer *pRenderer, const ShaderDescription &shaderDescription)
 
static std::variant< std::shared_ptr< ShaderPack >, ErrorcreateFromCache (Renderer *pRenderer, const ShaderDescription &shaderDescription, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason)
 

Private Member Functions

 ShaderPack (const std::string &sShaderName, ShaderType shaderType)
 

Static Private Member Functions

static void addEngineMacrosToShaderDescription (ShaderDescription &description, const std::set< ShaderMacro > &shaderConfigurationMacros, Renderer *pRenderer)
 

Private Attributes

std::pair< std::mutex, InternalResourcesmtxInternalResources
 
std::string sShaderName
 
ShaderType shaderType
 

Friends

class ShaderManager
 

Detailed Description

Represents a group of different variants of one shader (typically this means one shader compiled with different combinations of predefined macros).

Constructor & Destructor Documentation

◆ ShaderPack()

ne::ShaderPack::ShaderPack ( const std::string &  sShaderName,
ShaderType  shaderType 
)
private

Constructor to create an empty shader pack.

Parameters
sShaderNameInitial name of the shader.
shaderTypeType of shaders this pack stores.

Member Function Documentation

◆ addEngineMacrosToShaderDescription()

void ne::ShaderPack::addEngineMacrosToShaderDescription ( ShaderDescription description,
const std::set< ShaderMacro > &  shaderConfigurationMacros,
Renderer pRenderer 
)
staticprivate

Adds additional defined macros to shader description that engine shaders expect.

Parameters
descriptionShader description to modify.
shaderConfigurationMacrosMacros of the current shader configuration to add.
pRendererUsed renderer.

◆ compileShaderPack()

std::variant< std::shared_ptr< ShaderPack >, std::string, Error > ne::ShaderPack::compileShaderPack ( Renderer pRenderer,
const ShaderDescription shaderDescription 
)
static

Compiles a shader pack.

Parameters
pRendererUsed renderer.
shaderDescriptionDescription that describes the shader and how the shader should be compiled.
Returns
One of the three values: compiled shader pack, string containing shader compilation error/warning, internal error

◆ createFromCache()

std::variant< std::shared_ptr< ShaderPack >, Error > ne::ShaderPack::createFromCache ( Renderer pRenderer,
const ShaderDescription shaderDescription,
std::optional< ShaderCacheInvalidationReason > &  cacheInvalidationReason 
)
static

Creates a new shader pack using shader cache on the disk.

Parameters
pRendererUsed renderer.
shaderDescriptionDescription that describes the shader and how the shader should be compiled. Used for cache invalidation.
cacheInvalidationReasonWill be not empty if cache was invalidated. Used for testing.
Returns
Error if shader cache is corrupted or invalid, this also means that corrupted/invalid shader cache directory was deleted and cache for this shader no longer exists, otherwise a shader pack created using cache.

◆ getInternalResources()

std::pair< std::mutex, ShaderPack::InternalResources > * ne::ShaderPack::getInternalResources ( )

Returns internal resources that this shader pack uses.

Returns
Internal resources.

◆ getShader()

std::shared_ptr< Shader > ne::ShaderPack::getShader ( const std::set< ShaderMacro > &  shaderConfiguration)

Returns a shader that matches the the specified shader configuration.

Remarks
If the a shader that matches the target configuration is not found an error will be shown and an exception will be thrown.
Parameters
shaderConfigurationMacros that must be defined for the shader.
Returns
Found shader.

◆ getShaderName()

std::string ne::ShaderPack::getShaderName ( ) const

Returns unique name of this shader.

Returns
Unique name of this shader.

◆ getShaderType()

ShaderType ne::ShaderPack::getShaderType ( )

Returns type of this shader.

Returns
Shader type.

◆ releaseShaderPackDataFromMemoryIfLoaded()

bool ne::ShaderPack::releaseShaderPackDataFromMemoryIfLoaded ( )

Releases underlying shader bytecode for each shader from memory (this object will not be deleted) if the shader bytecode was loaded into memory. Next time this shader will be needed it will be loaded from disk.

Returns
false if at least one shader variant was released from memory, true if all variants were not loaded into memory.

Member Data Documentation

◆ mtxInternalResources

std::pair<std::mutex, InternalResources> ne::ShaderPack::mtxInternalResources
private

Used data.

◆ shaderType

ShaderType ne::ShaderPack::shaderType
private

Type of shaders this pack stores.

◆ sShaderName

std::string ne::ShaderPack::sShaderName
private

Initial shader name (without configuration text).


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