Ver código fonte

CFBO frame dummy values added
Added combo properties support
Bumped up GLSL version to 130 and added some extra definitions

This work goes on to #115, although the background won't start up yet because of shader compilation issues

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

Alexis Maiquez 4 anos atrás
pai
commit
09effd0303

+ 2 - 0
CMakeLists.txt

@@ -130,6 +130,8 @@ add_executable(
         src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp
         src/WallpaperEngine/Core/Projects/CPropertySlider.h
         src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
+        src/WallpaperEngine/Core/Projects/CPropertyCombo.h
+        src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp
 
         src/WallpaperEngine/Core/Scenes/CCamera.cpp
         src/WallpaperEngine/Core/Scenes/CCamera.h

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

@@ -85,6 +85,18 @@ nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const cha
     return value;
 }
 
+nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json::iterator& data, const char *key, const char *notFoundMsg)
+{
+    auto value = (*data).find (key);
+
+    if (value == (*data).end ())
+    {
+        throw std::runtime_error (notFoundMsg);
+    }
+
+    return value;
+}
+
 template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue)
 {
     auto value = data.find (key);

+ 1 - 0
src/WallpaperEngine/Core/Core.h

@@ -28,5 +28,6 @@ namespace WallpaperEngine::Core
     IntegerColor aToColori (const std::string& str);
 
     nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg);
+    nlohmann::json::iterator jsonFindRequired (nlohmann::json::iterator& data, const char *key, const char *notFoundMsg);
     template <typename T> T jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue);
 };

+ 9 - 1
src/WallpaperEngine/Core/Projects/CProperty.cpp

@@ -1,5 +1,7 @@
+#include <sstream>
 #include "CProperty.h"
 #include "CPropertyColor.h"
+#include "CPropertyCombo.h"
 #include "CPropertySlider.h"
 #include "CPropertyBoolean.h"
 
@@ -20,7 +22,13 @@ CProperty* CProperty::fromJSON (json data, const std::string& name)
     if (*type == CPropertySlider::Type)
         return CPropertySlider::fromJSON (data, name);
 
-    throw std::runtime_error ("Unexpected type for property");
+    if (*type == CPropertyCombo::Type)
+        return CPropertyCombo::fromJSON (data, name);
+
+    std::stringstream buffer;
+    buffer << "Unexpected type for property:" << *type << std::endl << data;
+    // throw an exception
+    throw std::runtime_error (buffer.str());
 }
 
 CProperty::CProperty (std::string name, std::string type, std::string text) :

+ 58 - 0
src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp

@@ -0,0 +1,58 @@
+#include "CPropertyCombo.h"
+#include "WallpaperEngine/Core/Core.h"
+
+using namespace WallpaperEngine::Core::Projects;
+
+CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name)
+{
+    auto value = data.find ("value");
+    auto text = data.find ("type");
+    auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
+
+    CPropertyCombo* combo = new CPropertyCombo (
+        name,
+        *text
+    );
+
+    if (options->is_array () == false)
+        throw std::runtime_error ("Property combo options should be an array");
+
+    auto cur = (*options).begin ();
+    auto end = (*options).end ();
+
+    for (; cur != end; cur ++)
+    {
+        if ((*cur).is_object () == false)
+        {
+            // TODO: PROPERLY REPORT THESE ISSUES
+            continue;
+        }
+
+        // check for label and value to ensure they're there
+        auto label = jsonFindRequired (*cur, "label", "Label is required for a property combo option");
+        auto value = jsonFindRequired (*cur, "value", "Value is required for a property combo option");
+
+        combo->addValue (*label, *value);
+    }
+
+    return combo;
+}
+
+CPropertyCombo::CPropertyCombo (const std::string& name, const std::string& text) :
+    CProperty (name, Type, text)
+{
+}
+
+
+
+void CPropertyCombo::addValue (std::string label, std::string value)
+{
+    CPropertyComboValue* prop = new CPropertyComboValue;
+
+    prop->label = std::move (label);
+    prop->value = std::move (value);
+
+    this->m_values.push_back (prop);
+}
+
+const std::string CPropertyCombo::Type = "combo";

