4 #include <unordered_map>
18 using std::unordered_map;
32 ShadowMapCreationShader::ShadowMapCreationShader(
Renderer* renderer): renderer(renderer)
42 for (
const auto& [shaderId, shader]:
shaders) {
43 shader->unloadTextures();
50 bool initialized =
true;
51 for (
const auto& [shaderId, shader]:
shaders) {
52 initialized&= shader->isInitialized();
59 for (
const auto& [shaderId, shader]:
shaders) {
74 for (
auto& shadowMappingShaderPreContext:
contexts) {
75 if (shadowMappingShaderPreContext.implementation !=
nullptr) {
76 shadowMappingShaderPreContext.implementation->unUseProgram(i);
78 shadowMappingShaderPreContext.implementation =
nullptr;
86 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
87 if (shadowMappingShaderPreContext.implementation ==
nullptr)
return;
88 shadowMappingShaderPreContext.implementation->updateMatrices(contextIdx);
92 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
93 if (shadowMappingShaderPreContext.implementation ==
nullptr)
return;
94 shadowMappingShaderPreContext.implementation->updateTextureMatrix(
renderer, contextIdx);
99 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
100 if (shadowMappingShaderPreContext.implementation ==
nullptr)
return;
101 shadowMappingShaderPreContext.implementation->updateMaterial(
renderer, contextIdx);
105 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
106 if (shadowMappingShaderPreContext.implementation ==
nullptr)
return;
107 shadowMappingShaderPreContext.implementation->updateShaderParameters(
renderer, contextIdx);
112 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
113 if (shadowMappingShaderPreContext.implementation ==
nullptr)
return;
114 shadowMappingShaderPreContext.implementation->bindTexture(
renderer, contextIdx, textureId);
120 if (StringTools::startsWith(
id,
string(
"pbr-")) ==
true) {
121 shaderId = StringTools::substring(
id, 4);
127 auto& shadowMappingShaderPreContext =
contexts[contextIdx];
128 auto currentImplementation = shadowMappingShaderPreContext.implementation;
129 auto shaderIt =
shaders.find(shaderId);
130 if (shaderIt ==
shaders.end()) {
131 shaderIt =
shaders.find(
"default");
133 auto nextImplementation = shaderIt->second;
134 if (currentImplementation != nextImplementation) {
135 if (currentImplementation !=
nullptr) currentImplementation->unUseProgram(contextIdx);
136 shadowMappingShaderPreContext.implementation = nextImplementation;
137 shadowMappingShaderPreContext.implementation->useProgram(
engine, contextIdx);
142 for (
const auto& [shaderId, shader]:
shaders) {
143 shader->unloadTextures();
144 shader->loadTextures(pathName);
static int getThreadCount()
virtual bool isSupportingMultithreadedRendering()=0
Shadow mapping shader base class to create shadow map.
Shadow mapping default shader class to create shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping foliage shader class to create shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping tree shader class to create shadow map.
static bool isSupported(Renderer *renderer)
Shadow mapping shader to create a shadow map.
void initialize()
Init shadow map creation shader program.
void updateMatrices(int contextIdx)
Set up matrices.
void useProgram(Engine *engine)
Use shadow map creation shader program.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Set up texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material.
unordered_map< string, ShadowMapCreationShaderImplementation * > shaders
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void loadTextures(const string &pathName)
Load textures.
void unUseProgram()
Unuse shadow map creation shader program.
~ShadowMapCreationShader()
Destructor.
vector< ShadowMapCreationShaderContext > contexts
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Pre shadow mapping shader for create shadow map.