|
@@ -4,10 +4,10 @@
|
|
|
|
|
|
|
|
#include "WallpaperEngine/Core/Core.h"
|
|
#include "WallpaperEngine/Core/Core.h"
|
|
|
#include "WallpaperEngine/Core/Objects/CImage.h"
|
|
#include "WallpaperEngine/Core/Objects/CImage.h"
|
|
|
-#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h"
|
|
|
|
|
-#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h"
|
|
|
|
|
-#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h"
|
|
|
|
|
-#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h"
|
|
|
|
|
|
|
+#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
|
|
|
|
+#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
|
|
|
|
|
+#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h"
|
|
|
|
|
+#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h"
|
|
|
|
|
|
|
|
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
|
|
|
|
|
|
@@ -46,6 +46,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object)
|
|
|
auto preview_it = content.find ("preview");
|
|
auto preview_it = content.find ("preview");
|
|
|
auto passes_it = content.find ("passes");
|
|
auto passes_it = content.find ("passes");
|
|
|
auto dependencies_it = content.find ("dependencies");
|
|
auto dependencies_it = content.find ("dependencies");
|
|
|
|
|
+ auto fbos_it = content.find ("fbos");
|
|
|
|
|
|
|
|
if (name_it == content.end ())
|
|
if (name_it == content.end ())
|
|
|
{
|
|
{
|
|
@@ -85,35 +86,18 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object)
|
|
|
object
|
|
object
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- auto cur = (*passes_it).begin ();
|
|
|
|
|
- auto end = (*passes_it).end ();
|
|
|
|
|
-
|
|
|
|
|
- for (; cur != end; cur ++)
|
|
|
|
|
- {
|
|
|
|
|
- auto materialfile = (*cur).find ("material");
|
|
|
|
|
-
|
|
|
|
|
- if (materialfile == (*cur).end ())
|
|
|
|
|
- {
|
|
|
|
|
- throw std::runtime_error ("Effect pass must have a material file");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- effect->insertMaterial (
|
|
|
|
|
- Images::CMaterial::fromFile ((*materialfile).get <std::string> ().c_str ())
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ CEffect::materialsFromJSON (passes_it, effect);
|
|
|
|
|
+ CEffect::dependencyFromJSON (dependencies_it, effect);
|
|
|
|
|
|
|
|
- cur = (*dependencies_it).begin ();
|
|
|
|
|
- end = (*dependencies_it).end ();
|
|
|
|
|
-
|
|
|
|
|
- for (; cur != end; cur ++)
|
|
|
|
|
|
|
+ if (fbos_it != content.end ())
|
|
|
{
|
|
{
|
|
|
- effect->insertDependency (*cur);
|
|
|
|
|
|
|
+ CEffect::fbosFromJSON (fbos_it, effect);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (effectpasses_it != data.end ())
|
|
if (effectpasses_it != data.end ())
|
|
|
{
|
|
{
|
|
|
- cur = (*effectpasses_it).begin ();
|
|
|
|
|
- end = (*effectpasses_it).end ();
|
|
|
|
|
|
|
+ auto cur = (*effectpasses_it).begin ();
|
|
|
|
|
+ auto end = (*effectpasses_it).end ();
|
|
|
|
|
|
|
|
for (int passNumber = 0; cur != end; cur ++, passNumber ++)
|
|
for (int passNumber = 0; cur != end; cur ++, passNumber ++)
|
|
|
{
|
|
{
|
|
@@ -149,19 +133,19 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object)
|
|
|
|
|
|
|
|
CImage* image = object->as <CImage> ();
|
|
CImage* image = object->as <CImage> ();
|
|
|
|
|
|
|
|
- texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ()->begin ());
|
|
|
|
|
|
|
+ texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ());
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
texture = *texturesCur;
|
|
texture = *texturesCur;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- std::vector<std::string>* passTextures = (*passCur)->getTextures ();
|
|
|
|
|
|
|
+ std::vector<std::string> passTextures = (*passCur)->getTextures ();
|
|
|
|
|
|
|
|
- if (textureNumber < passTextures->size ())
|
|
|
|
|
- passTextures->at (textureNumber) = texture;
|
|
|
|
|
|
|
+ if (textureNumber < passTextures.size ())
|
|
|
|
|
+ (*passCur)->setTexture (textureNumber, texture);
|
|
|
else
|
|
else
|
|
|
- passTextures->push_back (texture);
|
|
|
|
|
|
|
+ (*passCur)->insertTexture (texture);
|
|
|
|
|
|
|
|
textureNumber ++;
|
|
textureNumber ++;
|
|
|
}
|
|
}
|
|
@@ -169,43 +153,12 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object)
|
|
|
|
|
|
|
|
if (combos_it != (*cur).end ())
|
|
if (combos_it != (*cur).end ())
|
|
|
{
|
|
{
|
|
|
- auto comboCur = (*combos_it).begin ();
|
|
|
|
|
- auto comboEnd = (*combos_it).end ();
|
|
|
|
|
-
|
|
|
|
|
- for (; comboCur != comboEnd; comboCur ++)
|
|
|
|
|
- {
|
|
|
|
|
- (*passCur)->insertCombo (comboCur.key (), *comboCur);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ CEffect::combosFromJSON (combos_it, *passCur);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (constants_it != (*cur).end ())
|
|
if (constants_it != (*cur).end ())
|
|
|
{
|
|
{
|
|
|
- auto constantCur = (*constants_it).begin ();
|
|
|
|
|
- auto constantEnd = (*constants_it).end ();
|
|
|
|
|
-
|
|
|
|
|
- for (; constantCur != constantEnd; constantCur ++)
|
|
|
|
|
- {
|
|
|
|
|
- Effects::CShaderConstant* constant = nullptr;
|
|
|
|
|
-
|
|
|
|
|
- if ((*constantCur).is_number_float () == true)
|
|
|
|
|
- {
|
|
|
|
|
- constant = new Effects::CShaderConstantFloat ((*constantCur).get <irr::f32> ());
|
|
|
|
|
- }
|
|
|
|
|
- else if ((*constantCur).is_number_integer () == true)
|
|
|
|
|
- {
|
|
|
|
|
- constant = new Effects::CShaderConstantInteger ((*constantCur).get <irr::s32> ());
|
|
|
|
|
- }
|
|
|
|
|
- else if ((*constantCur).is_string () == true)
|
|
|
|
|
- {
|
|
|
|
|
- constant = new Effects::CShaderConstantVector3 (WallpaperEngine::Core::ato3vf (*constantCur));
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- throw std::runtime_error ("unknown shader constant type");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- (*passCur)->insertConstant (constantCur.key (), constant);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ CEffect::constantsFromJSON (constants_it, *passCur);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -214,6 +167,101 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object)
|
|
|
return effect;
|
|
return effect;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void CEffect::combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPassess* pass)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = (*combos_it).begin ();
|
|
|
|
|
+ auto end = (*combos_it).end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ pass->insertCombo (cur.key (), *cur);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPassess* pass)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = (*constants_it).begin ();
|
|
|
|
|
+ auto end = (*constants_it).end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Effects::Constants::CShaderConstant* constant = nullptr;
|
|
|
|
|
+
|
|
|
|
|
+ if ((*cur).is_number_float () == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ constant = new Effects::Constants::CShaderConstantFloat ((*cur).get <irr::f32> ());
|
|
|
|
|
+ }
|
|
|
|
|
+ else if ((*cur).is_number_integer () == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ constant = new Effects::Constants::CShaderConstantInteger ((*cur).get <irr::s32> ());
|
|
|
|
|
+ }
|
|
|
|
|
+ else if ((*cur).is_string () == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ constant = new Effects::Constants::CShaderConstantVector3 (WallpaperEngine::Core::ato3vf (*cur));
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ throw std::runtime_error ("unknown shader constant type");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pass->insertConstant (cur.key (), constant);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CEffect::fbosFromJSON (json::const_iterator fbos_it, CEffect* effect)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = (*fbos_it).begin ();
|
|
|
|
|
+ auto end = (*fbos_it).end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ effect->insertFBO (
|
|
|
|
|
+ Effects::CFBO::fromJSON (*cur)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CEffect::dependencyFromJSON (json::const_iterator dependencies_it, CEffect* effect)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = (*dependencies_it).begin ();
|
|
|
|
|
+ auto end = (*dependencies_it).end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ effect->insertDependency (*cur);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CEffect::materialsFromJSON (json::const_iterator passes_it, CEffect* effect)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = (*passes_it).begin ();
|
|
|
|
|
+ auto end = (*passes_it).end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ auto materialfile = (*cur).find ("material");
|
|
|
|
|
+ auto target = (*cur).find ("target");
|
|
|
|
|
+
|
|
|
|
|
+ if (materialfile == (*cur).end ())
|
|
|
|
|
+ {
|
|
|
|
|
+ throw std::runtime_error ("Effect pass must have a material file");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (target == (*cur).end ())
|
|
|
|
|
+ {
|
|
|
|
|
+ effect->insertMaterial (
|
|
|
|
|
+ Images::CMaterial::fromFile ((*materialfile).get <std::string> ().c_str ())
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ effect->insertMaterial (
|
|
|
|
|
+ Images::CMaterial::fromFile ((*materialfile).get <std::string> ().c_str (), *target)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const std::vector<std::string>& CEffect::getDependencies () const
|
|
const std::vector<std::string>& CEffect::getDependencies () const
|
|
|
{
|
|
{
|
|
|
return this->m_dependencies;
|
|
return this->m_dependencies;
|
|
@@ -224,6 +272,27 @@ const std::vector<Images::CMaterial*>& CEffect::getMaterials () const
|
|
|
return this->m_materials;
|
|
return this->m_materials;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const std::vector<Effects::CFBO*>& CEffect::getFbos () const
|
|
|
|
|
+{
|
|
|
|
|
+ return this->m_fbos;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Effects::CFBO* CEffect::findFBO (const std::string& name)
|
|
|
|
|
+{
|
|
|
|
|
+ auto cur = this->m_fbos.begin ();
|
|
|
|
|
+ auto end = this->m_fbos.end ();
|
|
|
|
|
+
|
|
|
|
|
+ for (; cur != end; cur ++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ((*cur)->getName () == name)
|
|
|
|
|
+ {
|
|
|
|
|
+ return (*cur);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ throw std::runtime_error ("cannot find fbo named " + name);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void CEffect::insertDependency (const std::string& dep)
|
|
void CEffect::insertDependency (const std::string& dep)
|
|
|
{
|
|
{
|
|
|
this->m_dependencies.push_back (dep);
|
|
this->m_dependencies.push_back (dep);
|
|
@@ -232,4 +301,9 @@ void CEffect::insertDependency (const std::string& dep)
|
|
|
void CEffect::insertMaterial (Images::CMaterial* material)
|
|
void CEffect::insertMaterial (Images::CMaterial* material)
|
|
|
{
|
|
{
|
|
|
this->m_materials.push_back (material);
|
|
this->m_materials.push_back (material);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CEffect::insertFBO (Effects::CFBO* fbo)
|
|
|
|
|
+{
|
|
|
|
|
+ this->m_fbos.push_back (fbo);
|
|
|
}
|
|
}
|