From 5a45c9a26b63cff96a9327946951b02023005b82 Mon Sep 17 00:00:00 2001 From: moetayuko Date: Tue, 3 Sep 2024 06:23:56 +0800 Subject: [PATCH] Workaround errors when loading wallpapers made recently (#244) * Add sampler2DComparison and uint to known types * Ignore unsupported `#require` preprocessor directive `#require LightingV1` is found in generic4.frag, genericimage4.frag, ... * Mark _alias_* textures as FBOs Currently not supported, but prevents loading from the file, thereby avoiding CAssetLoadException --- .../Render/Objects/Effects/CPass.cpp | 2 +- .../Render/Shaders/Compiler.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index bed28b7..ea0a6ae 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -451,7 +451,7 @@ void CPass::setupUniforms () { // resolve the texture first const ITexture* textureRef; - if (textureName.find ("_rt_") == 0) { + if (textureName.find ("_rt_") == 0 || textureName.find ("_alias_") == 0) { textureRef = this->getMaterial ()->getEffect ()->findFBO (textureName); if (textureRef == nullptr) diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 63e4348..1325237 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -265,6 +265,15 @@ void Compiler::precompile () { this->m_includesContent += this->lookupShaderFile (filename); this->m_includesContent += "\r\n// end of included from file " + filename + "\r\n"; } + } else if (this->peekString ("#require ", it)) { + // TODO: PROPERLY IMPLEMENT #require + this->m_compiledContent += "// #require "; + // ignore whitespaces + this->ignoreSpaces (it); + BREAK_IF_ERROR + std::string name = this->extractName (it); + BREAK_IF_ERROR + this->m_compiledContent += name; } else { this->m_compiledContent += '#'; ++it; @@ -694,7 +703,7 @@ void Compiler::parseParameterConfiguration (const std::string& type, const std:: value = *constant->second->as ()->getValue (); parameter = new Variables::CShaderVariableInteger (value); - } else if (type == "sampler2D") { + } else if (type == "sampler2D" || type == "sampler2DComparison") { // samplers can have special requirements, check what sampler we're working with and create definitions // if needed const auto textureName = data.find ("default"); @@ -755,7 +764,8 @@ const std::map& Compiler::getTextures () const { return this->m_textures; } -std::vector Compiler::sTypes = { - "vec4", "uvec4", "ivec4", "dvec4", "bvec4", "vec3", "uvec3", "ivec3", "dvec3", "bvec3", "vec2", - "uvec2", "ivec2", "dvec2", "bvec2", "float", "sampler2D", "mat4x3", "mat4", "mat3", "uint4", "void"}; +std::vector Compiler::sTypes = {"vec4", "uvec4", "ivec4", "dvec4", "bvec4", "vec3", + "uvec3", "ivec3", "dvec3", "bvec3", "vec2", "uvec2", + "ivec2", "dvec2", "bvec2", "float", "sampler2D", "sampler2DComparison", + "mat4x3", "mat4", "mat3", "uint", "uint4", "void"}; } // namespace WallpaperEngine::Render::Shaders