Pyrogenesis trunk
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CShaderManager Class Reference

Shader manager: loads and caches shader programs. More...

#include <ShaderManager.h>

Collaboration diagram for CShaderManager:
Collaboration graph
[legend]

Classes

struct  CacheKey
 
struct  EffectCacheKey
 Key for effect cache lookups. More...
 
struct  EffectCacheKeyHash
 

Public Types

using PipelineStateDescCallback = CShaderTechnique::PipelineStateDescCallback
 Load a shader effect with the pipeline state description overwriting. More...
 

Public Member Functions

 CShaderManager (Renderer::Backend::IDevice *device)
 
 ~CShaderManager ()
 
CShaderTechniquePtr LoadEffect (CStrIntern name, const CShaderDefines &defines)
 Load a shader effect. More...
 
CShaderTechniquePtr LoadEffect (CStrIntern name)
 Load a shader effect, with empty defines. More...
 
CShaderTechniquePtr LoadEffect (CStrIntern name, const CShaderDefines &defines, const PipelineStateDescCallback &callback)
 
size_t GetNumEffectsLoaded () const
 Returns the number of shader effects that are currently loaded. More...
 

Private Types

using EffectCacheMap = std::unordered_map< EffectCacheKey, CShaderTechniquePtr, EffectCacheKeyHash >
 
template<typename T >
using HotloadFilesMap = std::unordered_map< VfsPath, std::set< std::weak_ptr< T >, std::owner_less< std::weak_ptr< T > > > >
 

Private Member Functions

CShaderProgramPtr LoadProgram (const CStr &name, const CShaderDefines &defines)
 Load a shader program. More...
 
bool LoadTechnique (CShaderTechniquePtr &tech)
 
Status ReloadChangedFile (const VfsPath &path)
 
void AddTechniqueFileDependency (const CShaderTechniquePtr &technique, const VfsPath &path)
 Associates the file with the technique to be reloaded if the file has changed. More...
 
void AddProgramFileDependency (const CShaderProgramPtr &program, const VfsPath &path)
 Associates the file with the program to be reloaded if the file has changed. More...
 

Static Private Member Functions

static Status ReloadChangedFileCB (void *param, const VfsPath &path)
 

Private Attributes

Renderer::Backend::IDevicem_Device = nullptr
 
std::map< CacheKey, CShaderProgramPtrm_ProgramCache
 
EffectCacheMap m_EffectCache
 
HotloadFilesMap< CShaderTechniquem_HotloadTechniques
 
HotloadFilesMap< CShaderProgramm_HotloadPrograms
 

Detailed Description

Shader manager: loads and caches shader programs.

For a high-level overview of shaders and materials, see http://trac.wildfiregames.com/wiki/MaterialSystem

Member Typedef Documentation

◆ EffectCacheMap

◆ HotloadFilesMap

template<typename T >
using CShaderManager::HotloadFilesMap = std::unordered_map< VfsPath, std::set<std::weak_ptr<T>, std::owner_less<std::weak_ptr<T> >> >
private

◆ PipelineStateDescCallback

Load a shader effect with the pipeline state description overwriting.

TODO: we should set all needed states in XML.

Constructor & Destructor Documentation

◆ CShaderManager()

CShaderManager::CShaderManager ( Renderer::Backend::IDevice device)

◆ ~CShaderManager()

CShaderManager::~CShaderManager ( )

Member Function Documentation

◆ AddProgramFileDependency()

void CShaderManager::AddProgramFileDependency ( const CShaderProgramPtr program,
const VfsPath path 
)
private

Associates the file with the program to be reloaded if the file has changed.

◆ AddTechniqueFileDependency()

void CShaderManager::AddTechniqueFileDependency ( const CShaderTechniquePtr technique,
const VfsPath path 
)
private

Associates the file with the technique to be reloaded if the file has changed.

◆ GetNumEffectsLoaded()

size_t CShaderManager::GetNumEffectsLoaded ( ) const

Returns the number of shader effects that are currently loaded.

◆ LoadEffect() [1/3]

CShaderTechniquePtr CShaderManager::LoadEffect ( CStrIntern  name)

Load a shader effect, with empty defines.

◆ LoadEffect() [2/3]

CShaderTechniquePtr CShaderManager::LoadEffect ( CStrIntern  name,
const CShaderDefines defines 
)

Load a shader effect.

Effects can be implemented via many techniques; this returns the best usable technique.

Parameters
namename of effect XML specification (file is loaded from shaders/effects/${name}.xml)
defineskey/value set of preprocessor definitions
Returns
loaded technique, or empty technique on error

◆ LoadEffect() [3/3]

CShaderTechniquePtr CShaderManager::LoadEffect ( CStrIntern  name,
const CShaderDefines defines,
const PipelineStateDescCallback callback 
)

◆ LoadProgram()

CShaderProgramPtr CShaderManager::LoadProgram ( const CStr &  name,
const CShaderDefines defines 
)
private

Load a shader program.

Parameters
namename of shader XML specification (file is loaded from shaders/${name}.xml)
defineskey/value set of preprocessor definitions
Returns
loaded program, or null pointer on error

◆ LoadTechnique()

bool CShaderManager::LoadTechnique ( CShaderTechniquePtr tech)
private

◆ ReloadChangedFile()

Status CShaderManager::ReloadChangedFile ( const VfsPath path)
private

◆ ReloadChangedFileCB()

Status CShaderManager::ReloadChangedFileCB ( void *  param,
const VfsPath path 
)
staticprivate

Member Data Documentation

◆ m_Device

Renderer::Backend::IDevice* CShaderManager::m_Device = nullptr
private

◆ m_EffectCache

EffectCacheMap CShaderManager::m_EffectCache
private

◆ m_HotloadPrograms

HotloadFilesMap<CShaderProgram> CShaderManager::m_HotloadPrograms
private

◆ m_HotloadTechniques

HotloadFilesMap<CShaderTechnique> CShaderManager::m_HotloadTechniques
private

◆ m_ProgramCache

std::map<CacheKey, CShaderProgramPtr> CShaderManager::m_ProgramCache
private

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