+ 30 - 0
src/WallpaperEngine/Core/Projects/CPropertyCombo.h

@@ -0,0 +1,30 @@
+#pragma once
+
+#include "CProperty.h"
+
+namespace WallpaperEngine::Core::Projects
+{
+    using json = nlohmann::json;
+
+    class CPropertyComboValue
+    {
+    public:
+        std::string label;
+        std::string value;
+    };
+
+    class CPropertyCombo : public CProperty
+    {
+    public:
+        static CPropertyCombo* fromJSON (json data, const std::string& name);
+
+        static const std::string Type;
+
+    private:
+        CPropertyCombo (const std::string& name, const std::string& text);
+
+        void addValue (std::string label, std::string value);
+
+        std::vector <CPropertyComboValue*> m_values;
+    };
+};

+ 15 - 1
src/WallpaperEngine/Render/CFBO.cpp

@@ -42,6 +42,20 @@ CFBO::CFBO (std::string name, ITexture::TextureFormat format, float scale, uint3
         textureWidth, textureHeight,
         realWidth, realHeight
     };
+
+    // create the textureframe entries
+    TextureFrame* frame = new TextureFrame;
+
+    frame->frameNumber = 0;
+    frame->frametime = 0;
+    frame->height1 = textureHeight;
+    frame->height2 = realHeight;
+    frame->width1 = textureWidth;
+    frame->width2 = realWidth;
+    frame->x = 0;
+    frame->y = 0;
+
+    this->m_frames.push_back (frame);
 }
 
 const std::string& CFBO::getName () const
@@ -95,7 +109,7 @@ const uint32_t CFBO::getRealHeight () const
 
 const std::vector<ITexture::TextureFrame*>& CFBO::getFrames () const
 {
-    return std::vector<TextureFrame*> ();
+    return this->m_frames;
 }
 
 const glm::vec4* CFBO::getResolution () const

+ 2 - 0
src/WallpaperEngine/Render/CFBO.h

@@ -36,5 +36,7 @@ namespace WallpaperEngine::Render
         float m_scale;
         std::string m_name;
         ITexture::TextureFormat m_format;
+        /** Placeholder for frames, FBOs only have ONE */
+        std::vector<TextureFrame*> m_frames;
     };
 };

+ 9 - 4
src/WallpaperEngine/Render/Shaders/Compiler.cpp

@@ -478,12 +478,13 @@ namespace WallpaperEngine::Render::Shaders
         if (this->m_recursive == false)
         {
             // add the opengl compatibility at the top
-            finalCode =   "#version 120\n"
+            finalCode =   "#version 130\n"
                           "#define highp\n"
                           "#define mediump\n"
                           "#define lowp\n"
-                          "#define mul(x, y) (y * x)\n"
+                          "#define mul(x, y) ((y) * (x))\n"
                           "#define max(x, y) max (y, x)\n"
+                          "#define lerp mix\n"
                           "#define frac fract\n"
                           "#define CAST2(x) (vec2(x))\n"
                           "#define CAST3(x) (vec3(x))\n"
@@ -491,12 +492,16 @@ namespace WallpaperEngine::Render::Shaders
                           "#define CAST3X3(x) (mat3(x))\n"
                           "#define saturate(x) (clamp(x, 0.0, 1.0))\n"
                           "#define texSample2D texture2D\n"
-                          "#define texSample2DLod texture2D\n"
+                          "#define texSample2DLod textureLod\n"
                           "#define atan2 atan\n"
                           "#define ddx dFdx\n"
                           "#define ddy(x) dFdy(-(x))\n"
                           "#define GLSL 1\n"
-                          "#define HLSL 1\n";
+                          "#define HLSL 1\n"
+                          "#define float1 float\n"
+                          "#define float2 vec2\n"
+                          "#define float3 vec3\n"
+                          "#define float4 vec4\n";
 
             // add combo values
             auto cur = this->m_combos->begin ();