From 30bb8d6d72166d90eb9ed292262ac0029b38e104 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Sun, 5 Feb 2023 06:36:07 +0100 Subject: [PATCH] Small cleanup of pass initialization code Signed-off-by: Alexis Maiquez --- .../Render/Objects/Effects/CPass.cpp | 48 +++++++------------ .../Render/Objects/Effects/CPass.h | 1 + 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 2751601..975622f 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -782,42 +782,30 @@ void CPass::setupShaderVariables () } for (const auto& cur : this->m_vertShader->getParameters ()) - { - if (this->m_uniforms.find (cur->getName ()) != this->m_uniforms.end ()) - continue; - - if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - } + if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ()) + this->addUniform (cur); for (const auto& cur : this->m_fragShader->getParameters ()) - { - if (this->m_uniforms.find (cur->getName ()) != this->m_uniforms.end ()) - continue; + if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ()) + this->addUniform (cur); - if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - else if (cur->is ()) - this->addUniform (cur->getName (), const_cast (reinterpret_cast (cur->as ()->getValue ()))); - } } // define some basic methods for the template -/*template double Core::jsonFindDefault (nlohmann::json& data, const char *key, double defaultValue);*/ +void CPass::addUniform (CShaderVariable* value) +{ + if (value->is ()) + this->addUniform (value->getName (), const_cast (reinterpret_cast (value->as ()->getValue ()))); + else if (value->is ()) + this->addUniform (value->getName (), const_cast (reinterpret_cast (value->as ()->getValue ()))); + else if (value->is ()) + this->addUniform (value->getName (), const_cast (reinterpret_cast (value->as ()->getValue ()))); + else if (value->is ()) + this->addUniform (value->getName (), const_cast (reinterpret_cast (value->as ()->getValue ()))); + else if (value->is ()) + this->addUniform (value->getName (), const_cast (reinterpret_cast (value->as ()->getValue ()))); +} + void CPass::addUniform (const std::string& name, int value) { this->addUniform (name, UniformType::Integer, value); diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.h b/src/WallpaperEngine/Render/Objects/Effects/CPass.h index 1ada477..e255967 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.h @@ -89,6 +89,7 @@ namespace WallpaperEngine::Render::Objects::Effects void setupUniforms (); void setupAttributes (); void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value); + void addUniform (CShaderVariable* value); void addUniform (const std::string& name, int value); void addUniform (const std::string& name, double value); void addUniform (const std::string& name, float value);