Skylicht Engine
Loading...
Searching...
No Matches
CShaderManager.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "pch.h"
28#include "Utils/CSingleton.h"
29
30#include <functional>
31
32namespace Skylicht
33{
34
35 class CShader;
36 class IShaderCallback;
38
54 class SKYLICHT_API CShaderManager {
55 public:
57
58 protected:
59
62
65
67 std::vector<CShader*> m_listShader;
68
70 std::map<std::string, int> m_listShaderID;
71
72 public:
73 // Uniform storage for current draw command (used by shaders)
74
78
82
86
90
94
98
101 std::function<IShaderInstancing* (const char*)> OnCreateInstancingVertex;
102
103 public:
108
113
118
124 {
125 m_currentMeshBuffer = buffer;
126 }
127
133 {
134 return m_currentMeshBuffer;
135 }
136
142 {
144 }
145
151 {
153 }
154
159
164
169
174
179
184
189
194
201 CShader* loadShader(const char* shaderConfig);
202
209 bool rebuildShader(CShader* shader);
210
216 int getShaderIDByName(const char* name);
217
223 CShader* getShaderByName(const char* name);
224
230 CShader* getShaderByPath(const char* path);
231
238
245 std::string getShaderFileName(const char* fileName);
246
251 inline int getNumShader()
252 {
253 return (int)m_listShader.size();
254 }
255
262 {
263 return m_listShader[i];
264 }
265
266 protected:
267
278 bool buildShader(CShader* shader, io::IXMLReader* xmlReader, const char* source, const char* shaderFolder, bool rebuild);
279 };
280
281}
Represents a programmable shader, including uniforms, UI, resources, instancing and platform-specific...
Definition CShader.h:198
std::function< IShaderInstancing *(const char *)> OnCreateInstancingVertex
Definition CShaderManager.h:101
int getShaderIDByName(const char *name)
Get the material ID of a shader by its name.
CShader * getShaderByName(const char *name)
Get a shader instance by its name.
video::SVec4 ShaderVec4[10]
Definition CShaderManager.h:85
CShader * getShaderByID(int id)
Get a shader instance by its internal material ID.
void initMobileSGShader()
Initialize built-in shaders for mobile platforms.
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,...
void setCurrentMaterial(SMaterial &mat)
Set the material to be used for current rendering.
Definition CShaderManager.h:141
SMaterial * getCurrentMaterial()
Get the material currently used for rendering.
Definition CShaderManager.h:150
core::vector3df ShaderVec3[10]
Definition CShaderManager.h:81
std::map< std::string, int > m_listShaderID
Map from shader name to internal material ID.
Definition CShaderManager.h:70
IMeshBuffer * getCurrentMeshBuffer()
Get the mesh buffer currently used for rendering.
Definition CShaderManager.h:132
bool rebuildShader(CShader *shader)
Rebuild a shader by reloading its configuration from source file. Useful for hot-reloading,...
std::string getShaderFileName(const char *fileName)
Get the shader file name with the appropriate extension for the current graphics API....
CShader * getShaderByPath(const char *path)
Get a shader instance by its source path.
void initPBRForwarderShader()
Initialize built-in shaders for Physically-Based Rendering (PBR) forward pipeline.
void initBasicShader()
Initialize basic built-in shaders for basic rendering features.
u32 BoneCount
Definition CShaderManager.h:93
CShaderManager()
Constructor.
core::vector2df ShaderVec2[10]
Definition CShaderManager.h:77
f32 * BoneMatrix
Definition CShaderManager.h:89
void initShader()
Initialize all shader systems (calls basic and engine shader initializers).
int getNumShader()
Get the number of loaded shader materials.
Definition CShaderManager.h:251
SMaterial * m_currentMatRendering
Pointer to material currently being rendered.
Definition CShaderManager.h:64
IMeshBuffer * m_currentMeshBuffer
Pointer to mesh buffer currently being rendered.
Definition CShaderManager.h:61
CShader * getShader(int i)
Get a loaded shader material by index.
Definition CShaderManager.h:261
void initGUIShader()
Initialize built-in GUI shaders required for Skylicht's UI rendering.
CShader * loadShader(const char *shaderConfig)
Load a shader from an XML configuration file. If the shader is already loaded, returns the cached ins...
void initSGForwarderShader()
Initialize built-in shaders for Specular-Glossiness Forward rendering.
void initSGDeferredShader()
Initialize built-in shaders for Specular-Glossiness Deferred rendering.
std::vector< CShader * > m_listShader
List of loaded shaders.
Definition CShaderManager.h:67
void releaseAll()
Release all loaded shaders and associated resources.
void setCurrentMeshBuffer(IMeshBuffer *buffer)
Set the mesh buffer to be used for current rendering.
Definition CShaderManager.h:123
float LightmapIndex
Definition CShaderManager.h:97
void initSkylichtEngineShader()
Initialize all core engine shaders (deferred, forward, etc.).
virtual ~CShaderManager()
Destructor. Releases all loaded shaders.
Interface for shader callbacks, used to set constants in user-extended shaders.
Definition CShader.h:170
Abstract base class for GPU instancing logic in Skylicht-Engine.
Definition IShaderInstancing.h:45
Struct for holding a mesh with a single material.
Definition IMeshBuffer.h:42
Struct for holding parameters for a material renderer.
Definition SMaterial.h:255
#define DECLARE_SINGLETON(className)
Declare the standard singleton accessors for a class.
Definition CSingleton.h:36
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
IIrrXMLReader< wchar_t, IReferenceCounted > IXMLReader
An xml reader for wide characters, derived from IReferenceCounted.
Definition IXMLReader.h:19
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
Definition S3DVertex.h:301