Bläddra i källkod

~ fix images being rendered fliped horizontally
+ added support for arrays in shaders

Signed-off-by: Alexis Maiquez <almamu@almamu.com>

Alexis Maiquez 6 år sedan
förälder
incheckning
274bb08e4f

+ 4 - 4
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);

+ 31 - 5
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

+ 8 - 0
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