4 #include <unordered_map>
35 using std::unordered_map;
63 LightingShader::LightingShader(
Renderer* renderer): renderer(renderer)
95 for (
const auto& [shaderId, shader]:
shaders) {
102 bool initialized =
true;
103 for (
const auto& [shaderId, shader]:
shaders) {
104 if (shader->isInitialized() ==
false) {
105 Console::println(
"LightingShader::isInitialized(): " + shaderId +
": not initialized!");
107 shader->registerShader();
109 initialized&= shader->isInitialized();
116 for (
const auto& [shaderId, shader]:
shaders) {
117 shader->initialize();
123 for (
const auto& [shaderId, shader]:
shaders) {
124 shader->unloadTextures();
138 for (
auto& lightingShaderContext:
contexts) {
139 if (lightingShaderContext.implementation !=
nullptr) lightingShaderContext.implementation->unUseProgram(i);
140 lightingShaderContext.implementation =
nullptr;
148 auto& lightingShaderContext =
contexts[contextIdx];
149 if (lightingShaderContext.implementation ==
nullptr)
return;
150 lightingShaderContext.implementation->updateEffect(
renderer, contextIdx);
155 auto& lightingShaderContext =
contexts[contextIdx];
156 if (lightingShaderContext.implementation ==
nullptr)
return;
157 lightingShaderContext.implementation->updateMaterial(
renderer, contextIdx);
162 auto& lightingShaderContext =
contexts[contextIdx];
163 if (lightingShaderContext.implementation ==
nullptr)
return;
164 lightingShaderContext.implementation->updateLight(
renderer, contextIdx, lightId);
169 auto& lightingShaderContext =
contexts[contextIdx];
170 if (lightingShaderContext.implementation ==
nullptr)
return;
171 lightingShaderContext.implementation->updateMatrices(
renderer, contextIdx);
175 auto& lightingShaderContext =
contexts[contextIdx];
176 if (lightingShaderContext.implementation ==
nullptr)
return;
177 lightingShaderContext.implementation->updateTextureMatrix(
renderer, contextIdx);
185 StringTools::startsWith(
id,
"pbr-") ==
true) {
186 shaderId = StringTools::substring(
id, 4,
id.size());
188 auto& lightingShaderContext =
contexts[contextIdx];
189 auto currentImplementation = lightingShaderContext.implementation;
192 if (shaderIt ==
shaders.end()) shaderIt =
shaders.find(
"default");
193 auto nextImplementation = shaderIt->second;
194 if (currentImplementation != nextImplementation) {
195 if (currentImplementation !=
nullptr) currentImplementation->unUseProgram(contextIdx);
196 lightingShaderContext.implementation = nextImplementation;
197 lightingShaderContext.implementation->useProgram(
engine, contextIdx);
202 auto& lightingShaderContext =
contexts[contextIdx];
203 if (lightingShaderContext.implementation ==
nullptr)
return;
204 lightingShaderContext.implementation->updateShaderParameters(
renderer, contextIdx);
209 auto& lightingShaderContext =
contexts[contextIdx];
210 if (lightingShaderContext.implementation ==
nullptr)
return;
211 lightingShaderContext.implementation->bindTexture(
renderer, contextIdx, textureId);
216 for (
const auto& [shaderId, shader]:
shaders) {
217 shader->unloadTextures();
218 shader->loadTextures(pathName);
static int getThreadCount()
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Lighting shader implementation.
static bool isSupported(Renderer *renderer)
Interface to lighting shader program.
void initialize()
Initialize.
void updateLight(int contextIdx, int32_t lightId)
Update light to program.
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
vector< LightingShaderContext > contexts
~LightingShader()
Destructor.
void useProgram(Engine *engine)
Use lighting program.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Update texture matrix to program.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material to program.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void loadTextures(const string &pathName)
Load textures.
unordered_map< string, LightingShaderImplementation * > shaders
void unUseProgram()
Unuse lighting program.
virtual bool isSupportingMultithreadedRendering()=0
virtual bool isPBRAvailable()=0
const string & getShaderPrefix()
Get shader prefix.
Lighting shader implementation interface.