diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index e95f8fb..45abe3f 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -157,7 +157,7 @@ void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Object } else if ((*cur).is_number_integer () == true) { - constant = new Effects::Constants::CShaderConstantInteger ((*cur).get ()); + constant = new Effects::Constants::CShaderConstantInteger ((*cur).get ()); } else if ((*cur).is_string () == true) { diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 1e6fa6b..64120ea 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -105,9 +105,9 @@ const std::map& CPass::getConstants () const return this->m_constants; } -const std::map& CPass::getCombos () const +std::map* CPass::getCombos () { - return this->m_combos; + return &this->m_combos; } const std::string& CPass::getShader () const diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index 9779211..fdd581c 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -22,7 +22,7 @@ namespace WallpaperEngine::Core::Objects::Images::Materials const std::vector& getTextures () const; const std::map& getConstants () const; - const std::map& getCombos () const; + std::map* getCombos (); const std::string& getShader () const; const std::string& getBlendingMode () const; const std::string& getCullingMode () const; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 6f1f25d..f4cbbe9 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -270,10 +270,12 @@ void CPass::setupShaders () this->m_material->getImage ()->getContainer (), this->m_pass->getShader (), Shaders::Compiler::Type_Vertex, - this->m_fragShader->getCombos (), + this->m_pass->getCombos (), this->m_pass->getConstants () ); this->m_vertShader->precompile (); + this->m_fragShader->precompile (); + this->m_vertShader->precompile (); // compile the shaders GLuint vertexShaderID = compileShader (this->m_vertShader, GL_VERTEX_SHADER); diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 2b7bce6..9122cc9 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -28,7 +28,7 @@ namespace WallpaperEngine::Render::Shaders CContainer* container, std::string filename, Type type, - std::map combos, + std::map* combos, const std::map& constants, bool recursive) : m_combos (combos), @@ -228,6 +228,7 @@ namespace WallpaperEngine::Render::Shaders void Compiler::precompile() { + // TODO: SEPARATE THIS IN TWO SO THE COMBOS ARE DETECTED FIRST AND WE DO NOT REQUIRE DOUBLE COMPILATION OF THE SHADER'S SOURCE #define BREAK_IF_ERROR if (this->m_error == true) { throw std::runtime_error ("ERROR PRE-COMPILING SHADER" + this->m_errorInfo); } // parse the shader and find #includes and such things and translate them to the correct name // also remove any #version definition to prevent errors @@ -236,6 +237,7 @@ namespace WallpaperEngine::Render::Shaders // reset error indicator this->m_error = false; this->m_errorInfo = ""; + this->m_compiledContent = ""; // search preprocessor macros and parse them while (it != this->m_content.end () && this->m_error == false) @@ -459,8 +461,8 @@ namespace WallpaperEngine::Render::Shaders "#define GLSL 1\n\n"; // add combo values - auto cur = this->m_combos.begin (); - auto end = this->m_combos.end (); + auto cur = this->m_combos->begin (); + auto end = this->m_combos->end (); for (; cur != end; cur ++) { @@ -494,11 +496,11 @@ namespace WallpaperEngine::Render::Shaders this->m_compiledContent += "\n"; // check the combos - std::map::const_iterator entry = this->m_combos.find ((*combo).get ()); + std::map::const_iterator entry = this->m_combos->find ((*combo).get ()); // if the combo was not found in the predefined values this means that the default value in the JSON data can be used // so only define the ones that are not already defined - if (entry == this->m_combos.end ()) + if (entry == this->m_combos->end ()) { // if no combo is defined just load the default settings if ((*defvalue).is_number_float ()) @@ -507,7 +509,7 @@ namespace WallpaperEngine::Render::Shaders } else if ((*defvalue).is_number_integer ()) { - this->m_combos.insert (std::make_pair (*combo, (*defvalue).get ())); + this->m_combos->insert (std::make_pair (*combo, (*defvalue).get ())); } else if ((*defvalue).is_string ()) { @@ -576,10 +578,10 @@ namespace WallpaperEngine::Render::Shaders } else if (type == "int") { - irr::s32 value = 0; + int value = 0; if (constant == this->m_constants.end ()) - value = (*defvalue).get (); + value = (*defvalue).get (); else if ((*constant).second->is () == true) value = *(*constant).second->as ()->getValue (); else if ((*constant).second->is () == true) @@ -597,7 +599,7 @@ namespace WallpaperEngine::Render::Shaders if (combo != data.end ()) { // add the new combo to the list - this->m_combos.insert (std::make_pair (*combo, 1)); + this->m_combos->insert (std::make_pair (*combo, 1)); // also ensure that the textureName is loaded and we know about it CTexture* texture = this->m_container->readTexture ((*textureName).get ()); // extract the texture number from the name @@ -647,7 +649,7 @@ namespace WallpaperEngine::Render::Shaders return this->m_parameters; } - const std::map & Compiler::getCombos () const + std::map * Compiler::getCombos () const { return this->m_combos; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index bf5dcaf..62e94a3 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -54,7 +54,7 @@ namespace WallpaperEngine::Render::Shaders CContainer* container, std::string filename, Type type, - std::map combos, + std::map* combos, const std::map& constants, bool recursive = false ); @@ -85,7 +85,7 @@ namespace WallpaperEngine::Render::Shaders /** * @return The list of combos available for this shader after compilation */ - const std::map & getCombos () const; + std::map * getCombos () const; /** * @return The list of textures inferred from the shader's code */ @@ -228,7 +228,7 @@ namespace WallpaperEngine::Render::Shaders /** * The combos the shader should be generated with */ - std::map m_combos; + std::map * m_combos; /** * The shader constants with values for variables inside the shader */