Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CShaderManager Class Reference

Centralized manager for loading, caching, rebuilding, and controlling shader objects in Skylicht-Engine. More...

#include <Material/Shader/CShaderManager.h>

Public Member Functions

 CShaderManager ()
 Constructor.
virtual ~CShaderManager ()
 Destructor. Releases all loaded shaders.
void releaseAll ()
 Release all loaded shaders and associated resources.
void setCurrentMeshBuffer (IMeshBuffer *buffer)
 Set the mesh buffer to be used for current rendering.
IMeshBuffergetCurrentMeshBuffer ()
 Get the mesh buffer currently used for rendering.
void setCurrentMaterial (SMaterial &mat)
 Set the material to be used for current rendering.
SMaterialgetCurrentMaterial ()
 Get the material currently used for rendering.
void initGUIShader ()
 Initialize built-in GUI shaders required for Skylicht's UI rendering.
void initBasicShader ()
 Initialize basic built-in shaders for basic rendering features.
void initSGDeferredShader ()
 Initialize built-in shaders for Specular-Glossiness Deferred rendering.
void initSGForwarderShader ()
 Initialize built-in shaders for Specular-Glossiness Forward rendering.
void initMobileSGShader ()
 Initialize built-in shaders for mobile platforms.
void initPBRForwarderShader ()
 Initialize built-in shaders for Physically-Based Rendering (PBR) forward pipeline.
void initSkylichtEngineShader ()
 Initialize all core engine shaders (deferred, forward, etc.).
void initShader ()
 Initialize all shader systems (calls basic and engine shader initializers).
CShaderloadShader (const char *shaderConfig)
 Load a shader from an XML configuration file. If the shader is already loaded, returns the cached instance.
bool rebuildShader (CShader *shader)
 Rebuild a shader by reloading its configuration from source file. Useful for hot-reloading, debugging, or updating shaders at runtime.
int getShaderIDByName (const char *name)
 Get the material ID of a shader by its name.
CShadergetShaderByName (const char *name)
 Get a shader instance by its name.
CShadergetShaderByPath (const char *path)
 Get a shader instance by its source path.
CShadergetShaderByID (int id)
 Get a shader instance by its internal material ID.
std::string getShaderFileName (const char *fileName)
 Get the shader file name with the appropriate extension for the current graphics API. Appends .hlsl for Direct3D, .glsl for OpenGL.
int getNumShader ()
 Get the number of loaded shader materials.
CShadergetShader (int i)
 Get a loaded shader material by index.

Public Attributes

core::vector2df ShaderVec2 [10]
core::vector3df ShaderVec3 [10]
video::SVec4 ShaderVec4 [10]
f32BoneMatrix
u32 BoneCount
float LightmapIndex
std::function< IShaderInstancing *(const char *)> OnCreateInstancingVertex

Protected Member Functions

bool buildShader (CShader *shader, io::IXMLReader *xmlReader, const char *source, const char *shaderFolder, bool rebuild)
 Internal function to build a shader from XML, source, and folder. Handles dependency loading, instancing setup, and error logging.

Protected Attributes

IMeshBufferm_currentMeshBuffer
 Pointer to mesh buffer currently being rendered.
SMaterialm_currentMatRendering
 Pointer to material currently being rendered.
std::vector< CShader * > m_listShader
 List of loaded shaders.
std::map< std::string, int > m_listShaderID
 Map from shader name to internal material ID.

Detailed Description

Centralized manager for loading, caching, rebuilding, and controlling shader objects in Skylicht-Engine.

Handles initialization of built - in shaders for various rendering pipelines(basic, deferred, forward, mobile, PBR, etc.), manages shader instancing, uniform storage, and provides lookup functions for accessing shaders by name, path, or ID.

Allows for dynamic shader loading, rebuilding, and provides access to current rendering context (mesh / material).

Example usage :

CShaderManager *shaderMgr = CShaderManager::getInstance();
shaderMgr->loadShader("BuiltIn/Shader/Transparent/Transparent.xml");
CShaderManager()
Constructor.
CShader * loadShader(const char *shaderConfig)
Load a shader from an XML configuration file. If the shader is already loaded, returns the cached ins...

Member Function Documentation

◆ buildShader()

bool Skylicht::CShaderManager::buildShader ( CShader * shader,
io::IXMLReader * xmlReader,
const char * source,
const char * shaderFolder,
bool rebuild )
protected

Internal function to build a shader from XML, source, and folder. Handles dependency loading, instancing setup, and error logging.

