From fca645b25a43c48cd6f0b597912eef22b64e37ef Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Thu, 7 Apr 2022 23:34:03 +0200 Subject: [PATCH] ~ Fixed RG88 and R8 textures not loading properly ~ Fixed combo setting based on the textures supplied to the image ~ Fixed vec4 shader constants not using the default value Should fix #87 Signed-off-by: Alexis Maiquez Murcia --- src/WallpaperEngine/Assets/CTexture.cpp | 4 +- .../Render/Shaders/Compiler.cpp | 61 ++++++++++--------- src/WallpaperEngine/Render/Shaders/Compiler.h | 2 +- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/WallpaperEngine/Assets/CTexture.cpp b/src/WallpaperEngine/Assets/CTexture.cpp index db56de4..d64c82c 100644 --- a/src/WallpaperEngine/Assets/CTexture.cpp +++ b/src/WallpaperEngine/Assets/CTexture.cpp @@ -148,12 +148,14 @@ CTexture::CTexture (void* fileData) if (this->m_header->format == TextureFormat::RG88) textureFormat = GL_RG; else if (this->m_header->format == TextureFormat::R8) - textureFormat = GL_R; + textureFormat = GL_RED; } switch (internalFormat) { case GL_RGBA8: + case GL_RG8: + case GL_R8: glTexImage2D (GL_TEXTURE_2D, level, internalFormat, width, height, 0, textureFormat, GL_UNSIGNED_BYTE, diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index fd808f3..987d5cf 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -316,13 +316,6 @@ namespace WallpaperEngine::Render::Shaders it ++; } } - /*else if (*it == 'a') - { - if (this->peekString ("attribute", it) == true) - { - this->ignoreSpaces (it); - } - }*/ else if (*it == 'a') { // find attribute definitions @@ -387,7 +380,7 @@ namespace WallpaperEngine::Render::Shaders this->m_compiledContent += "// [COMBO] " + configuration; - this->parseComboConfiguration (configuration); BREAK_IF_ERROR; + this->parseComboConfiguration (configuration, 1); BREAK_IF_ERROR; } else if (this->peekString ("[COMBO_OFF]", it) == true) { @@ -400,11 +393,12 @@ namespace WallpaperEngine::Render::Shaders this->m_compiledContent += "// [COMBO_OFF] " + configuration; - this->parseComboConfiguration (configuration); BREAK_IF_ERROR; + this->parseComboConfiguration (configuration, 0); BREAK_IF_ERROR; } else { - this->ignoreUpToNextLineFeed (it); + // the comment can be ignored and put back as is + this->ignoreUpToNextLineFeed(it); this->m_compiledContent.append (begin, it); } } @@ -500,7 +494,7 @@ namespace WallpaperEngine::Render::Shaders #undef BREAK_IF_ERROR } - void Compiler::parseComboConfiguration (const std::string& content) + void Compiler::parseComboConfiguration (const std::string& content, int defaultValue) { json data = json::parse (content); auto combo = jsonFindRequired (data, "combo", "cannot parse combo information"); @@ -520,7 +514,7 @@ namespace WallpaperEngine::Render::Shaders if (defvalue == data.end ()) { // TODO: PROPERLY SUPPORT EMPTY COMBOS - this->m_combos->insert (std::make_pair (*combo, 0)); + this->m_combos->insert (std::make_pair (*combo, (int) defaultValue)); } else if ((*defvalue).is_number_float ()) { @@ -547,11 +541,13 @@ namespace WallpaperEngine::Render::Shaders auto material = data.find ("material"); auto defvalue = data.find ("default"); auto range = data.find ("range"); + auto combo = data.find ("combo"); // this is not a real parameter - if (material == data.end ()) - return; - auto constant = this->m_constants.find (*material); + auto constant = this->m_constants.end (); + + if (material != data.end ()) + constant = this->m_constants.find (*material); if (constant == this->m_constants.end () && defvalue == data.end ()) { @@ -565,7 +561,9 @@ namespace WallpaperEngine::Render::Shaders if (type == "vec4") { parameter = new Variables::CShaderVariableVector4 ( - WallpaperEngine::Core::aToVector4 (*defvalue) + constant == this->m_constants.end () + ? WallpaperEngine::Core::aToVector4 (*defvalue) + : *(*constant).second->as ()->getValue () ); } else if (type == "vec3") @@ -619,16 +617,20 @@ namespace WallpaperEngine::Render::Shaders { // add the new combo to the list this->m_combos->insert (std::make_pair (*combo, 1)); - // also ensure that the textureName is loaded and we know about it - ITexture* texture = this->m_container->readTexture ((*textureName).get ()); - // extract the texture number from the name - char value = name.at (std::string("g_Texture").length ()); - // now convert it to integer - int index = value - '0'; - this->m_textures.insert ( - std::make_pair (index, texture) - ); + if (textureName != data.end ()) + { + // also ensure that the textureName is loaded and we know about it + ITexture* texture = this->m_container->readTexture ((*textureName).get ()); + // extract the texture number from the name + char value = name.at (std::string("g_Texture").length ()); + // now convert it to integer + int index = value - '0'; + + this->m_textures.insert ( + std::make_pair (index, texture) + ); + } } // samplers are not saved, we can ignore them for now @@ -641,10 +643,13 @@ namespace WallpaperEngine::Render::Shaders return; } - parameter->setIdentifierName (*material); - parameter->setName (name); + if (material != data.end ()) + { + parameter->setIdentifierName (*material); + parameter->setName (name); - this->m_parameters.push_back (parameter); + this->m_parameters.push_back (parameter); + } } Variables::CShaderVariable* Compiler::findParameter (const std::string& identifier) diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 4a6e8d4..61560fd 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -188,7 +188,7 @@ namespace WallpaperEngine::Render::Shaders * * @param content The parameter configuration */ - void parseComboConfiguration (const std::string& content); + void parseComboConfiguration (const std::string& content, int defaultValue = 0); /** * Parses a parameter extra metadata created by wallpaper engine *