Przeglądaj źródła

Bumped up shader version to 150 (work on shaders not compiling for #115 and #117)
Improved jsonFindDefault to not crash when the value types do not match (should partially fix #116)

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

Alexis Maiquez 4 lat temu
rodzic
commit
8955ba791c

+ 19 - 0
src/WallpaperEngine/Core/Core.cpp

@@ -104,6 +104,25 @@ template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char
     if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
         return defaultValue;
 
+    // type checks
+    if ((std::is_same <T, float>::value || std::is_same <T, double>::value) && value->type () != nlohmann::detail::value_t::number_float)
+    {
+        fprintf(stderr, "%s is not of type double, returning default value\n", key);
+        return defaultValue;
+    }
+    else if (std::is_same <T, std::string>::value && value->type () != nlohmann::detail::value_t::string)
+    {
+        fprintf (stderr, "%s is not of type string, returning default value\n", key);
+        return defaultValue;
+    }
+    else if (std::is_same <T, bool>::value && value->type () != nlohmann::detail::value_t::boolean)
+    {
+        fprintf (stderr, "%s is not of type boolean, returning default value\n", key);
+        return defaultValue;
+    }
+
+    // TODO: SUPPORT INTEGERS AND OTHER TYPES
+
     return *value;
 }
 

+ 4 - 4
src/WallpaperEngine/Core/Objects/CEffect.cpp

@@ -36,18 +36,18 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object, CContainer* contai
     json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get <std::string> (), container));
 
     auto name_it = jsonFindRequired (content, "name", "Effect must have a name");
-    auto description_it = jsonFindRequired (content, "description", "Effect must have a description");
+    auto description = jsonFindDefault <std::string> (content, "description", "");
     auto group_it = jsonFindRequired (content, "group", "Effect must have a group");
-    auto preview_it = jsonFindRequired (content, "preview", "Effect must have a preview");
+    auto preview = jsonFindDefault <std::string> (content, "preview", "");
     auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
     auto dependencies_it = jsonFindRequired (content, "dependencies", "");
     auto fbos_it = content.find ("fbos");
 
     CEffect* effect = new CEffect (
         *name_it,
-        *description_it,
+        description,
         *group_it,
-        *preview_it,
+        preview,
         object
     );
 

+ 15 - 1
src/WallpaperEngine/Render/Shaders/Compiler.cpp

@@ -478,7 +478,7 @@ namespace WallpaperEngine::Render::Shaders
         if (this->m_recursive == false)
         {
             // add the opengl compatibility at the top
-            finalCode =   "#version 130\n"
+            finalCode =   "#version 150\n"
                           "#define highp\n"
                           "#define mediump\n"
                           "#define lowp\n"
@@ -503,6 +503,20 @@ namespace WallpaperEngine::Render::Shaders
                           "#define float3 vec3\n"
                           "#define float4 vec4\n";
 
+            if (this->m_type == Type_Vertex)
+            {
+                finalCode +=
+                    "#define varying out\n"
+                    "#define attribute in\n";
+            }
+            else
+            {
+                finalCode +=
+                    "#define varying in\n"
+                    "#define gl_FragColor glOutColor\n"
+                    "out vec4 glOutColor;\n";
+            }
+
             // add combo values
             auto cur = this->m_combos->begin ();
             auto end = this->m_combos->end ();