diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 49fcb73..f2f441b 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -66,7 +66,7 @@ class CMaterial { std::vector passes); CMaterial ( std::string name, std::string target, std::map textureBindings, - const std::vector passes); + std::vector passes); private: /** All the shader passes required to render this material */ diff --git a/src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp b/src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp index 54e6358..11399b5 100644 --- a/src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp +++ b/src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp @@ -28,10 +28,10 @@ void CPrettyPrinter::printWallpaper (const CWallpaper& wallpaper) { this->m_out << "FBOs count: " << fbos.size (); - if (fbos.size () > 0) { + if (!fbos.empty()) { this->increaseIndentation (); - for (const auto fbo : fbos) { + for (const auto& fbo : fbos) { this->printFBO (*fbo.second); } @@ -42,7 +42,7 @@ void CPrettyPrinter::printWallpaper (const CWallpaper& wallpaper) { const auto objects = scene->getObjectsByRenderOrder (); - if (objects.size () > 0) { + if (!objects.empty()) { this->m_out << "Objects count: " << objects.size (); this->increaseIndentation (); @@ -101,14 +101,14 @@ void CPrettyPrinter::printEffect (const CEffect& effect, int effectId) { this->m_out << "Visibility status: " << effect.isVisible (); this->lineEnd (); - const auto fbos = effect.getFBOs(); + const auto& fbos = effect.getFBOs(); this->m_out << "FBOs count: " << fbos.size(); - if (fbos.size() > 0) { + if (!fbos.empty()) { this->increaseIndentation (); - for (const auto fbo : fbos) { + for (const auto& [name, fbo] : fbos) { this->printFBO (*fbo); } @@ -117,7 +117,7 @@ void CPrettyPrinter::printEffect (const CEffect& effect, int effectId) { this->lineEnd (); } - const auto materials = effect.getMaterials (); + const auto& materials = effect.getMaterials (); for (const auto material : materials) { this->printMaterial (*material); @@ -148,11 +148,11 @@ void CPrettyPrinter::printMaterial (const CMaterial& material) { this->lineEnd (); } - const auto passes = material.getPasses (); + const auto& passes = material.getPasses (); this->m_out << "Passes count: " << passes.size (); - if (passes.size () > 0) { + if (!passes.empty()) { this->increaseIndentation (); int passId = 0; @@ -166,7 +166,7 @@ void CPrettyPrinter::printMaterial (const CMaterial& material) { const auto textureBinds = base->getTextureBinds (); - if (textureBinds.size () > 0) { + if (!textureBinds.empty()) { this->m_out << "Texture binds count: " << textureBinds.size (); this->increaseIndentation (); @@ -187,7 +187,7 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->m_out << "Pass " << passId << ":"; this->increaseIndentation (); - if (pass.getBlendingMode ().compare (base->getBlendingMode ()) != 0) { + if (pass.getBlendingMode () != base->getBlendingMode ()) { this->m_out << "Render blending mode: " << pass.getBlendingMode (); this->lineEnd (); this->m_out << "Blending mode: " << base->getBlendingMode (); @@ -207,11 +207,11 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->lineEnd (); const auto textures = base->getTextures (); - if (textures.size () > 0) { + if (!textures.empty()) { this->m_out << "Textures " << textures.size () << ":"; this->increaseIndentation (); - for (const auto texture : textures) { + for (const auto& texture : textures) { this->m_out << texture.first << ": " << texture.second; this->lineEnd (); } @@ -219,9 +219,9 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto fragmentTextures = pass.getShader ()->getFragment ().getTextures (); + const auto& fragmentTextures = pass.getShader ()->getFragment ().getTextures (); - if (fragmentTextures.size () > 0) { + if (!fragmentTextures.empty()) { this->m_out << "Fragment textures " << fragmentTextures.size () << ":"; this->increaseIndentation (); @@ -233,9 +233,9 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto vertexTextures = pass.getShader ()->getFragment ().getTextures (); + const auto& vertexTextures = pass.getShader ()->getFragment ().getTextures (); - if (vertexTextures.size () > 0) { + if (!vertexTextures.empty()) { this->m_out << "Vertex textures " << textures.size () << ":"; this->increaseIndentation (); @@ -247,13 +247,13 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto combos = base->getCombos(); + const auto& combos = base->getCombos(); - if (combos.size () > 0) { + if (!combos.empty()) { this->m_out << "Combos " << combos.size () << ":"; this->increaseIndentation (); - for (const auto combo : combos) { + for (const auto& combo : combos) { this->m_out << combo.first << " = " << combo.second; this->lineEnd (); } @@ -261,9 +261,9 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto vertexCombos = pass.getShader ()->getVertex ().getDiscoveredCombos (); + const auto& vertexCombos = pass.getShader ()->getVertex ().getDiscoveredCombos (); - if (vertexCombos.size () > 0) { + if (!vertexCombos.empty()) { this->m_out << "Vertex combos " << vertexCombos.size () << ":"; this->increaseIndentation (); @@ -275,9 +275,9 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto fragmentCombos = pass.getShader ()->getFragment ().getDiscoveredCombos (); + const auto& fragmentCombos = pass.getShader ()->getFragment ().getDiscoveredCombos (); - if (fragmentCombos.size () > 0) { + if (!fragmentCombos.empty()) { this->m_out << "Vertex combos " << fragmentCombos.size () << ":"; this->increaseIndentation (); @@ -289,13 +289,13 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) { this->decreaseIndentation (); } - const auto constants = base->getConstants (); + const auto& constants = base->getConstants (); - if (constants.size () > 0) { + if (!constants.empty()) { this->m_out << "Constants " << constants.size () << ":"; this->increaseIndentation (); - for (const auto constant : constants) { + for (const auto& constant : constants) { this->m_out << constant.first << " = " << constant.second->toString (); this->lineEnd (); } @@ -320,7 +320,7 @@ void CPrettyPrinter::printTextureInfo (const ITexture& texture) { this->m_out << "Is animated: " << texture.isAnimated (); this->lineEnd (); - const auto frames = texture.getFrames (); + const auto& frames = texture.getFrames (); if (frames.size () > 1) { this->m_out << frames.size () << " frames: "; diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp index 0cfa0e3..7a3e388 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -19,11 +19,13 @@ const std::vector& CEffect::getMaterials () const { } const CFBO* CEffect::findFBO (const std::string& name) const { - for (const auto& cur : this->m_fbos) - if (cur->getName () == name) - return cur; + const auto fbo = this->m_fbos.find (name); - return nullptr; + if (fbo == this->m_fbos.end ()) { + return nullptr; + } + + return fbo->second; } void CEffect::generatePasses () { @@ -34,17 +36,22 @@ void CEffect::generatePasses () { void CEffect::generateFBOs () { for (const auto& cur : this->m_effect->getFbos ()) { // TODO: IS THAT DIVISION OKAY? SHOULDN'T IT BE A MULTIPLICATION? WTF? - this->m_fbos.push_back (new CFBO (cur->getName (), - ITexture::TextureFormat::ARGB8888, // TODO: CHANGE - this->m_image->getTexture ()->getFlags (), // TODO: CHANGE - cur->getScale (), this->m_image->getSize ().x / cur->getScale (), - this->m_image->getSize ().y / cur->getScale (), - this->m_image->getSize ().x / cur->getScale (), - this->m_image->getSize ().y / cur->getScale ())); + this->m_fbos.insert (std::pair ( + cur->getName(), + new CFBO ( + // TODO: SET PROPER FLAGS AND FORMAT + cur->getName (), ITexture::TextureFormat::ARGB8888, + this->m_image->getTexture ()->getFlags (), cur->getScale (), + this->m_image->getSize ().x / cur->getScale (), + this->m_image->getSize ().y / cur->getScale (), + this->m_image->getSize ().x / cur->getScale (), + this->m_image->getSize ().y / cur->getScale () + ) + )); } } -const std::vector& CEffect::getFBOs () const { +const std::map& CEffect::getFBOs () const { return this->m_fbos; } diff --git a/src/WallpaperEngine/Render/Objects/CEffect.h b/src/WallpaperEngine/Render/Objects/CEffect.h index 46fd184..d5d578e 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.h +++ b/src/WallpaperEngine/Render/Objects/CEffect.h @@ -22,17 +22,17 @@ class CEffect { public: CEffect (CImage* image, const Core::Objects::CEffect* effect); - CImage* getImage () const; + [[nodiscard]] CImage* getImage () const; - const std::vector& getMaterials () const; + [[nodiscard]] const std::vector& getMaterials () const; - const CFBO* findFBO (const std::string& name) const; - bool isVisible () const; + [[nodiscard]] const CFBO* findFBO (const std::string& name) const; + [[nodiscard]] bool isVisible () const; protected: friend class WallpaperEngine::PrettyPrinter::CPrettyPrinter; - const std::vector& getFBOs () const; + [[nodiscard]] const std::map& getFBOs () const; private: void generatePasses (); @@ -41,7 +41,7 @@ class CEffect { CImage* m_image; const Core::Objects::CEffect* m_effect; - std::vector m_fbos; + std::map m_fbos; std::vector m_materials; }; } // namespace WallpaperEngine::Render::Objects diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index ce77499..746ac63 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -65,13 +65,17 @@ const ITexture* CPass::resolveTexture (const ITexture* expected, int index, cons } const CFBO* CPass::resolveFBO (const std::string& name) const { - const auto fbo = this->m_material->getEffect()->findFBO (name); + auto fbo = this->m_material->getEffect()->findFBO (name); if (fbo == nullptr) { - return this->m_material->getImage ()->getScene ()->findFBO (name); + fbo = this->m_material->getImage ()->getScene ()->findFBO (name); } - sLog.exception ("Tried to resolve and FBO without any luck: ", name); + if (fbo == nullptr) { + sLog.exception ("Tried to resolve and FBO without any luck: ", name); + } + + return fbo; } void CPass::setupRenderFramebuffer () { @@ -155,8 +159,8 @@ void CPass::setupRenderTexture () { glBindTexture (GL_TEXTURE_2D, texture->getTextureID (currentTexture)); // continue on the map from the second texture - if (!this->m_finalTextures.empty ()) { - for (const auto& [index, expectedTexture] : this->m_finalTextures) { + if (!this->m_textures.empty ()) { + for (const auto& [index, expectedTexture] : this->m_textures) { if (expectedTexture == nullptr) { texture = this->m_input; } else { @@ -265,8 +269,8 @@ void CPass::cleanupRenderSetup () { glBindTexture (GL_TEXTURE_2D, 0); // continue on the map from the second texture - if (!this->m_finalTextures.empty ()) { - for (const auto& [index, _] : this->m_finalTextures) { + if (!this->m_textures.empty ()) { + for (const auto& [index, _] : this->m_textures) { glActiveTexture (GL_TEXTURE0 + index); glBindTexture (GL_TEXTURE_2D, 0); } @@ -480,7 +484,7 @@ void CPass::setupTextureUniforms () { textureRef = this->getContext ().resolveTexture (textureName); } - this->m_finalTextures [index] = textureRef; + this->m_textures [index] = textureRef; } catch (std::runtime_error& ex) { sLog.error ("Cannot resolve texture ", textureName, " for fragment shader ", ex.what ()); } @@ -497,7 +501,7 @@ void CPass::setupTextureUniforms () { textureRef = this->getContext ().resolveTexture (textureName); } - this->m_finalTextures [index] = textureRef; + this->m_textures [index] = textureRef; } catch (std::runtime_error& ex) { sLog.error ("Cannot resolve texture ", textureName, " for fragment shader ", ex.what ()); } @@ -510,9 +514,9 @@ void CPass::setupTextureUniforms () { } if (textureName.find ("_rt_") == 0) { - this->m_finalTextures[index] = this->resolveFBO (textureName); + this->m_textures[index] = this->resolveFBO (textureName); } else if (!textureName.empty ()) { - this->m_finalTextures[index] = this->m_material->getImage ()->getContext ().resolveTexture (textureName); + this->m_textures[index] = this->m_material->getImage ()->getContext ().resolveTexture (textureName); } } @@ -520,10 +524,10 @@ void CPass::setupTextureUniforms () { for (const auto& [index, bind] : this->m_material->getMaterial ()->getTextureBinds ()) { if (bind->getName () == "previous") { // use nullptr as indication for "previous" texture - this->m_finalTextures [index] = nullptr; + this->m_textures [index] = nullptr; } else { // a normal bind, search for the corresponding FBO and set it - this->m_finalTextures [index] = this->resolveFBO (bind->getName ()); + this->m_textures [index] = this->resolveFBO (bind->getName ()); } } @@ -540,7 +544,7 @@ void CPass::setupTextureUniforms () { this->addUniform ("g_Texture7", 7); this->addUniform ("g_Texture0Resolution", texture->getResolution ()); - for (const auto& [textureIndex, expectedTexture] : this->m_finalTextures) { + for (const auto& [textureIndex, expectedTexture] : this->m_textures) { std::ostringstream namestream; namestream << "g_Texture" << textureIndex << "Resolution"; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.h b/src/WallpaperEngine/Render/Objects/Effects/CPass.h index 89a468b..084143b 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.h @@ -150,7 +150,6 @@ class CPass final : public Helpers::CContextAware { CMaterial* m_material; const Core::Objects::Images::Materials::CPass* m_pass; - std::map m_textures; std::map m_fbos; std::map m_combos; std::vector m_attribs; @@ -165,7 +164,7 @@ class CPass final : public Helpers::CContextAware { /** * Contains the final map of textures to be used */ - std::map m_finalTextures; + std::map m_textures; Render::Shaders::CShader* m_shader;