From 274bb08e4fcd042ac63a683812d2bf608304121b Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 24 Mar 2020 01:00:33 +0100 Subject: [PATCH] ~ fix images being rendered fliped horizontally + added support for arrays in shaders Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Render/Objects/CImage.cpp | 8 ++--- .../Render/Shaders/Compiler.cpp | 36 ++++++++++++++++--- src/WallpaperEngine/Render/Shaders/Compiler.h | 8 +++++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 72e81cf..6936e99 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -45,10 +45,10 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : // bottom left this->m_vertex [3].Pos = irr::core::vector3df (xleft, zbottom, z); - this->m_vertex [0].TCoords = irr::core::vector2df (1.0f, 0.0f); - this->m_vertex [1].TCoords = irr::core::vector2df (0.0f, 0.0f); - this->m_vertex [2].TCoords = irr::core::vector2df (0.0f, 1.0f); - this->m_vertex [3].TCoords = irr::core::vector2df (1.0f, 1.0f); + this->m_vertex [1].TCoords = irr::core::vector2df (1.0f, 0.0f); + this->m_vertex [0].TCoords = irr::core::vector2df (0.0f, 0.0f); + this->m_vertex [3].TCoords = irr::core::vector2df (0.0f, 1.0f); + this->m_vertex [2].TCoords = irr::core::vector2df (1.0f, 1.0f); this->m_vertex [0].Color = irr::video::SColor (255, 255, 255, 255); this->m_vertex [1].Color = irr::video::SColor (255, 255, 255, 255); diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index f410148..a287611 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -165,6 +165,30 @@ namespace WallpaperEngine::Render::Shaders return std::string (begin, cur); } + std::string Compiler::extractArray(std::string::const_iterator &it, bool mustExists) + { + std::string::const_iterator cur = it; + std::string::const_iterator begin = cur; + + if (*cur != '[') + { + if (mustExists == false) + return ""; + + this->m_error = true; + this->m_errorInfo = "Expected an array but found nothing"; + return ""; + } + + cur ++; + + while (cur != this->m_content.end () && *cur != ']') cur ++; + + it = ++cur; + + return std::string (begin, cur); + } + bool Compiler::isChar (std::string::const_iterator& it) { return ((*it) >= 'A' && (*it) <= 'Z') || ((*it) >= 'a' && (*it) <= 'z'); @@ -294,6 +318,8 @@ namespace WallpaperEngine::Render::Shaders this->ignoreSpaces (it); std::string name = this->extractName (it); BREAK_IF_ERROR this->ignoreSpaces (it); + std::string array = this->extractArray (it); BREAK_IF_ERROR + this->ignoreSpaces (it); this->expectSemicolon (it); BREAK_IF_ERROR this->ignoreSpaces (it); @@ -308,11 +334,11 @@ namespace WallpaperEngine::Render::Shaders // parse the parameter information this->parseParameterConfiguration (type, name, configuration); BREAK_IF_ERROR - this->m_compiledContent += "uniform " + type + " " + name + "; // " + configuration; + this->m_compiledContent += "uniform " + type + " " + name + array + "; // " + configuration; } else { - this->m_compiledContent += "uniform " + type + " " + name + ";"; + this->m_compiledContent += "uniform " + type + " " + name + array + ";"; } } } @@ -326,11 +352,11 @@ namespace WallpaperEngine::Render::Shaders this->ignoreSpaces (it); std::string name = this->extractName (it); BREAK_IF_ERROR this->ignoreSpaces (it); + std::string array = this->extractArray (it); BREAK_IF_ERROR + this->ignoreSpaces (it); this->expectSemicolon (it); BREAK_IF_ERROR - this->m_compiledContent += "// attribute"; - this->m_compiledContent += " " + type + " "; - this->m_compiledContent += name; + this->m_compiledContent += "// attribute " + type + " " + name + array; this->m_compiledContent += "; /* replaced by " + this->lookupReplaceSymbol (name) + " */"; } else diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 00a419e..467e553 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -132,6 +132,14 @@ namespace WallpaperEngine::Render::Shaders * @return The variable name */ std::string extractName (std::string::const_iterator& it); + /** + * Parses the current position as an array indicator + * + * @param it The position to start extracting the array from + * @param mustExists Whether the array indicator must exists or not + * @return + */ + std::string extractArray(std::string::const_iterator &it, bool mustExists = false); /** * Parses the current position as a quoted value, extracting it's value * and increasing the iterator at the same time