Parameters
shaderPointer to shader to build.
xmlReaderXML reader for shader config.
sourceSource path.
shaderFolderShader folder path.
rebuildTrue if rebuilding, false if initial load.
Returns
True if successful, false otherwise.

◆ getCurrentMaterial()

SMaterial * Skylicht::CShaderManager::getCurrentMaterial ( )
inline

Get the material currently used for rendering.

Returns
Pointer to current material.

◆ getCurrentMeshBuffer()

IMeshBuffer * Skylicht::CShaderManager::getCurrentMeshBuffer ( )
inline

Get the mesh buffer currently used for rendering.

Returns
Pointer to current mesh buffer.

◆ getNumShader()

int Skylicht::CShaderManager::getNumShader ( )
inline

Get the number of loaded shader materials.

Returns
Number of loaded shaders.

◆ getShader()

CShader * Skylicht::CShaderManager::getShader ( int i)
inline

Get a loaded shader material by index.

Parameters
iIndex of the shader.
Returns
Pointer to the CShader instance.

◆ getShaderByID()

CShader * Skylicht::CShaderManager::getShaderByID ( int id)

Get a shader instance by its internal material ID.

Parameters
idInternal material ID.
Returns
Pointer to the CShader instance, or NULL if not found.

◆ getShaderByName()

CShader * Skylicht::CShaderManager::getShaderByName ( const char * name)

Get a shader instance by its name.

Parameters
nameName of the shader.
Returns
Pointer to the CShader instance, or NULL if not found.

◆ getShaderByPath()

CShader * Skylicht::CShaderManager::getShaderByPath ( const char * path)

Get a shader instance by its source path.

Parameters
pathPath to shader source/config file.
Returns
Pointer to the CShader instance, or NULL if not found.

◆ getShaderFileName()

std::string Skylicht::CShaderManager::getShaderFileName ( const char * fileName)

Get the shader file name with the appropriate extension for the current graphics API. Appends .hlsl for Direct3D, .glsl for OpenGL.

Parameters
fileNameBase file name.
Returns
Shader file name with extension.

◆ getShaderIDByName()

int Skylicht::CShaderManager::getShaderIDByName ( const char * name)

Get the material ID of a shader by its name.

Parameters
nameName of the shader.
Returns
Internal material ID, or 0 if not found.

◆ loadShader()

CShader * Skylicht::CShaderManager::loadShader ( const char * shaderConfig)

Load a shader from an XML configuration file. If the shader is already loaded, returns the cached instance.

Parameters
shaderConfigPath to shader XML file.
Returns
Pointer to loaded CShader instance, or NULL if not found.

◆ rebuildShader()

bool Skylicht::CShaderManager::rebuildShader ( CShader * shader)

Rebuild a shader by reloading its configuration from source file. Useful for hot-reloading, debugging, or updating shaders at runtime.

Parameters
shaderPointer to shader to rebuild.
Returns
True if successful, false otherwise.

◆ setCurrentMaterial()

void Skylicht::CShaderManager::setCurrentMaterial ( SMaterial & mat)
inline

Set the material to be used for current rendering.

Parameters
matReference to material.

◆ setCurrentMeshBuffer()

void Skylicht::CShaderManager::setCurrentMeshBuffer ( IMeshBuffer * buffer)
inline

Set the mesh buffer to be used for current rendering.

Parameters
bufferPointer to mesh buffer.

Member Data Documentation

◆ BoneCount

u32 Skylicht::CShaderManager::BoneCount

Number of bones for skinning

See also
EUniformType, BONE_COUNT

◆ BoneMatrix

f32* Skylicht::CShaderManager::BoneMatrix

Pointer to bone matrix array for skinning

See also
EUniformType, BONE_MATRIX

◆ LightmapIndex

float Skylicht::CShaderManager::LightmapIndex

Current lightmap index

See also
EUniformType, LIGHTMAP_INDEX

◆ OnCreateInstancingVertex

std::function<IShaderInstancing* (const char*)> Skylicht::CShaderManager::OnCreateInstancingVertex

Callback for custom instancing implementation See documentation page : Shader information structure

◆ ShaderVec2

core::vector2df Skylicht::CShaderManager::ShaderVec2[10]

Array for vec2 uniforms(max 10)

See also
EUniformType, SHADER_VEC2

◆ ShaderVec3

core::vector3df Skylicht::CShaderManager::ShaderVec3[10]

Array for vec3 uniforms(max 10)

See also
EUniformType, SHADER_VEC3

◆ ShaderVec4

video::SVec4 Skylicht::CShaderManager::ShaderVec4[10]

Array for vec4 uniforms(max 10)

See also
EUniformType, SHADER_VEC4

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