4#include <unordered_map>
19using std::unordered_map;
33ShadowMapRenderShader::ShadowMapRenderShader(
Renderer* renderer): renderer(renderer)
44 for (
auto shaderIt:
shader) {
45 delete shaderIt.second;
51 bool initialized =
true;
52 for (
auto shaderIt:
shader) {
53 initialized&= shaderIt.second->isInitialized();
60 for (
auto shaderIt:
shader) {
61 shaderIt.second->initialize();
75 for (
auto& shadowMappingShaderRenderContext:
contexts) {
76 if (shadowMappingShaderRenderContext.implementation !=
nullptr) {
77 shadowMappingShaderRenderContext.implementation->unUseProgram(i);
79 shadowMappingShaderRenderContext.implementation =
nullptr;
87 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
88 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
89 shadowMappingShaderRenderContext.implementation->updateMatrices(contextIdx);
93 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
94 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
95 shadowMappingShaderRenderContext.implementation->updateTextureMatrix(
renderer, contextIdx);
100 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
101 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
102 shadowMappingShaderRenderContext.implementation->updateMaterial(
renderer, contextIdx);
106 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
107 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
108 shadowMappingShaderRenderContext.implementation->updateLight(
renderer, contextIdx,
lightId);
112 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
113 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
114 shadowMappingShaderRenderContext.implementation->updateShaderParameters(
renderer, contextIdx);
119 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
120 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
121 shadowMappingShaderRenderContext.implementation->bindTexture(
renderer, contextIdx, textureId);
127 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
128 if (shadowMappingShaderRenderContext.implementation ==
nullptr)
return;
129 shadowMappingShaderRenderContext.implementation->setDepthBiasMVPMatrix(contextIdx, this->depthBiasMVPMatrix);
139 if (StringTools::startsWith(
id,
string(
"pbr-")) ==
true) {
140 shaderId = StringTools::substring(
id, 4);
146 auto& shadowMappingShaderRenderContext =
contexts[contextIdx];
147 auto currentImplementation = shadowMappingShaderRenderContext.implementation;
148 auto shaderIt =
shader.find(shaderId);
149 if (shaderIt ==
shader.end()) {
150 shaderIt =
shader.find(
"default");
152 auto nextImplementation = shaderIt->second;
153 if (currentImplementation != nextImplementation) {
154 if (currentImplementation !=
nullptr) currentImplementation->unUseProgram(contextIdx);
155 shadowMappingShaderRenderContext.implementation = nextImplementation;
156 shadowMappingShaderRenderContext.implementation->useProgram(
engine, contextIdx);
159 shadowMappingShaderRenderContext.implementation->setDepthBiasMVPMatrix(contextIdx,
depthBiasMVPMatrix);
160 shadowMappingShaderRenderContext.implementation->setRenderLightId(
lightId);
static int getThreadCount()
virtual bool isSupportingMultithreadedRendering()=0
Shadow mapping default shader to render shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping foliage shader to render shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping tree shader to render shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping shader to render shadow maps.
void initialize()
Initialize shadow map render shader program.
void updateLight(int contextIdx, int32_t lightId)
Update light.
void updateMatrices(int contextIdx)
Update matrices.
void setDepthBiasMVPMatrix(int contextIdx, const Matrix4x4 &depthBiasMVPMatrix)
Set up program depth bias mvp matrix.
Matrix4x4 depthBiasMVPMatrix
void setRenderLightId(int32_t lightId)
Set light id.
void useProgram(Engine *engine)
Use shadow map render shader program.
~ShadowMapRenderShader()
Destructor.
void setShader(int contextIdx, const string &id)
Set shader.
vector< ShadowMapRenderShaderContext > contexts
void updateTextureMatrix(int contextIdx)
Update up texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void unUseProgram()
Unuse shadow map render shader program.
unordered_map< string, ShadowMapRenderShaderImplementation * > shader
Shadow mapping shader interface to render shadow map.