From 32a6a7af658cecd9c3cc51ab095c1ac917fb2ddc Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Sun, 8 Sep 2019 21:09:19 +0200 Subject: [PATCH 01/31] + Added parsing of shader constants for effects ~ Improved Shader Compiler parameter list to a better approach + Added support for one-pass effects with shaders (only first shader/pass will be applied) Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 22 +++ main.cpp | 10 +- src/WallpaperEngine/Core/CObject.cpp | 6 +- src/WallpaperEngine/Core/CObject.h | 1 + src/WallpaperEngine/Core/Objects/CEffect.cpp | 46 ++++++ src/WallpaperEngine/Core/Objects/CEffect.h | 4 + src/WallpaperEngine/Core/Objects/CImage.cpp | 6 + src/WallpaperEngine/Core/Objects/CImage.h | 1 + .../Core/Objects/Effects/CShaderConstant.cpp | 8 + .../Core/Objects/Effects/CShaderConstant.h | 20 +++ .../Objects/Effects/CShaderConstantFloat.cpp | 17 ++ .../Objects/Effects/CShaderConstantFloat.h | 22 +++ .../Effects/CShaderConstantInteger.cpp | 17 ++ .../Objects/Effects/CShaderConstantInteger.h | 22 +++ .../Objects/Effects/CShaderConstantString.cpp | 19 +++ .../Objects/Effects/CShaderConstantString.h | 22 +++ src/WallpaperEngine/Render/Objects/CImage.cpp | 148 ++++++++++++++++-- src/WallpaperEngine/Render/Objects/CImage.h | 5 + .../Render/Shaders/Compiler.cpp | 114 +++++--------- src/WallpaperEngine/Render/Shaders/Compiler.h | 33 +--- .../Shaders/Parameters/CShaderParameter.cpp | 46 ++++++ .../Shaders/Parameters/CShaderParameter.h | 37 +++++ .../Parameters/CShaderParameterFloat.cpp | 25 +++ .../Parameters/CShaderParameterFloat.h | 24 +++ .../Parameters/CShaderParameterInteger.cpp | 24 +++ .../Parameters/CShaderParameterInteger.h | 24 +++ .../Parameters/CShaderParameterVector2.cpp | 25 +++ .../Parameters/CShaderParameterVector2.h | 24 +++ .../Parameters/CShaderParameterVector3.cpp | 24 +++ .../Parameters/CShaderParameterVector3.h | 24 +++ .../Parameters/CShaderParameterVector4.cpp | 24 +++ .../Parameters/CShaderParameterVector4.h | 24 +++ 32 files changed, 752 insertions(+), 116 deletions(-) create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 52c4dde..607442f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,19 @@ add_executable( src/WallpaperEngine/Core/Core.h src/WallpaperEngine/Core/Core.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h + src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp + src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -76,6 +89,15 @@ add_executable( src/WallpaperEngine/Core/Objects/CParticle.cpp src/WallpaperEngine/Core/Objects/CParticle.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp + src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp diff --git a/main.cpp b/main.cpp index 6c978dc..bfd0a3a 100644 --- a/main.cpp +++ b/main.cpp @@ -301,6 +301,9 @@ int main (int argc, char* argv[]) while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) { + if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) + continue; + // if (device->isWindowActive ()) { currentTime = startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); @@ -316,17 +319,14 @@ int main (int argc, char* argv[]) // change viewport to render to the correct portion of the display IrrlichtContext->getDevice ()->getVideoDriver ()->setViewPort (*cur); - if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) - continue; - - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene(false, true, irr::video::SColor(0, 0, 0, 0)); + IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (false, true, irr::video::SColor(0, 0, 0, 0)); IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); } } else { - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene(false, true, irr::video::SColor(0, 0, 0, 0)); + IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (true, true, irr::video::SColor(0, 0, 0, 0)); IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); } diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 52bb31e..945b89d 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -33,7 +33,6 @@ CObject* CObject::fromJSON (json data) json::const_iterator visible_it = data.find ("visible"); json::const_iterator origin_it = data.find ("origin"); json::const_iterator scale_it = data.find ("scale"); - json::const_iterator size_it = data.find ("size"); json::const_iterator angles_it = data.find ("angles"); json::const_iterator name_it = data.find ("name"); json::const_iterator effects_it = data.find ("effects"); @@ -152,6 +151,11 @@ std::vector* CObject::getEffects () return &this->m_effects; } +bool CObject::isVisible () +{ + return this->m_visible; +} + int CObject::getId () { return this->m_id; diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index 7b34aef..b33c303 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -31,6 +31,7 @@ namespace WallpaperEngine::Core irr::core::vector3df* getScale (); irr::core::vector3df* getAngles (); + bool isVisible (); protected: CObject ( bool visible, diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 2a84828..8a8fd34 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -3,6 +3,10 @@ #include #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/CShaderConstantString.h" +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine; @@ -111,6 +115,38 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) for (int passNumber = 0; cur != end; cur ++, passNumber ++) { + json::const_iterator constants_it = (*cur).find ("constantshadervalues"); + + if (constants_it == (*cur).end ()) + continue; + + json::const_iterator constantCur = (*constants_it).begin (); + json::const_iterator constantEnd = (*constants_it).end (); + + for (; constantCur != constantEnd; constantCur ++) + { + Effects::CShaderConstant* constant = nullptr; + + if ((*constantCur).is_number_float () == true) + { + constant = new Effects::CShaderConstantFloat ((*constantCur).get ()); + } + else if ((*constantCur).is_number_integer () == true) + { + constant = new Effects::CShaderConstantInteger ((*constantCur).get ()); + } + else if ((*constantCur).is_string () == true) + { + constant = new Effects::CShaderConstantString ((*constantCur).get ()); + } + else + { + throw std::runtime_error ("unknown shader constant type"); + } + + effect->insertConstant (constantCur.key (), constant); + } + json::const_iterator textures_it = (*cur).find ("textures"); if (textures_it == (*cur).end ()) @@ -172,6 +208,11 @@ std::vector* CEffect::getMaterials () return &this->m_materials; } +std::map* CEffect::getConstants () +{ + return &this->m_constants; +} + void CEffect::insertDependency (const std::string& dep) { this->m_dependencies.push_back (dep); @@ -180,4 +221,9 @@ void CEffect::insertDependency (const std::string& dep) void CEffect::insertMaterial (Images::CMaterial* material) { this->m_materials.push_back (material); +} + +void CEffect::insertConstant (const std::string& name, Effects::CShaderConstant* constant) +{ + this->m_constants.insert (std::pair (name, constant)); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index 66ee4b5..a23915b 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -3,6 +3,7 @@ #include #include +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" #include "WallpaperEngine/Core/CObject.h" #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" @@ -30,9 +31,11 @@ namespace WallpaperEngine::Core::Objects std::vector* getDependencies (); std::vector* getMaterials (); + std::map* getConstants (); protected: void insertDependency (const std::string& dep); void insertMaterial (Images::CMaterial* material); + void insertConstant (const std::string& name, Effects::CShaderConstant* constant); private: std::string m_name; std::string m_description; @@ -42,5 +45,6 @@ namespace WallpaperEngine::Core::Objects std::vector m_dependencies; std::vector m_materials; + std::map m_constants; }; } diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index 07c195c..76da058 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -64,4 +64,10 @@ Images::CMaterial* CImage::getMaterial () return this->m_material; } +irr::core::vector2df* CImage::getSize () +{ + return &this->m_size; +} + + const std::string CImage::Type = "image"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index f2528b5..38f5a94 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -27,6 +27,7 @@ namespace WallpaperEngine::Core::Objects ); Images::CMaterial* getMaterial (); + irr::core::vector2df* getSize (); protected: CImage ( diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp new file mode 100644 index 0000000..2ed3226 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp @@ -0,0 +1,8 @@ +#include "CShaderConstant.h" + +using namespace WallpaperEngine::Core::Objects::Effects; + +CShaderConstant::CShaderConstant (std::string type) : + m_type (std::move(type)) +{ +} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h new file mode 100644 index 0000000..1593e25 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + class CShaderConstant + { + public: + CShaderConstant (std::string type); + + template const T* As () const { assert (Is ()); return (const T*) this; } + template T* As () { assert (Is ()); return (T*) this; } + + template bool Is () { return this->m_type == T::Type; } + + private: + std::string m_type; + }; +} diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp new file mode 100644 index 0000000..cf70921 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp @@ -0,0 +1,17 @@ +#include "CShaderConstantFloat.h" + +using namespace WallpaperEngine::Core::Objects::Effects; + + +CShaderConstantFloat::CShaderConstantFloat (irr::f32 value) : + CShaderConstant (Type), + m_value (value) +{ +} + +irr::f32* CShaderConstantFloat::getValue () +{ + return &this->m_value; +} + +const std::string CShaderConstantFloat::Type = "float"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h new file mode 100644 index 0000000..992a19f --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h @@ -0,0 +1,22 @@ +#pragma once + +#include "CShaderConstant.h" + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + class CShaderConstantFloat : public CShaderConstant + { + public: + CShaderConstantFloat (irr::f32 value); + + irr::f32* getValue (); + + protected: + irr::f32 m_value; + + static const std::string Type; + }; +} diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp new file mode 100644 index 0000000..568bdf6 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp @@ -0,0 +1,17 @@ +#include "CShaderConstantInteger.h" + +using namespace WallpaperEngine::Core::Objects::Effects; + + +CShaderConstantInteger::CShaderConstantInteger (irr::s32 value) : + CShaderConstant (Type), + m_value (value) +{ +} + +irr::u32* CShaderConstantInteger::getValue () +{ + return &this->m_value; +} + +const std::string CShaderConstantInteger::Type = "integer"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h new file mode 100644 index 0000000..d49dcd6 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h @@ -0,0 +1,22 @@ +#pragma once + +#include "CShaderConstant.h" + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + class CShaderConstantInteger : public CShaderConstant + { + public: + CShaderConstantInteger (irr::s32 value); + + irr::u32* getValue (); + + protected: + irr::u32 m_value; + + static const std::string Type; + }; +} diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp new file mode 100644 index 0000000..431eccf --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp @@ -0,0 +1,19 @@ +#include "CShaderConstantString.h" + +#include + +using namespace WallpaperEngine::Core::Objects::Effects; + + +CShaderConstantString::CShaderConstantString (std::string value) : + CShaderConstant (Type), + m_value (std::move(value)) +{ +} + +std::string* CShaderConstantString::getValue () +{ + return &this->m_value; +} + +const std::string CShaderConstantString::Type = "string"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h new file mode 100644 index 0000000..d50bf9c --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h @@ -0,0 +1,22 @@ +#pragma once + +#include "CShaderConstant.h" + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + class CShaderConstantString : public CShaderConstant + { + public: + CShaderConstantString (std::string value); + + std::string* getValue (); + + protected: + std::string m_value; + + static const std::string Type; + }; +} diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index fcb718b..a94f242 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -1,9 +1,18 @@ #include "CImage.h" #include "WallpaperEngine/Render/Shaders/Compiler.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h" using namespace WallpaperEngine; using namespace WallpaperEngine::Render::Objects; +using namespace WallpaperEngine::Render::Shaders::Parameters; + +extern irr::f32 g_Time; CImage::CImage (CScene* scene, Core::Objects::CImage* image) : Render::CObject (scene, Type, image), @@ -82,17 +91,17 @@ void CImage::generateMaterial () // TODO: MOVE SHADER INITIALIZATION ELSEWHERE irr::io::path vertpath = std::string ("shaders/" + shader + ".vert").c_str (); irr::io::path fragpath = std::string ("shaders/" + shader + ".frag").c_str (); - Render::Shaders::Compiler* vertshader = new Render::Shaders::Compiler (vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); - Render::Shaders::Compiler* fragshader = new Render::Shaders::Compiler (fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); + this->m_vertexShader = new Render::Shaders::Compiler (vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); + this->m_pixelShader = new Render::Shaders::Compiler (fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); this->m_material.MaterialType = (irr::video::E_MATERIAL_TYPE) - this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()->addHighLevelShaderMaterial ( - vertshader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0, - fragshader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0, - this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, irr::video::EGSL_DEFAULT - ); + this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()->addHighLevelShaderMaterial ( + this->m_vertexShader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0, + this->m_pixelShader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0, + this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, irr::video::EGSL_DEFAULT + ); - this->m_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL; + // this->m_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL; this->m_material.setFlag (irr::video::EMF_LIGHTING, false); this->m_material.setFlag (irr::video::EMF_BLEND_OPERATION, true); } @@ -105,14 +114,133 @@ const irr::core::aabbox3d& CImage::getBoundingBox() const void CImage::OnRegisterSceneNode () { - SceneManager->registerNodeForRendering (this); + if (this->m_image->isVisible () == true) + SceneManager->registerNodeForRendering (this); ISceneNode::OnRegisterSceneNode (); } void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData) { - // TODO: SUPPORT SHADER PARAMETERS HERE + irr::f32 g_Texture0 = 0; + irr::f32 g_Texture1 = 1; + irr::f32 g_Texture2 = 2; + irr::f32 g_Texture3 = 3; + irr::f32 g_Texture4 = 4; + irr::f32 g_Texture5 = 5; + irr::f32 g_Texture6 = 6; + irr::f32 g_Texture7 = 7; + + irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + + irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + + irr::video::IVideoDriver* driver = services->getVideoDriver (); + + irr::core::matrix4 worldViewProj;worldViewProj.makeIdentity(); + worldViewProj = driver->getTransform(irr::video::ETS_PROJECTION); + worldViewProj *= driver->getTransform(irr::video::ETS_VIEW); + worldViewProj *= driver->getTransform(irr::video::ETS_WORLD); + + std::vector::const_iterator cur = this->m_vertexShader->getParameters ().begin (); + std::vector::const_iterator end = this->m_vertexShader->getParameters ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->Is () == true) + { + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::s32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + else if ( + (*cur)->Is () == true || + (*cur)->Is () == true || + (*cur)->Is () == true || + (*cur)->Is () == true) + { + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } + + cur = this->m_pixelShader->getParameters ().begin (); + end = this->m_pixelShader->getParameters ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->Is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::s32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + else if ( + (*cur)->Is () == true || + (*cur)->Is () == true || + (*cur)->Is () == true || + (*cur)->Is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } + + services->setVertexShaderConstant ("g_Time", &g_Time, 1); + services->setPixelShaderConstant ("g_Time", &g_Time, 1); + + services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16); + + services->setVertexShaderConstant ("g_Texture0Resolution", g_Texture0Resolution, 4); + services->setVertexShaderConstant ("g_Texture1Resolution", g_Texture1Resolution, 4); + services->setVertexShaderConstant ("g_Texture2Resolution", g_Texture2Resolution, 4); + services->setVertexShaderConstant ("g_Texture3Resolution", g_Texture3Resolution, 4); + services->setVertexShaderConstant ("g_Texture4Resolution", g_Texture4Resolution, 4); + services->setVertexShaderConstant ("g_Texture5Resolution", g_Texture5Resolution, 4); + services->setVertexShaderConstant ("g_Texture6Resolution", g_Texture6Resolution, 4); + services->setVertexShaderConstant ("g_Texture7Resolution", g_Texture7Resolution, 4); + + services->setVertexShaderConstant ("g_Texture0Rotation", g_Texture0Rotation, 4); + services->setVertexShaderConstant ("g_Texture1Rotation", g_Texture1Rotation, 4); + services->setVertexShaderConstant ("g_Texture2Rotation", g_Texture2Rotation, 4); + services->setVertexShaderConstant ("g_Texture3Rotation", g_Texture3Rotation, 4); + services->setVertexShaderConstant ("g_Texture4Rotation", g_Texture4Rotation, 4); + services->setVertexShaderConstant ("g_Texture5Rotation", g_Texture5Rotation, 4); + services->setVertexShaderConstant ("g_Texture6Rotation", g_Texture6Rotation, 4); + services->setVertexShaderConstant ("g_Texture7Rotation", g_Texture7Rotation, 4); + + services->setPixelShaderConstant ("g_Texture0", &g_Texture0, 1); + services->setPixelShaderConstant ("g_Texture1", &g_Texture1, 1); + services->setPixelShaderConstant ("g_Texture2", &g_Texture2, 1); + services->setPixelShaderConstant ("g_Texture3", &g_Texture3, 1); + services->setPixelShaderConstant ("g_Texture4", &g_Texture4, 1); + services->setPixelShaderConstant ("g_Texture5", &g_Texture5, 1); + services->setPixelShaderConstant ("g_Texture6", &g_Texture6, 1); + services->setPixelShaderConstant ("g_Texture7", &g_Texture7, 1); } const std::string CImage::Type = "image"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index 69de822..660c142 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -5,6 +5,8 @@ #include "WallpaperEngine/Render/CObject.h" #include "WallpaperEngine/Render/CScene.h" +#include "WallpaperEngine/Render/Shaders/Compiler.h" + using namespace WallpaperEngine; namespace WallpaperEngine::Render::Objects @@ -32,5 +34,8 @@ namespace WallpaperEngine::Render::Objects Core::Objects::CImage* m_image; irr::core::aabbox3d m_boundingBox; + + Render::Shaders::Compiler* m_vertexShader; + Render::Shaders::Compiler* m_pixelShader; }; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 6f74de4..a87b78f 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -10,6 +10,13 @@ #include #include +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h" +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h" + namespace WallpaperEngine::Render::Shaders { Compiler::Compiler (irr::io::path& file, Type type, std::map* combos, bool recursive) @@ -438,6 +445,13 @@ namespace WallpaperEngine::Render::Shaders } } + if (this->m_recursive == false) + { + + std::cout << "======================== COMPILED SHADER " << this->m_file.c_str () << " ========================" << std::endl; + std::cout << this->m_compiledContent << std::endl; + } + return this->m_compiledContent; #undef BREAK_IF_ERROR } @@ -499,102 +513,60 @@ namespace WallpaperEngine::Render::Shaders return; } - ShaderParameter* param = new ShaderParameter; + Parameters::CShaderParameter* parameter = nullptr; - param->identifierName = (*material).get (); - param->variableName = name; - param->type = type; - - if (type == "vec4" || type == "vec3") + if (type == "vec4") { - if ((*defvalue).is_string () == false) - { - irr::core::vector3df* vector = new irr::core::vector3df; - - vector->X = 0.0f; - vector->Y = 0.0f; - vector->Z = 0.0f; - - param->defaultValue = vector; - } - else - { - irr::core::vector3df tmp = WallpaperEngine::Core::ato3vf ((*defvalue).get ().c_str ()); - irr::core::vector3df* vector = new irr::core::vector3df; - - vector->X = tmp.X; - vector->Y = tmp.Y; - vector->Z = tmp.Z; - - param->defaultValue = vector; - } + parameter = new Parameters::CShaderParameterVector4 ( + WallpaperEngine::Core::ato3vf (*defvalue) + ); + } + else if (type == "vec3") + { + parameter = new Parameters::CShaderParameterVector3 ( + WallpaperEngine::Core::ato3vf (*defvalue) + ); } else if (type == "vec2") { - if ((*defvalue).is_string () == false) - { - irr::core::vector2df* vector = new irr::core::vector2df; - - vector->X = 0.0f; - vector->Y = 0.0f; - - param->defaultValue = vector; - } - else - { - irr::core::vector2df* vector = new irr::core::vector2df; - irr::core::vector2df tmp = WallpaperEngine::Core::ato2vf ((*defvalue).get ().c_str ()); - - vector->X = tmp.X; - vector->Y = tmp.Y; - - param->defaultValue = vector; - } + parameter = new Parameters::CShaderParameterVector2 ( + WallpaperEngine::Core::ato2vf (*defvalue) + ); } else if (type == "float") { - if ((*defvalue).is_number () == false) - { - irr::f32* val = new irr::f32; - - *val = 0.0f; - - param->defaultValue = val; - - } - else - { - irr::f32* val = new irr::f32; - - *val = (*defvalue).get (); - - param->defaultValue = val; - } + parameter = new Parameters::CShaderParameterFloat ((*defvalue).get ()); + } + else if (type == "int") + { + parameter = new Parameters::CShaderParameterInteger ((*defvalue).get ()); } else if (type == "sampler2D") { // samplers are not saved, we can ignore them for now - delete param; return; } else { this->m_error = true; - this->m_errorInfo = "Unknown parameter type: " + type + " for " + param->identifierName + " (" + param->variableName + ")"; + this->m_errorInfo = "Unknown parameter type: " + type + " for " + name; return; } - this->m_parameters.push_back (param); + parameter->setIdentifierName (*material); + parameter->setName (name); + + this->m_parameters.push_back (parameter); } - Compiler::ShaderParameter* Compiler::findParameter (std::string identifier) + Parameters::CShaderParameter* Compiler::findParameter (std::string identifier) { - std::vector::const_iterator cur = this->m_parameters.begin (); - std::vector::const_iterator end = this->m_parameters.end (); + std::vector::const_iterator cur = this->m_parameters.begin (); + std::vector::const_iterator end = this->m_parameters.end (); for (; cur != end; cur ++) { - if ((*cur)->identifierName == identifier) + if ((*cur)->getIdentifierName () == identifier) { return (*cur); } @@ -603,7 +575,7 @@ namespace WallpaperEngine::Render::Shaders return nullptr; } - std::vector & Compiler::getParameters () + std::vector & Compiler::getParameters () { return this->m_parameters; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 1db7f40..9140936 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -7,6 +7,7 @@ #include #include +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" namespace WallpaperEngine::Render::Shaders { @@ -18,32 +19,6 @@ namespace WallpaperEngine::Render::Shaders class Compiler { public: - /** - * Basic struct used to define all the shader variables - * the compiler will replace in pre-processing time - * to make sure the shaders compile under OpenGL - */ - struct VariableReplacement - { - const char* original; - const char* replacement; - }; - - struct TypeName - { - const char* name; - int size; - }; - - struct ShaderParameter - { - std::string type; - std::string variableName; - std::string identifierName; - void* defaultValue; - void* range [2]; - }; - /** * Types of shaders */ @@ -87,12 +62,12 @@ namespace WallpaperEngine::Render::Shaders * @param identifier The identifier to search for * @return The shader information */ - ShaderParameter* findParameter (std::string identifier); + Parameters::CShaderParameter* findParameter (std::string identifier); /** * @return The list of parameters available for this shader with their default values */ - std::vector & getParameters (); + std::vector & getParameters (); private: /** @@ -227,7 +202,7 @@ namespace WallpaperEngine::Render::Shaders /** * The parameters the shader needs */ - std::vector m_parameters; + std::vector m_parameters; /** * The combos the shader should be generated with */ diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp new file mode 100644 index 0000000..70e356b --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp @@ -0,0 +1,46 @@ +#include "CShaderParameter.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameter::CShaderParameter (void* defaultValue, void* value, std::string type) : + m_defaultValue (defaultValue), + m_value (value), + m_type (std::move(type)) +{ + +} + +void* CShaderParameter::getValue () +{ + if (this->m_value) + return this->m_value; + + return this->m_defaultValue; +} + +void CShaderParameter::setValue (void* value) +{ + this->m_value = value; +} + +std::string CShaderParameter::getIdentifierName () +{ + return this->m_identifierName; +} + +std::string CShaderParameter::getName () +{ + return this->m_name; +} + +void CShaderParameter::setIdentifierName (std::string identifierName) +{ + this->m_identifierName = std::move(identifierName); +} + +void CShaderParameter::setName (std::string name) +{ + this->m_name = std::move(name); +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h new file mode 100644 index 0000000..8cd91a8 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameter + { + public: + CShaderParameter (void* defaultValue, void* value, std::string type); + + template const T* As () const { assert (Is ()); return (const T*) this; } + template T* As () { assert (Is ()); return (T*) this; } + + template bool Is () { return this->m_type == T::Type; } + + std::string getIdentifierName (); + std::string getName (); + + void setIdentifierName (std::string identifierName); + void setName (std::string name); + void* getValue (); + + virtual int getSize () = 0; + + protected: + void setValue (void* value); + + private: + std::string m_identifierName; + std::string m_name; + std::string m_type; + + void* m_defaultValue; + void* m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp new file mode 100644 index 0000000..aeee7f6 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp @@ -0,0 +1,25 @@ +#include "CShaderParameterFloat.h" + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameterFloat::CShaderParameterFloat(irr::f32 defaultValue) : + m_defaultValue (defaultValue), + m_value (0), + CShaderParameter (&this->m_defaultValue, nullptr, Type) +{ + +} + +void CShaderParameterFloat::setValue (irr::f32 value) +{ + this->m_value = value; + + CShaderParameter::setValue (&this->m_value); +} + +int CShaderParameterFloat::getSize () +{ + return 1; +} + +const std::string CShaderParameterFloat::Type = "float"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h new file mode 100644 index 0000000..a8d4307 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h @@ -0,0 +1,24 @@ +#pragma once + +#include "CShaderParameter.h" + +#include + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameterFloat : public CShaderParameter + { + public: + CShaderParameterFloat (irr::f32 defaultValue); + + int getSize () override; + + void setValue (irr::f32 value); + + static const std::string Type; + + private: + irr::f32 m_defaultValue; + irr::f32 m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp new file mode 100644 index 0000000..1e997e1 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp @@ -0,0 +1,24 @@ +#include "CShaderParameterInteger.h" + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameterInteger::CShaderParameterInteger(irr::s32 defaultValue) : + m_defaultValue (defaultValue), + m_value (0), + CShaderParameter (&this->m_defaultValue, nullptr, Type) +{ + +} + +void CShaderParameterInteger::setValue (irr::s32 value) +{ + this->m_value = value; + CShaderParameter::setValue (&this->m_value); +} + +int CShaderParameterInteger::getSize () +{ + return 1; +} + +const std::string CShaderParameterInteger::Type = "int"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h new file mode 100644 index 0000000..79d750c --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h @@ -0,0 +1,24 @@ +#pragma once + +#include "CShaderParameter.h" + +#include + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameterInteger : public CShaderParameter + { + public: + CShaderParameterInteger (irr::s32 defaultValue); + + int getSize () override; + + static const std::string Type; + + void setValue (irr::s32 value); + + private: + irr::s32 m_defaultValue; + irr::s32 m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp new file mode 100644 index 0000000..0ffdb88 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp @@ -0,0 +1,25 @@ +#include "CShaderParameterVector2.h" + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameterVector2::CShaderParameterVector2 (const irr::core::vector2df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector2df ()), + CShaderParameter (&this->m_defaultValue, nullptr, Type) +{ + +} + +void CShaderParameterVector2::setValue (irr::core::vector2df value) +{ + this->m_value = value; + + CShaderParameter::setValue (&this->m_value); +} + +int CShaderParameterVector2::getSize () +{ + return 2; +} + +const std::string CShaderParameterVector2::Type = "vec2"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h new file mode 100644 index 0000000..7ce8b83 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameterVector2 : public CShaderParameter + { + public: + CShaderParameterVector2 (const irr::core::vector2df& defaultValue); + + int getSize () override; + + void setValue (irr::core::vector2df value); + + static const std::string Type; + + private: + irr::core::vector2df m_defaultValue; + irr::core::vector2df m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp new file mode 100644 index 0000000..e26191f --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp @@ -0,0 +1,24 @@ +#include "CShaderParameterVector3.h" + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameterVector3::CShaderParameterVector3 (const irr::core::vector3df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderParameter (&this->m_defaultValue, nullptr, Type) +{ + +} + +void CShaderParameterVector3::setValue (irr::core::vector3df value) +{ + this->m_value = value; + CShaderParameter::setValue (&this->m_value); +} + +int CShaderParameterVector3::getSize () +{ + return 3; +} + +const std::string CShaderParameterVector3::Type = "vec3"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h new file mode 100644 index 0000000..7216128 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameterVector3 : public CShaderParameter + { + public: + CShaderParameterVector3 (const irr::core::vector3df& defaultValue); + + int getSize () override; + + void setValue (irr::core::vector3df value); + + static const std::string Type; + + private: + irr::core::vector3df m_defaultValue; + irr::core::vector3df m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp new file mode 100644 index 0000000..75bc99e --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp @@ -0,0 +1,24 @@ +#include "CShaderParameterVector4.h" + +using namespace WallpaperEngine::Render::Shaders::Parameters; + +CShaderParameterVector4::CShaderParameterVector4 (const irr::core::vector3df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderParameter (&this->m_defaultValue, nullptr, Type) +{ + +} + +void CShaderParameterVector4::setValue (irr::core::vector3df value) +{ + this->m_value = value; + CShaderParameter::setValue (&this->m_value); +} + +int CShaderParameterVector4::getSize () +{ + return 4; +} + +const std::string CShaderParameterVector4::Type = "vec4"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h new file mode 100644 index 0000000..b378f18 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" + +namespace WallpaperEngine::Render::Shaders::Parameters +{ + class CShaderParameterVector4 : public CShaderParameter + { + public: + CShaderParameterVector4 (const irr::core::vector3df& defaultValue); + + int getSize () override; + + void setValue (irr::core::vector3df value); + + static const std::string Type; + + private: + irr::core::vector3df m_defaultValue; + irr::core::vector3df m_value; + }; +} From 7ab533aaabdc25d7d47487e999cf456d964773d3 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 02:30:29 +0200 Subject: [PATCH 02/31] + Support for multi-passes materials added Take in mind that this feature is still in development, so the result most likely will be very different from the actual wallpaper engine The final approach might be different from what's currently in use, but It's just a nice proof of concept approach Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Core/CObject.cpp | 5 + src/WallpaperEngine/Core/CObject.h | 1 + src/WallpaperEngine/Render/CCamera.cpp | 6 +- src/WallpaperEngine/Render/CCamera.h | 2 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 131 +++++++++++++----- src/WallpaperEngine/Render/Objects/CImage.h | 9 +- .../Render/Shaders/Compiler.cpp | 1 - 7 files changed, 116 insertions(+), 39 deletions(-) diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 945b89d..e69594d 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -146,6 +146,11 @@ irr::core::vector3df* CObject::getAngles () return &this->m_angles; } +std::string CObject::getName () +{ + return this->m_name; +} + std::vector* CObject::getEffects () { return &this->m_effects; diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index b33c303..6a7ecba 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -30,6 +30,7 @@ namespace WallpaperEngine::Core irr::core::vector3df* getOrigin (); irr::core::vector3df* getScale (); irr::core::vector3df* getAngles (); + std::string getName (); bool isVisible (); protected: diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index 435af98..539ed4c 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -32,7 +32,7 @@ irr::core::vector3df* CCamera::getUp () return this->m_camera->getUp (); } -void CCamera::setOrthogonalProjection (irr::u32 width, irr::u32 height) +void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) { irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( @@ -43,6 +43,6 @@ void CCamera::setOrthogonalProjection (irr::u32 width, irr::u32 height) this->m_sceneCamera->setProjectionMatrix (orthogonalProjection); this->m_scene->getContext ()->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_PROJECTION, orthogonalProjection); - this->m_scene->getContext ()->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_VIEW, orthogonalProjection); - this->m_scene->getContext ()->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_WORLD, orthogonalProjection); + this->m_scene->getContext ()->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_VIEW, identity); + this->m_scene->getContext ()->getDevice ()->getVideoDriver ()->setTransform (irr::video::ETS_WORLD, identity); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CCamera.h b/src/WallpaperEngine/Render/CCamera.h index 473d392..98d8442 100644 --- a/src/WallpaperEngine/Render/CCamera.h +++ b/src/WallpaperEngine/Render/CCamera.h @@ -14,7 +14,7 @@ namespace WallpaperEngine::Render CCamera (CScene* scene, Core::Scenes::CCamera* camera); ~CCamera (); - void setOrthogonalProjection (irr::u32 width, irr::u32 height); + void setOrthogonalProjection (irr::f32 width, irr::f32 height); irr::core::vector3df* getCenter (); irr::core::vector3df* getEye (); diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index a94f242..4a3ef54 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -16,7 +16,8 @@ extern irr::f32 g_Time; CImage::CImage (CScene* scene, Core::Objects::CImage* image) : Render::CObject (scene, Type, image), - m_image (image) + m_image (image), + m_passes (0) { // TODO: INITIALIZE NEEDED EFFECTS AND PROPERLY CALCULATE THESE? irr::f32 xright = this->m_image->getOrigin ()->X; @@ -58,11 +59,30 @@ void CImage::render() irr::video::IVideoDriver* driver = SceneManager->getVideoDriver (); - driver->setMaterial (this->m_material); - driver->drawVertexPrimitiveList ( - this->m_vertex, 4, indices, 1, - irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT - ); + std::vector::const_iterator cur = this->m_materials.begin (); + std::vector::const_iterator end = this->m_materials.end (); + + std::vector::const_iterator textureCur = this->m_renderTextures.begin (); + std::vector::const_iterator textureEnd = this->m_renderTextures.end (); + + for (; cur != end; cur ++) + { + if (textureCur == textureEnd) + { + driver->setRenderTarget (0, false, false); + } + else + { + driver->setRenderTarget (*textureCur, true, true, irr::video::SColor (0, 0, 0, 0)); + textureCur ++; + } + + driver->setMaterial (*cur); + driver->drawVertexPrimitiveList ( + this->m_vertex, 4, indices, 1, + irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT + ); + } } void CImage::generateMaterial () @@ -70,42 +90,88 @@ void CImage::generateMaterial () if (this->m_image->getMaterial ()->getPasses ()->empty () == true) return; - // TODO: SUPPORT OBJECT EFFECTS AND MULTIPLE MATERIAL PASSES - Core::Objects::Images::Materials::CPassess* pass = *this->m_image->getMaterial ()->getPasses ()->begin (); - std::string shader = pass->getShader (); + std::vector::const_iterator cur = this->m_image->getMaterial ()->getPasses ()->begin (); + std::vector::const_iterator end = this->m_image->getMaterial ()->getPasses ()->end (); + + for (; cur != end; cur ++, this->m_passes ++) + { + this->generatePass (*cur); + } + + std::vector::const_iterator effectCur = this->m_image->getEffects ()->begin (); + std::vector::const_iterator effectEnd = this->m_image->getEffects ()->end (); + + for (; effectCur != effectEnd; effectCur ++) + { + std::vector::const_iterator materialCur = (*effectCur)->getMaterials ()->begin (); + std::vector::const_iterator materialEnd = (*effectCur)->getMaterials ()->end (); + + for (; materialCur != materialEnd; materialCur ++) + { + cur = (*materialCur)->getPasses ()->begin (); + end = (*materialCur)->getPasses ()->end (); + + for (; cur != end; cur ++, this->m_passes ++) + { + this->generatePass (*cur); + } + } + } +} + +void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) +{ std::vector* textures = pass->getTextures (); + irr::video::SMaterial material; - std::vector::const_iterator cur = textures->begin (); - std::vector::const_iterator end = textures->end (); + std::vector::const_iterator texturesCur = textures->begin (); + std::vector::const_iterator texturesEnd = textures->end (); - for (int textureNumber = 0; cur != end; cur ++, textureNumber ++) + for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++, textureNumber ++) { // TODO: LOOK THIS UP PROPERLY - irr::io::path texturepath = std::string ("materials/" + (*cur) + ".tex").c_str (); + irr::io::path texturepath = std::string ("materials/" + (*texturesCur) + ".tex").c_str (); + irr::video::ITexture* texture = nullptr; - irr::video::ITexture* texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); + if (textureNumber == 0 && this->m_passes > 0) + { + texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( + irr::core::dimension2d ( + this->getScene ()->getScene ()->getOrthogonalProjection()->getWidth (), + this->getScene ()->getScene ()->getOrthogonalProjection()->getHeight () + ), ("_RT_" + this->m_image->getName ()).c_str () + ); - this->m_material.setTexture (textureNumber, texture); + this->m_renderTextures.push_back (texture); + } + else + { + texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); + } + + material.setTexture (textureNumber, texture); } // TODO: MOVE SHADER INITIALIZATION ELSEWHERE - irr::io::path vertpath = std::string ("shaders/" + shader + ".vert").c_str (); - irr::io::path fragpath = std::string ("shaders/" + shader + ".frag").c_str (); - this->m_vertexShader = new Render::Shaders::Compiler (vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); - this->m_pixelShader = new Render::Shaders::Compiler (fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); + irr::io::path vertpath = std::string ("shaders/" + pass->getShader () + ".vert").c_str (); + irr::io::path fragpath = std::string ("shaders/" + pass->getShader () + ".frag").c_str (); + Render::Shaders::Compiler* vertexShader = new Render::Shaders::Compiler (vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); + Render::Shaders::Compiler* pixelShader = new Render::Shaders::Compiler (fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); - this->m_material.MaterialType = (irr::video::E_MATERIAL_TYPE) + material.MaterialType = (irr::video::E_MATERIAL_TYPE) this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()->addHighLevelShaderMaterial ( - this->m_vertexShader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0, - this->m_pixelShader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0, - this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, irr::video::EGSL_DEFAULT + vertexShader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0, + pixelShader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0, + this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, this->m_passes, irr::video::EGSL_DEFAULT ); - // this->m_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL; - this->m_material.setFlag (irr::video::EMF_LIGHTING, false); - this->m_material.setFlag (irr::video::EMF_BLEND_OPERATION, true); -} + material.setFlag (irr::video::EMF_LIGHTING, false); + material.setFlag (irr::video::EMF_BLEND_OPERATION, true); + this->m_vertexShaders.push_back (vertexShader); + this->m_pixelShaders.push_back (pixelShader); + this->m_materials.push_back (material); +} const irr::core::aabbox3d& CImage::getBoundingBox() const { @@ -156,8 +222,11 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in worldViewProj *= driver->getTransform(irr::video::ETS_VIEW); worldViewProj *= driver->getTransform(irr::video::ETS_WORLD); - std::vector::const_iterator cur = this->m_vertexShader->getParameters ().begin (); - std::vector::const_iterator end = this->m_vertexShader->getParameters ().end (); + Render::Shaders::Compiler* vertexShader = this->m_vertexShaders.at (userData); + Render::Shaders::Compiler* pixelShader = this->m_pixelShaders.at (userData); + + std::vector::const_iterator cur = vertexShader->getParameters ().begin (); + std::vector::const_iterator end = vertexShader->getParameters ().end (); for (; cur != end; cur ++) { @@ -183,8 +252,8 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in } } - cur = this->m_pixelShader->getParameters ().begin (); - end = this->m_pixelShader->getParameters ().end (); + cur = pixelShader->getParameters ().begin (); + end = pixelShader->getParameters ().end (); for (; cur != end; cur ++) { diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index 660c142..9c30cdb 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -28,14 +28,17 @@ namespace WallpaperEngine::Render::Objects private: void generateMaterial (); + void generatePass (Core::Objects::Images::Materials::CPassess* pass); irr::video::S3DVertex m_vertex [4]; - irr::video::SMaterial m_material; + irr::u32 m_passes; + std::vector m_materials; + std::vector m_renderTextures; Core::Objects::CImage* m_image; irr::core::aabbox3d m_boundingBox; - Render::Shaders::Compiler* m_vertexShader; - Render::Shaders::Compiler* m_pixelShader; + std::vector m_vertexShaders; + std::vector m_pixelShaders; }; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index a87b78f..27c1d16 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -447,7 +447,6 @@ namespace WallpaperEngine::Render::Shaders if (this->m_recursive == false) { - std::cout << "======================== COMPILED SHADER " << this->m_file.c_str () << " ========================" << std::endl; std::cout << this->m_compiledContent << std::endl; } From d13ad3fdcaf192ca3fc0807b282c618060d85f5d Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 09:20:27 +0200 Subject: [PATCH 03/31] ~ moved passes counter to the correct place ~ generated unique name for pass textures Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Render/CCamera.cpp | 2 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index 539ed4c..6744c45 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -37,7 +37,7 @@ void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( width, height, - this->m_camera->getUp ()->X, + 0.0f, this->m_camera->getUp ()->Y ); diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 4a3ef54..95b6a7e 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -24,7 +24,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : irr::f32 xleft = -this->m_image->getOrigin ()->X; irr::f32 ztop = this->m_image->getOrigin ()->Y; irr::f32 zbottom = -this->m_image->getOrigin ()->Y; - irr::f32 z = this->getScene ()->getCamera ()->getEye ()->Z; + irr::f32 z = this->m_image->getOrigin ()->Z; // top left this->m_vertex [0].Pos = irr::core::vector3df (xleft, ztop, z); @@ -93,7 +93,7 @@ void CImage::generateMaterial () std::vector::const_iterator cur = this->m_image->getMaterial ()->getPasses ()->begin (); std::vector::const_iterator end = this->m_image->getMaterial ()->getPasses ()->end (); - for (; cur != end; cur ++, this->m_passes ++) + for (; cur != end; cur++) { this->generatePass (*cur); } @@ -101,17 +101,17 @@ void CImage::generateMaterial () std::vector::const_iterator effectCur = this->m_image->getEffects ()->begin (); std::vector::const_iterator effectEnd = this->m_image->getEffects ()->end (); - for (; effectCur != effectEnd; effectCur ++) + for (; effectCur != effectEnd; effectCur++) { std::vector::const_iterator materialCur = (*effectCur)->getMaterials ()->begin (); std::vector::const_iterator materialEnd = (*effectCur)->getMaterials ()->end (); - for (; materialCur != materialEnd; materialCur ++) + for (; materialCur != materialEnd; materialCur++) { cur = (*materialCur)->getPasses ()->begin (); end = (*materialCur)->getPasses ()->end (); - for (; cur != end; cur ++, this->m_passes ++) + for (; cur != end; cur++) { this->generatePass (*cur); } @@ -139,7 +139,7 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) irr::core::dimension2d ( this->getScene ()->getScene ()->getOrthogonalProjection()->getWidth (), this->getScene ()->getScene ()->getOrthogonalProjection()->getHeight () - ), ("_RT_" + this->m_image->getName ()).c_str () + ), ("_RT_" + this->m_image->getName () + std::to_string (textureNumber) + "_" + std::to_string (this->m_passes)).c_str () ); this->m_renderTextures.push_back (texture); @@ -167,10 +167,13 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) material.setFlag (irr::video::EMF_LIGHTING, false); material.setFlag (irr::video::EMF_BLEND_OPERATION, true); + material.Wireframe = false; + material.Lighting = false; this->m_vertexShaders.push_back (vertexShader); this->m_pixelShaders.push_back (pixelShader); this->m_materials.push_back (material); + this->m_passes ++; } const irr::core::aabbox3d& CImage::getBoundingBox() const From e285b313e06b8ee39809b1a0846b4328c796cf0b Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 09:46:29 +0200 Subject: [PATCH 04/31] ~ use clearcolor from scene instead of using black ~ camera should use it's own getters, not access the m_camera object directly Signed-off-by: Alexis Maiquez --- main.cpp | 4 ++-- src/WallpaperEngine/Render/CCamera.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index bfd0a3a..8146fd0 100644 --- a/main.cpp +++ b/main.cpp @@ -319,14 +319,14 @@ int main (int argc, char* argv[]) // change viewport to render to the correct portion of the display IrrlichtContext->getDevice ()->getVideoDriver ()->setViewPort (*cur); - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (false, true, irr::video::SColor(0, 0, 0, 0)); + IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (false, true, sceneRender->getScene ()->getClearColor ().toSColor()); IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); } } else { - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (true, true, irr::video::SColor(0, 0, 0, 0)); + IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (true, true, sceneRender->getScene ()->getClearColor ().toSColor()); IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); } diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index 6744c45..a337df7 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -8,7 +8,7 @@ CCamera::CCamera (CScene* scene, Core::Scenes::CCamera* camera) : m_scene (scene) { this->m_sceneCamera = scene->getContext ()->getDevice ()->getSceneManager ()->addCameraSceneNode ( - scene, *this->m_camera->getCenter (), *this->m_camera->getEye (), scene->nextId () + scene, *this->getCenter (), *this->getEye (), scene->nextId () ); } @@ -37,8 +37,8 @@ void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( width, height, - 0.0f, - this->m_camera->getUp ()->Y + this->getEye ()->Z, + this->getCenter ()->Z ); this->m_sceneCamera->setProjectionMatrix (orthogonalProjection); From f7be32eed3fd38de9e12a4ce818170ba7896c83e Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 10:13:06 +0200 Subject: [PATCH 05/31] ~ moved OnRegisterSceneNode to CObject as this function should barely change + support for sounds added Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 2 + src/WallpaperEngine/Render/CObject.cpp | 8 ++ src/WallpaperEngine/Render/CObject.h | 2 + src/WallpaperEngine/Render/CScene.cpp | 8 ++ src/WallpaperEngine/Render/Objects/CImage.cpp | 8 -- src/WallpaperEngine/Render/Objects/CImage.h | 1 - src/WallpaperEngine/Render/Objects/CSound.cpp | 78 +++++++++++++++++++ src/WallpaperEngine/Render/Objects/CSound.h | 37 +++++++++ 8 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/WallpaperEngine/Render/Objects/CSound.cpp create mode 100644 src/WallpaperEngine/Render/Objects/CSound.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 607442f..0f5b749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ add_executable( src/WallpaperEngine/Render/Objects/CImage.h src/WallpaperEngine/Render/Objects/CImage.cpp + src/WallpaperEngine/Render/Objects/CSound.h + src/WallpaperEngine/Render/Objects/CSound.cpp src/WallpaperEngine/FileSystem/FileSystem.cpp src/WallpaperEngine/FileSystem/FileSystem.h diff --git a/src/WallpaperEngine/Render/CObject.cpp b/src/WallpaperEngine/Render/CObject.cpp index 4547077..c9ea917 100644 --- a/src/WallpaperEngine/Render/CObject.cpp +++ b/src/WallpaperEngine/Render/CObject.cpp @@ -22,4 +22,12 @@ CObject::~CObject() CScene* CObject::getScene () { return this->m_scene; +} + +void CObject::OnRegisterSceneNode () +{ + if (this->m_object->isVisible () == true) + SceneManager->registerNodeForRendering (this); + + ISceneNode::OnRegisterSceneNode (); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CObject.h b/src/WallpaperEngine/Render/CObject.h index f92c5b4..196c4d7 100644 --- a/src/WallpaperEngine/Render/CObject.h +++ b/src/WallpaperEngine/Render/CObject.h @@ -23,6 +23,8 @@ namespace WallpaperEngine::Render CObject (CScene* scene, std::string type, Core::CObject *object); ~CObject (); + void OnRegisterSceneNode () override; + CScene* getScene (); private: diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index a9fcaff..54def38 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -1,5 +1,9 @@ #include "WallpaperEngine/Core/Objects/CImage.h" +#include "WallpaperEngine/Core/Objects/CSound.h" + #include "WallpaperEngine/Render/Objects/CImage.h" +#include "WallpaperEngine/Render/Objects/CSound.h" + #include "CScene.h" using namespace WallpaperEngine; @@ -28,6 +32,10 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : { new Objects::CImage (this, (*cur)->As ()); } + else if ((*cur)->Is () == true) + { + new Objects::CSound (this, (*cur)->As ()); + } } this->m_nextId = ++highestId; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 95b6a7e..23e4db9 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -181,14 +181,6 @@ const irr::core::aabbox3d& CImage::getBoundingBox() const return this->m_boundingBox; } -void CImage::OnRegisterSceneNode () -{ - if (this->m_image->isVisible () == true) - SceneManager->registerNodeForRendering (this); - - ISceneNode::OnRegisterSceneNode (); -} - void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData) { irr::f32 g_Texture0 = 0; diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index 9c30cdb..db8ec93 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -21,7 +21,6 @@ namespace WallpaperEngine::Render::Objects void render () override; const irr::core::aabbox3d& getBoundingBox() const override; - void OnRegisterSceneNode () override; protected: static const std::string Type; diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp new file mode 100644 index 0000000..02c7bc6 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -0,0 +1,78 @@ +#include +#include + +#include "CSound.h" + +using namespace WallpaperEngine::Render::Objects; + +CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : + CObject (scene, Type, sound), + m_sound (sound) +{ + this->setAutomaticCulling (irr::scene::EAC_OFF); + this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); + + this->load (); + this->play (); +} + +void CSound::load () +{ + std::vector::const_iterator cur = this->m_sound->getSounds ()->begin (); + std::vector::const_iterator end = this->m_sound->getSounds ()->end (); + + for (; cur != end; cur ++) + { + SDL_RWops* sdlRwops = nullptr; + Mix_Music* music = nullptr; + irr::io::IReadFile* readfile = this->getScene ()->getContext ()->getDevice ()->getFileSystem ()->createAndOpenFile ((*cur).c_str ()); + int filesize = readfile->getSize (); + char* filebuffer = new char [filesize]; + + readfile->read (filebuffer, filesize); + + sdlRwops = SDL_RWFromConstMem(filebuffer, filesize); + music = Mix_LoadMUS_RW (sdlRwops); + readfile->drop (); + + if (music == nullptr) + { + this->getScene ()->getContext ()->getDevice ()->getLogger ()->log ( + "cannot load audio", Mix_GetError (), irr::ELL_ERROR + ); + + continue; + } + + this->m_bufferReader.push_back (sdlRwops); + this->m_soundBuffer.push_back (filebuffer); + this->m_sdl.push_back (music); + } +} +void CSound::play () +{ + std::vector::const_iterator mixcur = this->m_sdl.begin (); + std::vector::const_iterator mixend = this->m_sdl.end (); + + for (; mixcur != mixend; mixcur ++) + { + if (Mix_PlayMusic ((*mixcur), -1) == -1) + { + this->getScene ()->getContext ()->getDevice ()->getLogger ()->log ( + "cannot play audio", Mix_GetError (), irr::ELL_ERROR + ); + } + } +} + +void CSound::render () +{ + +} + +const irr::core::aabbox3d& CSound::getBoundingBox() const +{ + return this->m_boundingBox; +} + +const std::string CSound::Type = "sound"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CSound.h b/src/WallpaperEngine/Render/Objects/CSound.h new file mode 100644 index 0000000..5451ead --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CSound.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "WallpaperEngine/Core/Objects/CSound.h" + +#include "WallpaperEngine/Render/CObject.h" + +using namespace WallpaperEngine; + +namespace WallpaperEngine::Render::Objects +{ + class CSound : public CObject + { + public: + CSound (CScene* scene, Core::Objects::CSound* sound); + + void render () override; + const irr::core::aabbox3d& getBoundingBox() const override; + + protected: + static const std::string Type; + + void load (); + void play (); + + private: + std::vector m_filenames; + std::vector m_sdl; + std::vector m_bufferReader; + std::vector m_soundBuffer; + + Core::Objects::CSound* m_sound; + irr::core::aabbox3d m_boundingBox; + }; +} From 3371e10b016d31bc7aecd2821198a66a503dfed5 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 16:06:00 +0200 Subject: [PATCH 06/31] ~ fixed segmentation fault when creating a scene + added check for texture rendering on startup ~ fixed possibly wrong texture size for passes ~ changed camera position Signed-off-by: Alexis Maiquez --- main.cpp | 7 +++ src/WallpaperEngine/Core/Scenes/CCamera.cpp | 6 +- src/WallpaperEngine/Render/CCamera.cpp | 6 +- src/WallpaperEngine/Render/CScene.cpp | 14 ++--- src/WallpaperEngine/Render/Objects/CImage.cpp | 58 ++++++++++--------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/main.cpp b/main.cpp index 8146fd0..c140b4a 100644 --- a/main.cpp +++ b/main.cpp @@ -132,6 +132,12 @@ int init_irrlicht() IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support"); } + if (IrrlichtContext->getDevice ()->getVideoDriver ()->queryFeature (irr::video::EVDF_RENDER_TO_TARGET) == false) + { + IrrlichtContext->getDevice ()->getLogger ()->log ("ERROR: Your hardware or this renderer do not support rendering to texture"); + return 1; + } + return 0; } @@ -299,6 +305,7 @@ int main (int argc, char* argv[]) irr::u32 startTime = 0; irr::u32 endTime = 0; + IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (sceneRender->getScene ()->getAmbientColor ().toSColor ()); while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) { if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index 743a50b..b9fd2ba 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -47,8 +47,8 @@ CCamera* CCamera::fromJSON (json data) } return new CCamera ( - WallpaperEngine::Core::ato3vf (*center_it), - WallpaperEngine::Core::ato3vf (*eye_it), - WallpaperEngine::Core::ato3vf (*up_it) + WallpaperEngine::Core::ato3vf (*center_it), + WallpaperEngine::Core::ato3vf (*eye_it), + WallpaperEngine::Core::ato3vf (*up_it) ); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index a337df7..1d52d58 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -8,7 +8,7 @@ CCamera::CCamera (CScene* scene, Core::Scenes::CCamera* camera) : m_scene (scene) { this->m_sceneCamera = scene->getContext ()->getDevice ()->getSceneManager ()->addCameraSceneNode ( - scene, *this->getCenter (), *this->getEye (), scene->nextId () + scene, *this->getEye (), *this->getCenter (), scene->nextId () ); } @@ -37,8 +37,8 @@ void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( width, height, - this->getEye ()->Z, - this->getCenter ()->Z + this->getCenter ()->Z, + this->getEye ()->Z ); this->m_sceneCamera->setProjectionMatrix (orthogonalProjection); diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 54def38..b71e697 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -18,6 +18,12 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : m_scene (project->getScene ()), m_context (context) { + this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); + this->m_camera->setOrthogonalProjection ( + this->m_scene->getOrthogonalProjection ()->getWidth (), + this->m_scene->getOrthogonalProjection ()->getHeight () + ); + std::vector::const_iterator cur = this->m_scene->getObjects ()->begin (); std::vector::const_iterator end = this->m_scene->getObjects ()->end (); @@ -41,12 +47,6 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : this->m_nextId = ++highestId; this->setAutomaticCulling (irr::scene::EAC_OFF); this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); - - this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); - this->m_camera->setOrthogonalProjection ( - this->m_scene->getOrthogonalProjection ()->getWidth (), - this->m_scene->getOrthogonalProjection ()->getHeight () - ); } CScene::~CScene () @@ -77,7 +77,7 @@ void CScene::render () { } -const irr::core::aabbox3d& CScene::getBoundingBox() const +const irr::core::aabbox3d& CScene::getBoundingBox () const { return this->m_boundingBox; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 23e4db9..0767c6d 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -54,7 +54,7 @@ void CImage::render() { uint16_t indices [] = { - 0, 1, 2, 3 + 3, 2, 1, 0 }; irr::video::IVideoDriver* driver = SceneManager->getVideoDriver (); @@ -69,7 +69,7 @@ void CImage::render() { if (textureCur == textureEnd) { - driver->setRenderTarget (0, false, false); + driver->setRenderTarget (irr::video::ERT_FRAME_BUFFER, false, false); } else { @@ -87,9 +87,6 @@ void CImage::render() void CImage::generateMaterial () { - if (this->m_image->getMaterial ()->getPasses ()->empty () == true) - return; - std::vector::const_iterator cur = this->m_image->getMaterial ()->getPasses ()->begin (); std::vector::const_iterator end = this->m_image->getMaterial ()->getPasses ()->end (); @@ -135,13 +132,17 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) if (textureNumber == 0 && this->m_passes > 0) { + irr::video::ITexture* originalTexture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); + texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( irr::core::dimension2d ( - this->getScene ()->getScene ()->getOrthogonalProjection()->getWidth (), - this->getScene ()->getScene ()->getOrthogonalProjection()->getHeight () + originalTexture->getSize ().Width, + originalTexture->getSize ().Height ), ("_RT_" + this->m_image->getName () + std::to_string (textureNumber) + "_" + std::to_string (this->m_passes)).c_str () ); + //originalTexture->drop (); + this->m_renderTextures.push_back (texture); } else @@ -149,6 +150,8 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); } + //texture->grab (); + material.setTexture (textureNumber, texture); } @@ -165,6 +168,7 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, this->m_passes, irr::video::EGSL_DEFAULT ); + // TODO: TAKE INTO ACCOUNT BLENDING AND CULLING METHODS FROM THE JSON material.setFlag (irr::video::EMF_LIGHTING, false); material.setFlag (irr::video::EMF_BLEND_OPERATION, true); material.Wireframe = false; @@ -192,30 +196,30 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in irr::f32 g_Texture6 = 6; irr::f32 g_Texture7 = 7; - irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; irr::video::IVideoDriver* driver = services->getVideoDriver (); - irr::core::matrix4 worldViewProj;worldViewProj.makeIdentity(); - worldViewProj = driver->getTransform(irr::video::ETS_PROJECTION); - worldViewProj *= driver->getTransform(irr::video::ETS_VIEW); - worldViewProj *= driver->getTransform(irr::video::ETS_WORLD); + irr::core::matrix4 worldViewProj; + worldViewProj = driver->getTransform (irr::video::ETS_PROJECTION); + worldViewProj *= driver->getTransform (irr::video::ETS_VIEW); + worldViewProj *= driver->getTransform (irr::video::ETS_WORLD); Render::Shaders::Compiler* vertexShader = this->m_vertexShaders.at (userData); Render::Shaders::Compiler* pixelShader = this->m_pixelShaders.at (userData); From 3587fdec1e2c1710e4ca21c2f88d6a6dde9a3dae Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 11:02:45 +0200 Subject: [PATCH 07/31] ~ changed all iterators to auto ~ changed most pointers to const references to prevent modification, specially from the background parser Signed-off-by: Alexis Maiquez --- main.cpp | 8 +- src/WallpaperEngine/Core/CObject.cpp | 44 ++-- src/WallpaperEngine/Core/CObject.h | 18 +- src/WallpaperEngine/Core/CProject.cpp | 24 +-- src/WallpaperEngine/Core/CProject.h | 8 +- src/WallpaperEngine/Core/CScene.cpp | 82 ++++---- src/WallpaperEngine/Core/CScene.h | 38 ++-- src/WallpaperEngine/Core/Core.cpp | 28 +-- src/WallpaperEngine/Core/Objects/CEffect.cpp | 62 +++--- src/WallpaperEngine/Core/Objects/CEffect.h | 6 +- src/WallpaperEngine/Core/Objects/CImage.cpp | 12 +- src/WallpaperEngine/Core/Objects/CImage.h | 4 +- .../Core/Objects/CParticle.cpp | 30 +-- src/WallpaperEngine/Core/Objects/CParticle.h | 6 +- src/WallpaperEngine/Core/Objects/CSound.cpp | 10 +- src/WallpaperEngine/Core/Objects/CSound.h | 2 +- .../Core/Objects/Effects/CShaderConstant.h | 6 +- .../Core/Objects/Images/CMaterial.cpp | 10 +- .../Core/Objects/Images/CMaterial.h | 2 +- .../Objects/Images/Materials/CPassess.cpp | 59 ++++-- .../Core/Objects/Images/Materials/CPassess.h | 10 +- .../Core/Objects/Particles/CControlPoint.cpp | 12 +- .../Core/Objects/Particles/CControlPoint.h | 4 +- .../Core/Objects/Particles/CEmitter.cpp | 28 +-- .../Core/Objects/Particles/CEmitter.h | 10 +- .../Core/Objects/Particles/CInitializer.cpp | 8 +- .../Core/Objects/Particles/CInitializer.h | 4 +- .../Particles/Initializers/CAlphaRandom.cpp | 8 +- .../Particles/Initializers/CAlphaRandom.h | 4 +- .../Initializers/CAngularVelocityRandom.cpp | 12 +- .../Initializers/CAngularVelocityRandom.h | 4 +- .../Particles/Initializers/CColorRandom.cpp | 12 +- .../Particles/Initializers/CColorRandom.h | 4 +- .../Initializers/CLifeTimeRandom.cpp | 8 +- .../Particles/Initializers/CLifeTimeRandom.h | 4 +- .../Initializers/CRotationRandom.cpp | 8 +- .../Particles/Initializers/CRotationRandom.h | 4 +- .../Particles/Initializers/CSizeRandom.cpp | 8 +- .../Particles/Initializers/CSizeRandom.h | 4 +- .../Initializers/CVelocityRandom.cpp | 12 +- .../Particles/Initializers/CVelocityRandom.h | 4 +- .../Core/Projects/CProperty.cpp | 73 ++++--- src/WallpaperEngine/Core/Projects/CProperty.h | 12 +- .../Core/Projects/CPropertyColor.cpp | 8 +- .../Core/Projects/CPropertyColor.h | 2 +- src/WallpaperEngine/Core/Scenes/CCamera.cpp | 18 +- src/WallpaperEngine/Core/Scenes/CCamera.h | 6 +- .../Core/Scenes/CProjection.cpp | 8 +- src/WallpaperEngine/Core/Scenes/CProjection.h | 4 +- src/WallpaperEngine/FileSystem/FileSystem.cpp | 2 +- src/WallpaperEngine/FileSystem/FileSystem.h | 2 +- src/WallpaperEngine/Irrlicht/CContext.cpp | 21 +- src/WallpaperEngine/Irrlicht/CFileList.cpp | 198 +++++++++--------- .../Irrlicht/CImageLoaderTEX.cpp | 4 +- src/WallpaperEngine/Render/CCamera.cpp | 15 +- src/WallpaperEngine/Render/CCamera.h | 10 +- src/WallpaperEngine/Render/CObject.cpp | 2 +- src/WallpaperEngine/Render/CObject.h | 4 +- src/WallpaperEngine/Render/CScene.cpp | 18 +- src/WallpaperEngine/Render/CScene.h | 12 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 98 +++++---- src/WallpaperEngine/Render/Objects/CSound.cpp | 6 +- .../Render/Shaders/Compiler.cpp | 52 +++-- src/WallpaperEngine/Render/Shaders/Compiler.h | 8 +- .../Shaders/Parameters/CShaderParameter.cpp | 6 +- .../Shaders/Parameters/CShaderParameter.h | 14 +- .../Parameters/CShaderParameterFloat.cpp | 2 +- .../Parameters/CShaderParameterFloat.h | 2 +- .../Parameters/CShaderParameterInteger.cpp | 2 +- .../Parameters/CShaderParameterInteger.h | 2 +- .../Parameters/CShaderParameterVector2.cpp | 2 +- .../Parameters/CShaderParameterVector2.h | 2 +- .../Parameters/CShaderParameterVector3.cpp | 2 +- .../Parameters/CShaderParameterVector3.h | 2 +- .../Parameters/CShaderParameterVector4.cpp | 2 +- .../Parameters/CShaderParameterVector4.h | 2 +- 76 files changed, 636 insertions(+), 618 deletions(-) diff --git a/main.cpp b/main.cpp index c140b4a..18d18b1 100644 --- a/main.cpp +++ b/main.cpp @@ -53,8 +53,8 @@ void initialize_viewports () if (info == nullptr) continue; - std::vector::iterator cur = Screens.begin (); - std::vector::iterator end = Screens.end (); + auto cur = Screens.begin (); + auto end = Screens.end (); for (; cur != end; cur ++) { @@ -318,8 +318,8 @@ int main (int argc, char* argv[]) if (Viewports.size () > 0) { - std::vector>::iterator cur = Viewports.begin (); - std::vector>::iterator end = Viewports.end (); + auto cur = Viewports.begin (); + auto end = Viewports.end (); for (; cur != end; cur ++) { diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index e69594d..b1ea1cf 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -29,13 +29,13 @@ CObject::CObject ( CObject* CObject::fromJSON (json data) { - json::const_iterator id_it = data.find ("id"); - json::const_iterator visible_it = data.find ("visible"); - json::const_iterator origin_it = data.find ("origin"); - json::const_iterator scale_it = data.find ("scale"); - json::const_iterator angles_it = data.find ("angles"); - json::const_iterator name_it = data.find ("name"); - json::const_iterator effects_it = data.find ("effects"); + auto id_it = data.find ("id"); + auto visible_it = data.find ("visible"); + auto origin_it = data.find ("origin"); + auto scale_it = data.find ("scale"); + auto angles_it = data.find ("angles"); + auto name_it = data.find ("name"); + auto effects_it = data.find ("effects"); bool visible = true; @@ -70,9 +70,9 @@ CObject* CObject::fromJSON (json data) visible = *visible_it; } - json::const_iterator image_it = data.find ("image"); - json::const_iterator sound_it = data.find ("sound"); - json::const_iterator particle_it = data.find ("particle"); + auto image_it = data.find ("image"); + auto sound_it = data.find ("sound"); + auto particle_it = data.find ("particle"); CObject* object = nullptr; @@ -117,8 +117,8 @@ CObject* CObject::fromJSON (json data) if (effects_it != data.end () && (*effects_it).is_array () == true) { - json::const_iterator cur = (*effects_it).begin (); - json::const_iterator end = (*effects_it).end (); + auto cur = (*effects_it).begin (); + auto end = (*effects_it).end (); for (; cur != end; cur ++) { @@ -131,29 +131,29 @@ CObject* CObject::fromJSON (json data) return object; } -irr::core::vector3df* CObject::getOrigin () +const irr::core::vector3df& CObject::getOrigin () const { - return &this->m_origin; + return this->m_origin; } -irr::core::vector3df* CObject::getScale () +const irr::core::vector3df& CObject::getScale () const { - return &this->m_scale; + return this->m_scale; } -irr::core::vector3df* CObject::getAngles () +const irr::core::vector3df& CObject::getAngles () const { - return &this->m_angles; + return this->m_angles; } -std::string CObject::getName () +const std::string& CObject::getName () const { return this->m_name; } -std::vector* CObject::getEffects () +const std::vector& CObject::getEffects () const { - return &this->m_effects; + return this->m_effects; } bool CObject::isVisible () @@ -161,7 +161,7 @@ bool CObject::isVisible () return this->m_visible; } -int CObject::getId () +const int CObject::getId () const { return this->m_id; } diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index 6a7ecba..9b1fa3f 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -19,18 +19,18 @@ namespace WallpaperEngine::Core public: static CObject* fromJSON (json data); - template const T* As () const { assert (Is ()); return (const T*) this; } - template T* As () { assert (Is ()); return (T*) this; } + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } - template bool Is () { return this->m_type == T::Type; } + template bool is () { return this->m_type == T::Type; } - std::vector* getEffects (); - int getId (); + const std::vector& getEffects () const; + const int getId () const; - irr::core::vector3df* getOrigin (); - irr::core::vector3df* getScale (); - irr::core::vector3df* getAngles (); - std::string getName (); + const irr::core::vector3df& getOrigin () const; + const irr::core::vector3df& getScale () const; + const irr::core::vector3df& getAngles () const; + const std::string& getName () const; bool isVisible (); protected: diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index 4740b57..af8f6e0 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -16,10 +16,10 @@ CProject* CProject::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - json::const_iterator title = content.find ("title"); - json::const_iterator type = content.find ("type"); - json::const_iterator file = content.find ("file"); - json::const_iterator general = content.find ("general"); + auto title = content.find ("title"); + auto type = content.find ("type"); + auto file = content.find ("file"); + auto general = content.find ("general"); if (title == content.end ()) { @@ -44,12 +44,12 @@ CProject* CProject::fromFile (const irr::io::path& filename) if (general != content.end ()) { - json::const_iterator properties = (*general).find ("properties"); + auto properties = (*general).find ("properties"); if (properties != (*general).end ()) { - json::const_iterator cur = (*properties).begin (); - json::const_iterator end = (*properties).end (); + auto cur = (*properties).begin (); + auto end = (*properties).end (); for (; cur != end; cur ++) { @@ -63,24 +63,24 @@ CProject* CProject::fromFile (const irr::io::path& filename) return project; } -CScene* CProject::getScene () +const CScene* CProject::getScene () const { return this->m_scene; } -std::string CProject::getTitle () +const std::string& CProject::getTitle () const { return this->m_title; } -std::string CProject::getType () +const std::string& CProject::getType () const { return this->m_type; } -std::vector* CProject::getProperties () +const std::vector& CProject::getProperties () const { - return &this->m_properties; + return this->m_properties; } void CProject::insertProperty (Projects::CProperty* property) diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index a806ec5..570b50b 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -17,11 +17,11 @@ namespace WallpaperEngine::Core public: static CProject* fromFile (const irr::io::path& filename); - CScene* getScene (); + const CScene* getScene () const; - std::string getTitle (); - std::string getType (); - std::vector* getProperties (); + const std::string& getTitle () const; + const std::string& getType () const; + const std::vector& getProperties () const; protected: CProject (std::string title, std::string type, CScene* scene); diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index 698770d..c7112d4 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -50,9 +50,9 @@ CScene* CScene::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - json::const_iterator camera_it = content.find ("camera"); - json::const_iterator general_it = content.find ("general"); - json::const_iterator objects_it = content.find ("objects"); + auto camera_it = content.find ("camera"); + auto general_it = content.find ("general"); + auto objects_it = content.find ("objects"); if (camera_it == content.end ()) { @@ -69,23 +69,23 @@ CScene* CScene::fromFile (const irr::io::path& filename) throw std::runtime_error ("Scenes must have a list of objects to display"); } - json::const_iterator ambientcolor_it = (*general_it).find ("ambientcolor"); - json::const_iterator bloom_it = (*general_it).find ("bloom"); - json::const_iterator bloomstrength_it = (*general_it).find ("bloomstrength"); - json::const_iterator bloomthreshold_it = (*general_it).find ("bloomthreshold"); - json::const_iterator camerafade_it = (*general_it).find ("camerafade"); - json::const_iterator cameraparallax_it = (*general_it).find ("cameraparallax"); - json::const_iterator cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount"); - json::const_iterator cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay"); - json::const_iterator cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence"); - json::const_iterator camerapreview_it = (*general_it).find ("camerapreview"); - json::const_iterator camerashake_it = (*general_it).find ("camerashake"); - json::const_iterator camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude"); - json::const_iterator camerashakeroughness_it = (*general_it).find ("camerashakeroughness"); - json::const_iterator camerashakespeed_it = (*general_it).find ("camerashakespeed"); - json::const_iterator clearcolor_it = (*general_it).find ("clearcolor"); - json::const_iterator orthogonalprojection_it = (*general_it).find ("orthogonalprojection"); - json::const_iterator skylightcolor_it = (*general_it).find ("skylightcolor"); + auto ambientcolor_it = (*general_it).find ("ambientcolor"); + auto bloom_it = (*general_it).find ("bloom"); + auto bloomstrength_it = (*general_it).find ("bloomstrength"); + auto bloomthreshold_it = (*general_it).find ("bloomthreshold"); + auto camerafade_it = (*general_it).find ("camerafade"); + auto cameraparallax_it = (*general_it).find ("cameraparallax"); + auto cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount"); + auto cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay"); + auto cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence"); + auto camerapreview_it = (*general_it).find ("camerapreview"); + auto camerashake_it = (*general_it).find ("camerashake"); + auto camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude"); + auto camerashakeroughness_it = (*general_it).find ("camerashakeroughness"); + auto camerashakespeed_it = (*general_it).find ("camerashakespeed"); + auto clearcolor_it = (*general_it).find ("clearcolor"); + auto orthogonalprojection_it = (*general_it).find ("orthogonalprojection"); + auto skylightcolor_it = (*general_it).find ("skylightcolor"); if (ambientcolor_it == (*general_it).end ()) { @@ -193,8 +193,8 @@ CScene* CScene::fromFile (const irr::io::path& filename) WallpaperEngine::Core::atoSColorf (*skylightcolor_it) ); - json::const_iterator cur = (*objects_it).begin (); - json::const_iterator end = (*objects_it).end (); + auto cur = (*objects_it).begin (); + auto end = (*objects_it).end (); for (; cur != end; cur ++) { @@ -207,9 +207,9 @@ CScene* CScene::fromFile (const irr::io::path& filename) } -std::vector* CScene::getObjects () +const std::vector& CScene::getObjects () const { - return &this->m_objects; + return this->m_objects; } void CScene::insertObject (CObject* object) @@ -227,7 +227,7 @@ void CScene::setProject (CProject* project) this->m_project = project; } -Scenes::CCamera* CScene::getCamera () +const Scenes::CCamera* CScene::getCamera () const { return this->m_camera; } @@ -237,82 +237,82 @@ const irr::video::SColorf &CScene::getAmbientColor() const return this->m_ambientColor; } -bool CScene::isBloom () const +const bool CScene::isBloom () const { return this->m_bloom; } -irr::f64 CScene::getBloomStrength () const +const irr::f64 CScene::getBloomStrength () const { return this->m_bloomStrength; } -irr::f64 CScene::getBloomThreshold () const +const irr::f64 CScene::getBloomThreshold () const { return this->m_bloomThreshold; } -bool CScene::isCameraFade () const +const bool CScene::isCameraFade () const { return this->m_cameraFade; } -bool CScene::isCameraParallax () const +const bool CScene::isCameraParallax () const { return this->m_cameraParallax; } -irr::f64 CScene::getCameraParallaxAmount () const +const irr::f64 CScene::getCameraParallaxAmount () const { return this->m_cameraParallaxAmount; } -irr::f64 CScene::getCameraParallaxDelay () const +const irr::f64 CScene::getCameraParallaxDelay () const { return this->m_cameraParallaxDelay; } -irr::f64 CScene::getCameraParallaxMouseInfluence () const +const irr::f64 CScene::getCameraParallaxMouseInfluence () const { return this->m_cameraParallaxMouseInfluence; } -bool CScene::isCameraPreview () const +const bool CScene::isCameraPreview () const { return this->m_cameraPreview; } -bool CScene::isCameraShake () const +const bool CScene::isCameraShake () const { return this->m_cameraShake; } -irr::f64 CScene::getCameraShakeAmplitude () const +const irr::f64 CScene::getCameraShakeAmplitude () const { return this->m_cameraShakeAmplitude; } -irr::f64 CScene::getCameraShakeRoughness () const +const irr::f64 CScene::getCameraShakeRoughness () const { return this->m_cameraShakeRoughness; } -irr::f64 CScene::getCameraShakeSpeed () const +const irr::f64 CScene::getCameraShakeSpeed () const { return this->m_cameraShakeSpeed; } -const irr::video::SColorf &CScene::getClearColor () const +const irr::video::SColorf& CScene::getClearColor () const { return this->m_clearColor; } -Scenes::CProjection* CScene::getOrthogonalProjection () const +const Scenes::CProjection* CScene::getOrthogonalProjection () const { return this->m_orthogonalProjection; } -const irr::video::SColorf &CScene::getSkylightColor () const +const irr::video::SColorf& CScene::getSkylightColor () const { return this->m_skylightColor; } diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index 4165463..842c499 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -22,26 +22,26 @@ namespace WallpaperEngine::Core static CScene* fromFile (const irr::io::path& filename); CProject* getProject (); - std::vector* getObjects (); + const std::vector& getObjects () const; - const irr::video::SColorf &getAmbientColor() const; - bool isBloom() const; - irr::f64 getBloomStrength() const; - irr::f64 getBloomThreshold() const; - bool isCameraFade() const; - bool isCameraParallax() const; - irr::f64 getCameraParallaxAmount() const; - irr::f64 getCameraParallaxDelay() const; - irr::f64 getCameraParallaxMouseInfluence() const; - bool isCameraPreview() const; - bool isCameraShake() const; - irr::f64 getCameraShakeAmplitude() const; - irr::f64 getCameraShakeRoughness() const; - irr::f64 getCameraShakeSpeed() const; - const irr::video::SColorf &getClearColor() const; - Scenes::CProjection *getOrthogonalProjection() const; - const irr::video::SColorf &getSkylightColor() const; - Scenes::CCamera* getCamera (); + const irr::video::SColorf& getAmbientColor() const; + const bool isBloom() const; + const irr::f64 getBloomStrength() const; + const irr::f64 getBloomThreshold() const; + const bool isCameraFade() const; + const bool isCameraParallax() const; + const irr::f64 getCameraParallaxAmount() const; + const irr::f64 getCameraParallaxDelay() const; + const irr::f64 getCameraParallaxMouseInfluence() const; + const bool isCameraPreview() const; + const bool isCameraShake() const; + const irr::f64 getCameraShakeAmplitude() const; + const irr::f64 getCameraShakeRoughness() const; + const irr::f64 getCameraShakeSpeed() const; + const irr::video::SColorf& getClearColor() const; + const Scenes::CProjection* getOrthogonalProjection() const; + const irr::video::SColorf& getSkylightColor() const; + const Scenes::CCamera* getCamera () const; protected: friend class CProject; diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 1d3f52f..90d00ea 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -1,7 +1,9 @@ #include #include "Core.h" -irr::core::vector3df WallpaperEngine::Core::ato3vf(const char *str) +using namespace WallpaperEngine; + +irr::core::vector3df Core::ato3vf(const char *str) { irr::f32 x = irr::core::fast_atof (str, &str); while (*str == ' ') str ++; irr::f32 y = irr::core::fast_atof (str, &str); while (*str == ' ') str ++; @@ -10,7 +12,7 @@ irr::core::vector3df WallpaperEngine::Core::ato3vf(const char *str) return irr::core::vector3df (x, y, z); } -irr::core::vector2df WallpaperEngine::Core::ato2vf (const char *str) +irr::core::vector2df Core::ato2vf (const char *str) { irr::f32 x = irr::core::fast_atof (str, &str); while (*str == ' ') str ++; irr::f32 y = irr::core::fast_atof (str, &str); @@ -18,19 +20,19 @@ irr::core::vector2df WallpaperEngine::Core::ato2vf (const char *str) return irr::core::vector2df (x, y); } -irr::core::vector3df WallpaperEngine::Core::ato3vf (const std::string& str) +irr::core::vector3df Core::ato3vf (const std::string& str) { - return WallpaperEngine::Core::ato3vf (str.c_str ()); + return Core::ato3vf (str.c_str ()); } -irr::core::vector2df WallpaperEngine::Core::ato2vf (const std::string& str) +irr::core::vector2df Core::ato2vf (const std::string& str) { - return WallpaperEngine::Core::ato2vf (str.c_str ()); + return Core::ato2vf (str.c_str ()); } -irr::video::SColorf WallpaperEngine::Core::atoSColorf (const char *str) +irr::video::SColorf Core::atoSColorf (const char *str) { - irr::core::vector3df vector = WallpaperEngine::Core::ato3vf (str); + irr::core::vector3df vector = Core::ato3vf (str); return irr::video::SColorf ( vector.X, @@ -39,12 +41,12 @@ irr::video::SColorf WallpaperEngine::Core::atoSColorf (const char *str) ); } -irr::video::SColorf WallpaperEngine::Core::atoSColorf (const std::string& str) +irr::video::SColorf Core::atoSColorf (const std::string& str) { - return WallpaperEngine::Core::atoSColorf (str.c_str ()); + return Core::atoSColorf (str.c_str ()); } -irr::video::SColor WallpaperEngine::Core::atoSColor (const char *str) +irr::video::SColor Core::atoSColor (const char *str) { irr::f32 r = irr::core::strtoul10 (str, &str); while (*str == ' ') str ++; irr::f32 g = irr::core::strtoul10 (str, &str); while (*str == ' ') str ++; @@ -53,7 +55,7 @@ irr::video::SColor WallpaperEngine::Core::atoSColor (const char *str) return irr::video::SColor (255, r, g, b); } -irr::video::SColor WallpaperEngine::Core::atoSColor (const std::string& str) +irr::video::SColor Core::atoSColor (const std::string& str) { - return WallpaperEngine::Core::atoSColor (str.c_str ()); + return Core::atoSColor (str.c_str ()); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 8a8fd34..346947e 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -28,8 +28,8 @@ CEffect::CEffect ( CEffect* CEffect::fromJSON (json data, Core::CObject* object) { - json::const_iterator file_it = data.find ("file"); - json::const_iterator effectpasses_it = data.find ("passes"); + auto file_it = data.find ("file"); + auto effectpasses_it = data.find ("passes"); if (file_it == data.end ()) { @@ -38,12 +38,12 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get ().c_str ())); - json::const_iterator name_it = content.find ("name"); - json::const_iterator description_it = content.find ("description"); - json::const_iterator group_it = content.find ("group"); - json::const_iterator preview_it = content.find ("preview"); - json::const_iterator passes_it = content.find ("passes"); - json::const_iterator dependencies_it = content.find ("dependencies"); + auto name_it = content.find ("name"); + auto description_it = content.find ("description"); + auto group_it = content.find ("group"); + auto preview_it = content.find ("preview"); + auto passes_it = content.find ("passes"); + auto dependencies_it = content.find ("dependencies"); if (name_it == content.end ()) { @@ -83,12 +83,12 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) object ); - json::const_iterator cur = (*passes_it).begin (); - json::const_iterator end = (*passes_it).end (); + auto cur = (*passes_it).begin (); + auto end = (*passes_it).end (); for (; cur != end; cur ++) { - json::const_iterator materialfile = (*cur).find ("material"); + auto materialfile = (*cur).find ("material"); if (materialfile == (*cur).end ()) { @@ -115,13 +115,13 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) for (int passNumber = 0; cur != end; cur ++, passNumber ++) { - json::const_iterator constants_it = (*cur).find ("constantshadervalues"); + auto constants_it = (*cur).find ("constantshadervalues"); if (constants_it == (*cur).end ()) continue; - json::const_iterator constantCur = (*constants_it).begin (); - json::const_iterator constantEnd = (*constants_it).end (); + auto constantCur = (*constants_it).begin (); + auto constantEnd = (*constants_it).end (); for (; constantCur != constantEnd; constantCur ++) { @@ -147,19 +147,19 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) effect->insertConstant (constantCur.key (), constant); } - json::const_iterator textures_it = (*cur).find ("textures"); + auto textures_it = (*cur).find ("textures"); if (textures_it == (*cur).end ()) continue; - Images::CMaterial* material = effect->getMaterials ()->at (passNumber); - std::vector::const_iterator materialCur = material->getPasses ()->begin (); - std::vector::const_iterator materialEnd = material->getPasses ()->end (); + Images::CMaterial* material = effect->getMaterials ().at (passNumber); + auto passCur = material->getPasses ().begin (); + auto passEnd = material->getPasses ().end (); - for (; materialCur != materialEnd; materialCur ++) + for (; passCur != passEnd; passCur ++) { - json::const_iterator texturesCur = (*textures_it).begin (); - json::const_iterator texturesEnd = (*textures_it).end (); + auto texturesCur = (*textures_it).begin (); + auto texturesEnd = (*textures_it).end (); for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++) { @@ -167,21 +167,21 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) if ((*texturesCur).is_null () == true) { - if (object->Is () == false) + if (object->is() == false) { throw std::runtime_error ("unexpected null texture for non-image object"); } - CImage* image = object->As (); + CImage* image = object->as(); - texture = (*(*image->getMaterial ()->getPasses ()->begin ())->getTextures ()->begin ()); + texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ()->begin ()); } else { texture = *texturesCur; } - std::vector* passTextures = (*materialCur)->getTextures (); + std::vector* passTextures = (*passCur)->getTextures (); if (textureNumber < passTextures->size ()) passTextures->at (textureNumber) = texture; @@ -198,19 +198,19 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) return effect; } -std::vector* CEffect::getDependencies () +const std::vector& CEffect::getDependencies () const { - return &this->m_dependencies; + return this->m_dependencies; } -std::vector* CEffect::getMaterials () +const std::vector& CEffect::getMaterials () const { - return &this->m_materials; + return this->m_materials; } -std::map* CEffect::getConstants () +const std::map& CEffect::getConstants () const { - return &this->m_constants; + return this->m_constants; } void CEffect::insertDependency (const std::string& dep) diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index a23915b..ab48862 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -29,9 +29,9 @@ namespace WallpaperEngine::Core::Objects static CEffect* fromJSON (json data, Core::CObject* object); - std::vector* getDependencies (); - std::vector* getMaterials (); - std::map* getConstants (); + const std::vector& getDependencies () const; + const std::vector& getMaterials () const; + const std::map& getConstants () const; protected: void insertDependency (const std::string& dep); void insertMaterial (Images::CMaterial* material); diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index 76da058..4ca86b0 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -30,8 +30,8 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - json::const_iterator image_it = data.find ("image"); - json::const_iterator size_it = data.find ("size"); + auto image_it = data.find ("image"); + auto size_it = data.find ("size"); if (size_it == data.end ()) { @@ -40,7 +40,7 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get ().c_str ())); - json::const_iterator material_it = content.find ("material"); + auto material_it = content.find ("material"); if (material_it == content.end ()) { @@ -59,14 +59,14 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( ); } -Images::CMaterial* CImage::getMaterial () +const Images::CMaterial* CImage::getMaterial () const { return this->m_material; } -irr::core::vector2df* CImage::getSize () +const irr::core::vector2df& CImage::getSize () const { - return &this->m_size; + return this->m_size; } diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index 38f5a94..6f5c88d 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -26,8 +26,8 @@ namespace WallpaperEngine::Core::Objects const irr::core::vector3df& angles ); - Images::CMaterial* getMaterial (); - irr::core::vector2df* getSize (); + const Images::CMaterial* getMaterial () const; + const irr::core::vector2df& getSize () const; protected: CImage ( diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index 8b334c8..df0b5ed 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -13,11 +13,11 @@ CParticle* CParticle::fromFile ( const irr::core::vector3df& scale) { json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - json::const_iterator controlpoint_it = data.find ("controlpoint"); - json::const_iterator starttime_it = data.find ("starttime"); - json::const_iterator maxcount_it = data.find ("maxcount"); - json::const_iterator emitter_it = data.find ("emitter"); - json::const_iterator initializer_it = data.find ("initializer"); + auto controlpoint_it = data.find ("controlpoint"); + auto starttime_it = data.find ("starttime"); + auto maxcount_it = data.find ("maxcount"); + auto emitter_it = data.find ("emitter"); + auto initializer_it = data.find ("initializer"); if (starttime_it == data.end ()) { @@ -50,8 +50,8 @@ CParticle* CParticle::fromFile ( if (controlpoint_it != data.end ()) { - json::const_iterator cur = (*controlpoint_it).begin (); - json::const_iterator end = (*controlpoint_it).end (); + auto cur = (*controlpoint_it).begin (); + auto end = (*controlpoint_it).end (); for (; cur != end; cur ++) { @@ -61,8 +61,8 @@ CParticle* CParticle::fromFile ( } } - json::const_iterator cur = (*emitter_it).begin (); - json::const_iterator end = (*emitter_it).end (); + auto cur = (*emitter_it).begin (); + auto end = (*emitter_it).end (); for (; cur != end; cur ++) { @@ -97,19 +97,19 @@ CParticle::CParticle ( { } -std::vector* CParticle::getEmitters () +const std::vector& CParticle::getEmitters () const { - return &this->m_emitters; + return this->m_emitters; } -std::vector* CParticle::getControlPoints () +const std::vector& CParticle::getControlPoints () const { - return &this->m_controlpoints; + return this->m_controlpoints; } -std::vector* CParticle::getInitializers () +const std::vector& CParticle::getInitializers () const { - return &this->m_initializers; + return this->m_initializers; } void CParticle::insertControlPoint (Particles::CControlPoint* controlpoint) diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index fec7b48..34bf6ac 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -26,9 +26,9 @@ namespace WallpaperEngine::Core::Objects const irr::core::vector3df& scale ); - std::vector* getEmitters (); - std::vector* getControlPoints (); - std::vector* getInitializers (); + const std::vector& getEmitters () const; + const std::vector& getControlPoints () const; + const std::vector& getInitializers () const; protected: CParticle ( diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 79a0dcf..6f6f6f4 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -25,7 +25,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - json::const_iterator sound_it = data.find ("sound"); + auto sound_it = data.find ("sound"); if (sound_it == data.end ()) { @@ -46,8 +46,8 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( angles ); - json::const_iterator cur = (*sound_it).begin (); - json::const_iterator end = (*sound_it).end (); + auto cur = (*sound_it).begin (); + auto end = (*sound_it).end (); for (; cur != end; cur ++) { @@ -62,9 +62,9 @@ void CSound::insertSound (std::string filename) this->m_sounds.push_back (filename); } -std::vector* CSound::getSounds () +const std::vector& CSound::getSounds () const { - return &this->m_sounds; + return this->m_sounds; } const std::string CSound::Type = "sound"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index ebb35f9..a9c4173 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -25,7 +25,7 @@ namespace WallpaperEngine::Core::Objects ); void insertSound (std::string filename); - std::vector* getSounds (); + const std::vector& getSounds () const; protected: CSound ( diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h index 1593e25..e038536 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h @@ -9,10 +9,10 @@ namespace WallpaperEngine::Core::Objects::Effects public: CShaderConstant (std::string type); - template const T* As () const { assert (Is ()); return (const T*) this; } - template T* As () { assert (Is ()); return (T*) this; } + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } - template bool Is () { return this->m_type == T::Type; } + template bool is () { return this->m_type == T::Type; } private: std::string m_type; diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index 71a284f..71ee169 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -20,7 +20,7 @@ CMaterial* CMaterial::fromFile (irr::io::path filename) CMaterial* CMaterial::fromJSON (json data) { - json::const_iterator passes_it = data.find ("passes"); + auto passes_it = data.find ("passes"); if (passes_it == data.end ()) { @@ -29,8 +29,8 @@ CMaterial* CMaterial::fromJSON (json data) CMaterial* material = new CMaterial (); - json::const_iterator cur = (*passes_it).begin (); - json::const_iterator end = (*passes_it).end (); + auto cur = (*passes_it).begin (); + auto end = (*passes_it).end (); for (; cur != end; cur ++) { @@ -47,7 +47,7 @@ void CMaterial::insertPass (Materials::CPassess* mass) this->m_passes.push_back (mass); } -std::vector * CMaterial::getPasses () +const std::vector & CMaterial::getPasses () const { - return &this->m_passes; + return this->m_passes; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index bc2ba04..fe6d1fc 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -17,7 +17,7 @@ namespace WallpaperEngine::Core::Objects::Images void insertPass (Materials::CPassess* mass); - std::vector * getPasses (); + const std::vector & getPasses () const; protected: CMaterial (); private: diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp index ac3ff48..8a97703 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp @@ -11,20 +11,15 @@ CPassess::CPassess (std::string blending, std::string cullmode, std::string dept { } -std::vector* CPassess::getTextures () -{ - return &this->m_textures; -} - CPassess* CPassess::fromJSON (json data) { - json::const_iterator blending_it = data.find ("blending"); - json::const_iterator cullmode_it = data.find ("cullmode"); - json::const_iterator depthtest_it = data.find ("depthtest"); - json::const_iterator depthwrite_it = data.find ("depthwrite"); - json::const_iterator shader_it = data.find ("shader"); - json::const_iterator textures_it = data.find ("textures"); - json::const_iterator combos_it = data.find ("combos"); + auto blending_it = data.find ("blending"); + auto cullmode_it = data.find ("cullmode"); + auto depthtest_it = data.find ("depthtest"); + auto depthwrite_it = data.find ("depthwrite"); + auto shader_it = data.find ("shader"); + auto textures_it = data.find ("textures"); + auto combos_it = data.find ("combos"); if (blending_it == data.end ()) { @@ -70,8 +65,8 @@ CPassess* CPassess::fromJSON (json data) if (textures_it != data.end ()) { - json::const_iterator cur = (*textures_it).begin (); - json::const_iterator end = (*textures_it).end (); + auto cur = (*textures_it).begin (); + auto end = (*textures_it).end (); for (;cur != end; cur ++) { @@ -88,8 +83,8 @@ CPassess* CPassess::fromJSON (json data) if (combos_it != data.end ()) { - json::const_iterator cur = (*combos_it).begin (); - json::const_iterator end = (*combos_it).end (); + auto cur = (*combos_it).begin (); + auto end = (*combos_it).end (); for (; cur != end; cur ++) { @@ -109,7 +104,6 @@ CPassess* CPassess::fromJSON (json data) return pass; } - void CPassess::insertTexture (const std::string& texture) { this->m_textures.push_back (texture); @@ -120,12 +114,37 @@ void CPassess::insertCombo (const std::string& name, int value) this->m_combos.insert (std::pair (name, value)); } -std::map* CPassess::getCombos () +std::vector* CPassess::getTextures () { - return &this->m_combos; + return &this->m_textures; } -std::string CPassess::getShader () +const std::map& CPassess::getCombos () const +{ + return this->m_combos; +} + +const std::string& CPassess::getShader () const { return this->m_shader; +} + +const std::string& CPassess::getBlendingMode () const +{ + return this->m_blending; +} + +const std::string& CPassess::getCullingMode () const +{ + return this->m_cullmode; +} + +const std::string& CPassess::getDepthTest () const +{ + return this->m_depthtest; +} + +const std::string& CPassess::getDepthWrite ()const +{ + return this->m_depthwrite; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h index eaf3214..1d1e3d5 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h @@ -12,8 +12,14 @@ namespace WallpaperEngine::Core::Objects::Images::Materials static CPassess* fromJSON (json data); std::vector* getTextures (); - std::map* getCombos (); - std::string getShader (); + + const std::map& getCombos () const; + const std::string& getShader () const; + const std::string& getBlendingMode () const; + const std::string& getCullingMode () const; + const std::string& getDepthTest () const; + const std::string& getDepthWrite () const; + protected: CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index 32be7d2..b89d975 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -6,9 +6,9 @@ using namespace WallpaperEngine::Core::Objects::Particles; CControlPoint* CControlPoint::fromJSON (json data) { - json::const_iterator flags_it = data.find ("flags"); - json::const_iterator id_it = data.find ("id"); - json::const_iterator offset_it = data.find ("offset"); + auto flags_it = data.find ("flags"); + auto id_it = data.find ("id"); + auto offset_it = data.find ("offset"); if (id_it == data.end ()) { @@ -47,12 +47,12 @@ void CControlPoint::setFlags (irr::u32 flags) this->m_flags = flags; } -irr::core::vector3df* CControlPoint::getOffset () +const irr::core::vector3df& CControlPoint::getOffset () const { - return &this->m_offset; + return this->m_offset; } -irr::u32 CControlPoint::getFlags () +const irr::u32 CControlPoint::getFlags () const { return this->m_flags; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index b642d28..2a00dd5 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -12,8 +12,8 @@ namespace WallpaperEngine::Core::Objects::Particles public: static CControlPoint* fromJSON (json data); - irr::core::vector3df* getOffset (); - irr::u32 getFlags (); + const irr::core::vector3df& getOffset () const; + const irr::u32 getFlags () const; protected: CControlPoint (irr::u32 id, irr::u32 flags = 0); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 86d00c7..21cccbe 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -6,13 +6,13 @@ using namespace WallpaperEngine::Core::Objects::Particles; CEmitter* CEmitter::fromJSON (json data) { - json::const_iterator directions_it = data.find ("directions"); - json::const_iterator distancemax_it = data.find ("distancemax"); - json::const_iterator distancemin_it = data.find ("distancemin"); - json::const_iterator id_it = data.find ("id"); - json::const_iterator name_it = data.find ("name"); - json::const_iterator origin_it = data.find ("origin"); - json::const_iterator rate_it = data.find ("rate"); + auto directions_it = data.find ("directions"); + auto distancemax_it = data.find ("distancemax"); + auto distancemin_it = data.find ("distancemin"); + auto id_it = data.find ("id"); + auto name_it = data.find ("name"); + auto origin_it = data.find ("origin"); + auto rate_it = data.find ("rate"); if (directions_it == data.end ()) { @@ -79,27 +79,27 @@ const std::string& CEmitter::getName () const return this->m_name; } -irr::u32 CEmitter::getDistanceMax () const +const irr::u32 CEmitter::getDistanceMax () const { return this->m_distancemax; } -irr::u32 CEmitter::getDistanceMin () const +const irr::u32 CEmitter::getDistanceMin () const { return this->m_distancemin; } -irr::core::vector3df* CEmitter::getDirections () +const irr::core::vector3df& CEmitter::getDirections () const { - return &this->m_directions; + return this->m_directions; } -irr::core::vector3df* CEmitter::getOrigin () +const irr::core::vector3df& CEmitter::getOrigin () const { - return &this->m_origin; + return this->m_origin; } -irr::f64 CEmitter::getRate () const +const irr::f64 CEmitter::getRate () const { return this->m_rate; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index 70b18de..f574b13 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -13,11 +13,11 @@ namespace WallpaperEngine::Core::Objects::Particles static CEmitter* fromJSON (json data); const std::string& getName () const; - irr::u32 getDistanceMax () const; - irr::u32 getDistanceMin () const; - irr::core::vector3df* getDirections (); - irr::core::vector3df* getOrigin (); - irr::f64 getRate () const; + const irr::u32 getDistanceMax () const; + const irr::u32 getDistanceMin () const; + const irr::core::vector3df& getDirections () const; + const irr::core::vector3df& getOrigin () const; + const irr::f64 getRate () const; protected: CEmitter ( const irr::core::vector3df& directions, diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index 7d1f506..39bf0f0 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -12,8 +12,8 @@ using namespace WallpaperEngine::Core::Objects::Particles; CInitializer* CInitializer::fromJSON (json data) { - json::const_iterator id_it = data.find ("id"); - json::const_iterator name_it = data.find ("name"); + auto id_it = data.find ("id"); + auto name_it = data.find ("name"); irr::u32 id = ((id_it == data.end ()) ? 0 : (irr::u32) (*id_it)); if (name_it == data.end ()) @@ -63,12 +63,12 @@ CInitializer::CInitializer (irr::u32 id, std::string name) : } -std::string& CInitializer::getName () +const std::string& CInitializer::getName () const { return this->m_name; } -irr::u32 CInitializer::getId () +const irr::u32 CInitializer::getId () const { return this->m_id; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index b1151eb..0aa6ee1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -12,8 +12,8 @@ namespace WallpaperEngine::Core::Objects::Particles public: static CInitializer* fromJSON (json data); - std::string& getName (); - irr::u32 getId (); + const std::string& getName () const; + const irr::u32 getId () const; protected: CInitializer (irr::u32 id, std::string name); private: diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index 7a52206..57be620 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -4,8 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAlphaRandom* CAlphaRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -27,12 +27,12 @@ CAlphaRandom::CAlphaRandom (irr::u32 id, irr::f64 min, irr::f64 max) : { } -irr::f64 CAlphaRandom::getMinimum () +const irr::f64 CAlphaRandom::getMinimum () const { return this->m_min; } -irr::f64 CAlphaRandom::getMaximum () +const irr::f64 CAlphaRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index 6f5845a..02a2d17 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CAlphaRandom : CInitializer { public: - irr::f64 getMinimum (); - irr::f64 getMaximum (); + const irr::f64 getMinimum () const; + const irr::f64 getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index 3e62294..de3b5a6 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -34,12 +34,12 @@ CAngularVelocityRandom::CAngularVelocityRandom (irr::u32 id, irr::core::vector3d { } -irr::core::vector3df* CAngularVelocityRandom::getMinimum () +const irr::core::vector3df& CAngularVelocityRandom::getMinimum () const { - return &this->m_min; + return this->m_min; } -irr::core::vector3df* CAngularVelocityRandom::getMaximum () +const irr::core::vector3df& CAngularVelocityRandom::getMaximum () const { - return &this->m_max; + return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index fda06f2..353dc3d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CAngularVelocityRandom : CInitializer { public: - irr::core::vector3df* getMinimum (); - irr::core::vector3df* getMaximum (); + const irr::core::vector3df& getMinimum () const; + const irr::core::vector3df& getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 4f543ca..927d7d6 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -34,12 +34,12 @@ CColorRandom::CColorRandom (irr::u32 id, irr::video::SColor min, irr::video::SCo { } -irr::video::SColor* CColorRandom::getMinimum () +const irr::video::SColor& CColorRandom::getMinimum () const { - return &this->m_min; + return this->m_min; } -irr::video::SColor* CColorRandom::getMaximum () +const irr::video::SColor& CColorRandom::getMaximum () const { - return &this->m_max; + return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index 4b19128..306469d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CColorRandom : CInitializer { public: - irr::video::SColor* getMinimum (); - irr::video::SColor* getMaximum (); + const irr::video::SColor& getMinimum () const; + const irr::video::SColor& getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 7d48927..c60ef6b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -4,8 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -28,12 +28,12 @@ CLifeTimeRandom::CLifeTimeRandom (irr::u32 id, irr::u32 min, irr::u32 max) : { } -irr::u32 CLifeTimeRandom::getMinimum () +const irr::u32 CLifeTimeRandom::getMinimum () const { return this->m_min; } -irr::u32 CLifeTimeRandom::getMaximum () +const irr::u32 CLifeTimeRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index 8acef3e..e6c7435 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CLifeTimeRandom : CInitializer { public: - irr::u32 getMinimum (); - irr::u32 getMaximum (); + const irr::u32 getMinimum () const; + const irr::u32 getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp index 0de09f7..2029f9b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp @@ -4,8 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CRotationRandom* CRotationRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); irr::f64 min = 0.0f; irr::f64 max = 360.0f; @@ -30,12 +30,12 @@ CRotationRandom::CRotationRandom (irr::u32 id, irr::f64 min, irr::f64 max) : { } -irr::f64 CRotationRandom::getMinimum () +const irr::f64 CRotationRandom::getMinimum () const { return this->m_min; } -irr::f64 CRotationRandom::getMaximum () +const irr::f64 CRotationRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h index 8b0c104..6c4acb4 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CRotationRandom : CInitializer { public: - irr::f64 getMinimum (); - irr::f64 getMaximum (); + const irr::f64 getMinimum () const; + const irr::f64 getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index ff34a80..ad67131 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -4,8 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -27,12 +27,12 @@ CSizeRandom::CSizeRandom (irr::u32 id, irr::u32 min, irr::u32 max) : { } -irr::u32 CSizeRandom::getMinimum () +const irr::u32 CSizeRandom::getMinimum () const { return this->m_min; } -irr::u32 CSizeRandom::getMaximum () +const irr::u32 CSizeRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index 693d5a5..afecd47 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CSizeRandom : CInitializer { public: - irr::u32 getMinimum (); - irr::u32 getMaximum (); + const irr::u32 getMinimum () const; + const irr::u32 getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 1a435d9..6c652fe 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CVelocityRandom* CVelocityRandom::fromJSON (json data, irr::u32 id) { - json::const_iterator min_it = data.find ("min"); - json::const_iterator max_it = data.find ("max"); + auto min_it = data.find ("min"); + auto max_it = data.find ("max"); if (min_it == data.end ()) { @@ -34,12 +34,12 @@ CVelocityRandom::CVelocityRandom (irr::u32 id, irr::core::vector3df min, irr::co { } -irr::core::vector3df* CVelocityRandom::getMinimum () +const irr::core::vector3df& CVelocityRandom::getMinimum () const { - return &this->m_min; + return this->m_min; } -irr::core::vector3df* CVelocityRandom::getMaximum () +const irr::core::vector3df& CVelocityRandom::getMaximum () const { - return &this->m_max; + return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index 56b6c9c..131b061 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -10,8 +10,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CVelocityRandom : CInitializer { public: - irr::core::vector3df* getMinimum (); - irr::core::vector3df* getMaximum (); + const irr::core::vector3df& getMinimum () const; + const irr::core::vector3df& getMaximum () const; protected: friend class CInitializer; diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index 1055b20..9054638 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -1,51 +1,50 @@ #include "CProperty.h" #include "CPropertyColor.h" -namespace WallpaperEngine::Core::Projects +using namespace WallpaperEngine::Core::Projects; + +CProperty* CProperty::fromJSON (json data, const std::string& name) { - CProperty* CProperty::fromJSON (json data, const std::string& name) + auto type = data.find ("type"); + auto value = data.find ("value"); + auto text = data.find ("text"); + + if (value == data.end ()) { - json::const_iterator type = data.find ("type"); - json::const_iterator value = data.find ("value"); - json::const_iterator text = data.find ("text"); - - if (value == data.end ()) - { - throw std::runtime_error ("Project properties must have the value field"); - } - - if (type == data.end ()) - { - throw std::runtime_error ("Project properties must have the type field"); - } - - if (*type == CPropertyColor::Type) - { - return CPropertyColor::fromJSON (data, name); - } - - throw std::runtime_error ("Unexpected type for property"); + throw std::runtime_error ("Project properties must have the value field"); } - CProperty::CProperty (std::string name, std::string type, std::string text) : - m_name (std::move(name)), - m_type (std::move(type)), - m_text (std::move(text)) + if (type == data.end ()) { + throw std::runtime_error ("Project properties must have the type field"); } - std::string& CProperty::getName () + if (*type == CPropertyColor::Type) { - return this->m_name; + return CPropertyColor::fromJSON (data, name); } - std::string& CProperty::getType () - { - return this->m_type; - } + throw std::runtime_error ("Unexpected type for property"); +} - std::string& CProperty::getText () - { - return this->m_text; - } -}; +CProperty::CProperty (std::string name, std::string type, std::string text) : + m_name (std::move(name)), + m_type (std::move(type)), + m_text (std::move(text)) +{ +} + +const std::string& CProperty::getName () const +{ + return this->m_name; +} + +const std::string& CProperty::getType () const +{ + return this->m_type; +} + +const std::string& CProperty::getText () const +{ + return this->m_text; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Projects/CProperty.h b/src/WallpaperEngine/Core/Projects/CProperty.h index 0f91ad5..29c4405 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.h +++ b/src/WallpaperEngine/Core/Projects/CProperty.h @@ -13,14 +13,14 @@ namespace WallpaperEngine::Core::Projects public: static CProperty* fromJSON (json data, const std::string& name); - template const T* As () const { assert (Is ()); return (const T*) this; } - template T* As () { assert (Is ()); return (T*) this; } + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } - template bool Is () { return this->m_type == T::Type; } + template bool is () { return this->m_type == T::Type; } - std::string& getName (); - std::string& getType (); - std::string& getText (); + const std::string& getName () const; + const std::string& getType () const; + const std::string& getText () const; protected: CProperty (std::string name, std::string type, std::string text); diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp index 73849de..31e70e6 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp @@ -5,8 +5,8 @@ using namespace WallpaperEngine::Core::Projects; CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name) { - json::const_iterator value = data.find ("value"); - json::const_iterator text = data.find ("type"); + auto value = data.find ("value"); + auto text = data.find ("type"); return new CPropertyColor ( WallpaperEngine::Core::atoSColor (*value), @@ -15,9 +15,9 @@ CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name) ); } -irr::video::SColor* CPropertyColor::getValue () +const irr::video::SColor& CPropertyColor::getValue () const { - return &this->m_color; + return this->m_color; } CPropertyColor::CPropertyColor (irr::video::SColor color, const std::string& name, const std::string& text) : diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index 3464d53..af4bd76 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -13,7 +13,7 @@ namespace WallpaperEngine::Core::Projects public: static CPropertyColor* fromJSON (json data, const std::string& name); - irr::video::SColor* getValue (); + const irr::video::SColor& getValue () const; static const std::string Type; diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index b9fd2ba..eadf5e0 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -10,26 +10,26 @@ CCamera::CCamera (irr::core::vector3df center, irr::core::vector3df eye, irr::co { } -irr::core::vector3df* CCamera::getCenter () +const irr::core::vector3df& CCamera::getCenter () const { - return &this->m_center; + return this->m_center; } -irr::core::vector3df* CCamera::getEye () +const irr::core::vector3df& CCamera::getEye () const { - return &this->m_eye; + return this->m_eye; } -irr::core::vector3df* CCamera::getUp () +const irr::core::vector3df& CCamera::getUp () const { - return &this->m_up; + return this->m_up; } CCamera* CCamera::fromJSON (json data) { - json::const_iterator center_it = data.find ("center"); - json::const_iterator eye_it = data.find ("eye"); - json::const_iterator up_it = data.find ("up"); + auto center_it = data.find ("center"); + auto eye_it = data.find ("eye"); + auto up_it = data.find ("up"); if (center_it == data.end ()) { diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.h b/src/WallpaperEngine/Core/Scenes/CCamera.h index 99d8438..1e9efce 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.h +++ b/src/WallpaperEngine/Core/Scenes/CCamera.h @@ -12,9 +12,9 @@ namespace WallpaperEngine::Core::Scenes public: static CCamera* fromJSON (json data); - irr::core::vector3df* getCenter (); - irr::core::vector3df* getEye (); - irr::core::vector3df* getUp (); + const irr::core::vector3df& getCenter () const; + const irr::core::vector3df& getEye () const; + const irr::core::vector3df& getUp () const; protected: CCamera (irr::core::vector3df center, irr::core::vector3df eye, irr::core::vector3df up); private: diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index e9f87cd..45bd412 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -9,20 +9,20 @@ CProjection::CProjection (irr::u32 width, irr::u32 height) : { } -irr::u32 CProjection::getWidth () +const irr::u32& CProjection::getWidth () const { return this->m_width; } -irr::u32 CProjection::getHeight () +const irr::u32& CProjection::getHeight () const { return this->m_height; } CProjection* CProjection::fromJSON (json data) { - json::const_iterator width_it = data.find ("width"); - json::const_iterator height_it = data.find ("height"); + auto width_it = data.find ("width"); + auto height_it = data.find ("height"); if (width_it == data.end ()) { diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index e225c67..537735f 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -12,8 +12,8 @@ namespace WallpaperEngine::Core::Scenes public: static CProjection* fromJSON (json data); - irr::u32 getWidth (); - irr::u32 getHeight (); + const irr::u32& getWidth () const; + const irr::u32& getHeight () const; protected: CProjection (irr::u32 width, irr::u32 height); private: diff --git a/src/WallpaperEngine/FileSystem/FileSystem.cpp b/src/WallpaperEngine/FileSystem/FileSystem.cpp index c1de720..7765c53 100644 --- a/src/WallpaperEngine/FileSystem/FileSystem.cpp +++ b/src/WallpaperEngine/FileSystem/FileSystem.cpp @@ -8,7 +8,7 @@ extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext; namespace WallpaperEngine::FileSystem { - std::string loadFullFile (irr::io::path file) + std::string loadFullFile (const irr::io::path& file) { irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file); diff --git a/src/WallpaperEngine/FileSystem/FileSystem.h b/src/WallpaperEngine/FileSystem/FileSystem.h index 7b63879..b79290b 100644 --- a/src/WallpaperEngine/FileSystem/FileSystem.h +++ b/src/WallpaperEngine/FileSystem/FileSystem.h @@ -16,5 +16,5 @@ namespace WallpaperEngine::FileSystem * @param file * @return */ - std::string loadFullFile (irr::io::path file); + std::string loadFullFile (const irr::io::path& file); } diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index 1f2755b..d296943 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -1,14 +1,13 @@ #include "CContext.h" -namespace WallpaperEngine::Irrlicht -{ - void CContext::setDevice (irr::IrrlichtDevice* device) - { - this->m_device = device; - } +using namespace WallpaperEngine::Irrlicht; - irr::IrrlichtDevice* CContext::getDevice () - { - return this->m_device; - } -}; \ No newline at end of file +void CContext::setDevice (irr::IrrlichtDevice* device) +{ + this->m_device = device; +} + +irr::IrrlichtDevice* CContext::getDevice () +{ + return this->m_device; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Irrlicht/CFileList.cpp b/src/WallpaperEngine/Irrlicht/CFileList.cpp index 9cf6c23..cbb55bd 100644 --- a/src/WallpaperEngine/Irrlicht/CFileList.cpp +++ b/src/WallpaperEngine/Irrlicht/CFileList.cpp @@ -2,135 +2,133 @@ #include "CFileList.h" -namespace WallpaperEngine::Irrlicht +using namespace WallpaperEngine::Irrlicht; +static const irr::io::path emptyFileListEntry; + +CFileList::CFileList (const irr::io::path& path, bool ignoreCase, bool ignorePaths) : + m_ignorePaths (ignorePaths), + m_ignoreCase (ignoreCase), + m_path(path) { - static const irr::io::path emptyFileListEntry; + this->m_path.replace ('\\', '/'); +} - CFileList::CFileList (const irr::io::path& path, bool ignoreCase, bool ignorePaths) : - m_ignorePaths (ignorePaths), - m_ignoreCase (ignoreCase), - m_path(path) - { - this->m_path.replace ('\\', '/'); - } +CFileList::~CFileList () +{ + this->m_files.clear (); +} - CFileList::~CFileList () - { - this->m_files.clear (); - } +irr::u32 CFileList::getFileCount () const +{ + return this->m_files.size (); +} - irr::u32 CFileList::getFileCount () const - { - return this->m_files.size (); - } +void CFileList::sort () +{ + this->m_files.sort (); +} - void CFileList::sort () - { - this->m_files.sort (); - } - - const irr::io::path& CFileList::getFileName (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].Name : emptyFileListEntry; - } +const irr::io::path& CFileList::getFileName (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].Name : emptyFileListEntry; +} //! Gets the full name of a file in the list, path included, based on an index. - const irr::io::path& CFileList::getFullFileName (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].FullName : emptyFileListEntry; - } +const irr::io::path& CFileList::getFullFileName (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].FullName : emptyFileListEntry; +} //! adds a file or folder - irr::u32 CFileList::addItem (const irr::io::path& fullPath, irr::u32 offset, irr::u32 size, bool isDirectory, irr::u32 id) +irr::u32 CFileList::addItem (const irr::io::path& fullPath, irr::u32 offset, irr::u32 size, bool isDirectory, irr::u32 id) +{ + SFileListEntry entry; + entry.ID = id ? id : this->m_files.size (); + entry.Offset = offset; + entry.Size = size; + entry.Name = fullPath; + entry.Name.replace ('\\', '/'); + entry.IsDirectory = isDirectory; + + // remove trailing slash + if (entry.Name.lastChar () == '/') { - SFileListEntry entry; - entry.ID = id ? id : this->m_files.size (); - entry.Offset = offset; - entry.Size = size; - entry.Name = fullPath; - entry.Name.replace ('\\', '/'); - entry.IsDirectory = isDirectory; + entry.IsDirectory = true; + entry.Name [entry.Name.size ()-1] = 0; + entry.Name.validate (); + } - // remove trailing slash - if (entry.Name.lastChar () == '/') - { - entry.IsDirectory = true; - entry.Name [entry.Name.size ()-1] = 0; - entry.Name.validate (); - } + if (this->m_ignoreCase) + entry.Name.make_lower (); - if (this->m_ignoreCase) - entry.Name.make_lower (); + entry.FullName = entry.Name; + irr::core::deletePathFromFilename (entry.Name); + + if (this->m_ignorePaths) entry.FullName = entry.Name; - irr::core::deletePathFromFilename (entry.Name); + this->m_files.push_back (entry); - if (this->m_ignorePaths) - entry.FullName = entry.Name; - - this->m_files.push_back (entry); - - return this->m_files.size () - 1; - } + return this->m_files.size () - 1; +} //! Returns the ID of a file in the file list, based on an index. - irr::u32 CFileList::getID (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].ID : 0; - } +irr::u32 CFileList::getID (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].ID : 0; +} - bool CFileList::isDirectory (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].IsDirectory : false; - } +bool CFileList::isDirectory (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].IsDirectory : false; +} //! Returns the size of a file - irr::u32 CFileList::getFileSize (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].Size : 0; - } +irr::u32 CFileList::getFileSize (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].Size : 0; +} //! Returns the size of a file - irr::u32 CFileList::getFileOffset (irr::u32 index) const - { - return (index < this->m_files.size ()) ? this->m_files [index].Offset : 0; - } +irr::u32 CFileList::getFileOffset (irr::u32 index) const +{ + return (index < this->m_files.size ()) ? this->m_files [index].Offset : 0; +} //! Searches for a file or folder within the list, returns the index - irr::s32 CFileList::findFile (const irr::io::path& filename, bool isDirectory = false) const +irr::s32 CFileList::findFile (const irr::io::path& filename, bool isDirectory = false) const +{ + SFileListEntry entry; + // we only need FullName to be set for the search + entry.FullName = filename; + entry.IsDirectory = isDirectory; + + // exchange + entry.FullName.replace('\\', '/'); + + // remove trailing slash + if (entry.FullName.lastChar () == '/') { - SFileListEntry entry; - // we only need FullName to be set for the search - entry.FullName = filename; - entry.IsDirectory = isDirectory; - - // exchange - entry.FullName.replace('\\', '/'); - - // remove trailing slash - if (entry.FullName.lastChar () == '/') - { - entry.IsDirectory = true; - entry.FullName [entry.FullName.size ()-1] = 0; - entry.FullName.validate (); - } - - if (this->m_ignoreCase) - entry.FullName.make_lower (); - - if (this->m_ignorePaths) - irr::core::deletePathFromFilename (entry.FullName); - - return this->m_files.binary_search (entry); + entry.IsDirectory = true; + entry.FullName [entry.FullName.size ()-1] = 0; + entry.FullName.validate (); } + if (this->m_ignoreCase) + entry.FullName.make_lower (); + + if (this->m_ignorePaths) + irr::core::deletePathFromFilename (entry.FullName); + + return this->m_files.binary_search (entry); +} + //! Returns the base path of the file list - const irr::io::path& CFileList::getPath () const - { - return m_path; - } -}; +const irr::io::path& CFileList::getPath () const +{ + return m_path; +} diff --git a/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp b/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp index bfef8cb..18f86ea 100644 --- a/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp +++ b/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp @@ -46,8 +46,8 @@ namespace WallpaperEngine::Irrlicht CImageLoaderTex::TextureContainer::~TextureContainer () { - std::vector ::const_iterator cur = this->mipmaps.begin (); - std::vector ::const_iterator end = this->mipmaps.end (); + auto cur = this->mipmaps.begin (); + auto end = this->mipmaps.end (); for (; cur != end; cur ++) { diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index 1d52d58..cd6445e 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -3,13 +3,14 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; -CCamera::CCamera (CScene* scene, Core::Scenes::CCamera* camera) : +CCamera::CCamera (CScene* scene, const Core::Scenes::CCamera* camera) : m_camera (camera), m_scene (scene) { this->m_sceneCamera = scene->getContext ()->getDevice ()->getSceneManager ()->addCameraSceneNode ( - scene, *this->getEye (), *this->getCenter (), scene->nextId () + scene, this->getEye (), this->getCenter (), scene->nextId () ); + this->m_sceneCamera->setUpVector (this->getUp ()); } CCamera::~CCamera () @@ -17,17 +18,17 @@ CCamera::~CCamera () this->m_sceneCamera->remove (); } -irr::core::vector3df* CCamera::getCenter () +const irr::core::vector3df& CCamera::getCenter () const { return this->m_camera->getCenter (); } -irr::core::vector3df* CCamera::getEye () +const irr::core::vector3df& CCamera::getEye () const { return this->m_camera->getEye (); } -irr::core::vector3df* CCamera::getUp () +const irr::core::vector3df& CCamera::getUp () const { return this->m_camera->getUp (); } @@ -37,8 +38,8 @@ void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( width, height, - this->getCenter ()->Z, - this->getEye ()->Z + this->getCenter ().Z, + this->getEye ().Z ); this->m_sceneCamera->setProjectionMatrix (orthogonalProjection); diff --git a/src/WallpaperEngine/Render/CCamera.h b/src/WallpaperEngine/Render/CCamera.h index 98d8442..30ad469 100644 --- a/src/WallpaperEngine/Render/CCamera.h +++ b/src/WallpaperEngine/Render/CCamera.h @@ -11,17 +11,17 @@ namespace WallpaperEngine::Render class CCamera { public: - CCamera (CScene* scene, Core::Scenes::CCamera* camera); + CCamera (CScene* scene, const Core::Scenes::CCamera* camera); ~CCamera (); void setOrthogonalProjection (irr::f32 width, irr::f32 height); - irr::core::vector3df* getCenter (); - irr::core::vector3df* getEye (); - irr::core::vector3df* getUp (); + const irr::core::vector3df& getCenter () const; + const irr::core::vector3df& getEye () const; + const irr::core::vector3df& getUp () const; private: - Core::Scenes::CCamera* m_camera; + const Core::Scenes::CCamera* m_camera; irr::scene::ICameraSceneNode* m_sceneCamera; CScene* m_scene; }; diff --git a/src/WallpaperEngine/Render/CObject.cpp b/src/WallpaperEngine/Render/CObject.cpp index c9ea917..879f880 100644 --- a/src/WallpaperEngine/Render/CObject.cpp +++ b/src/WallpaperEngine/Render/CObject.cpp @@ -19,7 +19,7 @@ CObject::~CObject() { } -CScene* CObject::getScene () +CScene* CObject::getScene () const { return this->m_scene; } diff --git a/src/WallpaperEngine/Render/CObject.h b/src/WallpaperEngine/Render/CObject.h index 196c4d7..d6cdad5 100644 --- a/src/WallpaperEngine/Render/CObject.h +++ b/src/WallpaperEngine/Render/CObject.h @@ -21,11 +21,11 @@ namespace WallpaperEngine::Render protected: CObject (CScene* scene, std::string type, Core::CObject *object); - ~CObject (); + ~CObject () override; void OnRegisterSceneNode () override; - CScene* getScene (); + CScene* getScene () const; private: std::string m_type; diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index b71e697..cce0147 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -9,7 +9,7 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; -CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : +CScene::CScene (const Core::CProject* project, Irrlicht::CContext* context) : irr::scene::ISceneNode ( context->getDevice ()->getSceneManager ()->getRootSceneNode (), context->getDevice ()->getSceneManager () @@ -24,8 +24,8 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : this->m_scene->getOrthogonalProjection ()->getHeight () ); - std::vector::const_iterator cur = this->m_scene->getObjects ()->begin (); - std::vector::const_iterator end = this->m_scene->getObjects ()->end (); + auto cur = this->m_scene->getObjects ().begin (); + auto end = this->m_scene->getObjects ().end (); int highestId = 0; @@ -34,13 +34,13 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : if ((*cur)->getId () > highestId) highestId = (*cur)->getId (); - if ((*cur)->Is () == true) + if ((*cur)->is() == true) { - new Objects::CImage (this, (*cur)->As ()); + new Objects::CImage (this, (*cur)->as()); } - else if ((*cur)->Is () == true) + else if ((*cur)->is() == true) { - new Objects::CSound (this, (*cur)->As ()); + new Objects::CSound (this, (*cur)->as()); } } @@ -58,12 +58,12 @@ Irrlicht::CContext* CScene::getContext () return this->m_context; } -Core::CScene* CScene::getScene () +const Core::CScene* CScene::getScene () const { return this->m_scene; } -CCamera* CScene::getCamera () +CCamera* CScene::getCamera () const { return this->m_camera; } diff --git a/src/WallpaperEngine/Render/CScene.h b/src/WallpaperEngine/Render/CScene.h index cf0e63e..77d34fd 100644 --- a/src/WallpaperEngine/Render/CScene.h +++ b/src/WallpaperEngine/Render/CScene.h @@ -14,20 +14,20 @@ namespace WallpaperEngine::Render class CScene : public irr::scene::ISceneNode { public: - CScene (Core::CProject* project, Irrlicht::CContext* context); - ~CScene (); + CScene (const Core::CProject* project, Irrlicht::CContext* context); + ~CScene () override; Irrlicht::CContext* getContext (); - Core::CScene* getScene (); - CCamera* getCamera (); + const Core::CScene* getScene () const; + CCamera* getCamera () const; int nextId (); void render () override; const irr::core::aabbox3d& getBoundingBox() const override; void OnRegisterSceneNode () override; private: - Core::CProject* m_project; - Core::CScene* m_scene; + const Core::CProject* m_project; + const Core::CScene* m_scene; CCamera* m_camera; Irrlicht::CContext* m_context; irr::u32 m_nextId; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 0767c6d..96618ce 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -20,11 +20,11 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : m_passes (0) { // TODO: INITIALIZE NEEDED EFFECTS AND PROPERLY CALCULATE THESE? - irr::f32 xright = this->m_image->getOrigin ()->X; - irr::f32 xleft = -this->m_image->getOrigin ()->X; - irr::f32 ztop = this->m_image->getOrigin ()->Y; - irr::f32 zbottom = -this->m_image->getOrigin ()->Y; - irr::f32 z = this->m_image->getOrigin ()->Z; + irr::f32 xright = this->m_image->getOrigin ().X; + irr::f32 xleft = -this->m_image->getOrigin ().X; + irr::f32 ztop = this->m_image->getOrigin ().Y; + irr::f32 zbottom = -this->m_image->getOrigin ().Y; + irr::f32 z = this->m_image->getOrigin ().Z; // top left this->m_vertex [0].Pos = irr::core::vector3df (xleft, ztop, z); @@ -59,11 +59,11 @@ void CImage::render() irr::video::IVideoDriver* driver = SceneManager->getVideoDriver (); - std::vector::const_iterator cur = this->m_materials.begin (); - std::vector::const_iterator end = this->m_materials.end (); + auto cur = this->m_materials.begin (); + auto end = this->m_materials.end (); - std::vector::const_iterator textureCur = this->m_renderTextures.begin (); - std::vector::const_iterator textureEnd = this->m_renderTextures.end (); + auto textureCur = this->m_renderTextures.begin (); + auto textureEnd = this->m_renderTextures.end (); for (; cur != end; cur ++) { @@ -87,26 +87,26 @@ void CImage::render() void CImage::generateMaterial () { - std::vector::const_iterator cur = this->m_image->getMaterial ()->getPasses ()->begin (); - std::vector::const_iterator end = this->m_image->getMaterial ()->getPasses ()->end (); + auto cur = this->m_image->getMaterial ()->getPasses ().begin (); + auto end = this->m_image->getMaterial ()->getPasses ().end (); for (; cur != end; cur++) { this->generatePass (*cur); } - std::vector::const_iterator effectCur = this->m_image->getEffects ()->begin (); - std::vector::const_iterator effectEnd = this->m_image->getEffects ()->end (); + auto effectCur = this->m_image->getEffects ().begin (); + auto effectEnd = this->m_image->getEffects ().end (); for (; effectCur != effectEnd; effectCur++) { - std::vector::const_iterator materialCur = (*effectCur)->getMaterials ()->begin (); - std::vector::const_iterator materialEnd = (*effectCur)->getMaterials ()->end (); + auto materialCur = (*effectCur)->getMaterials ().begin (); + auto materialEnd = (*effectCur)->getMaterials ().end (); for (; materialCur != materialEnd; materialCur++) { - cur = (*materialCur)->getPasses ()->begin (); - end = (*materialCur)->getPasses ()->end (); + cur = (*materialCur)->getPasses ().begin (); + end = (*materialCur)->getPasses ().end (); for (; cur != end; cur++) { @@ -121,8 +121,8 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) std::vector* textures = pass->getTextures (); irr::video::SMaterial material; - std::vector::const_iterator texturesCur = textures->begin (); - std::vector::const_iterator texturesEnd = textures->end (); + auto texturesCur = textures->begin (); + auto texturesEnd = textures->end (); for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++, textureNumber ++) { @@ -141,8 +141,6 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) ), ("_RT_" + this->m_image->getName () + std::to_string (textureNumber) + "_" + std::to_string (this->m_passes)).c_str () ); - //originalTexture->drop (); - this->m_renderTextures.push_back (texture); } else @@ -150,8 +148,6 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); } - //texture->grab (); - material.setTexture (textureNumber, texture); } @@ -196,23 +192,23 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in irr::f32 g_Texture6 = 6; irr::f32 g_Texture7 = 7; - irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; + irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ().X, this->m_image->getAngles ().Y, this->m_image->getAngles ().Z, this->m_image->getAngles ().Z }; - irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; - irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; + irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ().X, this->m_image->getSize ().Y, this->m_image->getSize ().X, this->m_image->getSize ().Y }; irr::video::IVideoDriver* driver = services->getVideoDriver (); @@ -224,12 +220,12 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in Render::Shaders::Compiler* vertexShader = this->m_vertexShaders.at (userData); Render::Shaders::Compiler* pixelShader = this->m_pixelShaders.at (userData); - std::vector::const_iterator cur = vertexShader->getParameters ().begin (); - std::vector::const_iterator end = vertexShader->getParameters ().end (); + auto cur = vertexShader->getParameters ().begin (); + auto end = vertexShader->getParameters ().end (); for (; cur != end; cur ++) { - if ((*cur)->Is () == true) + if ((*cur)->is () == true) { services->setVertexShaderConstant ( (*cur)->getName ().c_str (), @@ -238,10 +234,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->Is () == true || - (*cur)->Is () == true || - (*cur)->Is () == true || - (*cur)->Is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setVertexShaderConstant ( (*cur)->getName ().c_str (), @@ -256,7 +252,7 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in for (; cur != end; cur ++) { - if ((*cur)->Is () == true) + if ((*cur)->is () == true) { services->setPixelShaderConstant ( (*cur)->getName ().c_str (), @@ -265,10 +261,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->Is () == true || - (*cur)->Is () == true || - (*cur)->Is () == true || - (*cur)->Is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setPixelShaderConstant ( (*cur)->getName ().c_str (), diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp index 02c7bc6..d38db69 100644 --- a/src/WallpaperEngine/Render/Objects/CSound.cpp +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -18,8 +18,8 @@ CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : void CSound::load () { - std::vector::const_iterator cur = this->m_sound->getSounds ()->begin (); - std::vector::const_iterator end = this->m_sound->getSounds ()->end (); + std::vector::const_iterator cur = this->m_sound->getSounds ().begin (); + std::vector::const_iterator end = this->m_sound->getSounds ().end (); for (; cur != end; cur ++) { @@ -31,7 +31,7 @@ void CSound::load () readfile->read (filebuffer, filesize); - sdlRwops = SDL_RWFromConstMem(filebuffer, filesize); + sdlRwops = SDL_RWFromConstMem (filebuffer, filesize); music = Mix_LoadMUS_RW (sdlRwops); readfile->drop (); diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 27c1d16..1f6f3cd 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -19,13 +19,16 @@ namespace WallpaperEngine::Render::Shaders { - Compiler::Compiler (irr::io::path& file, Type type, std::map* combos, bool recursive) + Compiler::Compiler (irr::io::path& file, Type type, const std::map& combos, bool recursive) : + m_combos (combos), + m_recursive (recursive), + m_type (type), + m_file (file), + m_error (""), + m_errorInfo ("") { - this->m_recursive = recursive; - this->m_combos = combos; - // begin with an space so it gets ignored properly on parse - if (recursive == false) + if (this->m_recursive == false) { // compatibility layer for OpenGL shaders this->m_content = "#version 120\n" @@ -47,8 +50,8 @@ namespace WallpaperEngine::Render::Shaders "#define ddy(x) dFdy(-(x))\n" "#define GLSL 1\n\n"; - std::map::const_iterator cur = this->m_combos->begin (); - std::map::const_iterator end = this->m_combos->end (); + auto cur = this->m_combos.begin (); + auto end = this->m_combos.end (); for (; cur != end; cur ++) { @@ -61,11 +64,6 @@ namespace WallpaperEngine::Render::Shaders } this->m_content.append (WallpaperEngine::FileSystem::loadFullFile (file)); - - // append file content - this->m_type = type; - - this->m_file = file; } bool Compiler::peekString(std::string str, std::string::const_iterator& it) @@ -126,8 +124,8 @@ namespace WallpaperEngine::Render::Shaders std::string Compiler::extractType (std::string::const_iterator& it) { - std::vector::const_iterator cur = sTypes.begin (); - std::vector::const_iterator end = sTypes.end (); + auto cur = sTypes.begin (); + auto end = sTypes.end (); while (cur != end) { @@ -227,8 +225,8 @@ namespace WallpaperEngine::Render::Shaders std::string Compiler::lookupReplaceSymbol (std::string symbol) { - std::map::const_iterator cur = sVariableReplacement.begin (); - std::map::const_iterator end = sVariableReplacement.end (); + auto cur = sVariableReplacement.begin (); + auto end = sVariableReplacement.end (); while (cur != end) { @@ -458,8 +456,8 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseComboConfiguration (const std::string& content) { json data = json::parse (content); - json::const_iterator combo = data.find ("combo"); - json::const_iterator defvalue = data.find ("default"); + auto combo = data.find ("combo"); + auto defvalue = data.find ("default"); // add line feed just in case this->m_compiledContent += "\n"; @@ -470,11 +468,11 @@ namespace WallpaperEngine::Render::Shaders } // check the combos - std::map::const_iterator entry = this->m_combos->find ((*combo).get ()); + std::map::const_iterator entry = this->m_combos.find ((*combo).get ()); // if the combo was not found in the predefined values this means that the default value in the JSON data can be used // so only define the ones that are not already defined - if (entry == this->m_combos->end ()) + if (entry == this->m_combos.end ()) { // if no combo is defined just load the default settings if ((*defvalue).is_number_float ()) @@ -499,9 +497,9 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseParameterConfiguration (const std::string& type, const std::string& name, const std::string& content) { json data = json::parse (content); - json::const_iterator material = data.find ("material"); - json::const_iterator defvalue = data.find ("default"); - json::const_iterator range = data.find ("range"); + auto material = data.find ("material"); + auto defvalue = data.find ("default"); + auto range = data.find ("range"); // this is not a real parameter if (material == data.end () || defvalue == data.end ()) @@ -558,10 +556,10 @@ namespace WallpaperEngine::Render::Shaders this->m_parameters.push_back (parameter); } - Parameters::CShaderParameter* Compiler::findParameter (std::string identifier) + Parameters::CShaderParameter* Compiler::findParameter (const std::string& identifier) { - std::vector::const_iterator cur = this->m_parameters.begin (); - std::vector::const_iterator end = this->m_parameters.end (); + auto cur = this->m_parameters.begin (); + auto end = this->m_parameters.end (); for (; cur != end; cur ++) { @@ -574,7 +572,7 @@ namespace WallpaperEngine::Render::Shaders return nullptr; } - std::vector & Compiler::getParameters () + const std::vector & Compiler::getParameters () const { return this->m_parameters; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 9140936..0c757d8 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -46,7 +46,7 @@ namespace WallpaperEngine::Render::Shaders * @param type The type of shader * @param recursive Whether the compiler should add base definitions or not */ - Compiler (irr::io::path& file, Type type, std::map* combos, bool recursive = false); + Compiler (irr::io::path& file, Type type, const std::map& combos, bool recursive = false); /** * Performs the actual pre-compilation/pre-processing over the shader files * This step is kinda big, replaces variables names on sVariableReplacement, @@ -62,12 +62,12 @@ namespace WallpaperEngine::Render::Shaders * @param identifier The identifier to search for * @return The shader information */ - Parameters::CShaderParameter* findParameter (std::string identifier); + Parameters::CShaderParameter* findParameter (const std::string& identifier); /** * @return The list of parameters available for this shader with their default values */ - std::vector & getParameters (); + const std::vector & getParameters () const; private: /** @@ -206,7 +206,7 @@ namespace WallpaperEngine::Render::Shaders /** * The combos the shader should be generated with */ - std::map * m_combos; + const std::map & m_combos; /** * Whether this compilation is a recursive one or not */ diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp index 70e356b..5bdcfd6 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp @@ -12,7 +12,7 @@ CShaderParameter::CShaderParameter (void* defaultValue, void* value, std::string } -void* CShaderParameter::getValue () +const void* CShaderParameter::getValue () const { if (this->m_value) return this->m_value; @@ -25,12 +25,12 @@ void CShaderParameter::setValue (void* value) this->m_value = value; } -std::string CShaderParameter::getIdentifierName () +const std::string& CShaderParameter::getIdentifierName () const { return this->m_identifierName; } -std::string CShaderParameter::getName () +const std::string& CShaderParameter::getName () const { return this->m_name; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h index 8cd91a8..49e8a3a 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h @@ -9,19 +9,19 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameter (void* defaultValue, void* value, std::string type); - template const T* As () const { assert (Is ()); return (const T*) this; } - template T* As () { assert (Is ()); return (T*) this; } + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } - template bool Is () { return this->m_type == T::Type; } + template bool is () { return this->m_type == T::Type; } - std::string getIdentifierName (); - std::string getName (); + const std::string& getIdentifierName () const; + const std::string& getName () const; void setIdentifierName (std::string identifierName); void setName (std::string name); - void* getValue (); + const void* getValue () const; - virtual int getSize () = 0; + virtual const int getSize () const = 0; protected: void setValue (void* value); diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp index aeee7f6..7faff21 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp @@ -17,7 +17,7 @@ void CShaderParameterFloat::setValue (irr::f32 value) CShaderParameter::setValue (&this->m_value); } -int CShaderParameterFloat::getSize () +const int CShaderParameterFloat::getSize () const { return 1; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h index a8d4307..8bfc3fe 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameterFloat (irr::f32 defaultValue); - int getSize () override; + const int getSize () const override; void setValue (irr::f32 value); diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp index 1e997e1..63b02b1 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp @@ -16,7 +16,7 @@ void CShaderParameterInteger::setValue (irr::s32 value) CShaderParameter::setValue (&this->m_value); } -int CShaderParameterInteger::getSize () +const int CShaderParameterInteger::getSize () const { return 1; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h index 79d750c..a16169a 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameterInteger (irr::s32 defaultValue); - int getSize () override; + const int getSize () const override; static const std::string Type; diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp index 0ffdb88..63e6b4d 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp @@ -17,7 +17,7 @@ void CShaderParameterVector2::setValue (irr::core::vector2df value) CShaderParameter::setValue (&this->m_value); } -int CShaderParameterVector2::getSize () +const int CShaderParameterVector2::getSize () const { return 2; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h index 7ce8b83..0e7e5b3 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameterVector2 (const irr::core::vector2df& defaultValue); - int getSize () override; + const int getSize () const override; void setValue (irr::core::vector2df value); diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp index e26191f..4425368 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp @@ -16,7 +16,7 @@ void CShaderParameterVector3::setValue (irr::core::vector3df value) CShaderParameter::setValue (&this->m_value); } -int CShaderParameterVector3::getSize () +const int CShaderParameterVector3::getSize () const { return 3; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h index 7216128..536bffc 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameterVector3 (const irr::core::vector3df& defaultValue); - int getSize () override; + const int getSize () const override; void setValue (irr::core::vector3df value); diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp index 75bc99e..de624aa 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp @@ -16,7 +16,7 @@ void CShaderParameterVector4::setValue (irr::core::vector3df value) CShaderParameter::setValue (&this->m_value); } -int CShaderParameterVector4::getSize () +const int CShaderParameterVector4::getSize () const { return 4; } diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h index b378f18..e98eb9f 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h +++ b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Shaders::Parameters public: CShaderParameterVector4 (const irr::core::vector3df& defaultValue); - int getSize () override; + const int getSize () const override; void setValue (irr::core::vector3df value); From ce67c0bf645b4812d0893de86bbf5ad7e732d088 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 11:32:15 +0200 Subject: [PATCH 08/31] ~ moved file resolution to the Irrlicht Context class Signed-off-by: Alexis Maiquez --- main.cpp | 43 +++++++++---------- src/WallpaperEngine/FileSystem/FileSystem.cpp | 29 ++++++------- src/WallpaperEngine/Irrlicht/CContext.cpp | 30 +++++++++++++ src/WallpaperEngine/Irrlicht/CContext.h | 8 ++++ src/WallpaperEngine/Render/Objects/CImage.cpp | 11 ++--- .../Render/Shaders/Compiler.cpp | 9 ++-- src/WallpaperEngine/Render/Shaders/Compiler.h | 13 +++++- 7 files changed, 95 insertions(+), 48 deletions(-) diff --git a/main.cpp b/main.cpp index 18d18b1..5b44922 100644 --- a/main.cpp +++ b/main.cpp @@ -20,14 +20,12 @@ bool IsRootWindow = false; std::vector Screens; std::vector> Viewports; -irr::SIrrlichtCreationParameters _irr_params; - irr::f32 g_Time = 0; WallpaperEngine::Irrlicht::CContext* IrrlichtContext; -void initialize_viewports () +void initialize_viewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters) { - if (IsRootWindow == false || Screens.size () == 0) + if (IsRootWindow == false || Screens.empty () == true) return; Display* display = XOpenDisplay (NULL); @@ -82,33 +80,34 @@ void initialize_viewports () XRRFreeScreenResources (screenResources); - _irr_params.WindowId = reinterpret_cast (DefaultRootWindow (display)); + irrlichtCreationParameters.WindowId = reinterpret_cast (DefaultRootWindow (display)); } int init_irrlicht() { IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (); + irr::SIrrlichtCreationParameters irrlichtCreationParameters; // prepare basic configuration for irrlicht - _irr_params.AntiAlias = 8; - _irr_params.Bits = 16; + irrlichtCreationParameters.AntiAlias = 8; + irrlichtCreationParameters.Bits = 16; // _irr_params.DeviceType = Irrlicht::EIDT_X11; - _irr_params.DriverType = irr::video::EDT_OPENGL; - _irr_params.Doublebuffer = false; - _irr_params.EventReceiver = nullptr; - _irr_params.Fullscreen = false; - _irr_params.HandleSRGB = false; - _irr_params.IgnoreInput = true; - _irr_params.Stencilbuffer = true; - _irr_params.UsePerformanceTimer = false; - _irr_params.Vsync = false; - _irr_params.WithAlphaChannel = false; - _irr_params.ZBufferBits = 24; - _irr_params.LoggingLevel = irr::ELL_DEBUG; + irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL; + irrlichtCreationParameters.Doublebuffer = false; + irrlichtCreationParameters.EventReceiver = nullptr; + irrlichtCreationParameters.Fullscreen = false; + irrlichtCreationParameters.HandleSRGB = false; + irrlichtCreationParameters.IgnoreInput = true; + irrlichtCreationParameters.Stencilbuffer = true; + irrlichtCreationParameters.UsePerformanceTimer = false; + irrlichtCreationParameters.Vsync = false; + irrlichtCreationParameters.WithAlphaChannel = false; + irrlichtCreationParameters.ZBufferBits = 24; + irrlichtCreationParameters.LoggingLevel = irr::ELL_DEBUG; - initialize_viewports (); + initialize_viewports (irrlichtCreationParameters); - IrrlichtContext->setDevice (irr::createDeviceEx (_irr_params)); + IrrlichtContext->setDevice (irr::createDeviceEx (irrlichtCreationParameters)); if (IrrlichtContext->getDevice () == nullptr) { @@ -210,7 +209,7 @@ int main (int argc, char* argv[]) { case 'r': IsRootWindow = true; - Screens.push_back (optarg); + Screens.emplace_back (optarg); break; case 'p': diff --git a/src/WallpaperEngine/FileSystem/FileSystem.cpp b/src/WallpaperEngine/FileSystem/FileSystem.cpp index 7765c53..0ee94a6 100644 --- a/src/WallpaperEngine/FileSystem/FileSystem.cpp +++ b/src/WallpaperEngine/FileSystem/FileSystem.cpp @@ -6,24 +6,23 @@ extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext; -namespace WallpaperEngine::FileSystem +using namespace WallpaperEngine; + +std::string FileSystem::loadFullFile (const irr::io::path& file) { - std::string loadFullFile (const irr::io::path& file) - { - irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file); + irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file); - if (reader == NULL) - throw std::runtime_error ("Cannot open file " + std::string (file.c_str ()) + " for reading"); + if (reader == nullptr) + throw std::runtime_error ("Cannot open file " + std::string (file.c_str ()) + " for reading"); - char* filedata = new char [reader->getSize () + 1]; - memset (filedata, 0, reader->getSize () + 1); + char* filedata = new char [reader->getSize () + 1]; + memset (filedata, 0, reader->getSize () + 1); - reader->read (filedata, reader->getSize ()); - reader->drop (); + reader->read (filedata, reader->getSize ()); + reader->drop (); - std::string content = filedata; - delete [] filedata; + std::string content = filedata; + delete [] filedata; - return content; - } -}; \ No newline at end of file + return content; +} diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index d296943..e3038cf 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -1,3 +1,4 @@ +#include #include "CContext.h" using namespace WallpaperEngine::Irrlicht; @@ -10,4 +11,33 @@ void CContext::setDevice (irr::IrrlichtDevice* device) irr::IrrlichtDevice* CContext::getDevice () { return this->m_device; +} + +irr::io::path CContext::resolveFile (const irr::io::path& file) +{ + if (this->getDevice ()->getFileSystem ()->existFile (file) == false) + { + throw std::runtime_error ("Cannot find file " + std::string (file.c_str ())); + } + + return file; +} + +irr::io::path CContext::resolveMaterials (const std::string& materialName) +{ + return this->resolveFile (std::string ("materials/" + materialName + ".tex").c_str ()); +} + +irr::io::path CContext::resolveVertexShader (const std::string& vertexShader) +{ + return this->resolveFile (std::string ("shaders/" + vertexShader + ".vert").c_str ()); +} +irr::io::path CContext::resolveFragmentShader (const std::string& fragmentShader) +{ + return this->resolveFile (std::string ("shaders/" + fragmentShader + ".frag").c_str ()); +} + +irr::io::path CContext::resolveIncludeShader (const std::string& includeShader) +{ + return this->resolveFile (std::string ("shaders/" + includeShader).c_str ()); } \ No newline at end of file diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index 4786d2a..1cb31fe 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -1,5 +1,7 @@ #pragma once +#include + #include namespace WallpaperEngine::Irrlicht @@ -10,7 +12,13 @@ namespace WallpaperEngine::Irrlicht void setDevice (irr::IrrlichtDevice* device); irr::IrrlichtDevice* getDevice (); + irr::io::path resolveMaterials (const std::string& materialName); + irr::io::path resolveVertexShader (const std::string& vertexShader); + irr::io::path resolveFragmentShader (const std::string& fragmentShader); + irr::io::path resolveIncludeShader (const std::string& includeShader); private: + irr::io::path resolveFile (const irr::io::path& file); + irr::IrrlichtDevice* m_device; }; }; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 96618ce..4a25828 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -127,7 +127,7 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++, textureNumber ++) { // TODO: LOOK THIS UP PROPERLY - irr::io::path texturepath = std::string ("materials/" + (*texturesCur) + ".tex").c_str (); + irr::io::path texturepath = this->getScene ()->getContext ()->resolveMaterials (*texturesCur); irr::video::ITexture* texture = nullptr; if (textureNumber == 0 && this->m_passes > 0) @@ -152,10 +152,11 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) } // TODO: MOVE SHADER INITIALIZATION ELSEWHERE - irr::io::path vertpath = std::string ("shaders/" + pass->getShader () + ".vert").c_str (); - irr::io::path fragpath = std::string ("shaders/" + pass->getShader () + ".frag").c_str (); - Render::Shaders::Compiler* vertexShader = new Render::Shaders::Compiler (vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); - Render::Shaders::Compiler* pixelShader = new Render::Shaders::Compiler (fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); + irr::io::path vertpath = this->getScene ()->getContext ()->resolveVertexShader (pass->getShader ()); + irr::io::path fragpath = this->getScene ()->getContext ()->resolveFragmentShader (pass->getShader ()); + + auto vertexShader = new Render::Shaders::Compiler (this->getScene ()->getContext (), vertpath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false); + auto pixelShader = new Render::Shaders::Compiler (this->getScene ()->getContext (), fragpath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false); material.MaterialType = (irr::video::E_MATERIAL_TYPE) this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()->addHighLevelShaderMaterial ( diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 1f6f3cd..be09043 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -19,13 +19,14 @@ namespace WallpaperEngine::Render::Shaders { - Compiler::Compiler (irr::io::path& file, Type type, const std::map& combos, bool recursive) : + Compiler::Compiler (Irrlicht::CContext* context, irr::io::path& file, Type type, const std::map& combos, bool recursive) : m_combos (combos), m_recursive (recursive), m_type (type), m_file (file), m_error (""), - m_errorInfo ("") + m_errorInfo (""), + m_context (context) { // begin with an space so it gets ignored properly on parse if (this->m_recursive == false) @@ -207,7 +208,7 @@ namespace WallpaperEngine::Render::Shaders std::string Compiler::lookupShaderFile (std::string filename) { // get file information - irr::io::path shader = ("shaders/" + filename).c_str (); + irr::io::path shader = this->m_context->resolveIncludeShader (filename); if (shader == "") { @@ -218,7 +219,7 @@ namespace WallpaperEngine::Render::Shaders // now compile the new shader // do not include the default header (as it's already included in the parent) - Compiler loader (shader, this->m_type, this->m_combos, true); + Compiler loader (this->m_context, shader, this->m_type, this->m_combos, true); return loader.precompile (); } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 0c757d8..d9b4299 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -6,7 +6,10 @@ #include #include -#include +#include "WallpaperEngine/FileSystem/FileSystem.h" + +#include "WallpaperEngine/Irrlicht/CContext.h" + #include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" namespace WallpaperEngine::Render::Shaders @@ -42,11 +45,13 @@ namespace WallpaperEngine::Render::Shaders * the pre-processing and compilation of the shader, adding * required definitions if needed * + * @param context The irrlicht context * @param file The file to load * @param type The type of shader + * @param combos Settings for the shader * @param recursive Whether the compiler should add base definitions or not */ - Compiler (irr::io::path& file, Type type, const std::map& combos, bool recursive = false); + Compiler (Irrlicht::CContext* context, irr::io::path& file, Type type, const std::map& combos, bool recursive = false); /** * Performs the actual pre-compilation/pre-processing over the shader files * This step is kinda big, replaces variables names on sVariableReplacement, @@ -211,5 +216,9 @@ namespace WallpaperEngine::Render::Shaders * Whether this compilation is a recursive one or not */ bool m_recursive; + /** + * The irrlicht context in use + */ + Irrlicht::CContext* m_context; }; } From d03edb7c1e2336461fce841f15fa95d12d733d58 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 12:55:45 +0200 Subject: [PATCH 09/31] ~ cleaned up main function and moved initialization functions to a more proper place ~ check for SDL initialization before playing audio to prevent error messages when there is not really any error ~ changed a missed iterator to auto on CSound Signed-off-by: Alexis Maiquez --- main.cpp | 293 +++++------------- src/WallpaperEngine/Irrlicht/CContext.cpp | 164 ++++++++++ src/WallpaperEngine/Irrlicht/CContext.h | 19 ++ src/WallpaperEngine/Render/CScene.cpp | 2 + src/WallpaperEngine/Render/CScene.h | 5 + src/WallpaperEngine/Render/Objects/CImage.cpp | 1 - src/WallpaperEngine/Render/Objects/CImage.h | 1 - src/WallpaperEngine/Render/Objects/CSound.cpp | 19 +- 8 files changed, 275 insertions(+), 229 deletions(-) diff --git a/main.cpp b/main.cpp index 5b44922..ab179c8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,158 +1,27 @@ #include #include -#include -#include #include #include #include -#include -#include - #include "WallpaperEngine/Render/Shaders/Compiler.h" -#include "WallpaperEngine/Irrlicht/CImageLoaderTEX.h" #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Irrlicht/CContext.h" #include "WallpaperEngine/Render/CScene.h" -bool IsRootWindow = false; -std::vector Screens; -std::vector> Viewports; +enum BACKGROUND_RUN_MODE +{ + RUN_MODE_UNKNOWN = 0, + RUN_MODE_HELP = 1, + RUN_MODE_DIRECTORY = 2, + RUN_MODE_PACKAGE = 3 +}; +// TODO: MOVE GLOBAL SHADER VARIABLES TO THEIR OWN CLASS irr::f32 g_Time = 0; -WallpaperEngine::Irrlicht::CContext* IrrlichtContext; -void initialize_viewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters) -{ - if (IsRootWindow == false || Screens.empty () == true) - return; - - Display* display = XOpenDisplay (NULL); - int xrandr_result, xrandr_error; - - if (!XRRQueryExtension (display, &xrandr_result, &xrandr_error)) - { - std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl; - return; - } - - XRRScreenResources* screenResources = XRRGetScreenResources (display, DefaultRootWindow (display)); - - // there are some situations where xrandr returns null (like screen not using the extension) - if (screenResources == nullptr) - return; - - for (int i = 0; i < screenResources->noutput; i ++) - { - XRROutputInfo* info = XRRGetOutputInfo (display, screenResources, screenResources->outputs [i]); - - // there are some situations where xrandr returns null (like screen not using the extension) - if (info == nullptr) - continue; - - auto cur = Screens.begin (); - auto end = Screens.end (); - - for (; cur != end; cur ++) - { - if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0) - { - XRRCrtcInfo* crtc = XRRGetCrtcInfo (display, screenResources, info->crtc); - - std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl; - - irr::core::rect viewport; - - viewport.UpperLeftCorner.X = crtc->x; - viewport.UpperLeftCorner.Y = crtc->y; - viewport.LowerRightCorner.X = crtc->x + crtc->width; - viewport.LowerRightCorner.Y = crtc->y + crtc->height; - - Viewports.push_back (viewport); - - XRRFreeCrtcInfo (crtc); - } - } - - XRRFreeOutputInfo (info); - } - - XRRFreeScreenResources (screenResources); - - irrlichtCreationParameters.WindowId = reinterpret_cast (DefaultRootWindow (display)); -} - -int init_irrlicht() -{ - IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (); - - irr::SIrrlichtCreationParameters irrlichtCreationParameters; - // prepare basic configuration for irrlicht - irrlichtCreationParameters.AntiAlias = 8; - irrlichtCreationParameters.Bits = 16; - // _irr_params.DeviceType = Irrlicht::EIDT_X11; - irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL; - irrlichtCreationParameters.Doublebuffer = false; - irrlichtCreationParameters.EventReceiver = nullptr; - irrlichtCreationParameters.Fullscreen = false; - irrlichtCreationParameters.HandleSRGB = false; - irrlichtCreationParameters.IgnoreInput = true; - irrlichtCreationParameters.Stencilbuffer = true; - irrlichtCreationParameters.UsePerformanceTimer = false; - irrlichtCreationParameters.Vsync = false; - irrlichtCreationParameters.WithAlphaChannel = false; - irrlichtCreationParameters.ZBufferBits = 24; - irrlichtCreationParameters.LoggingLevel = irr::ELL_DEBUG; - - initialize_viewports (irrlichtCreationParameters); - - IrrlichtContext->setDevice (irr::createDeviceEx (irrlichtCreationParameters)); - - if (IrrlichtContext->getDevice () == nullptr) - { - return 1; - } - - IrrlichtContext->getDevice ()->setWindowCaption (L"Test game"); - - // check for ps and vs support - if ( - IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_PIXEL_SHADER_1_1) == false && - IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false) - { - IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Pixel shaders disabled because of missing driver/hardware support"); - } - - if ( - IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_VERTEX_SHADER_1_1) == false && - IrrlichtContext->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false) - { - IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support"); - } - - if (IrrlichtContext->getDevice ()->getVideoDriver ()->queryFeature (irr::video::EVDF_RENDER_TO_TARGET) == false) - { - IrrlichtContext->getDevice ()->getLogger ()->log ("ERROR: Your hardware or this renderer do not support rendering to texture"); - return 1; - } - - return 0; -} - -void preconfigure_wallpaper_engine () -{ - // load the assets from wallpaper engine - IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive ("assets.zip", true, false); - - // register custom loaders - IrrlichtContext->getDevice ()->getVideoDriver()->addExternalImageLoader ( - new WallpaperEngine::Irrlicht::CImageLoaderTex (IrrlichtContext) - ); - IrrlichtContext->getDevice ()->getFileSystem ()->addArchiveLoader ( - new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (IrrlichtContext) - ); -} +WallpaperEngine::Irrlicht::CContext* IrrlichtContext = nullptr; void print_help (const char* route) { @@ -181,21 +50,24 @@ std::string stringPathFixes(const std::string& s){ int main (int argc, char* argv[]) { - int mode = 0; - int max_fps = 30; - bool audio_support = true; + std::vector screens; + bool isRootWindow = false; + + int mode = RUN_MODE_UNKNOWN; + int maximumFPS = 30; + bool shouldEnableAudio = true; std::string path; int option_index = 0; static struct option long_options [] = { - {"screen-root", required_argument, 0, 'r'}, - {"pkg", required_argument, 0, 'p'}, - {"dir", required_argument, 0, 'd'}, - {"silent", no_argument, 0, 's'}, - {"help", no_argument, 0, 'h'}, - {"fps", required_argument, 0, 'f'}, - {nullptr, 0, 0, 0} + {"screen-root", required_argument, 0, 'r'}, + {"pkg", required_argument, 0, 'p'}, + {"dir", required_argument, 0, 'd'}, + {"silent", no_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {"fps", required_argument, 0, 'f'}, + {nullptr, 0, 0, 0} }; while (true) @@ -208,30 +80,32 @@ int main (int argc, char* argv[]) switch (c) { case 'r': - IsRootWindow = true; - Screens.emplace_back (optarg); + isRootWindow = true; + screens.emplace_back (optarg); break; case 'p': - mode = 1; + if (mode == RUN_MODE_UNKNOWN) + mode = RUN_MODE_PACKAGE; path = optarg; break; case 'd': - mode = 2; + if (mode == RUN_MODE_UNKNOWN) + mode = RUN_MODE_DIRECTORY; path = optarg; break; case 's': - audio_support = false; + shouldEnableAudio = false; break; case 'h': - print_help (argv [0]); - return 0; + mode = RUN_MODE_HELP; + break; case 'f': - max_fps = atoi (optarg); + maximumFPS = atoi (optarg); break; default: @@ -239,55 +113,51 @@ int main (int argc, char* argv[]) } } - if (init_irrlicht ()) + if (mode == RUN_MODE_UNKNOWN || mode == RUN_MODE_HELP) { + print_help (argv [0]); + return 0; + } + + try + { + IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (screens, isRootWindow); + IrrlichtContext->initializeContext (); + } + catch (std::runtime_error& ex) + { + std::cerr << ex.what () << std::endl; + return 1; } - preconfigure_wallpaper_engine (); + path = stringPathFixes (path); - irr::io::path wallpaper_path; - irr::io::path project_path; + irr::io::path wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ()); + irr::io::path project_path = wallpaper_path + "project.json"; irr::io::path scene_path; - switch (mode) + if (mode == RUN_MODE_PACKAGE) { - case 0: - print_help (argv [0]); - return 0; - - // pkg mode - case 1: - path = stringPathFixes(path); - wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ()); - project_path = wallpaper_path + "project.json"; - scene_path = wallpaper_path + "scene.pkg"; - - IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive (scene_path, true, false); // add the pkg file to the lookup list - break; - - // folder mode - case 2: - path = stringPathFixes(path); - wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ()); - project_path = wallpaper_path + "project.json"; - - // set our working directory - IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path); - break; - - default: - break; + irr::io::path scene_path = wallpaper_path + "scene.pkg"; + // add the package file to the lookup list + IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive (scene_path, true, false); + } + else if (mode == RUN_MODE_DIRECTORY) + { + project_path = wallpaper_path + "project.json"; + // set the working directory to the project folder + IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path); } - if (audio_support == true) + if (shouldEnableAudio == true) { int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG; if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags)) { IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR); - return -1; + return 2; } // initialize audio engine @@ -295,52 +165,29 @@ int main (int argc, char* argv[]) } WallpaperEngine::Core::CProject* project = WallpaperEngine::Core::CProject::fromFile (project_path); - WallpaperEngine::Render::CScene* sceneRender = new WallpaperEngine::Render::CScene (project, IrrlichtContext); + WallpaperEngine::Render::CScene* scene = new WallpaperEngine::Render::CScene (project, IrrlichtContext); - irr::u32 lastTime = 0; - irr::u32 minimumTime = 1000 / max_fps; + irr::u32 minimumTime = 1000 / maximumFPS; irr::u32 currentTime = 0; irr::u32 startTime = 0; irr::u32 endTime = 0; - IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (sceneRender->getScene ()->getAmbientColor ().toSColor ()); + IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (scene->getScene ()->getAmbientColor ().toSColor ()); + while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) { if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) continue; - // if (device->isWindowActive ()) - { - currentTime = startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - g_Time = currentTime / 1000.0f; + currentTime = startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); + g_Time = currentTime / 1000.0f; - if (Viewports.size () > 0) - { - auto cur = Viewports.begin (); - auto end = Viewports.end (); + IrrlichtContext->renderFrame (scene); - for (; cur != end; cur ++) - { - // change viewport to render to the correct portion of the display - IrrlichtContext->getDevice ()->getVideoDriver ()->setViewPort (*cur); + endTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (false, true, sceneRender->getScene ()->getClearColor ().toSColor()); - IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); - IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); - } - } - else - { - IrrlichtContext->getDevice ()->getVideoDriver ()->beginScene (true, true, sceneRender->getScene ()->getClearColor ().toSColor()); - IrrlichtContext->getDevice ()->getSceneManager ()->drawAll (); - IrrlichtContext->getDevice ()->getVideoDriver ()->endScene (); - } - - endTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - - IrrlichtContext->getDevice ()->sleep (minimumTime - (endTime - startTime), false); - } + IrrlichtContext->getDevice ()->sleep (minimumTime - (endTime - startTime), false); } SDL_Quit (); diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index e3038cf..b797ad0 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -1,13 +1,177 @@ +#include #include +#include + +#include +#include + +#include "WallpaperEngine/Irrlicht/CImageLoaderTEX.h" +#include "WallpaperEngine/Irrlicht/CPkgReader.h" + #include "CContext.h" using namespace WallpaperEngine::Irrlicht; +CContext::CContext (std::vector screens, bool isRootWindow) : + m_screens (std::move(screens)), + m_isRootWindow (isRootWindow) +{ +} + void CContext::setDevice (irr::IrrlichtDevice* device) { this->m_device = device; } +void CContext::initializeContext () +{ + irr::SIrrlichtCreationParameters irrlichtCreationParameters; + + // prepare basic configuration for irrlicht + irrlichtCreationParameters.AntiAlias = 8; + irrlichtCreationParameters.Bits = 16; + // _irr_params.DeviceType = Irrlicht::EIDT_X11; + irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL; + irrlichtCreationParameters.Doublebuffer = false; + irrlichtCreationParameters.EventReceiver = nullptr; + irrlichtCreationParameters.Fullscreen = false; + irrlichtCreationParameters.HandleSRGB = false; + irrlichtCreationParameters.IgnoreInput = true; + irrlichtCreationParameters.Stencilbuffer = true; + irrlichtCreationParameters.UsePerformanceTimer = false; + irrlichtCreationParameters.Vsync = false; + irrlichtCreationParameters.WithAlphaChannel = false; + irrlichtCreationParameters.ZBufferBits = 24; + irrlichtCreationParameters.LoggingLevel = irr::ELL_DEBUG; + + this->initializeViewports (irrlichtCreationParameters); + + this->setDevice (irr::createDeviceEx (irrlichtCreationParameters)); + + if (this->getDevice () == nullptr) + { + throw std::runtime_error ("Cannot create irrlicht device"); + } + + this->getDevice ()->setWindowCaption (L"Test game"); + + // check for ps and vs support + if ( + this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_PIXEL_SHADER_2_0) == false && + this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false) + { + throw std::runtime_error ("Pixel Shader 2.0 not supported by your video driver/hardware"); + } + + if ( + this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_VERTEX_SHADER_2_0) == false && + this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false) + { + throw std::runtime_error ("Vertex Shader 2.0 not supported by your video driver/hardware"); + } + + if (this->getDevice ()->getVideoDriver ()->queryFeature (irr::video::EVDF_RENDER_TO_TARGET) == false) + { + throw std::runtime_error ("Render to texture not supported by your video driver/hardware"); + } + + // load the assets from wallpaper engine + this->getDevice ()->getFileSystem ()->addFileArchive ("assets.zip", true, false); + + // register custom loaders + this->getDevice ()->getVideoDriver()->addExternalImageLoader ( + new WallpaperEngine::Irrlicht::CImageLoaderTex (this) + ); + this->getDevice ()->getFileSystem ()->addArchiveLoader ( + new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (this) + ); +} + +void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCreationParameters) +{ + if (this->m_isRootWindow == false || this->m_screens.empty () == true) + return; + + Display* display = XOpenDisplay (nullptr); + int xrandr_result, xrandr_error; + + if (!XRRQueryExtension (display, &xrandr_result, &xrandr_error)) + { + std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl; + return; + } + + XRRScreenResources* screenResources = XRRGetScreenResources (display, DefaultRootWindow (display)); + + // there are some situations where xrandr returns null (like screen not using the extension) + if (screenResources == nullptr) + return; + + for (int i = 0; i < screenResources->noutput; i ++) + { + XRROutputInfo* info = XRRGetOutputInfo (display, screenResources, screenResources->outputs [i]); + + // there are some situations where xrandr returns null (like screen not using the extension) + if (info == nullptr) + continue; + + auto cur = this->m_screens.begin (); + auto end = this->m_screens.end (); + + for (; cur != end; cur ++) + { + if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0) + { + XRRCrtcInfo* crtc = XRRGetCrtcInfo (display, screenResources, info->crtc); + + std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl; + + irr::core::rect viewport; + + viewport.UpperLeftCorner.X = crtc->x; + viewport.UpperLeftCorner.Y = crtc->y; + viewport.LowerRightCorner.X = crtc->x + crtc->width; + viewport.LowerRightCorner.Y = crtc->y + crtc->height; + + this->m_viewports.push_back (viewport); + + XRRFreeCrtcInfo (crtc); + } + } + + XRRFreeOutputInfo (info); + } + + XRRFreeScreenResources (screenResources); + + irrlichtCreationParameters.WindowId = reinterpret_cast (DefaultRootWindow (display)); +} + +void CContext::renderFrame (Render::CScene* scene) +{ + if (this->m_viewports.empty () == true) + { + this->getDevice ()->getVideoDriver ()->beginScene (true, true, scene->getScene ()->getClearColor ().toSColor()); + this->getDevice ()->getSceneManager ()->drawAll (); + this->getDevice ()->getVideoDriver ()->endScene (); + } + else + { + auto cur = this->m_viewports.begin (); + auto end = this->m_viewports.end (); + + for (; cur != end; cur ++) + { + // change viewport to render to the correct portion of the display + this->getDevice ()->getVideoDriver ()->setViewPort (*cur); + + this->getDevice ()->getVideoDriver ()->beginScene (false, true, scene->getScene ()->getClearColor ().toSColor()); + this->getDevice ()->getSceneManager ()->drawAll (); + this->getDevice ()->getVideoDriver ()->endScene (); + } + } +} + irr::IrrlichtDevice* CContext::getDevice () { return this->m_device; diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index 1cb31fe..b6acc4f 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -1,15 +1,28 @@ #pragma once +#include #include #include +#include "WallpaperEngine/Render/CScene.h" + +namespace WallpaperEngine::Render +{ + class CScene; +}; + namespace WallpaperEngine::Irrlicht { class CContext { public: + CContext (std::vector screens, bool isRootWindow = false); + void setDevice (irr::IrrlichtDevice* device); + void initializeContext (); + + void renderFrame (Render::CScene* scene); irr::IrrlichtDevice* getDevice (); irr::io::path resolveMaterials (const std::string& materialName); @@ -17,8 +30,14 @@ namespace WallpaperEngine::Irrlicht irr::io::path resolveFragmentShader (const std::string& fragmentShader); irr::io::path resolveIncludeShader (const std::string& includeShader); private: + void initializeViewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters); + irr::io::path resolveFile (const irr::io::path& file); irr::IrrlichtDevice* m_device; + + std::vector m_screens; + std::vector m_viewports; + bool m_isRootWindow; }; }; diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index cce0147..2f72881 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -1,3 +1,5 @@ +#include "WallpaperEngine/Irrlicht/CContext.h" + #include "WallpaperEngine/Core/Objects/CImage.h" #include "WallpaperEngine/Core/Objects/CSound.h" diff --git a/src/WallpaperEngine/Render/CScene.h b/src/WallpaperEngine/Render/CScene.h index 77d34fd..5307a8d 100644 --- a/src/WallpaperEngine/Render/CScene.h +++ b/src/WallpaperEngine/Render/CScene.h @@ -7,6 +7,11 @@ #include "WallpaperEngine/Irrlicht/CContext.h" +namespace WallpaperEngine::Irrlicht +{ + class CContext; +}; + namespace WallpaperEngine::Render { class CCamera; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 4a25828..2206500 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -126,7 +126,6 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++, textureNumber ++) { - // TODO: LOOK THIS UP PROPERLY irr::io::path texturepath = this->getScene ()->getContext ()->resolveMaterials (*texturesCur); irr::video::ITexture* texture = nullptr; diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index db8ec93..0be5003 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -11,7 +11,6 @@ using namespace WallpaperEngine; namespace WallpaperEngine::Render::Objects { - // TODO: MOVE IShaderConstantSetCallBack TO IT'S OWN CLASS OR ORGANIZE THIS BETTER class CImage : public CObject, public irr::video::IShaderConstantSetCallBack { public: diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp index d38db69..5a9fac4 100644 --- a/src/WallpaperEngine/Render/Objects/CSound.cpp +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -18,8 +19,13 @@ CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : void CSound::load () { - std::vector::const_iterator cur = this->m_sound->getSounds ().begin (); - std::vector::const_iterator end = this->m_sound->getSounds ().end (); + if (SDL_WasInit (SDL_INIT_AUDIO) != SDL_INIT_AUDIO) + { + return; + } + + auto cur = this->m_sound->getSounds ().begin (); + auto end = this->m_sound->getSounds ().end (); for (; cur != end; cur ++) { @@ -51,8 +57,13 @@ void CSound::load () } void CSound::play () { - std::vector::const_iterator mixcur = this->m_sdl.begin (); - std::vector::const_iterator mixend = this->m_sdl.end (); + if (SDL_WasInit (SDL_INIT_AUDIO) != SDL_INIT_AUDIO) + { + return; + } + + auto mixcur = this->m_sdl.begin (); + auto mixend = this->m_sdl.end (); for (; mixcur != mixend; mixcur ++) { From d7cf8af7cabd479990b38e048a81a316e62a155c Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 13:27:18 +0200 Subject: [PATCH 10/31] + created global variable storage for shaders + added g_Time to global variable storage - removed global g_Time from main ~ changed "shader parameters" to "shader variables" as it's a more apt naming Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 27 +++++---- main.cpp | 8 +-- src/WallpaperEngine/Irrlicht/CContext.cpp | 19 +++++++ src/WallpaperEngine/Irrlicht/CContext.h | 9 +++ src/WallpaperEngine/Render/Objects/CImage.cpp | 57 ++++++++++++------- .../Render/Shaders/Compiler.cpp | 28 ++++----- src/WallpaperEngine/Render/Shaders/Compiler.h | 8 +-- .../Shaders/Parameters/CShaderParameter.cpp | 46 --------------- .../Parameters/CShaderParameterFloat.cpp | 25 -------- .../Parameters/CShaderParameterInteger.cpp | 24 -------- .../Parameters/CShaderParameterInteger.h | 24 -------- .../Parameters/CShaderParameterVector2.cpp | 25 -------- .../Parameters/CShaderParameterVector2.h | 24 -------- .../Parameters/CShaderParameterVector3.cpp | 24 -------- .../Parameters/CShaderParameterVector3.h | 24 -------- .../Parameters/CShaderParameterVector4.cpp | 24 -------- .../Parameters/CShaderParameterVector4.h | 24 -------- .../Shaders/Variables/CShaderVariable.cpp | 46 +++++++++++++++ .../CShaderVariable.h} | 6 +- .../Variables/CShaderVariableFloat.cpp | 34 +++++++++++ .../CShaderVariableFloat.h} | 9 +-- .../Variables/CShaderVariableFloatPointer.cpp | 26 +++++++++ .../Variables/CShaderVariableFloatPointer.h | 21 +++++++ .../Variables/CShaderVariableInteger.cpp | 33 +++++++++++ .../Variables/CShaderVariableInteger.h | 25 ++++++++ .../Variables/CShaderVariableVector2.cpp | 35 ++++++++++++ .../Variables/CShaderVariableVector2.h | 25 ++++++++ .../Variables/CShaderVariableVector3.cpp | 31 ++++++++++ .../Variables/CShaderVariableVector3.h | 25 ++++++++ .../Variables/CShaderVariableVector4.cpp | 33 +++++++++++ .../Variables/CShaderVariableVector4.h | 25 ++++++++ 31 files changed, 467 insertions(+), 327 deletions(-) delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp delete mode 100644 src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp rename src/WallpaperEngine/Render/Shaders/{Parameters/CShaderParameter.h => Variables/CShaderVariable.h} (83%) create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp rename src/WallpaperEngine/Render/Shaders/{Parameters/CShaderParameterFloat.h => Variables/CShaderVariableFloat.h} (50%) create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f5b749..8f8ac87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,18 +25,21 @@ add_executable( src/WallpaperEngine/Core/Core.h src/WallpaperEngine/Core/Core.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h - src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp + + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp diff --git a/main.cpp b/main.cpp index ab179c8..56d1578 100644 --- a/main.cpp +++ b/main.cpp @@ -18,9 +18,6 @@ enum BACKGROUND_RUN_MODE RUN_MODE_PACKAGE = 3 }; -// TODO: MOVE GLOBAL SHADER VARIABLES TO THEIR OWN CLASS -irr::f32 g_Time = 0; - WallpaperEngine::Irrlicht::CContext* IrrlichtContext = nullptr; void print_help (const char* route) @@ -168,8 +165,6 @@ int main (int argc, char* argv[]) WallpaperEngine::Render::CScene* scene = new WallpaperEngine::Render::CScene (project, IrrlichtContext); irr::u32 minimumTime = 1000 / maximumFPS; - irr::u32 currentTime = 0; - irr::u32 startTime = 0; irr::u32 endTime = 0; @@ -180,8 +175,7 @@ int main (int argc, char* argv[]) if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) continue; - currentTime = startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - g_Time = currentTime / 1000.0f; + startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); IrrlichtContext->renderFrame (scene); diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index b797ad0..a482a12 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -8,8 +8,11 @@ #include "WallpaperEngine/Irrlicht/CImageLoaderTEX.h" #include "WallpaperEngine/Irrlicht/CPkgReader.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" + #include "CContext.h" +using namespace WallpaperEngine; using namespace WallpaperEngine::Irrlicht; CContext::CContext (std::vector screens, bool isRootWindow) : @@ -85,6 +88,10 @@ void CContext::initializeContext () this->getDevice ()->getFileSystem ()->addArchiveLoader ( new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (this) ); + // register time shader variable + this->insertShaderVariable ( + new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, 1, "g_Time") + ); } void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCreationParameters) @@ -149,6 +156,8 @@ void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCr void CContext::renderFrame (Render::CScene* scene) { + this->m_time = this->getDevice ()->getTimer ()->getTime () / 1000.0f; + if (this->m_viewports.empty () == true) { this->getDevice ()->getVideoDriver ()->beginScene (true, true, scene->getScene ()->getClearColor ().toSColor()); @@ -172,6 +181,16 @@ void CContext::renderFrame (Render::CScene* scene) } } +void CContext::insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable) +{ + this->m_globalShaderVariables.push_back (variable); +} + +const std::vector& CContext::getShaderVariables () const +{ + return this->m_globalShaderVariables; +} + irr::IrrlichtDevice* CContext::getDevice () { return this->m_device; diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index b6acc4f..6a00f99 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -7,6 +7,8 @@ #include "WallpaperEngine/Render/CScene.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" + namespace WallpaperEngine::Render { class CScene; @@ -22,6 +24,9 @@ namespace WallpaperEngine::Irrlicht void setDevice (irr::IrrlichtDevice* device); void initializeContext (); + void insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable); + const std::vector& getShaderVariables () const; + void renderFrame (Render::CScene* scene); irr::IrrlichtDevice* getDevice (); @@ -36,6 +41,10 @@ namespace WallpaperEngine::Irrlicht irr::IrrlichtDevice* m_device; + std::vector m_globalShaderVariables; + + irr::f32 m_time; + std::vector m_screens; std::vector m_viewports; bool m_isRootWindow; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 2206500..2eef681 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -1,16 +1,18 @@ #include "CImage.h" #include "WallpaperEngine/Render/Shaders/Compiler.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" + +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" using namespace WallpaperEngine; using namespace WallpaperEngine::Render::Objects; -using namespace WallpaperEngine::Render::Shaders::Parameters; +using namespace WallpaperEngine::Render::Shaders::Variables; extern irr::f32 g_Time; @@ -225,7 +227,7 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in for (; cur != end; cur ++) { - if ((*cur)->is () == true) + if ((*cur)->is () == true) { services->setVertexShaderConstant ( (*cur)->getName ().c_str (), @@ -234,10 +236,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setVertexShaderConstant ( (*cur)->getName ().c_str (), @@ -252,7 +254,7 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in for (; cur != end; cur ++) { - if ((*cur)->is () == true) + if ((*cur)->is () == true) { services->setPixelShaderConstant ( (*cur)->getName ().c_str (), @@ -261,10 +263,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setPixelShaderConstant ( (*cur)->getName ().c_str (), @@ -274,8 +276,25 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in } } - services->setVertexShaderConstant ("g_Time", &g_Time, 1); - services->setPixelShaderConstant ("g_Time", &g_Time, 1); + cur = this->getScene ()->getContext ()->getShaderVariables ().begin (); + end = this->getScene ()->getContext ()->getShaderVariables ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16); diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index be09043..c899dc4 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -10,12 +10,12 @@ #include #include -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" namespace WallpaperEngine::Render::Shaders { @@ -511,33 +511,33 @@ namespace WallpaperEngine::Render::Shaders return; } - Parameters::CShaderParameter* parameter = nullptr; + Variables::CShaderVariable* parameter = nullptr; if (type == "vec4") { - parameter = new Parameters::CShaderParameterVector4 ( + parameter = new Variables::CShaderVariableVector4 ( WallpaperEngine::Core::ato3vf (*defvalue) ); } else if (type == "vec3") { - parameter = new Parameters::CShaderParameterVector3 ( + parameter = new Variables::CShaderVariableVector3 ( WallpaperEngine::Core::ato3vf (*defvalue) ); } else if (type == "vec2") { - parameter = new Parameters::CShaderParameterVector2 ( + parameter = new Variables::CShaderVariableVector2 ( WallpaperEngine::Core::ato2vf (*defvalue) ); } else if (type == "float") { - parameter = new Parameters::CShaderParameterFloat ((*defvalue).get ()); + parameter = new Variables::CShaderVariableFloat ((*defvalue).get ()); } else if (type == "int") { - parameter = new Parameters::CShaderParameterInteger ((*defvalue).get ()); + parameter = new Variables::CShaderVariableInteger ((*defvalue).get ()); } else if (type == "sampler2D") { @@ -557,7 +557,7 @@ namespace WallpaperEngine::Render::Shaders this->m_parameters.push_back (parameter); } - Parameters::CShaderParameter* Compiler::findParameter (const std::string& identifier) + Variables::CShaderVariable* Compiler::findParameter (const std::string& identifier) { auto cur = this->m_parameters.begin (); auto end = this->m_parameters.end (); @@ -573,7 +573,7 @@ namespace WallpaperEngine::Render::Shaders return nullptr; } - const std::vector & Compiler::getParameters () const + const std::vector & Compiler::getParameters () const { return this->m_parameters; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index d9b4299..00a419e 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -10,7 +10,7 @@ #include "WallpaperEngine/Irrlicht/CContext.h" -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" namespace WallpaperEngine::Render::Shaders { @@ -67,12 +67,12 @@ namespace WallpaperEngine::Render::Shaders * @param identifier The identifier to search for * @return The shader information */ - Parameters::CShaderParameter* findParameter (const std::string& identifier); + Variables::CShaderVariable* findParameter (const std::string& identifier); /** * @return The list of parameters available for this shader with their default values */ - const std::vector & getParameters () const; + const std::vector & getParameters () const; private: /** @@ -207,7 +207,7 @@ namespace WallpaperEngine::Render::Shaders /** * The parameters the shader needs */ - std::vector m_parameters; + std::vector m_parameters; /** * The combos the shader should be generated with */ diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp deleted file mode 100644 index 5bdcfd6..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "CShaderParameter.h" - -#include - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameter::CShaderParameter (void* defaultValue, void* value, std::string type) : - m_defaultValue (defaultValue), - m_value (value), - m_type (std::move(type)) -{ - -} - -const void* CShaderParameter::getValue () const -{ - if (this->m_value) - return this->m_value; - - return this->m_defaultValue; -} - -void CShaderParameter::setValue (void* value) -{ - this->m_value = value; -} - -const std::string& CShaderParameter::getIdentifierName () const -{ - return this->m_identifierName; -} - -const std::string& CShaderParameter::getName () const -{ - return this->m_name; -} - -void CShaderParameter::setIdentifierName (std::string identifierName) -{ - this->m_identifierName = std::move(identifierName); -} - -void CShaderParameter::setName (std::string name) -{ - this->m_name = std::move(name); -} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp deleted file mode 100644 index 7faff21..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "CShaderParameterFloat.h" - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameterFloat::CShaderParameterFloat(irr::f32 defaultValue) : - m_defaultValue (defaultValue), - m_value (0), - CShaderParameter (&this->m_defaultValue, nullptr, Type) -{ - -} - -void CShaderParameterFloat::setValue (irr::f32 value) -{ - this->m_value = value; - - CShaderParameter::setValue (&this->m_value); -} - -const int CShaderParameterFloat::getSize () const -{ - return 1; -} - -const std::string CShaderParameterFloat::Type = "float"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp deleted file mode 100644 index 63b02b1..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "CShaderParameterInteger.h" - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameterInteger::CShaderParameterInteger(irr::s32 defaultValue) : - m_defaultValue (defaultValue), - m_value (0), - CShaderParameter (&this->m_defaultValue, nullptr, Type) -{ - -} - -void CShaderParameterInteger::setValue (irr::s32 value) -{ - this->m_value = value; - CShaderParameter::setValue (&this->m_value); -} - -const int CShaderParameterInteger::getSize () const -{ - return 1; -} - -const std::string CShaderParameterInteger::Type = "int"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h deleted file mode 100644 index a16169a..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterInteger.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "CShaderParameter.h" - -#include - -namespace WallpaperEngine::Render::Shaders::Parameters -{ - class CShaderParameterInteger : public CShaderParameter - { - public: - CShaderParameterInteger (irr::s32 defaultValue); - - const int getSize () const override; - - static const std::string Type; - - void setValue (irr::s32 value); - - private: - irr::s32 m_defaultValue; - irr::s32 m_value; - }; -} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp deleted file mode 100644 index 63e6b4d..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "CShaderParameterVector2.h" - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameterVector2::CShaderParameterVector2 (const irr::core::vector2df& defaultValue) : - m_defaultValue (defaultValue), - m_value (irr::core::vector2df ()), - CShaderParameter (&this->m_defaultValue, nullptr, Type) -{ - -} - -void CShaderParameterVector2::setValue (irr::core::vector2df value) -{ - this->m_value = value; - - CShaderParameter::setValue (&this->m_value); -} - -const int CShaderParameterVector2::getSize () const -{ - return 2; -} - -const std::string CShaderParameterVector2::Type = "vec2"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h deleted file mode 100644 index 0e7e5b3..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector2.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" - -namespace WallpaperEngine::Render::Shaders::Parameters -{ - class CShaderParameterVector2 : public CShaderParameter - { - public: - CShaderParameterVector2 (const irr::core::vector2df& defaultValue); - - const int getSize () const override; - - void setValue (irr::core::vector2df value); - - static const std::string Type; - - private: - irr::core::vector2df m_defaultValue; - irr::core::vector2df m_value; - }; -} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp deleted file mode 100644 index 4425368..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "CShaderParameterVector3.h" - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameterVector3::CShaderParameterVector3 (const irr::core::vector3df& defaultValue) : - m_defaultValue (defaultValue), - m_value (irr::core::vector3df ()), - CShaderParameter (&this->m_defaultValue, nullptr, Type) -{ - -} - -void CShaderParameterVector3::setValue (irr::core::vector3df value) -{ - this->m_value = value; - CShaderParameter::setValue (&this->m_value); -} - -const int CShaderParameterVector3::getSize () const -{ - return 3; -} - -const std::string CShaderParameterVector3::Type = "vec3"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h deleted file mode 100644 index 536bffc..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector3.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" - -namespace WallpaperEngine::Render::Shaders::Parameters -{ - class CShaderParameterVector3 : public CShaderParameter - { - public: - CShaderParameterVector3 (const irr::core::vector3df& defaultValue); - - const int getSize () const override; - - void setValue (irr::core::vector3df value); - - static const std::string Type; - - private: - irr::core::vector3df m_defaultValue; - irr::core::vector3df m_value; - }; -} diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp deleted file mode 100644 index de624aa..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "CShaderParameterVector4.h" - -using namespace WallpaperEngine::Render::Shaders::Parameters; - -CShaderParameterVector4::CShaderParameterVector4 (const irr::core::vector3df& defaultValue) : - m_defaultValue (defaultValue), - m_value (irr::core::vector3df ()), - CShaderParameter (&this->m_defaultValue, nullptr, Type) -{ - -} - -void CShaderParameterVector4::setValue (irr::core::vector3df value) -{ - this->m_value = value; - CShaderParameter::setValue (&this->m_value); -} - -const int CShaderParameterVector4::getSize () const -{ - return 4; -} - -const std::string CShaderParameterVector4::Type = "vec4"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h b/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h deleted file mode 100644 index e98eb9f..0000000 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterVector4.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include "WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h" - -namespace WallpaperEngine::Render::Shaders::Parameters -{ - class CShaderParameterVector4 : public CShaderParameter - { - public: - CShaderParameterVector4 (const irr::core::vector3df& defaultValue); - - const int getSize () const override; - - void setValue (irr::core::vector3df value); - - static const std::string Type; - - private: - irr::core::vector3df m_defaultValue; - irr::core::vector3df m_value; - }; -} diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp new file mode 100644 index 0000000..a6782af --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp @@ -0,0 +1,46 @@ +#include "CShaderVariable.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariable::CShaderVariable (void* defaultValue, void* value, std::string type) : + m_defaultValue (defaultValue), + m_value (value), + m_type (std::move(type)) +{ + +} + +const void* CShaderVariable::getValue () const +{ + if (this->m_value) + return this->m_value; + + return this->m_defaultValue; +} + +void CShaderVariable::setValue (void* value) +{ + this->m_value = value; +} + +const std::string& CShaderVariable::getIdentifierName () const +{ + return this->m_identifierName; +} + +const std::string& CShaderVariable::getName () const +{ + return this->m_name; +} + +void CShaderVariable::setIdentifierName (std::string identifierName) +{ + this->m_identifierName = std::move(identifierName); +} + +void CShaderVariable::setName (std::string name) +{ + this->m_name = std::move(name); +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h similarity index 83% rename from src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h rename to src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h index 49e8a3a..a100936 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameter.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h @@ -2,12 +2,12 @@ #include -namespace WallpaperEngine::Render::Shaders::Parameters +namespace WallpaperEngine::Render::Shaders::Variables { - class CShaderParameter + class CShaderVariable { public: - CShaderParameter (void* defaultValue, void* value, std::string type); + CShaderVariable (void* defaultValue, void* value, std::string type); template const T* as () const { assert (is ()); return (const T*) this; } template T* as () { assert (is ()); return (T*) this; } diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp new file mode 100644 index 0000000..c719c12 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp @@ -0,0 +1,34 @@ +#include "CShaderVariableFloat.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariableFloat::CShaderVariableFloat(irr::f32 defaultValue) : + m_defaultValue (defaultValue), + m_value (0), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ +} + +CShaderVariableFloat::CShaderVariableFloat(irr::f32 defaultValue, std::string name) : + m_defaultValue (defaultValue), + m_value (0), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ + this->setName (std::move(name)); +} + +void CShaderVariableFloat::setValue (irr::f32 value) +{ + this->m_value = value; + + CShaderVariable::setValue (&this->m_value); +} + +const int CShaderVariableFloat::getSize () const +{ + return 1; +} + +const std::string CShaderVariableFloat::Type = "float"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h similarity index 50% rename from src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h rename to src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h index 8bfc3fe..38fb62c 100644 --- a/src/WallpaperEngine/Render/Shaders/Parameters/CShaderParameterFloat.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h @@ -1,15 +1,16 @@ #pragma once -#include "CShaderParameter.h" +#include "CShaderVariable.h" #include -namespace WallpaperEngine::Render::Shaders::Parameters +namespace WallpaperEngine::Render::Shaders::Variables { - class CShaderParameterFloat : public CShaderParameter + class CShaderVariableFloat : public CShaderVariable { public: - CShaderParameterFloat (irr::f32 defaultValue); + explicit CShaderVariableFloat (irr::f32 defaultValue); + CShaderVariableFloat (irr::f32 defaultValue, std::string name); const int getSize () const override; diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp new file mode 100644 index 0000000..4a7bd7c --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp @@ -0,0 +1,26 @@ +#include "CShaderVariableFloatPointer.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + + +CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size) : + m_size (size), + CShaderVariable (value, nullptr, Type) +{ +} + +CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size, std::string name) : + m_size (size), + CShaderVariable (value, nullptr, Type) +{ + this->setName (std::move(name)); +} + +const int CShaderVariableFloatPointer::getSize () const +{ + return this->m_size; +} + +const std::string CShaderVariableFloatPointer::Type = "pointer"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h new file mode 100644 index 0000000..30428fe --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h @@ -0,0 +1,21 @@ +#pragma once + +#include "CShaderVariable.h" + +#include + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableFloatPointer : public CShaderVariable + { + public: + CShaderVariableFloatPointer (irr::f32* value, int size); + CShaderVariableFloatPointer (irr::f32* value, int size, std::string name); + + const int getSize () const override; + + static const std::string Type; + private: + int m_size; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.cpp new file mode 100644 index 0000000..95d5796 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.cpp @@ -0,0 +1,33 @@ +#include "CShaderVariableInteger.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariableInteger::CShaderVariableInteger(irr::s32 defaultValue) : + m_defaultValue (defaultValue), + m_value (0), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ +} + +CShaderVariableInteger::CShaderVariableInteger(irr::s32 defaultValue, std::string name) : + m_defaultValue (defaultValue), + m_value (0), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ + this->setName (std::move(name)); +} + +void CShaderVariableInteger::setValue (irr::s32 value) +{ + this->m_value = value; + CShaderVariable::setValue (&this->m_value); +} + +const int CShaderVariableInteger::getSize () const +{ + return 1; +} + +const std::string CShaderVariableInteger::Type = "int"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h new file mode 100644 index 0000000..71c6960 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h @@ -0,0 +1,25 @@ +#pragma once + +#include "CShaderVariable.h" + +#include + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableInteger : public CShaderVariable + { + public: + explicit CShaderVariableInteger (irr::s32 defaultValue); + CShaderVariableInteger (irr::s32 defaultValue, std::string name); + + const int getSize () const override; + + static const std::string Type; + + void setValue (irr::s32 value); + + private: + irr::s32 m_defaultValue; + irr::s32 m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.cpp new file mode 100644 index 0000000..ccd8bc4 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.cpp @@ -0,0 +1,35 @@ +#include "CShaderVariableVector2.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariableVector2::CShaderVariableVector2 (const irr::core::vector2df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector2df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ +} + +CShaderVariableVector2::CShaderVariableVector2 (const irr::core::vector2df& defaultValue, std::string name) : + m_defaultValue (defaultValue), + m_value (irr::core::vector2df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ + this->setName (std::move(name)); +} + + +void CShaderVariableVector2::setValue (const irr::core::vector2df& value) +{ + this->m_value = value; + + CShaderVariable::setValue (&this->m_value); +} + +const int CShaderVariableVector2::getSize () const +{ + return 2; +} + +const std::string CShaderVariableVector2::Type = "vec2"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h new file mode 100644 index 0000000..d2ee5bd --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableVector2 : public CShaderVariable + { + public: + explicit CShaderVariableVector2 (const irr::core::vector2df& defaultValue); + CShaderVariableVector2 (const irr::core::vector2df& defaultValue, std::string name); + + const int getSize () const override; + + void setValue (const irr::core::vector2df& value); + + static const std::string Type; + + private: + irr::core::vector2df m_defaultValue; + irr::core::vector2df m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp new file mode 100644 index 0000000..2ac1441 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp @@ -0,0 +1,31 @@ +#include "CShaderVariableVector3.h" + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariableVector3::CShaderVariableVector3 (const irr::core::vector3df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ +} + +CShaderVariableVector3::CShaderVariableVector3 (const irr::core::vector3df& defaultValue, std::string name) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ + this->setName (name); +} + +void CShaderVariableVector3::setValue (const irr::core::vector3df& value) +{ + this->m_value = value; + CShaderVariable::setValue (&this->m_value); +} + +const int CShaderVariableVector3::getSize () const +{ + return 3; +} + +const std::string CShaderVariableVector3::Type = "vec3"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h new file mode 100644 index 0000000..e62f31d --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableVector3 : public CShaderVariable + { + public: + explicit CShaderVariableVector3 (const irr::core::vector3df& defaultValue); + CShaderVariableVector3 (const irr::core::vector3df& defaultValue, std::string name); + + const int getSize () const override; + + void setValue (const irr::core::vector3df& value); + + static const std::string Type; + + private: + irr::core::vector3df m_defaultValue; + irr::core::vector3df m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp new file mode 100644 index 0000000..7604c81 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp @@ -0,0 +1,33 @@ +#include "CShaderVariableVector4.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + +CShaderVariableVector4::CShaderVariableVector4 (const irr::core::vector3df& defaultValue) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ +} + +CShaderVariableVector4::CShaderVariableVector4 (const irr::core::vector3df& defaultValue, std::string name) : + m_defaultValue (defaultValue), + m_value (irr::core::vector3df ()), + CShaderVariable (&this->m_defaultValue, nullptr, Type) +{ + this->setName (std::move(name)); +} + +void CShaderVariableVector4::setValue (const irr::core::vector3df& value) +{ + this->m_value = value; + CShaderVariable::setValue (&this->m_value); +} + +const int CShaderVariableVector4::getSize () const +{ + return 4; +} + +const std::string CShaderVariableVector4::Type = "vec4"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h new file mode 100644 index 0000000..f6db61b --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableVector4 : public CShaderVariable + { + public: + explicit CShaderVariableVector4 (const irr::core::vector3df& defaultValue); + CShaderVariableVector4 (const irr::core::vector3df& defaultValue, std::string name); + + const int getSize () const override; + + void setValue (const irr::core::vector3df& value); + + static const std::string Type; + + private: + irr::core::vector3df m_defaultValue; + irr::core::vector3df m_value; + }; +} From dc36adb200c4bd0ba44930a37d80743ae446a070 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 13:54:28 +0200 Subject: [PATCH 11/31] + added mouse input handling and mouse position variable to shaders + added vector2 pointer class for shader parameters Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 4 ++++ src/WallpaperEngine/Irrlicht/CContext.cpp | 16 ++++++++++--- src/WallpaperEngine/Irrlicht/CContext.h | 4 ++++ .../Irrlicht/CEventReceiver.cpp | 20 ++++++++++++++++ src/WallpaperEngine/Irrlicht/CEventReceiver.h | 18 ++++++++++++++ src/WallpaperEngine/Render/Objects/CImage.cpp | 16 ++++++------- .../Render/Shaders/Compiler.cpp | 2 +- .../Variables/CShaderVariableFloatPointer.cpp | 10 ++++---- .../Variables/CShaderVariableFloatPointer.h | 5 ++-- .../CShaderVariableVector2Pointer.cpp | 24 +++++++++++++++++++ .../Variables/CShaderVariableVector2Pointer.h | 19 +++++++++++++++ 11 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 src/WallpaperEngine/Irrlicht/CEventReceiver.cpp create mode 100644 src/WallpaperEngine/Irrlicht/CEventReceiver.h create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp create mode 100644 src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f8ac87..377b167 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,8 @@ add_executable( src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h + src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -59,6 +61,8 @@ add_executable( src/WallpaperEngine/FileSystem/FileSystem.cpp src/WallpaperEngine/FileSystem/FileSystem.h + src/WallpaperEngine/Irrlicht/CEventReceiver.h + src/WallpaperEngine/Irrlicht/CEventReceiver.cpp src/WallpaperEngine/Irrlicht/CContext.h src/WallpaperEngine/Irrlicht/CContext.cpp src/WallpaperEngine/Irrlicht/CImageLoaderTEX.h diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index a482a12..ad4713f 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -9,6 +9,7 @@ #include "WallpaperEngine/Irrlicht/CPkgReader.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h" #include "CContext.h" @@ -30,16 +31,19 @@ void CContext::initializeContext () { irr::SIrrlichtCreationParameters irrlichtCreationParameters; + // initialize event receiver first + this->m_eventReceiver = new CEventReceiver (); + // prepare basic configuration for irrlicht irrlichtCreationParameters.AntiAlias = 8; irrlichtCreationParameters.Bits = 16; // _irr_params.DeviceType = Irrlicht::EIDT_X11; irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL; irrlichtCreationParameters.Doublebuffer = false; - irrlichtCreationParameters.EventReceiver = nullptr; + irrlichtCreationParameters.EventReceiver = this->m_eventReceiver; irrlichtCreationParameters.Fullscreen = false; irrlichtCreationParameters.HandleSRGB = false; - irrlichtCreationParameters.IgnoreInput = true; + irrlichtCreationParameters.IgnoreInput = false; irrlichtCreationParameters.Stencilbuffer = true; irrlichtCreationParameters.UsePerformanceTimer = false; irrlichtCreationParameters.Vsync = false; @@ -90,7 +94,11 @@ void CContext::initializeContext () ); // register time shader variable this->insertShaderVariable ( - new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, 1, "g_Time") + new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, "g_Time") + ); + // register normalized uv position for mouse + this->insertShaderVariable ( + new Render::Shaders::Variables::CShaderVariableVector2Pointer (&this->m_pointerPosition, "g_PointerPosition") ); } @@ -157,6 +165,8 @@ void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCr void CContext::renderFrame (Render::CScene* scene) { this->m_time = this->getDevice ()->getTimer ()->getTime () / 1000.0f; + this->m_pointerPosition.X = this->m_eventReceiver->getPosition ().X / (irr::f32) this->getDevice ()->getVideoDriver ()->getScreenSize ().Width; + this->m_pointerPosition.Y = this->m_eventReceiver->getPosition ().Y / (irr::f32) this->getDevice ()->getVideoDriver ()->getScreenSize ().Height; if (this->m_viewports.empty () == true) { diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index 6a00f99..cf11321 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -9,6 +9,8 @@ #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" +#include "CEventReceiver.h" + namespace WallpaperEngine::Render { class CScene; @@ -40,10 +42,12 @@ namespace WallpaperEngine::Irrlicht irr::io::path resolveFile (const irr::io::path& file); irr::IrrlichtDevice* m_device; + CEventReceiver* m_eventReceiver; std::vector m_globalShaderVariables; irr::f32 m_time; + irr::core::vector2df m_pointerPosition; std::vector m_screens; std::vector m_viewports; diff --git a/src/WallpaperEngine/Irrlicht/CEventReceiver.cpp b/src/WallpaperEngine/Irrlicht/CEventReceiver.cpp new file mode 100644 index 0000000..6b03212 --- /dev/null +++ b/src/WallpaperEngine/Irrlicht/CEventReceiver.cpp @@ -0,0 +1,20 @@ +#include "CEventReceiver.h" + +using namespace WallpaperEngine::Irrlicht; + +bool CEventReceiver::OnEvent(const irr::SEvent &event) +{ + if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == irr::EMIE_MOUSE_MOVED) + { + this->m_position.X = event.MouseInput.X; + this->m_position.Y = event.MouseInput.Y; + return true; + } + + return false; +} + +const irr::core::position2di& CEventReceiver::getPosition () const +{ + return this->m_position; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Irrlicht/CEventReceiver.h b/src/WallpaperEngine/Irrlicht/CEventReceiver.h new file mode 100644 index 0000000..8f0a6a8 --- /dev/null +++ b/src/WallpaperEngine/Irrlicht/CEventReceiver.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace WallpaperEngine::Irrlicht +{ + class CEventReceiver : public irr::IEventReceiver + { + public: + // This is the one method that we have to implement + bool OnEvent(const irr::SEvent& event) override; + + const irr::core::position2di& getPosition () const; + + private: + irr::core::position2di m_position; + }; +} diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 2eef681..61cec20 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -236,10 +236,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setVertexShaderConstant ( (*cur)->getName ().c_str (), @@ -263,10 +263,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in ); } else if ( - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true || - (*cur)->is () == true) + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) { services->setPixelShaderConstant ( (*cur)->getName ().c_str (), diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index c899dc4..f410148 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -516,7 +516,7 @@ namespace WallpaperEngine::Render::Shaders if (type == "vec4") { parameter = new Variables::CShaderVariableVector4 ( - WallpaperEngine::Core::ato3vf (*defvalue) + WallpaperEngine::Core::ato3vf (*defvalue) ); } else if (type == "vec3") diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp index 4a7bd7c..919f05b 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp @@ -5,14 +5,12 @@ using namespace WallpaperEngine::Render::Shaders::Variables; -CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size) : - m_size (size), +CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value) : CShaderVariable (value, nullptr, Type) { } -CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size, std::string name) : - m_size (size), +CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, std::string name) : CShaderVariable (value, nullptr, Type) { this->setName (std::move(name)); @@ -20,7 +18,7 @@ CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int si const int CShaderVariableFloatPointer::getSize () const { - return this->m_size; + return 1; } -const std::string CShaderVariableFloatPointer::Type = "pointer"; \ No newline at end of file +const std::string CShaderVariableFloatPointer::Type = "pointer_float"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h index 30428fe..f4654cd 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h @@ -9,13 +9,12 @@ namespace WallpaperEngine::Render::Shaders::Variables class CShaderVariableFloatPointer : public CShaderVariable { public: - CShaderVariableFloatPointer (irr::f32* value, int size); - CShaderVariableFloatPointer (irr::f32* value, int size, std::string name); + explicit CShaderVariableFloatPointer (irr::f32* value); + CShaderVariableFloatPointer (irr::f32* value, std::string name); const int getSize () const override; static const std::string Type; private: - int m_size; }; } diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp new file mode 100644 index 0000000..1bcf0f0 --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp @@ -0,0 +1,24 @@ +#include "CShaderVariableVector2Pointer.h" + +#include + +using namespace WallpaperEngine::Render::Shaders::Variables; + + +CShaderVariableVector2Pointer::CShaderVariableVector2Pointer(irr::core::vector2df* value) : + CShaderVariable (value, nullptr, Type) +{ +} + +CShaderVariableVector2Pointer::CShaderVariableVector2Pointer(irr::core::vector2df* value, std::string name) : + CShaderVariable (value, nullptr, Type) +{ + this->setName (std::move(name)); +} + +const int CShaderVariableVector2Pointer::getSize () const +{ + return 2; +} + +const std::string CShaderVariableVector2Pointer::Type = "pointer_vector2"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h new file mode 100644 index 0000000..7123c5b --- /dev/null +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h @@ -0,0 +1,19 @@ +#pragma once + +#include "CShaderVariable.h" + +#include + +namespace WallpaperEngine::Render::Shaders::Variables +{ + class CShaderVariableVector2Pointer : public CShaderVariable + { + public: + CShaderVariableVector2Pointer (irr::core::vector2df* value); + CShaderVariableVector2Pointer (irr::core::vector2df* value, std::string name); + + const int getSize () const override; + + static const std::string Type; + }; +} From 4358e7c173375c75bb527618040b96eb1f62fb6d Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 14:54:49 +0200 Subject: [PATCH 12/31] - removed shader string constants, shaders do not have any, for future reference, these might be vectors or colors + shader constants now should be correctly applied as values for variables whenever possible Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 2 - main.cpp | 3 -- src/WallpaperEngine/Core/Objects/CEffect.cpp | 3 +- .../Objects/Effects/CShaderConstantFloat.h | 3 +- .../Objects/Effects/CShaderConstantInteger.h | 3 +- .../Objects/Effects/CShaderConstantString.cpp | 19 ------- .../Objects/Effects/CShaderConstantString.h | 22 -------- src/WallpaperEngine/Render/Objects/CImage.cpp | 52 +++++++++++++++++-- src/WallpaperEngine/Render/Objects/CImage.h | 2 +- 9 files changed, 52 insertions(+), 57 deletions(-) delete mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp delete mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 377b167..1381320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,8 +102,6 @@ add_executable( src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp diff --git a/main.cpp b/main.cpp index 56d1578..8a76317 100644 --- a/main.cpp +++ b/main.cpp @@ -4,8 +4,6 @@ #include #include -#include "WallpaperEngine/Render/Shaders/Compiler.h" - #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Irrlicht/CContext.h" #include "WallpaperEngine/Render/CScene.h" @@ -132,7 +130,6 @@ int main (int argc, char* argv[]) irr::io::path wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ()); irr::io::path project_path = wallpaper_path + "project.json"; - irr::io::path scene_path; if (mode == RUN_MODE_PACKAGE) { diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 346947e..74703b6 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -5,7 +5,6 @@ #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/CShaderConstantString.h" #include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h" #include "WallpaperEngine/FileSystem/FileSystem.h" @@ -137,7 +136,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) } else if ((*constantCur).is_string () == true) { - constant = new Effects::CShaderConstantString ((*constantCur).get ()); + throw std::runtime_error ("String constants not supported yet"); } else { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h index 992a19f..625785a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h @@ -14,9 +14,8 @@ namespace WallpaperEngine::Core::Objects::Effects irr::f32* getValue (); + static const std::string Type; protected: irr::f32 m_value; - - static const std::string Type; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h index d49dcd6..eb6d1d2 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h @@ -14,9 +14,8 @@ namespace WallpaperEngine::Core::Objects::Effects irr::u32* getValue (); + static const std::string Type; protected: irr::u32 m_value; - - static const std::string Type; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp deleted file mode 100644 index 431eccf..0000000 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "CShaderConstantString.h" - -#include - -using namespace WallpaperEngine::Core::Objects::Effects; - - -CShaderConstantString::CShaderConstantString (std::string value) : - CShaderConstant (Type), - m_value (std::move(value)) -{ -} - -std::string* CShaderConstantString::getValue () -{ - return &this->m_value; -} - -const std::string CShaderConstantString::Type = "string"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h deleted file mode 100644 index d50bf9c..0000000 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantString.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "CShaderConstant.h" - -#include -#include - -namespace WallpaperEngine::Core::Objects::Effects -{ - class CShaderConstantString : public CShaderConstant - { - public: - CShaderConstantString (std::string value); - - std::string* getValue (); - - protected: - std::string m_value; - - static const std::string Type; - }; -} diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 61cec20..f500000 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -7,10 +7,17 @@ #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" - #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h" + +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h" +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h" using namespace WallpaperEngine; + +using namespace WallpaperEngine::Core::Objects::Effects; + using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Shaders::Variables; @@ -94,7 +101,7 @@ void CImage::generateMaterial () for (; cur != end; cur++) { - this->generatePass (*cur); + this->generatePass (*cur, nullptr); } auto effectCur = this->m_image->getEffects ().begin (); @@ -112,13 +119,13 @@ void CImage::generateMaterial () for (; cur != end; cur++) { - this->generatePass (*cur); + this->generatePass (*cur, *effectCur); } } } } -void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) +void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Core::Objects::CEffect* effect) { std::vector* textures = pass->getTextures (); irr::video::SMaterial material; @@ -166,6 +173,43 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, this->m_passes, irr::video::EGSL_DEFAULT ); + if (effect) + { + // find variables in the shaders and set the value with the constants if possible + auto cur = effect->getConstants ().begin (); + auto end = effect->getConstants ().end (); + + for (; cur != end; cur ++) + { + CShaderVariable* vertexVar = vertexShader->findParameter ((*cur).first); + CShaderVariable* pixelVar = pixelShader->findParameter ((*cur).first); + + if (pixelVar) + { + if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + } + + if (vertexVar) + { + if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + } + } + } + // TODO: TAKE INTO ACCOUNT BLENDING AND CULLING METHODS FROM THE JSON material.setFlag (irr::video::EMF_LIGHTING, false); material.setFlag (irr::video::EMF_BLEND_OPERATION, true); diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index 0be5003..4ac4a8b 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -26,7 +26,7 @@ namespace WallpaperEngine::Render::Objects private: void generateMaterial (); - void generatePass (Core::Objects::Images::Materials::CPassess* pass); + void generatePass (Core::Objects::Images::Materials::CPassess* pass, Core::Objects::CEffect* effect); irr::video::S3DVertex m_vertex [4]; irr::u32 m_passes; From 318a99d5ca132a800c9a42cc66c718543f98c0f2 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 15:01:59 +0200 Subject: [PATCH 13/31] + added vector3 support for shader constants (looks like strings were vector3 after all) Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 2 ++ src/WallpaperEngine/Core/Objects/CEffect.cpp | 5 ++++- .../Effects/CShaderConstantVector3.cpp | 17 +++++++++++++++ .../Objects/Effects/CShaderConstantVector3.h | 21 +++++++++++++++++++ src/WallpaperEngine/Render/Objects/CImage.cpp | 9 ++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1381320..41446e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,8 @@ add_executable( src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h + src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 74703b6..553f240 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -2,10 +2,13 @@ #include +#include "WallpaperEngine/Core/Core.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/FileSystem/FileSystem.h" using namespace WallpaperEngine; @@ -136,7 +139,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) } else if ((*constantCur).is_string () == true) { - throw std::runtime_error ("String constants not supported yet"); + constant = new Effects::CShaderConstantVector3 (WallpaperEngine::Core::ato3vf (*constantCur)); } else { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp new file mode 100644 index 0000000..d1fd1cb --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp @@ -0,0 +1,17 @@ +#include "CShaderConstantVector3.h" + +using namespace WallpaperEngine::Core::Objects::Effects; + + +CShaderConstantVector3::CShaderConstantVector3 (irr::core::vector3df value) : + CShaderConstant (Type), + m_value (value) +{ +} + +irr::core::vector3df* CShaderConstantVector3::getValue () +{ + return &this->m_value; +} + +const std::string CShaderConstantVector3::Type = "vector3"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h new file mode 100644 index 0000000..faf1bdc --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h @@ -0,0 +1,21 @@ +#pragma once + +#include "CShaderConstant.h" + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + class CShaderConstantVector3 : public CShaderConstant + { + public: + CShaderConstantVector3 (irr::core::vector3df value); + + irr::core::vector3df* getValue (); + + static const std::string Type; + protected: + irr::core::vector3df m_value; + }; +} diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index f500000..0647482 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -13,6 +13,7 @@ #include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" #include "WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h" #include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h" +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h" using namespace WallpaperEngine; @@ -194,6 +195,10 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Cor { pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); } + else if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } } if (vertexVar) @@ -206,6 +211,10 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Cor { vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } } } } From e32bc4d6f181309b01b588cea22fef7ce9db8689 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 10 Sep 2019 15:28:59 +0200 Subject: [PATCH 14/31] ~ effect parsing now takes into account combos and assigns the shader constants to the proper shader pass Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Core/Objects/CEffect.cpp | 128 +++++++++--------- src/WallpaperEngine/Core/Objects/CEffect.h | 3 - .../Objects/Images/Materials/CPassess.cpp | 11 ++ .../Core/Objects/Images/Materials/CPassess.h | 8 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 67 +++++---- 5 files changed, 116 insertions(+), 101 deletions(-) diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 553f240..60ddbd8 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -98,7 +98,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) } effect->insertMaterial ( - Images::CMaterial::fromFile ((*materialfile).get ().c_str ()) + Images::CMaterial::fromFile ((*materialfile).get ().c_str ()) ); } @@ -118,82 +118,96 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) for (int passNumber = 0; cur != end; cur ++, passNumber ++) { auto constants_it = (*cur).find ("constantshadervalues"); - - if (constants_it == (*cur).end ()) - continue; - - 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 ()); - } - else if ((*constantCur).is_number_integer () == true) - { - constant = new Effects::CShaderConstantInteger ((*constantCur).get ()); - } - else if ((*constantCur).is_string () == true) - { - constant = new Effects::CShaderConstantVector3 (WallpaperEngine::Core::ato3vf (*constantCur)); - } - else - { - throw std::runtime_error ("unknown shader constant type"); - } - - effect->insertConstant (constantCur.key (), constant); - } - + auto combos_it = (*cur).find ("combos"); auto textures_it = (*cur).find ("textures"); - if (textures_it == (*cur).end ()) + if (constants_it == (*cur).end () && combos_it == (*cur).end () && textures_it == (*cur).end ()) continue; Images::CMaterial* material = effect->getMaterials ().at (passNumber); + auto passCur = material->getPasses ().begin (); auto passEnd = material->getPasses ().end (); for (; passCur != passEnd; passCur ++) { - auto texturesCur = (*textures_it).begin (); - auto texturesEnd = (*textures_it).end (); - - for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++) + if (textures_it != (*cur).end ()) { - std::string texture; + auto texturesCur = (*textures_it).begin (); + auto texturesEnd = (*textures_it).end (); - if ((*texturesCur).is_null () == true) + for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++) { - if (object->is() == false) + std::string texture; + + if ((*texturesCur).is_null () == true) { - throw std::runtime_error ("unexpected null texture for non-image object"); + if (object->is () == false) + { + throw std::runtime_error ("unexpected null texture for non-image object"); + } + + CImage* image = object->as (); + + texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ()->begin ()); + } + else + { + texture = *texturesCur; } - CImage* image = object->as(); + std::vector* passTextures = (*passCur)->getTextures (); - texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ()->begin ()); + if (textureNumber < passTextures->size ()) + passTextures->at (textureNumber) = texture; + else + passTextures->push_back (texture); + + textureNumber ++; } - else + } + + if (combos_it != (*cur).end ()) + { + auto comboCur = (*combos_it).begin (); + auto comboEnd = (*combos_it).end (); + + for (; comboCur != comboEnd; comboCur ++) { - texture = *texturesCur; + (*passCur)->insertCombo (comboCur.key (), *comboCur); } + } - std::vector* passTextures = (*passCur)->getTextures (); + if (constants_it != (*cur).end ()) + { + auto constantCur = (*constants_it).begin (); + auto constantEnd = (*constants_it).end (); - if (textureNumber < passTextures->size ()) - passTextures->at (textureNumber) = texture; - else - passTextures->push_back (texture); + for (; constantCur != constantEnd; constantCur ++) + { + Effects::CShaderConstant* constant = nullptr; - textureNumber ++; + if ((*constantCur).is_number_float () == true) + { + constant = new Effects::CShaderConstantFloat ((*constantCur).get ()); + } + else if ((*constantCur).is_number_integer () == true) + { + constant = new Effects::CShaderConstantInteger ((*constantCur).get ()); + } + 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); + } } } - } } @@ -210,11 +224,6 @@ const std::vector& CEffect::getMaterials () const return this->m_materials; } -const std::map& CEffect::getConstants () const -{ - return this->m_constants; -} - void CEffect::insertDependency (const std::string& dep) { this->m_dependencies.push_back (dep); @@ -223,9 +232,4 @@ void CEffect::insertDependency (const std::string& dep) void CEffect::insertMaterial (Images::CMaterial* material) { this->m_materials.push_back (material); -} - -void CEffect::insertConstant (const std::string& name, Effects::CShaderConstant* constant) -{ - this->m_constants.insert (std::pair (name, constant)); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index ab48862..ac84553 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -31,11 +31,9 @@ namespace WallpaperEngine::Core::Objects const std::vector& getDependencies () const; const std::vector& getMaterials () const; - const std::map& getConstants () const; protected: void insertDependency (const std::string& dep); void insertMaterial (Images::CMaterial* material); - void insertConstant (const std::string& name, Effects::CShaderConstant* constant); private: std::string m_name; std::string m_description; @@ -45,6 +43,5 @@ namespace WallpaperEngine::Core::Objects std::vector m_dependencies; std::vector m_materials; - std::map m_constants; }; } diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp index 8a97703..2ed0daa 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp @@ -1,5 +1,6 @@ #include "CPassess.h" +using namespace WallpaperEngine::Core::Objects::Effects; using namespace WallpaperEngine::Core::Objects::Images::Materials; CPassess::CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) : @@ -119,6 +120,11 @@ std::vector* CPassess::getTextures () return &this->m_textures; } +const std::map& CPassess::getConstants () const +{ + return this->m_constants; +} + const std::map& CPassess::getCombos () const { return this->m_combos; @@ -147,4 +153,9 @@ const std::string& CPassess::getDepthTest () const const std::string& CPassess::getDepthWrite ()const { return this->m_depthwrite; +} + +void CPassess::insertConstant (const std::string& name, CShaderConstant* constant) +{ + this->m_constants.insert (std::pair (name, constant)); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h index 1d1e3d5..a6d9eb4 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h @@ -2,6 +2,8 @@ #include +#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" + namespace WallpaperEngine::Core::Objects::Images::Materials { using json = nlohmann::json; @@ -12,6 +14,7 @@ namespace WallpaperEngine::Core::Objects::Images::Materials static CPassess* fromJSON (json data); std::vector* getTextures (); + const std::map& getConstants () const; const std::map& getCombos () const; const std::string& getShader () const; @@ -20,11 +23,13 @@ namespace WallpaperEngine::Core::Objects::Images::Materials const std::string& getDepthTest () const; const std::string& getDepthWrite () const; + void insertCombo (const std::string& name, int value); + void insertConstant (const std::string& name, Effects::CShaderConstant* constant); + protected: CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); void insertTexture (const std::string& texture); - void insertCombo (const std::string& name, int value); private: std::string m_blending; @@ -34,5 +39,6 @@ namespace WallpaperEngine::Core::Objects::Images::Materials std::string m_shader; std::vector m_textures; std::map m_combos; + std::map m_constants; }; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 0647482..3076af9 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -174,47 +174,44 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Cor this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, this->m_passes, irr::video::EGSL_DEFAULT ); - if (effect) + // find variables in the shaders and set the value with the constants if possible + auto cur = pass->getConstants ().begin (); + auto end = pass->getConstants ().end (); + + for (; cur != end; cur ++) { - // find variables in the shaders and set the value with the constants if possible - auto cur = effect->getConstants ().begin (); - auto end = effect->getConstants ().end (); + CShaderVariable* vertexVar = vertexShader->findParameter ((*cur).first); + CShaderVariable* pixelVar = pixelShader->findParameter ((*cur).first); - for (; cur != end; cur ++) + if (pixelVar) { - CShaderVariable* vertexVar = vertexShader->findParameter ((*cur).first); - CShaderVariable* pixelVar = pixelShader->findParameter ((*cur).first); - - if (pixelVar) + if (pixelVar->is () && (*cur).second->is ()) { - if (pixelVar->is () && (*cur).second->is ()) - { - pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } - else if (pixelVar->is () && (*cur).second->is ()) - { - pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } - else if (pixelVar->is () && (*cur).second->is ()) - { - pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); } - - if (vertexVar) + else if (pixelVar->is () && (*cur).second->is ()) { - if (vertexVar->is () && (*cur).second->is ()) - { - vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } - else if (vertexVar->is () && (*cur).second->is ()) - { - vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } - else if (vertexVar->is () && (*cur).second->is ()) - { - vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); - } + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + } + + if (vertexVar) + { + if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); } } } From 5e94fc7bab688dde8149cfbf545a6130101ee9ee Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 11 Sep 2019 09:15:50 +0200 Subject: [PATCH 15/31] + added parsing of dependencies for objects + added fbos parsing from effect files ~ cleaned up effect parsing code ~ support for texture target parsing in materials for texture render targets ~ changed way of modifying textures from passes to a more abstracted way ~ moved shader constants to it's own namespace Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 19 +- src/WallpaperEngine/Core/CObject.cpp | 21 ++ src/WallpaperEngine/Core/CObject.h | 3 + src/WallpaperEngine/Core/Objects/CEffect.cpp | 204 ++++++++++++------ src/WallpaperEngine/Core/Objects/CEffect.h | 15 +- .../Core/Objects/Effects/CFBO.cpp | 40 ++++ .../Core/Objects/Effects/CFBO.h | 28 +++ .../{ => Constants}/CShaderConstant.cpp | 2 +- .../Effects/{ => Constants}/CShaderConstant.h | 2 +- .../{ => Constants}/CShaderConstantFloat.cpp | 2 +- .../{ => Constants}/CShaderConstantFloat.h | 2 +- .../CShaderConstantInteger.cpp | 2 +- .../{ => Constants}/CShaderConstantInteger.h | 2 +- .../CShaderConstantVector3.cpp | 2 +- .../{ => Constants}/CShaderConstantVector3.h | 2 +- .../Core/Objects/Images/CMaterial.cpp | 36 +++- .../Core/Objects/Images/CMaterial.h | 9 +- .../Objects/Images/Materials/CPassess.cpp | 11 +- .../Core/Objects/Images/Materials/CPassess.h | 17 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 16 +- 20 files changed, 333 insertions(+), 102 deletions(-) create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CFBO.h rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstant.cpp (63%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstant.h (87%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantFloat.cpp (80%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantFloat.h (84%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantInteger.cpp (81%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantInteger.h (84%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantVector3.cpp (82%) rename src/WallpaperEngine/Core/Objects/Effects/{ => Constants}/CShaderConstantVector3.h (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41446e9..df36a5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,14 +98,17 @@ add_executable( src/WallpaperEngine/Core/Objects/CParticle.cpp src/WallpaperEngine/Core/Objects/CParticle.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h - src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp + src/WallpaperEngine/Core/Objects/Effects/CFBO.h + src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp + + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h + src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index b1ea1cf..6cf6f88 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -36,6 +36,7 @@ CObject* CObject::fromJSON (json data) auto angles_it = data.find ("angles"); auto name_it = data.find ("name"); auto effects_it = data.find ("effects"); + auto dependencies_it = data.find ("dependencies"); bool visible = true; @@ -128,6 +129,17 @@ CObject* CObject::fromJSON (json data) } } + if (dependencies_it != data.end () && (*dependencies_it).is_array () == true) + { + auto cur = (*dependencies_it).begin (); + auto end = (*dependencies_it).end (); + + for (; cur != end; cur ++) + { + object->insertDependency (*cur); + } + } + return object; } @@ -156,6 +168,11 @@ const std::vector& CObject::getEffects () const return this->m_effects; } +const std::vector& CObject::getDependencies () const +{ + return this->m_dependencies; +} + bool CObject::isVisible () { return this->m_visible; @@ -169,4 +186,8 @@ const int CObject::getId () const void CObject::insertEffect (Objects::CEffect* effect) { this->m_effects.push_back (effect); +} +void CObject::insertDependency (irr::u32 dependency) +{ + this->m_dependencies.push_back (dependency); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index 9b1fa3f..67fb78a 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -25,6 +25,7 @@ namespace WallpaperEngine::Core template bool is () { return this->m_type == T::Type; } const std::vector& getEffects () const; + const std::vector& getDependencies () const; const int getId () const; const irr::core::vector3df& getOrigin () const; @@ -45,6 +46,7 @@ namespace WallpaperEngine::Core ); void insertEffect (Objects::CEffect* effect); + void insertDependency (irr::u32 dependency); private: std::string m_type; @@ -56,5 +58,6 @@ namespace WallpaperEngine::Core irr::core::vector3df m_angles; std::vector m_effects; + std::vector m_dependencies; }; }; diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 60ddbd8..7c8b76f 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -4,10 +4,10 @@ #include "WallpaperEngine/Core/Core.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" @@ -46,6 +46,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) auto preview_it = content.find ("preview"); auto passes_it = content.find ("passes"); auto dependencies_it = content.find ("dependencies"); + auto fbos_it = content.find ("fbos"); if (name_it == content.end ()) { @@ -85,35 +86,18 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) object ); - auto cur = (*passes_it).begin (); - auto end = (*passes_it).end (); + CEffect::materialsFromJSON (passes_it, effect); + CEffect::dependencyFromJSON (dependencies_it, effect); - for (; cur != end; cur ++) + if (fbos_it != content.end ()) { - 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 ().c_str ()) - ); - } - - cur = (*dependencies_it).begin (); - end = (*dependencies_it).end (); - - for (; cur != end; cur ++) - { - effect->insertDependency (*cur); + CEffect::fbosFromJSON (fbos_it, effect); } 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 ++) { @@ -149,19 +133,19 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) CImage* image = object->as (); - texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ()->begin ()); + texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ()); } else { texture = *texturesCur; } - std::vector* passTextures = (*passCur)->getTextures (); + std::vector passTextures = (*passCur)->getTextures (); - if (textureNumber < passTextures->size ()) - passTextures->at (textureNumber) = texture; + if (textureNumber < passTextures.size ()) + (*passCur)->setTexture (textureNumber, texture); else - passTextures->push_back (texture); + (*passCur)->insertTexture (texture); textureNumber ++; } @@ -169,43 +153,12 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) 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 ()) { - 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 ()); - } - else if ((*constantCur).is_number_integer () == true) - { - constant = new Effects::CShaderConstantInteger ((*constantCur).get ()); - } - 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; } +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 ()); + } + else if ((*cur).is_number_integer () == true) + { + constant = new Effects::Constants::CShaderConstantInteger ((*cur).get ()); + } + 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 ().c_str ()) + ); + } + else + { + effect->insertMaterial ( + Images::CMaterial::fromFile ((*materialfile).get ().c_str (), *target) + ); + } + } +} + const std::vector& CEffect::getDependencies () const { return this->m_dependencies; @@ -224,6 +272,27 @@ const std::vector& CEffect::getMaterials () const return this->m_materials; } +const std::vector& 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) { this->m_dependencies.push_back (dep); @@ -232,4 +301,9 @@ void CEffect::insertDependency (const std::string& dep) void CEffect::insertMaterial (Images::CMaterial* material) { this->m_materials.push_back (material); +} + +void CEffect::insertFBO (Effects::CFBO* fbo) +{ + this->m_fbos.push_back (fbo); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index ac84553..a463068 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -3,7 +3,8 @@ #include #include -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Effects/CFBO.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/CObject.h" #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" @@ -31,9 +32,20 @@ namespace WallpaperEngine::Core::Objects const std::vector& getDependencies () const; const std::vector& getMaterials () const; + const std::vector& getFbos () const; + + Effects::CFBO* findFBO (const std::string& name); protected: + static void constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPassess* pass); + static void combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPassess* pass); + static void fbosFromJSON (json::const_iterator fbos_it, CEffect* effect); + static void dependencyFromJSON (json::const_iterator dependencies_it, CEffect* effect); + static void materialsFromJSON (json::const_iterator passes_it, CEffect* effect); + void insertDependency (const std::string& dep); void insertMaterial (Images::CMaterial* material); + void insertFBO (Effects::CFBO* fbo); + private: std::string m_name; std::string m_description; @@ -43,5 +55,6 @@ namespace WallpaperEngine::Core::Objects std::vector m_dependencies; std::vector m_materials; + std::vector m_fbos; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp b/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp new file mode 100644 index 0000000..c585068 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp @@ -0,0 +1,40 @@ +#include "CFBO.h" + +#include + +using namespace WallpaperEngine::Core::Objects::Effects; + +CFBO::CFBO (std::string name, irr::f32 scale, std::string format) : + m_name (std::move(name)), + m_scale (scale), + m_format(std::move(format)) +{ +} + +CFBO* CFBO::fromJSON (json data) +{ + auto name_it = data.find ("name"); + auto scale_it = data.find ("scale"); + auto format_it = data.find ("format"); + + return new CFBO ( + *name_it, + *scale_it, + *format_it + ); +} + +const std::string& CFBO::getName () const +{ + return this->m_name; +} + +const irr::f32& CFBO::getScale () const +{ + return this->m_scale; +} + +const std::string& CFBO::getFormat () const +{ + return this->m_format; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CFBO.h b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h new file mode 100644 index 0000000..679672b --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + using json = nlohmann::json; + + class CFBO + { + public: + CFBO (std::string name, irr::f32 scale, std::string format); + + static CFBO* fromJSON (json data); + + const std::string& getName () const; + const irr::f32& getScale () const; + const std::string& getFormat () const; + + private: + std::string m_name; + irr::f32 m_scale; + std::string m_format; + }; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp similarity index 63% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp index 2ed3226..995fc68 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp @@ -1,6 +1,6 @@ #include "CShaderConstant.h" -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; CShaderConstant::CShaderConstant (std::string type) : m_type (std::move(type)) diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h similarity index 87% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h index e038536..9d2688a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstant.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h @@ -2,7 +2,7 @@ #include -namespace WallpaperEngine::Core::Objects::Effects +namespace WallpaperEngine::Core::Objects::Effects::Constants { class CShaderConstant { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp similarity index 80% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp index cf70921..c55cd4e 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp @@ -1,6 +1,6 @@ #include "CShaderConstantFloat.h" -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; CShaderConstantFloat::CShaderConstantFloat (irr::f32 value) : diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h similarity index 84% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h index 625785a..bdcead1 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h @@ -5,7 +5,7 @@ #include #include -namespace WallpaperEngine::Core::Objects::Effects +namespace WallpaperEngine::Core::Objects::Effects::Constants { class CShaderConstantFloat : public CShaderConstant { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp similarity index 81% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp index 568bdf6..e7b7a59 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp @@ -1,6 +1,6 @@ #include "CShaderConstantInteger.h" -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; CShaderConstantInteger::CShaderConstantInteger (irr::s32 value) : diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h similarity index 84% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h index eb6d1d2..4016230 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h @@ -5,7 +5,7 @@ #include #include -namespace WallpaperEngine::Core::Objects::Effects +namespace WallpaperEngine::Core::Objects::Effects::Constants { class CShaderConstantInteger : public CShaderConstant { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp similarity index 82% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp index d1fd1cb..2573818 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp @@ -1,6 +1,6 @@ #include "CShaderConstantVector3.h" -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; CShaderConstantVector3::CShaderConstantVector3 (irr::core::vector3df value) : diff --git a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h similarity index 86% rename from src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h rename to src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h index faf1bdc..7abe9a4 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h @@ -5,7 +5,7 @@ #include #include -namespace WallpaperEngine::Core::Objects::Effects +namespace WallpaperEngine::Core::Objects::Effects::Constants { class CShaderConstantVector3 : public CShaderConstant { diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index 71ee169..4f3583c 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -7,16 +7,32 @@ using namespace WallpaperEngine::Core::Objects::Images; -CMaterial::CMaterial () +CMaterial::CMaterial () : + m_target ("") { } -CMaterial* CMaterial::fromFile (irr::io::path filename) +CMaterial* CMaterial::fromFile (const irr::io::path& filename) { return fromJSON ( json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)) ); } +CMaterial* CMaterial::fromFile (const irr::io::path& filename, const std::string& target) +{ + return fromJSON ( + json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)), target + ); +} + +CMaterial* CMaterial::fromJSON (json data, const std::string& target) +{ + CMaterial* material = fromJSON (data); + + material->setTarget (target); + + return material; +} CMaterial* CMaterial::fromJSON (json data) { @@ -35,7 +51,7 @@ CMaterial* CMaterial::fromJSON (json data) for (; cur != end; cur ++) { material->insertPass ( - Materials::CPassess::fromJSON (*cur) + Materials::CPassess::fromJSON (*cur) ); } @@ -47,7 +63,21 @@ void CMaterial::insertPass (Materials::CPassess* mass) this->m_passes.push_back (mass); } +void CMaterial::setTarget (const std::string& target) +{ + this->m_target = target; +} + const std::vector & CMaterial::getPasses () const { return this->m_passes; +} +const std::string& CMaterial::getTarget () const +{ + return this->m_target; +} + +const bool CMaterial::hasTarget () const +{ + return this->m_target.empty () == false; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index fe6d1fc..107c341 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -12,15 +12,22 @@ namespace WallpaperEngine::Core::Objects::Images class CMaterial { public: - static CMaterial* fromFile (irr::io::path filename); + static CMaterial* fromFile (const irr::io::path& filename); static CMaterial* fromJSON (json data); + static CMaterial* fromFile (const irr::io::path& filename, const std::string& target); + static CMaterial* fromJSON (json data, const std::string& target); void insertPass (Materials::CPassess* mass); const std::vector & getPasses () const; + const std::string& getTarget () const; + const bool hasTarget () const; protected: CMaterial (); + + void setTarget (const std::string& target); private: std::vector m_passes; + std::string m_target; }; }; diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp index 2ed0daa..5873126 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp @@ -1,6 +1,6 @@ #include "CPassess.h" -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Images::Materials; CPassess::CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) : @@ -110,14 +110,19 @@ void CPassess::insertTexture (const std::string& texture) this->m_textures.push_back (texture); } +void CPassess::setTexture (int index, const std::string& texture) +{ + this->m_textures.at (index) = texture; +} + void CPassess::insertCombo (const std::string& name, int value) { this->m_combos.insert (std::pair (name, value)); } -std::vector* CPassess::getTextures () +const std::vector& CPassess::getTextures () const { - return &this->m_textures; + return this->m_textures; } const std::map& CPassess::getConstants () const diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h index a6d9eb4..6e3e042 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h @@ -2,7 +2,12 @@ #include -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" + +namespace WallpaperEngine::Core::Objects +{ + class CEffect; +}; namespace WallpaperEngine::Core::Objects::Images::Materials { @@ -10,11 +15,12 @@ namespace WallpaperEngine::Core::Objects::Images::Materials class CPassess { + friend class Core::Objects::CEffect; public: static CPassess* fromJSON (json data); - std::vector* getTextures (); - const std::map& getConstants () const; + const std::vector& getTextures () const; + const std::map& getConstants () const; const std::map& getCombos () const; const std::string& getShader () const; @@ -24,12 +30,13 @@ namespace WallpaperEngine::Core::Objects::Images::Materials const std::string& getDepthWrite () const; void insertCombo (const std::string& name, int value); - void insertConstant (const std::string& name, Effects::CShaderConstant* constant); + void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant); protected: CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); void insertTexture (const std::string& texture); + void setTexture (int index, const std::string& texture); private: std::string m_blending; @@ -39,6 +46,6 @@ namespace WallpaperEngine::Core::Objects::Images::Materials std::string m_shader; std::vector m_textures; std::map m_combos; - std::map m_constants; + std::map m_constants; }; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 3076af9..922ee99 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -10,14 +10,14 @@ #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h" -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstant.h" -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantFloat.h" -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantInteger.h" -#include "WallpaperEngine/Core/Objects/Effects/CShaderConstantVector3.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h" using namespace WallpaperEngine; -using namespace WallpaperEngine::Core::Objects::Effects; +using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Shaders::Variables; @@ -128,11 +128,11 @@ void CImage::generateMaterial () void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Core::Objects::CEffect* effect) { - std::vector* textures = pass->getTextures (); + std::vector textures = pass->getTextures (); irr::video::SMaterial material; - auto texturesCur = textures->begin (); - auto texturesEnd = textures->end (); + auto texturesCur = textures.begin (); + auto texturesEnd = textures.end (); for (int textureNumber = 0; texturesCur != texturesEnd; texturesCur ++, textureNumber ++) { From cbe79b535b2014c8f72ffe636783fffb9fce011a Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 11 Sep 2019 15:32:57 +0200 Subject: [PATCH 16/31] ~ changed wrong class name crom CPassess to CPass + added parsing of bind section for shader passes ~ various new classes to properly handle texture targets, shader passes and materials Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 15 +- src/WallpaperEngine/Core/Objects/CEffect.cpp | 30 ++- src/WallpaperEngine/Core/Objects/CEffect.h | 4 +- .../Core/Objects/Effects/CBind.cpp | 39 +++ .../Core/Objects/Effects/CBind.h | 26 ++ .../Core/Objects/Images/CMaterial.cpp | 17 +- .../Core/Objects/Images/CMaterial.h | 12 +- .../Materials/{CPassess.cpp => CPass.cpp} | 32 +-- .../Images/Materials/{CPassess.h => CPass.h} | 6 +- .../Render/Objects/CEffect.cpp | 90 +++++++ src/WallpaperEngine/Render/Objects/CEffect.h | 47 ++++ src/WallpaperEngine/Render/Objects/CImage.cpp | 16 +- src/WallpaperEngine/Render/Objects/CImage.h | 13 +- .../Render/Objects/Effects/CFBO.cpp | 34 +++ .../Render/Objects/Effects/CFBO.h | 25 ++ .../Render/Objects/Effects/CMaterial.cpp | 46 ++++ .../Render/Objects/Effects/CMaterial.h | 52 ++++ .../Render/Objects/Effects/CPass.cpp | 255 ++++++++++++++++++ .../Render/Objects/Effects/CPass.h | 41 +++ 19 files changed, 757 insertions(+), 43 deletions(-) create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CBind.cpp create mode 100644 src/WallpaperEngine/Core/Objects/Effects/CBind.h rename src/WallpaperEngine/Core/Objects/Images/Materials/{CPassess.cpp => CPass.cpp} (76%) rename src/WallpaperEngine/Core/Objects/Images/Materials/{CPassess.h => CPass.h} (88%) create mode 100644 src/WallpaperEngine/Render/Objects/CEffect.cpp create mode 100644 src/WallpaperEngine/Render/Objects/CEffect.h create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CFBO.cpp create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CFBO.h create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CMaterial.h create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CPass.cpp create mode 100644 src/WallpaperEngine/Render/Objects/Effects/CPass.h diff --git a/CMakeLists.txt b/CMakeLists.txt index df36a5d..40c5622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,15 @@ add_executable( src/WallpaperEngine/Render/Objects/CImage.cpp src/WallpaperEngine/Render/Objects/CSound.h src/WallpaperEngine/Render/Objects/CSound.cpp + src/WallpaperEngine/Render/Objects/CEffect.h + src/WallpaperEngine/Render/Objects/CEffect.cpp + + src/WallpaperEngine/Render/Objects/Effects/CFBO.h + src/WallpaperEngine/Render/Objects/Effects/CFBO.cpp + src/WallpaperEngine/Render/Objects/Effects/CPass.h + src/WallpaperEngine/Render/Objects/Effects/CPass.cpp + src/WallpaperEngine/Render/Objects/Effects/CMaterial.h + src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp src/WallpaperEngine/FileSystem/FileSystem.cpp src/WallpaperEngine/FileSystem/FileSystem.h @@ -100,6 +109,8 @@ add_executable( src/WallpaperEngine/Core/Objects/Effects/CFBO.h src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp + src/WallpaperEngine/Core/Objects/Effects/CBind.h + src/WallpaperEngine/Core/Objects/Effects/CBind.cpp src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp @@ -135,8 +146,8 @@ add_executable( src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp src/WallpaperEngine/Core/Objects/Images/CMaterial.h - src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp - src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h + src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp + src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h ) target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES}) \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 7c8b76f..8a63905 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -167,7 +167,7 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object) return effect; } -void CEffect::combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPassess* pass) +void CEffect::combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPass* pass) { auto cur = (*combos_it).begin (); auto end = (*combos_it).end (); @@ -178,7 +178,7 @@ void CEffect::combosFromJSON (json::const_iterator combos_it, Core::Objects::Ima } } -void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPassess* pass) +void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPass* pass) { auto cur = (*constants_it).begin (); auto end = (*constants_it).end (); @@ -241,24 +241,38 @@ void CEffect::materialsFromJSON (json::const_iterator passes_it, CEffect* effect { auto materialfile = (*cur).find ("material"); auto target = (*cur).find ("target"); + auto bind = (*cur).find ("bind"); if (materialfile == (*cur).end ()) { throw std::runtime_error ("Effect pass must have a material file"); } + Images::CMaterial* material = nullptr; + if (target == (*cur).end ()) { - effect->insertMaterial ( - Images::CMaterial::fromFile ((*materialfile).get ().c_str ()) - ); + material = Images::CMaterial::fromFile ((*materialfile).get ().c_str ()); } else { - effect->insertMaterial ( - Images::CMaterial::fromFile ((*materialfile).get ().c_str (), *target) - ); + material = Images::CMaterial::fromFile ((*materialfile).get ().c_str (), *target); } + + if (bind != (*cur).end ()) + { + auto bindCur = (*bind).begin (); + auto bindEnd = (*bind).end (); + + for (; bindCur != bindEnd; bindCur ++) + { + material->insertTextureBind ( + Effects::CBind::fromJSON (*bindCur) + ); + } + } + + effect->insertMaterial (material); } } diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index a463068..c05db72 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -36,8 +36,8 @@ namespace WallpaperEngine::Core::Objects Effects::CFBO* findFBO (const std::string& name); protected: - static void constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPassess* pass); - static void combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPassess* pass); + static void constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPass* pass); + static void combosFromJSON (json::const_iterator combos_it, Core::Objects::Images::Materials::CPass* pass); static void fbosFromJSON (json::const_iterator fbos_it, CEffect* effect); static void dependencyFromJSON (json::const_iterator dependencies_it, CEffect* effect); static void materialsFromJSON (json::const_iterator passes_it, CEffect* effect); diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp new file mode 100644 index 0000000..c890115 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -0,0 +1,39 @@ +#include "CBind.h" + +#include + +using namespace WallpaperEngine::Core::Objects::Effects; + +CBind::CBind (std::string name, irr::u32 index) : + m_name (std::move(name)), + m_index (index) +{ +} + +CBind* CBind::fromJSON (json data) +{ + auto name_it = data.find ("name"); + auto index_it = data.find ("index"); + + if (name_it == data.end ()) + { + throw std::runtime_error ("bind must have texture name"); + } + + if (index_it == data.end ()) + { + throw std::runtime_error ("bind must have index"); + } + + return new CBind (*name_it, *index_it); +} + +const std::string& CBind::getName () const +{ + return this->m_name; +} + +const irr::u32& CBind::getIndex () const +{ + return this->m_index; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.h b/src/WallpaperEngine/Core/Objects/Effects/CBind.h new file mode 100644 index 0000000..a4cbeb1 --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include +#include + +namespace WallpaperEngine::Core::Objects::Effects +{ + using json = nlohmann::json; + + class CBind + { + public: + static CBind* fromJSON (json data); + + CBind (std::string name, irr::u32 index); + + const std::string& getName () const; + const irr::u32& getIndex () const; + + private: + std::string m_name; + irr::u32 m_index; + }; +} diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index 4f3583c..af269b2 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -5,6 +5,7 @@ #include "WallpaperEngine/FileSystem/FileSystem.h" +using namespace WallpaperEngine::Core::Objects; using namespace WallpaperEngine::Core::Objects::Images; CMaterial::CMaterial () : @@ -51,27 +52,37 @@ CMaterial* CMaterial::fromJSON (json data) for (; cur != end; cur ++) { material->insertPass ( - Materials::CPassess::fromJSON (*cur) + Materials::CPass::fromJSON (*cur) ); } return material; } -void CMaterial::insertPass (Materials::CPassess* mass) +void CMaterial::insertPass (Materials::CPass* mass) { this->m_passes.push_back (mass); } +void CMaterial::insertTextureBind (Effects::CBind* bind) +{ + this->m_textureBindings.push_back (bind); +} + void CMaterial::setTarget (const std::string& target) { this->m_target = target; } -const std::vector & CMaterial::getPasses () const +const std::vector & CMaterial::getPasses () const { return this->m_passes; } +const std::vector & CMaterial::getTextureBinds () const +{ + return this->m_textureBindings; +} + const std::string& CMaterial::getTarget () const { return this->m_target; diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 107c341..0fe2e54 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -3,7 +3,8 @@ #include #include -#include "WallpaperEngine/Core/Objects/Images/Materials/CPassess.h" +#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" +#include "WallpaperEngine/Core/Objects/Effects/CBind.h" namespace WallpaperEngine::Core::Objects::Images { @@ -17,9 +18,11 @@ namespace WallpaperEngine::Core::Objects::Images static CMaterial* fromFile (const irr::io::path& filename, const std::string& target); static CMaterial* fromJSON (json data, const std::string& target); - void insertPass (Materials::CPassess* mass); + void insertPass (Materials::CPass* mass); + void insertTextureBind (Effects::CBind* bind); - const std::vector & getPasses () const; + const std::vector & getPasses () const; + const std::vector & getTextureBinds () const; const std::string& getTarget () const; const bool hasTarget () const; protected: @@ -27,7 +30,8 @@ namespace WallpaperEngine::Core::Objects::Images void setTarget (const std::string& target); private: - std::vector m_passes; + std::vector m_passes; + std::vector m_textureBindings; std::string m_target; }; }; diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp similarity index 76% rename from src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp rename to src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 5873126..8db6d1a 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -1,9 +1,9 @@ -#include "CPassess.h" +#include "CPass.h" using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Images::Materials; -CPassess::CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) : +CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) : m_blending (std::move(blending)), m_cullmode (std::move(cullmode)), m_depthtest (std::move(depthtest)), @@ -12,7 +12,7 @@ CPassess::CPassess (std::string blending, std::string cullmode, std::string dept { } -CPassess* CPassess::fromJSON (json data) +CPass* CPass::fromJSON (json data) { auto blending_it = data.find ("blending"); auto cullmode_it = data.find ("cullmode"); @@ -56,7 +56,7 @@ CPassess* CPassess::fromJSON (json data) } } - CPassess* pass = new CPassess ( + CPass* pass = new CPass ( *blending_it, *cullmode_it, *depthtest_it, @@ -105,62 +105,62 @@ CPassess* CPassess::fromJSON (json data) return pass; } -void CPassess::insertTexture (const std::string& texture) +void CPass::insertTexture (const std::string& texture) { this->m_textures.push_back (texture); } -void CPassess::setTexture (int index, const std::string& texture) +void CPass::setTexture (int index, const std::string& texture) { this->m_textures.at (index) = texture; } -void CPassess::insertCombo (const std::string& name, int value) +void CPass::insertCombo (const std::string& name, int value) { this->m_combos.insert (std::pair (name, value)); } -const std::vector& CPassess::getTextures () const +const std::vector& CPass::getTextures () const { return this->m_textures; } -const std::map& CPassess::getConstants () const +const std::map& CPass::getConstants () const { return this->m_constants; } -const std::map& CPassess::getCombos () const +const std::map& CPass::getCombos () const { return this->m_combos; } -const std::string& CPassess::getShader () const +const std::string& CPass::getShader () const { return this->m_shader; } -const std::string& CPassess::getBlendingMode () const +const std::string& CPass::getBlendingMode () const { return this->m_blending; } -const std::string& CPassess::getCullingMode () const +const std::string& CPass::getCullingMode () const { return this->m_cullmode; } -const std::string& CPassess::getDepthTest () const +const std::string& CPass::getDepthTest () const { return this->m_depthtest; } -const std::string& CPassess::getDepthWrite ()const +const std::string& CPass::getDepthWrite ()const { return this->m_depthwrite; } -void CPassess::insertConstant (const std::string& name, CShaderConstant* constant) +void CPass::insertConstant (const std::string& name, CShaderConstant* constant) { this->m_constants.insert (std::pair (name, constant)); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h similarity index 88% rename from src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h rename to src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index 6e3e042..517c2cd 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -13,11 +13,11 @@ namespace WallpaperEngine::Core::Objects::Images::Materials { using json = nlohmann::json; - class CPassess + class CPass { friend class Core::Objects::CEffect; public: - static CPassess* fromJSON (json data); + static CPass* fromJSON (json data); const std::vector& getTextures () const; const std::map& getConstants () const; @@ -33,7 +33,7 @@ namespace WallpaperEngine::Core::Objects::Images::Materials void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant); protected: - CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); + CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); void insertTexture (const std::string& texture); void setTexture (int index, const std::string& texture); diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp new file mode 100644 index 0000000..92a90f2 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -0,0 +1,90 @@ +#include "CEffect.h" + +using namespace WallpaperEngine::Render::Objects; + +CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect, Irrlicht::CContext* context, irr::video::ITexture* input) : + m_context (context), + m_image (image), + m_effect (effect), + m_inputTexture (input) +{ + irr::core::dimension2du size = irr::core::dimension2du ( + this->m_image->getImage ()->getSize ().X, + this->m_image->getImage ()->getSize ().Y + ); + + this->m_outputTexture = this->m_context->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( + size, + ( + "_rt_WALLENGINELINUX_OUTPUT_" + + std::to_string (image->getImage ()->getId ()) + "_" + + std::to_string (this->m_image->getEffects ().size ()) + + "_output" + ).c_str () + ); + + this->generateFBOs (); + this->generatePasses (); +} + +const irr::video::ITexture* CEffect::getInputTexture () const +{ + return this->m_inputTexture; +} + +const irr::video::ITexture* CEffect::getOutputTexture () const +{ + return this->m_outputTexture; +} + +const CImage* CEffect::getImage () const +{ + return this->m_image; +} + +const std::vector& CEffect::getMaterials () const +{ + return this->m_materials; +} + +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; + } + } + + return nullptr; +} + +void CEffect::generatePasses () +{ + auto cur = this->m_effect->getMaterials ().begin (); + auto end = this->m_effect->getMaterials ().end (); + + for (; cur != end; cur ++) + { + this->m_materials.push_back ( + new Effects::CMaterial (this->m_context, this, *cur) + ); + } +} + +void CEffect::generateFBOs () +{ + auto cur = this->m_effect->getFbos ().begin (); + auto end = this->m_effect->getFbos ().end (); + + for (; cur != end; cur ++) + { + this->m_fbos.push_back ( + new Effects::CFBO (*cur, this->m_image->getImage (), this->m_context) + ); + } +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CEffect.h b/src/WallpaperEngine/Render/Objects/CEffect.h new file mode 100644 index 0000000..717ba25 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CEffect.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +#include "WallpaperEngine/Irrlicht/CContext.h" + +#include "WallpaperEngine/Render/Objects/CImage.h" +#include "WallpaperEngine/Render/Objects/Effects/CFBO.h" +#include "WallpaperEngine/Render/Objects/Effects/CPass.h" +#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h" + +namespace WallpaperEngine::Render::Objects::Effects +{ + class CMaterial; +} + +namespace WallpaperEngine::Render::Objects +{ + class CImage; + + class CEffect + { + public: + CEffect (CImage* image, Core::Objects::CEffect* effect, Irrlicht::CContext* context, irr::video::ITexture* input); + + const irr::video::ITexture* getOutputTexture () const; + const irr::video::ITexture* getInputTexture () const; + const CImage* getImage () const; + + const std::vector& getMaterials () const; + + Effects::CFBO* findFBO (const std::string& name); + private: + void generatePasses (); + void generateFBOs (); + + Irrlicht::CContext* m_context; + CImage* m_image; + Core::Objects::CEffect* m_effect; + + std::vector m_fbos; + std::vector m_materials; + + irr::video::ITexture* m_inputTexture; + irr::video::ITexture* m_outputTexture; + }; +}; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 922ee99..72e81cf 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -102,7 +102,7 @@ void CImage::generateMaterial () for (; cur != end; cur++) { - this->generatePass (*cur, nullptr); + this->generatePass (*cur); } auto effectCur = this->m_image->getEffects ().begin (); @@ -120,13 +120,13 @@ void CImage::generateMaterial () for (; cur != end; cur++) { - this->generatePass (*cur, *effectCur); + this->generatePass (*cur); } } } } -void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass, Core::Objects::CEffect* effect) +void CImage::generatePass (Core::Objects::Images::Materials::CPass* pass) { std::vector textures = pass->getTextures (); irr::video::SMaterial material; @@ -233,6 +233,16 @@ const irr::core::aabbox3d& CImage::getBoundingBox() const return this->m_boundingBox; } +const Core::Objects::CImage* CImage::getImage () const +{ + return this->m_image; +} + +const std::vector& CImage::getEffects () const +{ + return this->m_effects; +} + void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData) { irr::f32 g_Texture0 = 0; diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index 4ac4a8b..1a04ec1 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -2,6 +2,7 @@ #include "WallpaperEngine/Core/Objects/CImage.h" +#include "WallpaperEngine/Render/Objects/CEffect.h" #include "WallpaperEngine/Render/CObject.h" #include "WallpaperEngine/Render/CScene.h" @@ -11,22 +12,28 @@ using namespace WallpaperEngine; namespace WallpaperEngine::Render::Objects { + class CEffect; + class CImage : public CObject, public irr::video::IShaderConstantSetCallBack { public: CImage (CScene* scene, Core::Objects::CImage* image); - virtual void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData); + void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData) override; void render () override; const irr::core::aabbox3d& getBoundingBox() const override; + const Core::Objects::CImage* getImage () const; + const std::vector& getEffects () const; + protected: static const std::string Type; private: + void generateFBOs (); void generateMaterial (); - void generatePass (Core::Objects::Images::Materials::CPassess* pass, Core::Objects::CEffect* effect); + void generatePass (Core::Objects::Images::Materials::CPass* pass); irr::video::S3DVertex m_vertex [4]; irr::u32 m_passes; @@ -36,6 +43,8 @@ namespace WallpaperEngine::Render::Objects Core::Objects::CImage* m_image; irr::core::aabbox3d m_boundingBox; + std::vector m_effects; + std::vector m_vertexShaders; std::vector m_pixelShaders; }; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CFBO.cpp b/src/WallpaperEngine/Render/Objects/Effects/CFBO.cpp new file mode 100644 index 0000000..1b8bc01 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CFBO.cpp @@ -0,0 +1,34 @@ +#include "CFBO.h" + +using namespace WallpaperEngine::Render::Objects::Effects; + +CFBO::CFBO (Core::Objects::Effects::CFBO* fbo, const Core::Objects::CImage* image, Irrlicht::CContext* context) : + m_fbo (fbo) +{ + irr::core::dimension2du size = irr::core::dimension2du ( + image->getSize ().X * this->getScale (), + image->getSize ().Y * this->getScale () + ); + + context->getDevice ()->getVideoDriver ()->addRenderTargetTexture (size, this->getName ().c_str ()); +} + +const irr::video::ITexture* CFBO::getTexture () const +{ + return this->m_texture; +} + +const std::string& CFBO::getName () const +{ + return this->m_fbo->getName (); +} + +const irr::f32& CFBO::getScale () const +{ + return this->m_fbo->getScale (); +} + +const std::string& CFBO::getFormat () const +{ + return this->m_fbo->getFormat (); +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/Effects/CFBO.h b/src/WallpaperEngine/Render/Objects/Effects/CFBO.h new file mode 100644 index 0000000..9660c21 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CFBO.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "WallpaperEngine/Core/Objects/Effects/CFBO.h" +#include "WallpaperEngine/Core/Objects/CImage.h" + +#include "WallpaperEngine/Irrlicht/CContext.h" + +namespace WallpaperEngine::Render::Objects::Effects +{ + class CFBO + { + public: + CFBO (Core::Objects::Effects::CFBO* fbo, const Core::Objects::CImage* image, Irrlicht::CContext* context); + + const irr::video::ITexture* getTexture () const; + const std::string& getName () const; + const irr::f32& getScale () const; + const std::string& getFormat () const; + private: + irr::video::ITexture* m_texture; + const Core::Objects::Effects::CFBO* m_fbo; + }; +}; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp new file mode 100644 index 0000000..68ab2fc --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp @@ -0,0 +1,46 @@ +#include "CMaterial.h" + +using namespace WallpaperEngine::Render::Objects; + +using namespace WallpaperEngine::Render::Objects::Effects; + +CMaterial::CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material) : + m_context (context), + m_effect (effect), + m_material (material) +{ + this->generatePasses (); +} + +const std::vector& CMaterial::getPasses () const +{ + return this->m_passes; +} + +const CImage* CMaterial::getImage () const +{ + return this->m_effect->getImage (); +} + +const irr::video::ITexture* CMaterial::getOutputTexture () const +{ + return this->m_outputTexture; +} + +const irr::video::ITexture* CMaterial::getInputTexture () const +{ + return this->m_inputTexture; +} + +void CMaterial::generatePasses () +{ + auto cur = this->m_material->getPasses ().begin (); + auto end = this->m_material->getPasses ().end (); + + for (; cur != end; cur ++) + { + this->m_passes.push_back ( + new CPass (this->m_context, this, *cur) + ); + } +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h new file mode 100644 index 0000000..76addfb --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +#include "WallpaperEngine/Core/Objects/Images/CMaterial.h" +#include "WallpaperEngine/Core/Objects/CEffect.h" + +#include "WallpaperEngine/Irrlicht/CContext.h" + +#include "WallpaperEngine/Render/Objects/Effects/CPass.h" +#include "WallpaperEngine/Render/Objects/CEffect.h" + +#include "CPass.h" + +using namespace WallpaperEngine; + +namespace WallpaperEngine::Render::Objects +{ + class CEffect; + class CImage; +} + +namespace WallpaperEngine::Render::Objects::Effects +{ + class CPass; + + class CMaterial + { + friend class CPass; + public: + CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material); + + const irr::video::ITexture* getOutputTexture () const; + const irr::video::ITexture* getInputTexture () const; + + const std::vector& getPasses () const; + const CImage* getImage () const; + + private: + void generatePasses (); + + Irrlicht::CContext* m_context; + + irr::video::ITexture* m_inputTexture; + irr::video::ITexture* m_outputTexture; + + Render::Objects::CEffect* m_effect; + Core::Objects::Images::CMaterial* m_material; + + std::vector m_passes; + }; +}; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp new file mode 100644 index 0000000..3a4ef54 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -0,0 +1,255 @@ +#include "CPass.h" + +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableInteger.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" +#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h" + +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h" +#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h" + +using namespace WallpaperEngine::Core::Objects::Effects::Constants; +using namespace WallpaperEngine::Render::Shaders::Variables; + +using namespace WallpaperEngine::Render::Objects::Effects; + +CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass) : + m_material (material), + m_pass (pass), + m_context (context), + m_inputTexture (nullptr), + m_outputTexture (nullptr) +{ + irr::io::path vertPath = this->m_context->resolveVertexShader (pass->getShader ()); + irr::io::path fragPath = this->m_context->resolveFragmentShader (pass->getShader ()); + // register fragment shader + this->m_fragShader = new Render::Shaders::Compiler ( + this->m_context, vertPath, Render::Shaders::Compiler::Type::Type_Pixel, pass->getCombos (), false + ); + // register vertex shader + this->m_vertShader = new Render::Shaders::Compiler ( + this->m_context, fragPath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false + ); + + // initialize material data and compile shader used for this pass + this->m_irrlichtMaterial.Wireframe = false; + this->m_irrlichtMaterial.Lighting = false; + this->m_irrlichtMaterial.setFlag (irr::video::EMF_LIGHTING, false); + this->m_irrlichtMaterial.setFlag (irr::video::EMF_BLEND_OPERATION, true); + this->m_irrlichtMaterial.MaterialType = (irr::video::E_MATERIAL_TYPE) + this->m_context->getDevice ()->getVideoDriver ()->getGPUProgrammingServices ()->addHighLevelShaderMaterial ( + this->m_vertShader->precompile ().c_str (), "main", irr::video::EVST_VS_2_0, + this->m_fragShader->precompile ().c_str (), "main", irr::video::EPST_PS_2_0, + this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, irr::video::EGSL_DEFAULT + ); + + this->setupShaderVariables (); +} + +const irr::video::ITexture* CPass::getOutputTexture () const +{ + return this->m_outputTexture; +} + +const irr::video::ITexture* CPass::getInputTexture () const +{ + return this->m_inputTexture; +} + +const irr::video::SMaterial& CPass::getMaterial () const +{ + return this->m_irrlichtMaterial; +} + +void CPass::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData) +{ + irr::f32 g_Texture0 = 0; + irr::f32 g_Texture1 = 1; + irr::f32 g_Texture2 = 2; + irr::f32 g_Texture3 = 3; + irr::f32 g_Texture4 = 4; + irr::f32 g_Texture5 = 5; + irr::f32 g_Texture6 = 6; + irr::f32 g_Texture7 = 7; + + const Core::Objects::CImage* image = this->m_material->getImage ()->getImage (); + + irr::f32 g_Texture0Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture1Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture2Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture3Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture4Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture5Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture6Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + irr::f32 g_Texture7Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z }; + + irr::f32 g_Texture0Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture1Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture2Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture3Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture4Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture5Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture6Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + irr::f32 g_Texture7Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y }; + + irr::video::IVideoDriver* driver = services->getVideoDriver (); + + irr::core::matrix4 worldViewProj; + worldViewProj = driver->getTransform (irr::video::ETS_PROJECTION); + worldViewProj *= driver->getTransform (irr::video::ETS_VIEW); + worldViewProj *= driver->getTransform (irr::video::ETS_WORLD); + + auto cur = this->m_vertShader->getParameters ().begin (); + auto end = this->m_vertShader->getParameters ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->is () == true) + { + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::s32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + else if ( + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) + { + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } + + cur = this->m_fragShader->getParameters ().begin (); + end = this->m_fragShader->getParameters ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::s32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + else if ( + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true || + (*cur)->is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } + + cur = this->m_context->getShaderVariables ().begin (); + end = this->m_context->getShaderVariables ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->is () == true) + { + services->setPixelShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + services->setVertexShaderConstant ( + (*cur)->getName ().c_str (), + (irr::f32*) (*cur)->getValue (), + (*cur)->getSize () + ); + } + } + + services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16); + + services->setVertexShaderConstant ("g_Texture0Resolution", g_Texture0Resolution, 4); + services->setVertexShaderConstant ("g_Texture1Resolution", g_Texture1Resolution, 4); + services->setVertexShaderConstant ("g_Texture2Resolution", g_Texture2Resolution, 4); + services->setVertexShaderConstant ("g_Texture3Resolution", g_Texture3Resolution, 4); + services->setVertexShaderConstant ("g_Texture4Resolution", g_Texture4Resolution, 4); + services->setVertexShaderConstant ("g_Texture5Resolution", g_Texture5Resolution, 4); + services->setVertexShaderConstant ("g_Texture6Resolution", g_Texture6Resolution, 4); + services->setVertexShaderConstant ("g_Texture7Resolution", g_Texture7Resolution, 4); + + services->setVertexShaderConstant ("g_Texture0Rotation", g_Texture0Rotation, 4); + services->setVertexShaderConstant ("g_Texture1Rotation", g_Texture1Rotation, 4); + services->setVertexShaderConstant ("g_Texture2Rotation", g_Texture2Rotation, 4); + services->setVertexShaderConstant ("g_Texture3Rotation", g_Texture3Rotation, 4); + services->setVertexShaderConstant ("g_Texture4Rotation", g_Texture4Rotation, 4); + services->setVertexShaderConstant ("g_Texture5Rotation", g_Texture5Rotation, 4); + services->setVertexShaderConstant ("g_Texture6Rotation", g_Texture6Rotation, 4); + services->setVertexShaderConstant ("g_Texture7Rotation", g_Texture7Rotation, 4); + + services->setPixelShaderConstant ("g_Texture0", &g_Texture0, 1); + services->setPixelShaderConstant ("g_Texture1", &g_Texture1, 1); + services->setPixelShaderConstant ("g_Texture2", &g_Texture2, 1); + services->setPixelShaderConstant ("g_Texture3", &g_Texture3, 1); + services->setPixelShaderConstant ("g_Texture4", &g_Texture4, 1); + services->setPixelShaderConstant ("g_Texture5", &g_Texture5, 1); + services->setPixelShaderConstant ("g_Texture6", &g_Texture6, 1); + services->setPixelShaderConstant ("g_Texture7", &g_Texture7, 1); +} + +void CPass::setupShaderVariables () +{ + // find variables in the shaders and set the value with the constants if possible + auto cur = this->m_pass->getConstants ().begin (); + auto end = this->m_pass->getConstants ().end (); + + for (; cur != end; cur ++) + { + CShaderVariable* vertexVar = this->m_vertShader->findParameter ((*cur).first); + CShaderVariable* pixelVar = this->m_fragShader->findParameter ((*cur).first); + + if (pixelVar) + { + if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (pixelVar->is () && (*cur).second->is ()) + { + pixelVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + } + + if (vertexVar) + { + if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + else if (vertexVar->is () && (*cur).second->is ()) + { + vertexVar->as ()->setValue (*(*cur).second->as ()->getValue ()); + } + } + } +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.h b/src/WallpaperEngine/Render/Objects/Effects/CPass.h new file mode 100644 index 0000000..591ed0b --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include "WallpaperEngine/Irrlicht/CContext.h" + +#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h" +#include "WallpaperEngine/Render/Shaders/Compiler.h" + +namespace WallpaperEngine::Render::Objects::Effects +{ + class CMaterial; + + class CPass : public irr::video::IShaderConstantSetCallBack + { + public: + CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass); + + void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData) override; + + const irr::video::ITexture* getOutputTexture () const; + const irr::video::ITexture* getInputTexture () const; + + const irr::video::SMaterial& getMaterial () const; + + private: + void setupShaderVariables (); + + CMaterial* m_material; + Core::Objects::Images::Materials::CPass* m_pass; + Irrlicht::CContext* m_context; + + irr::video::ITexture* m_inputTexture; + irr::video::ITexture* m_outputTexture; + + irr::video::SMaterial m_irrlichtMaterial; + + Render::Shaders::Compiler* m_fragShader; + Render::Shaders::Compiler* m_vertShader; + }; +} From 8d2f2adcfa279ea8825d26473068dd40665504cf Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 11 Sep 2019 15:52:51 +0200 Subject: [PATCH 17/31] ~ added proper texture input/output Signed-off-by: Alexis Maiquez --- .../Render/Objects/CEffect.cpp | 12 ++++++---- .../Render/Objects/Effects/CMaterial.cpp | 24 +++++++++++++++---- .../Render/Objects/Effects/CMaterial.h | 4 ++-- .../Render/Objects/Effects/CPass.cpp | 15 +++++++++--- .../Render/Objects/Effects/CPass.h | 4 ++-- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp index 92a90f2..166661c 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -19,7 +19,7 @@ CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect, Irrlicht::CCont "_rt_WALLENGINELINUX_OUTPUT_" + std::to_string (image->getImage ()->getId ()) + "_" + std::to_string (this->m_image->getEffects ().size ()) + - "_output" + "_effect_output" ).c_str () ); @@ -67,12 +67,16 @@ void CEffect::generatePasses () { auto cur = this->m_effect->getMaterials ().begin (); auto end = this->m_effect->getMaterials ().end (); + const irr::video::ITexture* inputTexture = this->getInputTexture (); for (; cur != end; cur ++) { - this->m_materials.push_back ( - new Effects::CMaterial (this->m_context, this, *cur) - ); + Effects::CMaterial* material = new Effects::CMaterial (this->m_context, this, *cur, inputTexture); + + // next input texture will be the output texture of the material + inputTexture = material->getOutputTexture (); + + this->m_materials.push_back (material); } } diff --git a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp index 68ab2fc..390f19a 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp @@ -4,11 +4,22 @@ using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Objects::Effects; -CMaterial::CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material) : +CMaterial::CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material, const irr::video::ITexture* texture) : m_context (context), m_effect (effect), - m_material (material) + m_material (material), + m_inputTexture (texture) { + this->m_outputTexture = this->m_context->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( + this->m_inputTexture->getSize (), + ( + "_rt_WALLENGINELINUX_OUTPUT_" + + std::to_string (this->m_effect->getImage ()->getImage ()->getId ()) + "_" + + std::to_string (this->m_effect->getImage ()->getEffects ().size ()) + + "_material_output" + ).c_str () + ); + this->generatePasses (); } @@ -36,11 +47,14 @@ void CMaterial::generatePasses () { auto cur = this->m_material->getPasses ().begin (); auto end = this->m_material->getPasses ().end (); + const irr::video::ITexture* inputTexture = this->getInputTexture (); for (; cur != end; cur ++) { - this->m_passes.push_back ( - new CPass (this->m_context, this, *cur) - ); + CPass* pass = new CPass (this->m_context, this, *cur, inputTexture); + + inputTexture = pass->getOutputTexture (); + + this->m_passes.push_back (pass); } } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h index 76addfb..daff5c4 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h @@ -28,7 +28,7 @@ namespace WallpaperEngine::Render::Objects::Effects { friend class CPass; public: - CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material); + CMaterial (Irrlicht::CContext* context, Render::Objects::CEffect* effect, Core::Objects::Images::CMaterial* material, const irr::video::ITexture* texture); const irr::video::ITexture* getOutputTexture () const; const irr::video::ITexture* getInputTexture () const; @@ -41,7 +41,7 @@ namespace WallpaperEngine::Render::Objects::Effects Irrlicht::CContext* m_context; - irr::video::ITexture* m_inputTexture; + const irr::video::ITexture* m_inputTexture; irr::video::ITexture* m_outputTexture; Render::Objects::CEffect* m_effect; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 3a4ef54..1bcf6d4 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -19,13 +19,23 @@ using namespace WallpaperEngine::Render::Shaders::Variables; using namespace WallpaperEngine::Render::Objects::Effects; -CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass) : +CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass, const irr::video::ITexture* texture) : m_material (material), m_pass (pass), m_context (context), - m_inputTexture (nullptr), + m_inputTexture (texture), m_outputTexture (nullptr) { + this->m_outputTexture = this->m_context->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( + this->m_inputTexture->getSize (), + ( + "_rt_WALLENGINELINUX_OUTPUT_" + + std::to_string (this->m_material->getImage ()->getImage ()->getId ()) + "_" + + std::to_string (this->m_material->getImage ()->getEffects ().size ()) + + "_pass_output" + ).c_str () + ); + irr::io::path vertPath = this->m_context->resolveVertexShader (pass->getShader ()); irr::io::path fragPath = this->m_context->resolveFragmentShader (pass->getShader ()); // register fragment shader @@ -36,7 +46,6 @@ CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::I this->m_vertShader = new Render::Shaders::Compiler ( this->m_context, fragPath, Render::Shaders::Compiler::Type::Type_Vertex, pass->getCombos (), false ); - // initialize material data and compile shader used for this pass this->m_irrlichtMaterial.Wireframe = false; this->m_irrlichtMaterial.Lighting = false; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.h b/src/WallpaperEngine/Render/Objects/Effects/CPass.h index 591ed0b..c140cd7 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.h @@ -14,7 +14,7 @@ namespace WallpaperEngine::Render::Objects::Effects class CPass : public irr::video::IShaderConstantSetCallBack { public: - CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass); + CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass, const irr::video::ITexture* texture); void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData) override; @@ -30,7 +30,7 @@ namespace WallpaperEngine::Render::Objects::Effects Core::Objects::Images::Materials::CPass* m_pass; Irrlicht::CContext* m_context; - irr::video::ITexture* m_inputTexture; + const irr::video::ITexture* m_inputTexture; irr::video::ITexture* m_outputTexture; irr::video::SMaterial m_irrlichtMaterial; From 67be40032a02d14acc5e975fd9dedd179b202372 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 17 Mar 2020 09:15:19 +1000 Subject: [PATCH 18/31] Removed duplicate code --- src/WallpaperEngine/Irrlicht/CContext.cpp | 16 +++++++++------- src/WallpaperEngine/Irrlicht/CContext.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index ad4713f..af5d152 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -170,9 +170,7 @@ void CContext::renderFrame (Render::CScene* scene) if (this->m_viewports.empty () == true) { - this->getDevice ()->getVideoDriver ()->beginScene (true, true, scene->getScene ()->getClearColor ().toSColor()); - this->getDevice ()->getSceneManager ()->drawAll (); - this->getDevice ()->getVideoDriver ()->endScene (); + this->drawScene(scene, true); } else { @@ -183,14 +181,18 @@ void CContext::renderFrame (Render::CScene* scene) { // change viewport to render to the correct portion of the display this->getDevice ()->getVideoDriver ()->setViewPort (*cur); - - this->getDevice ()->getVideoDriver ()->beginScene (false, true, scene->getScene ()->getClearColor ().toSColor()); - this->getDevice ()->getSceneManager ()->drawAll (); - this->getDevice ()->getVideoDriver ()->endScene (); + this->drawScene(scene, false); } } } +void CContext::drawScene(Render::CScene* scene, bool backBuffer) +{ + this->getDevice ()->getVideoDriver ()->beginScene (false, true, scene->getScene ()->getClearColor ().toSColor()); + this->getDevice ()->getSceneManager ()->drawAll (); + this->getDevice ()->getVideoDriver ()->endScene (); +} + void CContext::insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable) { this->m_globalShaderVariables.push_back (variable); diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index cf11321..bf75949 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -38,6 +38,7 @@ namespace WallpaperEngine::Irrlicht irr::io::path resolveIncludeShader (const std::string& includeShader); private: void initializeViewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters); + void drawScene(Render::CScene* scene, bool backBuffer); irr::io::path resolveFile (const irr::io::path& file); From d57ad95ab4f1a09210d5a1a427a87ff92b53e946 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 17 Mar 2020 09:19:28 +1000 Subject: [PATCH 19/31] Fix code style --- src/WallpaperEngine/Irrlicht/CContext.cpp | 6 +++--- src/WallpaperEngine/Irrlicht/CContext.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index af5d152..95183d6 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -170,7 +170,7 @@ void CContext::renderFrame (Render::CScene* scene) if (this->m_viewports.empty () == true) { - this->drawScene(scene, true); + this->drawScene (scene, true); } else { @@ -181,12 +181,12 @@ void CContext::renderFrame (Render::CScene* scene) { // change viewport to render to the correct portion of the display this->getDevice ()->getVideoDriver ()->setViewPort (*cur); - this->drawScene(scene, false); + this->drawScene (scene, false); } } } -void CContext::drawScene(Render::CScene* scene, bool backBuffer) +void CContext::drawScene (Render::CScene* scene, bool backBuffer) { this->getDevice ()->getVideoDriver ()->beginScene (false, true, scene->getScene ()->getClearColor ().toSColor()); this->getDevice ()->getSceneManager ()->drawAll (); diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index bf75949..c456b92 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -38,7 +38,7 @@ namespace WallpaperEngine::Irrlicht irr::io::path resolveIncludeShader (const std::string& includeShader); private: void initializeViewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters); - void drawScene(Render::CScene* scene, bool backBuffer); + void drawScene (Render::CScene* scene, bool backBuffer); irr::io::path resolveFile (const irr::io::path& file); From 96839dd61b49376ec53ba77ed55f757d0e01c28e Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 17 Mar 2020 10:34:55 +1000 Subject: [PATCH 20/31] Use backBuffer parameter in drawScene --- src/WallpaperEngine/Irrlicht/CContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index 95183d6..1b2d6fd 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -188,7 +188,7 @@ void CContext::renderFrame (Render::CScene* scene) void CContext::drawScene (Render::CScene* scene, bool backBuffer) { - this->getDevice ()->getVideoDriver ()->beginScene (false, true, scene->getScene ()->getClearColor ().toSColor()); + this->getDevice ()->getVideoDriver ()->beginScene (backBuffer, true, scene->getScene ()->getClearColor ().toSColor()); this->getDevice ()->getSceneManager ()->drawAll (); this->getDevice ()->getVideoDriver ()->endScene (); } From 274bb08e4fcd042ac63a683812d2bf608304121b Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 24 Mar 2020 01:00:33 +0100 Subject: [PATCH 21/31] ~ 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 From e30f62d7a17a92bacb0ade7d1145d0e0aaee6619 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 24 Mar 2020 15:32:27 +1000 Subject: [PATCH 22/31] Clean up json.find(...) calls --- src/WallpaperEngine/Core/CObject.cpp | 35 +---- src/WallpaperEngine/Core/CProject.cpp | 23 +-- src/WallpaperEngine/Core/CScene.cpp | 140 +++--------------- src/WallpaperEngine/Core/Core.cpp | 12 +- src/WallpaperEngine/Core/Core.h | 3 + src/WallpaperEngine/Core/Objects/CEffect.cpp | 49 +----- src/WallpaperEngine/Core/Objects/CImage.cpp | 14 +- .../Core/Objects/CParticle.cpp | 29 +--- src/WallpaperEngine/Core/Objects/CSound.cpp | 9 +- .../Core/Objects/Effects/CBind.cpp | 16 +- .../Core/Objects/Images/CMaterial.cpp | 8 +- .../Core/Objects/Images/Materials/CPass.cpp | 37 +---- .../Core/Objects/Particles/CControlPoint.cpp | 7 +- .../Core/Objects/Particles/CEmitter.cpp | 42 +----- .../Core/Objects/Particles/CInitializer.cpp | 8 +- .../Particles/Initializers/CAlphaRandom.cpp | 16 +- .../Initializers/CAngularVelocityRandom.cpp | 14 +- .../Particles/Initializers/CColorRandom.cpp | 14 +- .../Initializers/CLifeTimeRandom.cpp | 16 +- .../Particles/Initializers/CSizeRandom.cpp | 16 +- .../Initializers/CVelocityRandom.cpp | 14 +- .../Core/Projects/CProperty.cpp | 16 +- src/WallpaperEngine/Core/Scenes/CCamera.cpp | 21 +-- .../Core/Scenes/CProjection.cpp | 14 +- .../Render/Shaders/Compiler.cpp | 11 +- 25 files changed, 114 insertions(+), 470 deletions(-) diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 6cf6f88..dd94a56 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -29,42 +29,17 @@ CObject::CObject ( CObject* CObject::fromJSON (json data) { - auto id_it = data.find ("id"); + auto id_it = jsonFindValueRequired(&data, "id", "Objects must have id"); auto visible_it = data.find ("visible"); - auto origin_it = data.find ("origin"); - auto scale_it = data.find ("scale"); - auto angles_it = data.find ("angles"); - auto name_it = data.find ("name"); + auto origin_it = jsonFindValueRequired(&data, "origin", "Objects must have origin point"); + auto scale_it = jsonFindValueRequired(&data, "scale", "Objects must have scale"); + auto angles_it = jsonFindValueRequired(&data, "angles", "Objects must have angles"); + auto name_it = jsonFindValueRequired(&data, "name", "Objects must have name"); auto effects_it = data.find ("effects"); auto dependencies_it = data.find ("dependencies"); bool visible = true; - if (id_it == data.end ()) - { - throw std::runtime_error ("Objects must have id"); - } - - if (origin_it == data.end ()) - { - throw std::runtime_error ("Objects must have origin point"); - } - - if (scale_it == data.end ()) - { - throw std::runtime_error ("Objects must have scale"); - } - - if (angles_it == data.end ()) - { - throw std::runtime_error ("Objects must have angles"); - } - - if (name_it == data.end ()) - { - throw std::runtime_error ("Objects must have name"); - } - // visibility is optional if (visible_it != data.end ()) { diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index af8f6e0..663416b 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -2,6 +2,8 @@ #include "CProject.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core; CProject::CProject (std::string title, std::string type, CScene *scene) : @@ -16,26 +18,11 @@ CProject* CProject::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto title = content.find ("title"); - auto type = content.find ("type"); - auto file = content.find ("file"); + auto title = jsonFindValueRequired (&content, "title", "Project title missing"); + auto type = jsonFindValueRequired (&content, "title", "Project type missing"); + auto file = jsonFindValueRequired (&content, "title", "Project's main file missing"); auto general = content.find ("general"); - if (title == content.end ()) - { - throw std::runtime_error ("Project title missing"); - } - - if (type == content.end ()) - { - throw std::runtime_error ("Project type missing"); - } - - if (file == content.end ()) - { - throw std::runtime_error ("Project's main file missing"); - } - CProject* project = new CProject ( *title, *type, diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index c7112d4..835040f 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -50,127 +50,27 @@ CScene* CScene::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto camera_it = content.find ("camera"); - auto general_it = content.find ("general"); - auto objects_it = content.find ("objects"); + auto camera_it = jsonFindValueRequired(&content, "camera", "Scenes must have a defined camera"); + auto general_it = jsonFindValueRequired(&content, "general", "Scenes must have a general section"); + auto objects_it = jsonFindValueRequired(&content, "objects", "Scenes must have a list of objects to display"); - if (camera_it == content.end ()) - { - throw std::runtime_error ("Scenes must have a defined camera"); - } - - if (general_it == content.end ()) - { - throw std::runtime_error ("Scenes must have a general section"); - } - - if (objects_it == content.end ()) - { - throw std::runtime_error ("Scenes must have a list of objects to display"); - } - - auto ambientcolor_it = (*general_it).find ("ambientcolor"); - auto bloom_it = (*general_it).find ("bloom"); - auto bloomstrength_it = (*general_it).find ("bloomstrength"); - auto bloomthreshold_it = (*general_it).find ("bloomthreshold"); - auto camerafade_it = (*general_it).find ("camerafade"); - auto cameraparallax_it = (*general_it).find ("cameraparallax"); - auto cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount"); - auto cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay"); - auto cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence"); - auto camerapreview_it = (*general_it).find ("camerapreview"); - auto camerashake_it = (*general_it).find ("camerashake"); - auto camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude"); - auto camerashakeroughness_it = (*general_it).find ("camerashakeroughness"); - auto camerashakespeed_it = (*general_it).find ("camerashakespeed"); - auto clearcolor_it = (*general_it).find ("clearcolor"); - auto orthogonalprojection_it = (*general_it).find ("orthogonalprojection"); - auto skylightcolor_it = (*general_it).find ("skylightcolor"); - - if (ambientcolor_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have ambient color"); - } - - if (bloom_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have bloom flag"); - } - - if (bloomstrength_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have bloom strength"); - } - - if (bloomthreshold_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have bloom threshold"); - } - - if (camerafade_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera fade"); - } - - if (cameraparallax_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera parallax"); - } - - if (cameraparallaxamount_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera parallax amount"); - } - - if (cameraparallaxdelay_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera parallax delay"); - } - - if (cameraparallaxmouseinfluence_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera parallax mouse influence"); - } - - if (camerapreview_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera preview"); - } - - if (camerashake_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera shake"); - } - - if (camerashakeamplitude_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera shake amplitude"); - } - - if (camerashakeroughness_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera shake roughness"); - } - - if (camerashakespeed_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have camera shake speed"); - } - - if (clearcolor_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have clear color"); - } - - if (orthogonalprojection_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have orthogonal projection info"); - } - - if (skylightcolor_it == (*general_it).end ()) - { - throw std::runtime_error ("General section must have skylight color"); - } + auto ambientcolor_it = jsonFindValueRequired(&(*general_it), "ambientcolor", "General section must have ambient color"); + auto bloom_it = jsonFindValueRequired(&(*general_it), "bloom", "General section must have bloom flag"); + auto bloomstrength_it = jsonFindValueRequired(&(*general_it), "bloomstrength", "General section must have bloom strength"); + auto bloomthreshold_it = jsonFindValueRequired(&(*general_it), "bloomthreshold", "General section must have bloom threshold"); + auto camerafade_it = jsonFindValueRequired(&(*general_it), "camerafade", "General section must have camera fade"); + auto cameraparallax_it = jsonFindValueRequired(&(*general_it), "cameraparallax", "General section must have camera parallax"); + auto cameraparallaxamount_it = jsonFindValueRequired(&(*general_it), "cameraparallaxamount", "General section must have camera parallax amount"); + auto cameraparallaxdelay_it = jsonFindValueRequired(&(*general_it), "cameraparallaxdelay", "General section must have camera parallax delay"); + auto cameraparallaxmouseinfluence_it = jsonFindValueRequired(&(*general_it), "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); + auto camerapreview_it = jsonFindValueRequired(&(*general_it), "camerapreview", "General section must have camera preview"); + auto camerashake_it = jsonFindValueRequired(&(*general_it), "camerashake", "General section must have camera shake"); + auto camerashakeamplitude_it = jsonFindValueRequired(&(*general_it), "camerashakeamplitude", "General section must have camera shake amplitude"); + auto camerashakeroughness_it = jsonFindValueRequired(&(*general_it), "camerashakeroughness", "General section must have camera shake roughness"); + auto camerashakespeed_it = jsonFindValueRequired(&(*general_it), "camerashakespeed", "General section must have camera shake speed"); + auto clearcolor_it = jsonFindValueRequired(&(*general_it), "clearcolor", "General section must have clear color"); + auto orthogonalprojection_it = jsonFindValueRequired(&(*general_it), "orthogonalprojection", "General section must have orthogonal projection info"); + auto skylightcolor_it = jsonFindValueRequired(&(*general_it), "skylightcolor", "General section must have skylight color"); CScene* scene = new CScene ( Scenes::CCamera::fromJSON (*camera_it), diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 90d00ea..662b542 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -58,4 +58,14 @@ irr::video::SColor Core::atoSColor (const char *str) irr::video::SColor Core::atoSColor (const std::string& str) { return Core::atoSColor (str.c_str ()); -} \ No newline at end of file +} + +nlohmann::detail::iter_impl jsonFindValueRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) +{ + auto value = data->find (key); + if (value == data->end ()) + { + throw std::runtime_error (notFoundMsg); + } + return value; +} diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index 1918580..d52d078 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -2,6 +2,7 @@ #include #include +#include namespace WallpaperEngine::Core { @@ -16,4 +17,6 @@ namespace WallpaperEngine::Core irr::video::SColor atoSColor (const char *str); irr::video::SColor atoSColor (const std::string& str); + + nlohmann::detail::iter_impl jsonFindValueRequired (nlohmann::json *data, const char *key, const char *notFoundMsg); }; diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 8a63905..a23946f 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -30,54 +30,19 @@ CEffect::CEffect ( CEffect* CEffect::fromJSON (json data, Core::CObject* object) { - auto file_it = data.find ("file"); + auto file_it = jsonFindValueRequired(&data, "file", "Object effect must have a file"); auto effectpasses_it = data.find ("passes"); - if (file_it == data.end ()) - { - throw std::runtime_error ("Object effect must have a file"); - } - json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get ().c_str ())); - auto name_it = content.find ("name"); - auto description_it = content.find ("description"); - auto group_it = content.find ("group"); - auto preview_it = content.find ("preview"); - auto passes_it = content.find ("passes"); - auto dependencies_it = content.find ("dependencies"); + auto name_it = jsonFindValueRequired(&content, "name", "Effect must have a name"); + auto description_it = jsonFindValueRequired(&content, "description", "Effect must have a description"); + auto group_it = jsonFindValueRequired(&content, "group", "Effect must have a group"); + auto preview_it = jsonFindValueRequired(&content, "preview", "Effect must have a preview"); + auto passes_it = jsonFindValueRequired(&content, "passes", "Effect must have a pass list"); + auto dependencies_it = jsonFindValueRequired(&content, "dependencies", ""); auto fbos_it = content.find ("fbos"); - if (name_it == content.end ()) - { - throw std::runtime_error ("Effect must have a name"); - } - - if (description_it == content.end ()) - { - throw std::runtime_error ("Effect must have a description"); - } - - if (group_it == content.end ()) - { - throw std::runtime_error ("Effect must have a group"); - } - - if (preview_it == content.end ()) - { - throw std::runtime_error ("Effect must have a preview"); - } - - if (passes_it == content.end ()) - { - throw std::runtime_error ("Effect must have a pass list"); - } - - if (dependencies_it == content.end ()) - { - throw std::runtime_error ("Effect must have dependencies"); - } - CEffect* effect = new CEffect ( *name_it, *description_it, diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index 4ca86b0..f11a74e 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -31,21 +31,11 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( const irr::core::vector3df& angles) { auto image_it = data.find ("image"); - auto size_it = data.find ("size"); - - if (size_it == data.end ()) - { - throw std::runtime_error ("Images must have size"); - } + auto size_it = jsonFindValueRequired(&data, "size", "Images must have size"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get ().c_str ())); - auto material_it = content.find ("material"); - - if (material_it == content.end ()) - { - throw std::runtime_error ("Image must have a material"); - } + auto material_it = jsonFindValueRequired(&content, "material", "Image must have a material"); return new CImage ( Images::CMaterial::fromFile ((*material_it).get ().c_str ()), diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index df0b5ed..e791fee 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -1,5 +1,6 @@ #include "CParticle.h" #include "WallpaperEngine/FileSystem/FileSystem.h" +#include "WallpaperEngine/Core/Core.h" #include @@ -14,30 +15,10 @@ CParticle* CParticle::fromFile ( { json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); auto controlpoint_it = data.find ("controlpoint"); - auto starttime_it = data.find ("starttime"); - auto maxcount_it = data.find ("maxcount"); - auto emitter_it = data.find ("emitter"); - auto initializer_it = data.find ("initializer"); - - if (starttime_it == data.end ()) - { - throw std::runtime_error ("Particles must have start time"); - } - - if (maxcount_it == data.end ()) - { - throw std::runtime_error ("Particles must have maximum count"); - } - - if (emitter_it == data.end ()) - { - throw std::runtime_error ("Particles must have emitters"); - } - - if (initializer_it == data.end ()) - { - throw std::runtime_error ("Particles must have initializers"); - } + auto starttime_it = jsonFindValueRequired(&data, "starttime", "Particles must have start time"); + auto maxcount_it = jsonFindValueRequired(&data, "maxcount", "Particles must have maximum count"); + auto emitter_it = jsonFindValueRequired(&data, "emitter", "Particles must have emitters"); + auto initializer_it = jsonFindValueRequired(&data, "initializer", "Particles must have initializers"); CParticle* particle = new CParticle ( *starttime_it, diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 6f6f6f4..c74728c 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -3,6 +3,8 @@ #include "WallpaperEngine/Core/CObject.h" #include "CSound.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects; CSound::CSound ( @@ -25,12 +27,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - auto sound_it = data.find ("sound"); - - if (sound_it == data.end ()) - { - throw std::runtime_error ("Sound information not present"); - } + auto sound_it = jsonFindValueRequired(&data, "sound", "Sound information not present"); if ((*sound_it).is_array () == false) { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp index c890115..6b57c8b 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -1,5 +1,7 @@ #include "CBind.h" +#include "WallpaperEngine/Core/Core.h" + #include using namespace WallpaperEngine::Core::Objects::Effects; @@ -12,18 +14,8 @@ CBind::CBind (std::string name, irr::u32 index) : CBind* CBind::fromJSON (json data) { - auto name_it = data.find ("name"); - auto index_it = data.find ("index"); - - if (name_it == data.end ()) - { - throw std::runtime_error ("bind must have texture name"); - } - - if (index_it == data.end ()) - { - throw std::runtime_error ("bind must have index"); - } + auto name_it = jsonFindValueRequired(&data, "name", "bind must have texture name"); + auto index_it = jsonFindValueRequired(&data, "index", "bind must have index"); return new CBind (*name_it, *index_it); } diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index af269b2..b930fa7 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -3,6 +3,7 @@ #include #include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core::Objects; @@ -37,12 +38,7 @@ CMaterial* CMaterial::fromJSON (json data, const std::string& target) CMaterial* CMaterial::fromJSON (json data) { - auto passes_it = data.find ("passes"); - - if (passes_it == data.end ()) - { - throw std::runtime_error ("Material must have at least one pass"); - } + auto passes_it = jsonFindValueRequired(&data, "passes", "Material must have at least one pass"); CMaterial* material = new CMaterial (); diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 8db6d1a..a1de485 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -1,5 +1,7 @@ #include "CPass.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Images::Materials; @@ -14,39 +16,14 @@ CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, CPass* CPass::fromJSON (json data) { - auto blending_it = data.find ("blending"); - auto cullmode_it = data.find ("cullmode"); - auto depthtest_it = data.find ("depthtest"); - auto depthwrite_it = data.find ("depthwrite"); - auto shader_it = data.find ("shader"); + auto blending_it = jsonFindValueRequired(&data, "blending", "Material pass must have blending specified"); + auto cullmode_it = jsonFindValueRequired(&data, "cullmode", "Material pass must have cullmode specified"); + auto depthtest_it = jsonFindValueRequired(&data, "depthtest", "Material pass must have depthtest specified"); + auto depthwrite_it = jsonFindValueRequired(&data, "depthwrite", "Material pass must have depthwrite specified"); + auto shader_it = jsonFindValueRequired(&data, "shader", "Material pass must have shader specified"); auto textures_it = data.find ("textures"); auto combos_it = data.find ("combos"); - if (blending_it == data.end ()) - { - throw std::runtime_error ("Material pass must have blending specified"); - } - - if (cullmode_it == data.end ()) - { - throw std::runtime_error ("Material pass must have cullmode specified"); - } - - if (depthtest_it == data.end ()) - { - throw std::runtime_error ("Material pass must have depthtest specified"); - } - - if (depthwrite_it == data.end ()) - { - throw std::runtime_error ("Material pass must have depthwrite specified"); - } - - if (shader_it == data.end ()) - { - throw std::runtime_error ("Material pass must have shader specified"); - } - if (textures_it != data.end ()) { // TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index b89d975..b86edc4 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -7,14 +7,9 @@ using namespace WallpaperEngine::Core::Objects::Particles; CControlPoint* CControlPoint::fromJSON (json data) { auto flags_it = data.find ("flags"); - auto id_it = data.find ("id"); + auto id_it = jsonFindValueRequired(&data, "id", "Particle's control point must have id"); auto offset_it = data.find ("offset"); - if (id_it == data.end ()) - { - throw std::runtime_error ("Particle's control point must have id"); - } - CControlPoint* controlpoint = new CControlPoint (*id_it, 0); if (offset_it != data.end ()) diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 21cccbe..e218caa 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -6,43 +6,13 @@ using namespace WallpaperEngine::Core::Objects::Particles; CEmitter* CEmitter::fromJSON (json data) { - auto directions_it = data.find ("directions"); - auto distancemax_it = data.find ("distancemax"); - auto distancemin_it = data.find ("distancemin"); + auto directions_it = jsonFindValueRequired(&data, "directions", "Particle emitter must have direction specified"); + auto distancemax_it = jsonFindValueRequired(&data, "distancemax", "Particle emitter must have maximum distance"); + auto distancemin_it = jsonFindValueRequired(&data, "distancemin", "Particle emitter must have minimum distance"); auto id_it = data.find ("id"); - auto name_it = data.find ("name"); - auto origin_it = data.find ("origin"); - auto rate_it = data.find ("rate"); - - if (directions_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have direction specified"); - } - - if (distancemax_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have maximum distance"); - } - - if (distancemin_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have minimum distance"); - } - - if (name_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have a name"); - } - - if (origin_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have an origin"); - } - - if (rate_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have a rate"); - } + auto name_it = jsonFindValueRequired(&data, "name", "Particle emitter must have a name"); + auto origin_it = jsonFindValueRequired(&data, "origin", "Particle emitter must have an origin"); + auto rate_it = jsonFindValueRequired(&data, "rate", "Particle emitter must have a rate"); return new CEmitter ( WallpaperEngine::Core::ato3vf (*directions_it), diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index 39bf0f0..88ade0f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -1,5 +1,6 @@ #include "CInitializer.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h" @@ -13,14 +14,9 @@ using namespace WallpaperEngine::Core::Objects::Particles; CInitializer* CInitializer::fromJSON (json data) { auto id_it = data.find ("id"); - auto name_it = data.find ("name"); + auto name_it = jsonFindValueRequired(&data, "name", "Particle's initializer must have a name"); irr::u32 id = ((id_it == data.end ()) ? 0 : (irr::u32) (*id_it)); - if (name_it == data.end ()) - { - throw std::runtime_error ("Particle's initializer must have a name"); - } - if (*name_it == "lifetimerandom") { return Initializers::CLifeTimeRandom::fromJSON (data, id); diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index 57be620..b538689 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -1,21 +1,13 @@ #include "CAlphaRandom.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAlphaRandom* CAlphaRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Alpharandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Alpharandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Alpharandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "max", "Alpharandom initializer must have a maximum value"); return new CAlphaRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index de3b5a6..7be392c 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -6,18 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Angularvelocityrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Angularvelocityrandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Angularvelocityrandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "max", "Angularvelocityrandom initializer must have a maximum value"); return new CAngularVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 927d7d6..79a19ab 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -6,18 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Colorrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Colorrandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Colorrandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "min", "Colorrandom initializer must have a maximum value"); return new CColorRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index c60ef6b..8536d81 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -1,21 +1,13 @@ #include "CLifeTimeRandom.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Lifetimerandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Lifetimerandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Lifetimerandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "min", "Lifetimerandom initializer must have a maximum value"); return new CLifeTimeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index ad67131..fbe76e9 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -1,21 +1,13 @@ #include "CSizeRandom.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Sizerandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Sizerandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Sizerandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "min", "Sizerandom initializer must have a maximum value"); return new CSizeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 6c652fe..5904bee 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -6,18 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CVelocityRandom* CVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Velocityrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Velocityrandom initializer must have a maximum value"); - } + auto min_it = jsonFindValueRequired(&data, "min", "Velocityrandom initializer must have a minimum value"); + auto max_it = jsonFindValueRequired(&data, "max", "Velocityrandom initializer must have a maximum value"); return new CVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index 9054638..55e5990 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -1,24 +1,16 @@ #include "CProperty.h" #include "CPropertyColor.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Projects; CProperty* CProperty::fromJSON (json data, const std::string& name) { - auto type = data.find ("type"); - auto value = data.find ("value"); + auto type = jsonFindValueRequired(&data, "type", "Project properties must have the type field"); + auto value = jsonFindValueRequired(&data, "value", "Project properties must have the value field"); auto text = data.find ("text"); - if (value == data.end ()) - { - throw std::runtime_error ("Project properties must have the value field"); - } - - if (type == data.end ()) - { - throw std::runtime_error ("Project properties must have the type field"); - } - if (*type == CPropertyColor::Type) { return CPropertyColor::fromJSON (data, name); diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index eadf5e0..5cab7ee 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -27,24 +27,9 @@ const irr::core::vector3df& CCamera::getUp () const CCamera* CCamera::fromJSON (json data) { - auto center_it = data.find ("center"); - auto eye_it = data.find ("eye"); - auto up_it = data.find ("up"); - - if (center_it == data.end ()) - { - throw std::runtime_error ("Camera must have a center position"); - } - - if (eye_it == data.end ()) - { - throw std::runtime_error ("Camera must have an eye position"); - } - - if (up_it == data.end ()) - { - throw std::runtime_error ("Camera must have a up position"); - } + auto center_it = jsonFindValueRequired(&data, "center", "Camera must have a center position"); + auto eye_it = jsonFindValueRequired(&data, "eye", "Camera must have an eye position"); + auto up_it = jsonFindValueRequired(&data, "up", "Camera must have a up position"); return new CCamera ( WallpaperEngine::Core::ato3vf (*center_it), diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index 45bd412..58a1c60 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -21,18 +21,8 @@ const irr::u32& CProjection::getHeight () const CProjection* CProjection::fromJSON (json data) { - auto width_it = data.find ("width"); - auto height_it = data.find ("height"); - - if (width_it == data.end ()) - { - throw std::runtime_error ("Projection must have width"); - } - - if (height_it == data.end ()) - { - throw std::runtime_error ("Projection must have height"); - } + auto width_it = jsonFindValueRequired(&data, "width", "Projection must have width"); + auto height_it = jsonFindValueRequired(&data, "height", "Projection must have height"); return new CProjection ( *width_it, diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index a287611..2aa8313 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -17,6 +17,8 @@ #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" +using namespace WallpaperEngine::Core; + namespace WallpaperEngine::Render::Shaders { Compiler::Compiler (Irrlicht::CContext* context, irr::io::path& file, Type type, const std::map& combos, bool recursive) : @@ -483,17 +485,12 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseComboConfiguration (const std::string& content) { json data = json::parse (content); - auto combo = data.find ("combo"); - auto defvalue = data.find ("default"); + auto combo = jsonFindValueRequired(&data, "combo", "cannot parse combo information"); + auto defvalue = jsonFindValueRequired(&data, "default", "cannot parse combo information"); // add line feed just in case this->m_compiledContent += "\n"; - if (combo == data.end () || defvalue == data.end ()) - { - throw std::runtime_error ("cannot parse combo information"); - } - // check the combos std::map::const_iterator entry = this->m_combos.find ((*combo).get ()); From 5122206d8307bb4356335a1f76cba7984d01f379 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 24 Mar 2020 15:38:56 +1000 Subject: [PATCH 23/31] Renames jsonFindValueRequired to jsonFindRequired --- src/WallpaperEngine/Core/CObject.cpp | 10 ++--- src/WallpaperEngine/Core/CScene.cpp | 40 +++++++++---------- src/WallpaperEngine/Core/Core.cpp | 2 +- src/WallpaperEngine/Core/Core.h | 2 +- src/WallpaperEngine/Core/Objects/CEffect.cpp | 14 +++---- src/WallpaperEngine/Core/Objects/CImage.cpp | 4 +- .../Core/Objects/CParticle.cpp | 8 ++-- src/WallpaperEngine/Core/Objects/CSound.cpp | 2 +- .../Core/Objects/Effects/CBind.cpp | 4 +- .../Core/Objects/Images/CMaterial.cpp | 2 +- .../Core/Objects/Images/Materials/CPass.cpp | 10 ++--- .../Core/Objects/Particles/CControlPoint.cpp | 2 +- .../Core/Objects/Particles/CEmitter.cpp | 12 +++--- .../Core/Objects/Particles/CInitializer.cpp | 2 +- .../Particles/Initializers/CAlphaRandom.cpp | 4 +- .../Initializers/CAngularVelocityRandom.cpp | 4 +- .../Particles/Initializers/CColorRandom.cpp | 4 +- .../Initializers/CLifeTimeRandom.cpp | 4 +- .../Particles/Initializers/CSizeRandom.cpp | 4 +- .../Initializers/CVelocityRandom.cpp | 4 +- .../Core/Projects/CProperty.cpp | 4 +- src/WallpaperEngine/Core/Scenes/CCamera.cpp | 6 +-- .../Core/Scenes/CProjection.cpp | 4 +- .../Render/Shaders/Compiler.cpp | 4 +- 24 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index dd94a56..f53a743 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -29,12 +29,12 @@ CObject::CObject ( CObject* CObject::fromJSON (json data) { - auto id_it = jsonFindValueRequired(&data, "id", "Objects must have id"); + auto id_it = jsonFindRequired (&data, "id", "Objects must have id"); auto visible_it = data.find ("visible"); - auto origin_it = jsonFindValueRequired(&data, "origin", "Objects must have origin point"); - auto scale_it = jsonFindValueRequired(&data, "scale", "Objects must have scale"); - auto angles_it = jsonFindValueRequired(&data, "angles", "Objects must have angles"); - auto name_it = jsonFindValueRequired(&data, "name", "Objects must have name"); + auto origin_it = jsonFindRequired (&data, "origin", "Objects must have origin point"); + auto scale_it = jsonFindRequired (&data, "scale", "Objects must have scale"); + auto angles_it = jsonFindRequired (&data, "angles", "Objects must have angles"); + auto name_it = jsonFindRequired (&data, "name", "Objects must have name"); auto effects_it = data.find ("effects"); auto dependencies_it = data.find ("dependencies"); diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index 835040f..ab7d937 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -50,27 +50,27 @@ CScene* CScene::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto camera_it = jsonFindValueRequired(&content, "camera", "Scenes must have a defined camera"); - auto general_it = jsonFindValueRequired(&content, "general", "Scenes must have a general section"); - auto objects_it = jsonFindValueRequired(&content, "objects", "Scenes must have a list of objects to display"); + auto camera_it = jsonFindRequired (&content, "camera", "Scenes must have a defined camera"); + auto general_it = jsonFindRequired (&content, "general", "Scenes must have a general section"); + auto objects_it = jsonFindRequired (&content, "objects", "Scenes must have a list of objects to display"); - auto ambientcolor_it = jsonFindValueRequired(&(*general_it), "ambientcolor", "General section must have ambient color"); - auto bloom_it = jsonFindValueRequired(&(*general_it), "bloom", "General section must have bloom flag"); - auto bloomstrength_it = jsonFindValueRequired(&(*general_it), "bloomstrength", "General section must have bloom strength"); - auto bloomthreshold_it = jsonFindValueRequired(&(*general_it), "bloomthreshold", "General section must have bloom threshold"); - auto camerafade_it = jsonFindValueRequired(&(*general_it), "camerafade", "General section must have camera fade"); - auto cameraparallax_it = jsonFindValueRequired(&(*general_it), "cameraparallax", "General section must have camera parallax"); - auto cameraparallaxamount_it = jsonFindValueRequired(&(*general_it), "cameraparallaxamount", "General section must have camera parallax amount"); - auto cameraparallaxdelay_it = jsonFindValueRequired(&(*general_it), "cameraparallaxdelay", "General section must have camera parallax delay"); - auto cameraparallaxmouseinfluence_it = jsonFindValueRequired(&(*general_it), "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); - auto camerapreview_it = jsonFindValueRequired(&(*general_it), "camerapreview", "General section must have camera preview"); - auto camerashake_it = jsonFindValueRequired(&(*general_it), "camerashake", "General section must have camera shake"); - auto camerashakeamplitude_it = jsonFindValueRequired(&(*general_it), "camerashakeamplitude", "General section must have camera shake amplitude"); - auto camerashakeroughness_it = jsonFindValueRequired(&(*general_it), "camerashakeroughness", "General section must have camera shake roughness"); - auto camerashakespeed_it = jsonFindValueRequired(&(*general_it), "camerashakespeed", "General section must have camera shake speed"); - auto clearcolor_it = jsonFindValueRequired(&(*general_it), "clearcolor", "General section must have clear color"); - auto orthogonalprojection_it = jsonFindValueRequired(&(*general_it), "orthogonalprojection", "General section must have orthogonal projection info"); - auto skylightcolor_it = jsonFindValueRequired(&(*general_it), "skylightcolor", "General section must have skylight color"); + auto ambientcolor_it = jsonFindRequired (&(*general_it), "ambientcolor", "General section must have ambient color"); + auto bloom_it = jsonFindRequired (&(*general_it), "bloom", "General section must have bloom flag"); + auto bloomstrength_it = jsonFindRequired (&(*general_it), "bloomstrength", "General section must have bloom strength"); + auto bloomthreshold_it = jsonFindRequired (&(*general_it), "bloomthreshold", "General section must have bloom threshold"); + auto camerafade_it = jsonFindRequired (&(*general_it), "camerafade", "General section must have camera fade"); + auto cameraparallax_it = jsonFindRequired (&(*general_it), "cameraparallax", "General section must have camera parallax"); + auto cameraparallaxamount_it = jsonFindRequired (&(*general_it), "cameraparallaxamount", "General section must have camera parallax amount"); + auto cameraparallaxdelay_it = jsonFindRequired (&(*general_it), "cameraparallaxdelay", "General section must have camera parallax delay"); + auto cameraparallaxmouseinfluence_it = jsonFindRequired (&(*general_it), "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); + auto camerapreview_it = jsonFindRequired (&(*general_it), "camerapreview", "General section must have camera preview"); + auto camerashake_it = jsonFindRequired (&(*general_it), "camerashake", "General section must have camera shake"); + auto camerashakeamplitude_it = jsonFindRequired (&(*general_it), "camerashakeamplitude", "General section must have camera shake amplitude"); + auto camerashakeroughness_it = jsonFindRequired (&(*general_it), "camerashakeroughness", "General section must have camera shake roughness"); + auto camerashakespeed_it = jsonFindRequired (&(*general_it), "camerashakespeed", "General section must have camera shake speed"); + auto clearcolor_it = jsonFindRequired (&(*general_it), "clearcolor", "General section must have clear color"); + auto orthogonalprojection_it = jsonFindRequired (&(*general_it), "orthogonalprojection", "General section must have orthogonal projection info"); + auto skylightcolor_it = jsonFindRequired (&(*general_it), "skylightcolor", "General section must have skylight color"); CScene* scene = new CScene ( Scenes::CCamera::fromJSON (*camera_it), diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 662b542..d496547 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -60,7 +60,7 @@ irr::video::SColor Core::atoSColor (const std::string& str) return Core::atoSColor (str.c_str ()); } -nlohmann::detail::iter_impl jsonFindValueRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) +nlohmann::detail::iter_impl jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) { auto value = data->find (key); if (value == data->end ()) diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index d52d078..f069fb2 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -18,5 +18,5 @@ namespace WallpaperEngine::Core irr::video::SColor atoSColor (const char *str); irr::video::SColor atoSColor (const std::string& str); - nlohmann::detail::iter_impl jsonFindValueRequired (nlohmann::json *data, const char *key, const char *notFoundMsg); + nlohmann::detail::iter_impl jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg); }; diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index a23946f..a5a159c 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -30,17 +30,17 @@ CEffect::CEffect ( CEffect* CEffect::fromJSON (json data, Core::CObject* object) { - auto file_it = jsonFindValueRequired(&data, "file", "Object effect must have a file"); + auto file_it = jsonFindRequired (&data, "file", "Object effect must have a file"); auto effectpasses_it = data.find ("passes"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get ().c_str ())); - auto name_it = jsonFindValueRequired(&content, "name", "Effect must have a name"); - auto description_it = jsonFindValueRequired(&content, "description", "Effect must have a description"); - auto group_it = jsonFindValueRequired(&content, "group", "Effect must have a group"); - auto preview_it = jsonFindValueRequired(&content, "preview", "Effect must have a preview"); - auto passes_it = jsonFindValueRequired(&content, "passes", "Effect must have a pass list"); - auto dependencies_it = jsonFindValueRequired(&content, "dependencies", ""); + auto name_it = jsonFindRequired (&content, "name", "Effect must have a name"); + auto description_it = jsonFindRequired (&content, "description", "Effect must have a description"); + auto group_it = jsonFindRequired (&content, "group", "Effect must have a group"); + auto preview_it = jsonFindRequired (&content, "preview", "Effect must have a 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 ( diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index f11a74e..e3eb080 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -31,11 +31,11 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( const irr::core::vector3df& angles) { auto image_it = data.find ("image"); - auto size_it = jsonFindValueRequired(&data, "size", "Images must have size"); + auto size_it = jsonFindRequired (&data, "size", "Images must have size"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get ().c_str ())); - auto material_it = jsonFindValueRequired(&content, "material", "Image must have a material"); + auto material_it = jsonFindRequired (&content, "material", "Image must have a material"); return new CImage ( Images::CMaterial::fromFile ((*material_it).get ().c_str ()), diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index e791fee..0564818 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -15,10 +15,10 @@ CParticle* CParticle::fromFile ( { json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); auto controlpoint_it = data.find ("controlpoint"); - auto starttime_it = jsonFindValueRequired(&data, "starttime", "Particles must have start time"); - auto maxcount_it = jsonFindValueRequired(&data, "maxcount", "Particles must have maximum count"); - auto emitter_it = jsonFindValueRequired(&data, "emitter", "Particles must have emitters"); - auto initializer_it = jsonFindValueRequired(&data, "initializer", "Particles must have initializers"); + auto starttime_it = jsonFindRequired (&data, "starttime", "Particles must have start time"); + auto maxcount_it = jsonFindRequired (&data, "maxcount", "Particles must have maximum count"); + auto emitter_it = jsonFindRequired (&data, "emitter", "Particles must have emitters"); + auto initializer_it = jsonFindRequired (&data, "initializer", "Particles must have initializers"); CParticle* particle = new CParticle ( *starttime_it, diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index c74728c..65f7668 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -27,7 +27,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - auto sound_it = jsonFindValueRequired(&data, "sound", "Sound information not present"); + auto sound_it = jsonFindRequired (&data, "sound", "Sound information not present"); if ((*sound_it).is_array () == false) { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp index 6b57c8b..ab8ce5e 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -14,8 +14,8 @@ CBind::CBind (std::string name, irr::u32 index) : CBind* CBind::fromJSON (json data) { - auto name_it = jsonFindValueRequired(&data, "name", "bind must have texture name"); - auto index_it = jsonFindValueRequired(&data, "index", "bind must have index"); + auto name_it = jsonFindRequired (&data, "name", "bind must have texture name"); + auto index_it = jsonFindRequired (&data, "index", "bind must have index"); return new CBind (*name_it, *index_it); } diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index b930fa7..22b9bb6 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -38,7 +38,7 @@ CMaterial* CMaterial::fromJSON (json data, const std::string& target) CMaterial* CMaterial::fromJSON (json data) { - auto passes_it = jsonFindValueRequired(&data, "passes", "Material must have at least one pass"); + auto passes_it = jsonFindRequired (&data, "passes", "Material must have at least one pass"); CMaterial* material = new CMaterial (); diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index a1de485..cb0f23c 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -16,11 +16,11 @@ CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, CPass* CPass::fromJSON (json data) { - auto blending_it = jsonFindValueRequired(&data, "blending", "Material pass must have blending specified"); - auto cullmode_it = jsonFindValueRequired(&data, "cullmode", "Material pass must have cullmode specified"); - auto depthtest_it = jsonFindValueRequired(&data, "depthtest", "Material pass must have depthtest specified"); - auto depthwrite_it = jsonFindValueRequired(&data, "depthwrite", "Material pass must have depthwrite specified"); - auto shader_it = jsonFindValueRequired(&data, "shader", "Material pass must have shader specified"); + auto blending_it = jsonFindRequired (&data, "blending", "Material pass must have blending specified"); + auto cullmode_it = jsonFindRequired (&data, "cullmode", "Material pass must have cullmode specified"); + auto depthtest_it = jsonFindRequired (&data, "depthtest", "Material pass must have depthtest specified"); + auto depthwrite_it = jsonFindRequired (&data, "depthwrite", "Material pass must have depthwrite specified"); + auto shader_it = jsonFindRequired (&data, "shader", "Material pass must have shader specified"); auto textures_it = data.find ("textures"); auto combos_it = data.find ("combos"); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index b86edc4..157e0d8 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -7,7 +7,7 @@ using namespace WallpaperEngine::Core::Objects::Particles; CControlPoint* CControlPoint::fromJSON (json data) { auto flags_it = data.find ("flags"); - auto id_it = jsonFindValueRequired(&data, "id", "Particle's control point must have id"); + auto id_it = jsonFindRequired (&data, "id", "Particle's control point must have id"); auto offset_it = data.find ("offset"); CControlPoint* controlpoint = new CControlPoint (*id_it, 0); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index e218caa..55e760f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -6,13 +6,13 @@ using namespace WallpaperEngine::Core::Objects::Particles; CEmitter* CEmitter::fromJSON (json data) { - auto directions_it = jsonFindValueRequired(&data, "directions", "Particle emitter must have direction specified"); - auto distancemax_it = jsonFindValueRequired(&data, "distancemax", "Particle emitter must have maximum distance"); - auto distancemin_it = jsonFindValueRequired(&data, "distancemin", "Particle emitter must have minimum distance"); + auto directions_it = jsonFindRequired (&data, "directions", "Particle emitter must have direction specified"); + auto distancemax_it = jsonFindRequired (&data, "distancemax", "Particle emitter must have maximum distance"); + auto distancemin_it = jsonFindRequired (&data, "distancemin", "Particle emitter must have minimum distance"); auto id_it = data.find ("id"); - auto name_it = jsonFindValueRequired(&data, "name", "Particle emitter must have a name"); - auto origin_it = jsonFindValueRequired(&data, "origin", "Particle emitter must have an origin"); - auto rate_it = jsonFindValueRequired(&data, "rate", "Particle emitter must have a rate"); + auto name_it = jsonFindRequired (&data, "name", "Particle emitter must have a name"); + auto origin_it = jsonFindRequired (&data, "origin", "Particle emitter must have an origin"); + auto rate_it = jsonFindRequired (&data, "rate", "Particle emitter must have a rate"); return new CEmitter ( WallpaperEngine::Core::ato3vf (*directions_it), diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index 88ade0f..a940b87 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -14,7 +14,7 @@ using namespace WallpaperEngine::Core::Objects::Particles; CInitializer* CInitializer::fromJSON (json data) { auto id_it = data.find ("id"); - auto name_it = jsonFindValueRequired(&data, "name", "Particle's initializer must have a name"); + auto name_it = jsonFindRequired (&data, "name", "Particle's initializer must have a name"); irr::u32 id = ((id_it == data.end ()) ? 0 : (irr::u32) (*id_it)); if (*name_it == "lifetimerandom") diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index b538689..ed18dda 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAlphaRandom* CAlphaRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Alpharandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "max", "Alpharandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Alpharandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "max", "Alpharandom initializer must have a maximum value"); return new CAlphaRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index 7be392c..251847b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Angularvelocityrandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "max", "Angularvelocityrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Angularvelocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "max", "Angularvelocityrandom initializer must have a maximum value"); return new CAngularVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 79a19ab..564ecff 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Colorrandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "min", "Colorrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Colorrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "min", "Colorrandom initializer must have a maximum value"); return new CColorRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 8536d81..7fc6495 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Lifetimerandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "min", "Lifetimerandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Lifetimerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "min", "Lifetimerandom initializer must have a maximum value"); return new CLifeTimeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index fbe76e9..8075424 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Sizerandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "min", "Sizerandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Sizerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "min", "Sizerandom initializer must have a maximum value"); return new CSizeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 5904bee..11272b6 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -6,8 +6,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CVelocityRandom* CVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindValueRequired(&data, "min", "Velocityrandom initializer must have a minimum value"); - auto max_it = jsonFindValueRequired(&data, "max", "Velocityrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (&data, "min", "Velocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (&data, "max", "Velocityrandom initializer must have a maximum value"); return new CVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index 55e5990..fee5d5e 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -7,8 +7,8 @@ using namespace WallpaperEngine::Core::Projects; CProperty* CProperty::fromJSON (json data, const std::string& name) { - auto type = jsonFindValueRequired(&data, "type", "Project properties must have the type field"); - auto value = jsonFindValueRequired(&data, "value", "Project properties must have the value field"); + auto type = jsonFindRequired (&data, "type", "Project properties must have the type field"); + auto value = jsonFindRequired (&data, "value", "Project properties must have the value field"); auto text = data.find ("text"); if (*type == CPropertyColor::Type) diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index 5cab7ee..28939b6 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -27,9 +27,9 @@ const irr::core::vector3df& CCamera::getUp () const CCamera* CCamera::fromJSON (json data) { - auto center_it = jsonFindValueRequired(&data, "center", "Camera must have a center position"); - auto eye_it = jsonFindValueRequired(&data, "eye", "Camera must have an eye position"); - auto up_it = jsonFindValueRequired(&data, "up", "Camera must have a up position"); + auto center_it = jsonFindRequired (&data, "center", "Camera must have a center position"); + auto eye_it = jsonFindRequired (&data, "eye", "Camera must have an eye position"); + auto up_it = jsonFindRequired (&data, "up", "Camera must have a up position"); return new CCamera ( WallpaperEngine::Core::ato3vf (*center_it), diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index 58a1c60..ca81861 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -21,8 +21,8 @@ const irr::u32& CProjection::getHeight () const CProjection* CProjection::fromJSON (json data) { - auto width_it = jsonFindValueRequired(&data, "width", "Projection must have width"); - auto height_it = jsonFindValueRequired(&data, "height", "Projection must have height"); + auto width_it = jsonFindRequired (&data, "width", "Projection must have width"); + auto height_it = jsonFindRequired (&data, "height", "Projection must have height"); return new CProjection ( *width_it, diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 2aa8313..64c49fd 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -485,8 +485,8 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseComboConfiguration (const std::string& content) { json data = json::parse (content); - auto combo = jsonFindValueRequired(&data, "combo", "cannot parse combo information"); - auto defvalue = jsonFindValueRequired(&data, "default", "cannot parse combo information"); + auto combo = jsonFindRequired (&data, "combo", "cannot parse combo information"); + auto defvalue = jsonFindRequired (&data, "default", "cannot parse combo information"); // add line feed just in case this->m_compiledContent += "\n"; From 7baa77ef7e3b49ea7264d2cd50ed32fa208c72d4 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 24 Mar 2020 19:04:44 +1000 Subject: [PATCH 24/31] Missed a few replacements of content.find --- src/WallpaperEngine/Core/CProject.cpp | 6 +++--- src/WallpaperEngine/Core/Core.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index 663416b..ba1940b 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -18,9 +18,9 @@ CProject* CProject::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto title = jsonFindValueRequired (&content, "title", "Project title missing"); - auto type = jsonFindValueRequired (&content, "title", "Project type missing"); - auto file = jsonFindValueRequired (&content, "title", "Project's main file missing"); + auto title = jsonFindRequired (&content, "title", "Project title missing"); + auto type = jsonFindRequired (&content, "title", "Project type missing"); + auto file = jsonFindRequired (&content, "title", "Project's main file missing"); auto general = content.find ("general"); CProject* project = new CProject ( diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index d496547..75c7076 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -60,7 +60,7 @@ irr::video::SColor Core::atoSColor (const std::string& str) return Core::atoSColor (str.c_str ()); } -nlohmann::detail::iter_impl jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) +nlohmann::detail::iter_impl Core::jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) { auto value = data->find (key); if (value == data->end ()) From 52fc0ffbacb1c17d13a64436877c8cfb0067e908 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 24 Mar 2020 20:31:31 +1000 Subject: [PATCH 25/31] Forgot to change key parameter to correct value --- src/WallpaperEngine/Core/CProject.cpp | 4 ++-- src/WallpaperEngine/FileSystem/FileSystem.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index ba1940b..5073345 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -19,8 +19,8 @@ CProject* CProject::fromFile (const irr::io::path& filename) json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); auto title = jsonFindRequired (&content, "title", "Project title missing"); - auto type = jsonFindRequired (&content, "title", "Project type missing"); - auto file = jsonFindRequired (&content, "title", "Project's main file missing"); + auto type = jsonFindRequired (&content, "type", "Project type missing"); + auto file = jsonFindRequired (&content, "file", "Project's main file missing"); auto general = content.find ("general"); CProject* project = new CProject ( diff --git a/src/WallpaperEngine/FileSystem/FileSystem.cpp b/src/WallpaperEngine/FileSystem/FileSystem.cpp index 0ee94a6..5011cbc 100644 --- a/src/WallpaperEngine/FileSystem/FileSystem.cpp +++ b/src/WallpaperEngine/FileSystem/FileSystem.cpp @@ -1,6 +1,8 @@ // filesystem includes #include "FileSystem.h" +#include + // engine includes #include "WallpaperEngine/Irrlicht/CContext.h" @@ -10,6 +12,7 @@ using namespace WallpaperEngine; std::string FileSystem::loadFullFile (const irr::io::path& file) { + std::cout << file.c_str() << std::endl; irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file); if (reader == nullptr) From 8172c970b13dcd746ef28c775734158f4ad28227 Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Tue, 24 Mar 2020 20:41:32 +1000 Subject: [PATCH 26/31] Forgot to change key parameter to correct value --- .../Core/Objects/Particles/Initializers/CColorRandom.cpp | 2 +- .../Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp | 2 +- .../Core/Objects/Particles/Initializers/CSizeRandom.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 564ecff..36e195e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -7,7 +7,7 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { auto min_it = jsonFindRequired (&data, "min", "Colorrandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "min", "Colorrandom initializer must have a maximum value"); + auto max_it = jsonFindRequired (&data, "max", "Colorrandom initializer must have a maximum value"); return new CColorRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 7fc6495..5bbd0a1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -7,7 +7,7 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { auto min_it = jsonFindRequired (&data, "min", "Lifetimerandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "min", "Lifetimerandom initializer must have a maximum value"); + auto max_it = jsonFindRequired (&data, "max", "Lifetimerandom initializer must have a maximum value"); return new CLifeTimeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index 8075424..0ef3b8c 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -7,7 +7,7 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { auto min_it = jsonFindRequired (&data, "min", "Sizerandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "min", "Sizerandom initializer must have a maximum value"); + auto max_it = jsonFindRequired (&data, "max", "Sizerandom initializer must have a maximum value"); return new CSizeRandom (id, *min_it, *max_it); } From b37c5192093b4a8bdf960aa11f86a046095035ac Mon Sep 17 00:00:00 2001 From: IceCryptonym Date: Wed, 25 Mar 2020 10:20:34 +1000 Subject: [PATCH 27/31] Nitpicks --- src/WallpaperEngine/Core/CObject.cpp | 12 +++--- src/WallpaperEngine/Core/CObject.h | 3 +- src/WallpaperEngine/Core/CProject.cpp | 8 ++-- src/WallpaperEngine/Core/CProject.h | 2 +- src/WallpaperEngine/Core/CScene.cpp | 41 +++++++++---------- src/WallpaperEngine/Core/CScene.h | 3 +- src/WallpaperEngine/Core/Core.cpp | 6 +-- src/WallpaperEngine/Core/Core.h | 2 +- src/WallpaperEngine/Core/Objects/CEffect.cpp | 15 ++++--- src/WallpaperEngine/Core/Objects/CEffect.h | 2 +- src/WallpaperEngine/Core/Objects/CImage.cpp | 5 +-- src/WallpaperEngine/Core/Objects/CImage.h | 2 +- .../Core/Objects/CParticle.cpp | 9 ++-- src/WallpaperEngine/Core/Objects/CParticle.h | 2 +- src/WallpaperEngine/Core/Objects/CSound.cpp | 4 +- src/WallpaperEngine/Core/Objects/CSound.h | 2 +- .../Core/Objects/Effects/CBind.cpp | 6 +-- .../Core/Objects/Effects/CBind.h | 3 +- .../Core/Objects/Images/CMaterial.cpp | 3 +- .../Core/Objects/Images/CMaterial.h | 3 +- .../Core/Objects/Images/Materials/CPass.cpp | 12 +++--- .../Core/Objects/Images/Materials/CPass.h | 2 +- .../Core/Objects/Particles/CControlPoint.cpp | 4 +- .../Core/Objects/Particles/CControlPoint.h | 3 +- .../Core/Objects/Particles/CEmitter.cpp | 14 +++---- .../Core/Objects/Particles/CEmitter.h | 3 +- .../Core/Objects/Particles/CInitializer.cpp | 3 +- .../Core/Objects/Particles/CInitializer.h | 3 +- .../Particles/Initializers/CAlphaRandom.cpp | 6 +-- .../Particles/Initializers/CAlphaRandom.h | 3 +- .../Initializers/CAngularVelocityRandom.cpp | 6 +-- .../Initializers/CAngularVelocityRandom.h | 3 +- .../Particles/Initializers/CColorRandom.cpp | 6 +-- .../Particles/Initializers/CColorRandom.h | 3 +- .../Initializers/CLifeTimeRandom.cpp | 6 +-- .../Particles/Initializers/CLifeTimeRandom.h | 3 +- .../Particles/Initializers/CSizeRandom.cpp | 6 +-- .../Particles/Initializers/CSizeRandom.h | 3 +- .../Initializers/CVelocityRandom.cpp | 6 +-- .../Particles/Initializers/CVelocityRandom.h | 3 +- .../Core/Projects/CProperty.cpp | 6 +-- src/WallpaperEngine/Core/Projects/CProperty.h | 2 +- .../Core/Projects/CPropertyColor.cpp | 1 - .../Core/Projects/CPropertyColor.h | 2 + src/WallpaperEngine/Core/Scenes/CCamera.cpp | 7 ++-- src/WallpaperEngine/Core/Scenes/CCamera.h | 3 +- .../Core/Scenes/CProjection.cpp | 5 +-- src/WallpaperEngine/Core/Scenes/CProjection.h | 3 +- .../Render/Shaders/Compiler.cpp | 5 +-- src/WallpaperEngine/Render/Shaders/Compiler.h | 3 +- 50 files changed, 124 insertions(+), 144 deletions(-) diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index f53a743..a0f67af 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -5,8 +5,6 @@ #include "WallpaperEngine/Core/Objects/CSound.h" #include "WallpaperEngine/Core/Objects/CParticle.h" -#include "Core.h" - using namespace WallpaperEngine::Core; CObject::CObject ( @@ -29,12 +27,12 @@ CObject::CObject ( CObject* CObject::fromJSON (json data) { - auto id_it = jsonFindRequired (&data, "id", "Objects must have id"); + auto id_it = jsonFindRequired (data, "id", "Objects must have id"); auto visible_it = data.find ("visible"); - auto origin_it = jsonFindRequired (&data, "origin", "Objects must have origin point"); - auto scale_it = jsonFindRequired (&data, "scale", "Objects must have scale"); - auto angles_it = jsonFindRequired (&data, "angles", "Objects must have angles"); - auto name_it = jsonFindRequired (&data, "name", "Objects must have name"); + auto origin_it = jsonFindRequired (data, "origin", "Objects must have origin point"); + auto scale_it = jsonFindRequired (data, "scale", "Objects must have scale"); + auto angles_it = jsonFindRequired (data, "angles", "Objects must have angles"); + auto name_it = jsonFindRequired (data, "name", "Objects must have name"); auto effects_it = data.find ("effects"); auto dependencies_it = data.find ("dependencies"); diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index 67fb78a..4e036b9 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "Core.h" + #include "WallpaperEngine/Core/Objects/CEffect.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index 5073345..0fb84f7 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -2,8 +2,6 @@ #include "CProject.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core; CProject::CProject (std::string title, std::string type, CScene *scene) : @@ -18,9 +16,9 @@ CProject* CProject::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto title = jsonFindRequired (&content, "title", "Project title missing"); - auto type = jsonFindRequired (&content, "type", "Project type missing"); - auto file = jsonFindRequired (&content, "file", "Project's main file missing"); + auto title = jsonFindRequired (content, "title", "Project title missing"); + auto type = jsonFindRequired (content, "type", "Project type missing"); + auto file = jsonFindRequired (content, "file", "Project's main file missing"); auto general = content.find ("general"); CProject* project = new CProject ( diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index 570b50b..aee6396 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include "CScene.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Projects/CProperty.h" namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index ab7d937..b1339ff 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -1,7 +1,6 @@ #include "CScene.h" #include "CProject.h" -#include "Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core; @@ -50,27 +49,27 @@ CScene* CScene::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto camera_it = jsonFindRequired (&content, "camera", "Scenes must have a defined camera"); - auto general_it = jsonFindRequired (&content, "general", "Scenes must have a general section"); - auto objects_it = jsonFindRequired (&content, "objects", "Scenes must have a list of objects to display"); + auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera"); + auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section"); + auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display"); - auto ambientcolor_it = jsonFindRequired (&(*general_it), "ambientcolor", "General section must have ambient color"); - auto bloom_it = jsonFindRequired (&(*general_it), "bloom", "General section must have bloom flag"); - auto bloomstrength_it = jsonFindRequired (&(*general_it), "bloomstrength", "General section must have bloom strength"); - auto bloomthreshold_it = jsonFindRequired (&(*general_it), "bloomthreshold", "General section must have bloom threshold"); - auto camerafade_it = jsonFindRequired (&(*general_it), "camerafade", "General section must have camera fade"); - auto cameraparallax_it = jsonFindRequired (&(*general_it), "cameraparallax", "General section must have camera parallax"); - auto cameraparallaxamount_it = jsonFindRequired (&(*general_it), "cameraparallaxamount", "General section must have camera parallax amount"); - auto cameraparallaxdelay_it = jsonFindRequired (&(*general_it), "cameraparallaxdelay", "General section must have camera parallax delay"); - auto cameraparallaxmouseinfluence_it = jsonFindRequired (&(*general_it), "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); - auto camerapreview_it = jsonFindRequired (&(*general_it), "camerapreview", "General section must have camera preview"); - auto camerashake_it = jsonFindRequired (&(*general_it), "camerashake", "General section must have camera shake"); - auto camerashakeamplitude_it = jsonFindRequired (&(*general_it), "camerashakeamplitude", "General section must have camera shake amplitude"); - auto camerashakeroughness_it = jsonFindRequired (&(*general_it), "camerashakeroughness", "General section must have camera shake roughness"); - auto camerashakespeed_it = jsonFindRequired (&(*general_it), "camerashakespeed", "General section must have camera shake speed"); - auto clearcolor_it = jsonFindRequired (&(*general_it), "clearcolor", "General section must have clear color"); - auto orthogonalprojection_it = jsonFindRequired (&(*general_it), "orthogonalprojection", "General section must have orthogonal projection info"); - auto skylightcolor_it = jsonFindRequired (&(*general_it), "skylightcolor", "General section must have skylight color"); + auto ambientcolor_it = jsonFindRequired (*general_it, "ambientcolor", "General section must have ambient color"); + auto bloom_it = jsonFindRequired (*general_it, "bloom", "General section must have bloom flag"); + auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength"); + auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold"); + auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade"); + auto cameraparallax_it = jsonFindRequired (*general_it, "cameraparallax", "General section must have camera parallax"); + auto cameraparallaxamount_it = jsonFindRequired (*general_it, "cameraparallaxamount", "General section must have camera parallax amount"); + auto cameraparallaxdelay_it = jsonFindRequired (*general_it, "cameraparallaxdelay", "General section must have camera parallax delay"); + auto cameraparallaxmouseinfluence_it = jsonFindRequired (*general_it, "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); + auto camerapreview_it = jsonFindRequired (*general_it, "camerapreview", "General section must have camera preview"); + auto camerashake_it = jsonFindRequired (*general_it, "camerashake", "General section must have camera shake"); + auto camerashakeamplitude_it = jsonFindRequired (*general_it, "camerashakeamplitude", "General section must have camera shake amplitude"); + auto camerashakeroughness_it = jsonFindRequired (*general_it, "camerashakeroughness", "General section must have camera shake roughness"); + auto camerashakespeed_it = jsonFindRequired (*general_it, "camerashakespeed", "General section must have camera shake speed"); + auto clearcolor_it = jsonFindRequired (*general_it, "clearcolor", "General section must have clear color"); + auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info"); + auto skylightcolor_it = jsonFindRequired (*general_it, "skylightcolor", "General section must have skylight color"); CScene* scene = new CScene ( Scenes::CCamera::fromJSON (*camera_it), diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index 842c499..c9a828c 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -1,11 +1,12 @@ #pragma once #include -#include #include "CProject.h" #include "CObject.h" +#include "Core.h" + #include "WallpaperEngine/Core/Scenes/CCamera.h" #include "WallpaperEngine/Core/Scenes/CProjection.h" diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 75c7076..2867315 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -60,10 +60,10 @@ irr::video::SColor Core::atoSColor (const std::string& str) return Core::atoSColor (str.c_str ()); } -nlohmann::detail::iter_impl Core::jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg) +nlohmann::detail::iter_impl Core::jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg) { - auto value = data->find (key); - if (value == data->end ()) + auto value = data.find (key); + if (value == data.end ()) { throw std::runtime_error (notFoundMsg); } diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index f069fb2..7cd9612 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -18,5 +18,5 @@ namespace WallpaperEngine::Core irr::video::SColor atoSColor (const char *str); irr::video::SColor atoSColor (const std::string& str); - nlohmann::detail::iter_impl jsonFindRequired (nlohmann::json *data, const char *key, const char *notFoundMsg); + nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg); }; diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index a5a159c..f28a5d1 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -2,7 +2,6 @@ #include -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/CImage.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h" @@ -30,17 +29,17 @@ CEffect::CEffect ( CEffect* CEffect::fromJSON (json data, Core::CObject* object) { - auto file_it = jsonFindRequired (&data, "file", "Object effect must have a file"); + auto file_it = jsonFindRequired (data, "file", "Object effect must have a file"); auto effectpasses_it = data.find ("passes"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get ().c_str ())); - auto name_it = jsonFindRequired (&content, "name", "Effect must have a name"); - auto description_it = jsonFindRequired (&content, "description", "Effect must have a description"); - auto group_it = jsonFindRequired (&content, "group", "Effect must have a group"); - auto preview_it = jsonFindRequired (&content, "preview", "Effect must have a preview"); - auto passes_it = jsonFindRequired (&content, "passes", "Effect must have a pass list"); - auto dependencies_it = jsonFindRequired (&content, "dependencies", ""); + auto name_it = jsonFindRequired (content, "name", "Effect must have a name"); + auto description_it = jsonFindRequired (content, "description", "Effect must have a description"); + auto group_it = jsonFindRequired (content, "group", "Effect must have a group"); + auto preview_it = jsonFindRequired (content, "preview", "Effect must have a 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 ( diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index c05db72..61ce37e 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Effects/CFBO.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/CObject.h" diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index e3eb080..0fcbd5a 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -1,7 +1,6 @@ #include "CImage.h" #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core::Objects; @@ -31,11 +30,11 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( const irr::core::vector3df& angles) { auto image_it = data.find ("image"); - auto size_it = jsonFindRequired (&data, "size", "Images must have size"); + auto size_it = jsonFindRequired (data, "size", "Images must have size"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get ().c_str ())); - auto material_it = jsonFindRequired (&content, "material", "Image must have a material"); + auto material_it = jsonFindRequired (content, "material", "Image must have a material"); return new CImage ( Images::CMaterial::fromFile ((*material_it).get ().c_str ()), diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index 6f5c88d..477f7cf 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -1,10 +1,10 @@ #pragma once -#include #include #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index 0564818..66ab725 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -1,6 +1,5 @@ #include "CParticle.h" #include "WallpaperEngine/FileSystem/FileSystem.h" -#include "WallpaperEngine/Core/Core.h" #include @@ -15,10 +14,10 @@ CParticle* CParticle::fromFile ( { json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); auto controlpoint_it = data.find ("controlpoint"); - auto starttime_it = jsonFindRequired (&data, "starttime", "Particles must have start time"); - auto maxcount_it = jsonFindRequired (&data, "maxcount", "Particles must have maximum count"); - auto emitter_it = jsonFindRequired (&data, "emitter", "Particles must have emitters"); - auto initializer_it = jsonFindRequired (&data, "initializer", "Particles must have initializers"); + auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time"); + auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count"); + auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters"); + auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers"); CParticle* particle = new CParticle ( *starttime_it, diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index 34bf6ac..78605d3 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -1,12 +1,12 @@ #pragma once #include -#include #include "WallpaperEngine/Core/Objects/Particles/CControlPoint.h" #include "WallpaperEngine/Core/Objects/Particles/CEmitter.h" #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 65f7668..e0b0f7b 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -3,8 +3,6 @@ #include "WallpaperEngine/Core/CObject.h" #include "CSound.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects; CSound::CSound ( @@ -27,7 +25,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - auto sound_it = jsonFindRequired (&data, "sound", "Sound information not present"); + auto sound_it = jsonFindRequired (data, "sound", "Sound information not present"); if ((*sound_it).is_array () == false) { diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index a9c4173..1d220dd 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -1,8 +1,8 @@ #pragma once #include -#include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp index ab8ce5e..090cf8a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -1,7 +1,5 @@ #include "CBind.h" -#include "WallpaperEngine/Core/Core.h" - #include using namespace WallpaperEngine::Core::Objects::Effects; @@ -14,8 +12,8 @@ CBind::CBind (std::string name, irr::u32 index) : CBind* CBind::fromJSON (json data) { - auto name_it = jsonFindRequired (&data, "name", "bind must have texture name"); - auto index_it = jsonFindRequired (&data, "index", "bind must have index"); + auto name_it = jsonFindRequired (data, "name", "bind must have texture name"); + auto index_it = jsonFindRequired (data, "index", "bind must have index"); return new CBind (*name_it, *index_it); } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.h b/src/WallpaperEngine/Core/Objects/Effects/CBind.h index a4cbeb1..1b946d1 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.h @@ -3,7 +3,8 @@ #include #include -#include + +#include "WallpaperEngine/Core/Core.h" namespace WallpaperEngine::Core::Objects::Effects { diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index 22b9bb6..069b5d5 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -3,7 +3,6 @@ #include #include -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core::Objects; @@ -38,7 +37,7 @@ CMaterial* CMaterial::fromJSON (json data, const std::string& target) CMaterial* CMaterial::fromJSON (json data) { - auto passes_it = jsonFindRequired (&data, "passes", "Material must have at least one pass"); + auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass"); CMaterial* material = new CMaterial (); diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 0fe2e54..6bde2cf 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -1,11 +1,12 @@ #pragma once #include -#include #include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" #include "WallpaperEngine/Core/Objects/Effects/CBind.h" +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Images { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index cb0f23c..1e6fa6b 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -1,7 +1,5 @@ #include "CPass.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Images::Materials; @@ -16,11 +14,11 @@ CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, CPass* CPass::fromJSON (json data) { - auto blending_it = jsonFindRequired (&data, "blending", "Material pass must have blending specified"); - auto cullmode_it = jsonFindRequired (&data, "cullmode", "Material pass must have cullmode specified"); - auto depthtest_it = jsonFindRequired (&data, "depthtest", "Material pass must have depthtest specified"); - auto depthwrite_it = jsonFindRequired (&data, "depthwrite", "Material pass must have depthwrite specified"); - auto shader_it = jsonFindRequired (&data, "shader", "Material pass must have shader specified"); + auto blending_it = jsonFindRequired (data, "blending", "Material pass must have blending specified"); + auto cullmode_it = jsonFindRequired (data, "cullmode", "Material pass must have cullmode specified"); + auto depthtest_it = jsonFindRequired (data, "depthtest", "Material pass must have depthtest specified"); + auto depthwrite_it = jsonFindRequired (data, "depthwrite", "Material pass must have depthwrite specified"); + auto shader_it = jsonFindRequired (data, "shader", "Material pass must have shader specified"); auto textures_it = data.find ("textures"); auto combos_it = data.find ("combos"); diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index 517c2cd..9779211 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index 157e0d8..63775db 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -1,13 +1,11 @@ #include "CControlPoint.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles; CControlPoint* CControlPoint::fromJSON (json data) { auto flags_it = data.find ("flags"); - auto id_it = jsonFindRequired (&data, "id", "Particle's control point must have id"); + auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id"); auto offset_it = data.find ("offset"); CControlPoint* controlpoint = new CControlPoint (*id_it, 0); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index 2a00dd5..a34dcfa 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 55e760f..a0e23fc 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -1,18 +1,16 @@ #include "CEmitter.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles; CEmitter* CEmitter::fromJSON (json data) { - auto directions_it = jsonFindRequired (&data, "directions", "Particle emitter must have direction specified"); - auto distancemax_it = jsonFindRequired (&data, "distancemax", "Particle emitter must have maximum distance"); - auto distancemin_it = jsonFindRequired (&data, "distancemin", "Particle emitter must have minimum distance"); + auto directions_it = jsonFindRequired (data, "directions", "Particle emitter must have direction specified"); + auto distancemax_it = jsonFindRequired (data, "distancemax", "Particle emitter must have maximum distance"); + auto distancemin_it = jsonFindRequired (data, "distancemin", "Particle emitter must have minimum distance"); auto id_it = data.find ("id"); - auto name_it = jsonFindRequired (&data, "name", "Particle emitter must have a name"); - auto origin_it = jsonFindRequired (&data, "origin", "Particle emitter must have an origin"); - auto rate_it = jsonFindRequired (&data, "rate", "Particle emitter must have a rate"); + auto name_it = jsonFindRequired (data, "name", "Particle emitter must have a name"); + auto origin_it = jsonFindRequired (data, "origin", "Particle emitter must have an origin"); + auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate"); return new CEmitter ( WallpaperEngine::Core::ato3vf (*directions_it), diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index f574b13..1959812 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index a940b87..8cab735 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -1,6 +1,5 @@ #include "CInitializer.h" -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h" @@ -14,7 +13,7 @@ using namespace WallpaperEngine::Core::Objects::Particles; CInitializer* CInitializer::fromJSON (json data) { auto id_it = data.find ("id"); - auto name_it = jsonFindRequired (&data, "name", "Particle's initializer must have a name"); + auto name_it = jsonFindRequired (data, "name", "Particle's initializer must have a name"); irr::u32 id = ((id_it == data.end ()) ? 0 : (irr::u32) (*id_it)); if (*name_it == "lifetimerandom") diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index 0aa6ee1..3f5c1f3 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index ed18dda..d21882d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -1,13 +1,11 @@ #include "CAlphaRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAlphaRandom* CAlphaRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Alpharandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Alpharandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value"); return new CAlphaRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index 02a2d17..7531e1f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index 251847b..401eaad 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -1,13 +1,11 @@ #include "CAngularVelocityRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Angularvelocityrandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Angularvelocityrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value"); return new CAngularVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index 353dc3d..f1f6344 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 36e195e..51bd81f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -1,13 +1,11 @@ #include "CColorRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Colorrandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Colorrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value"); return new CColorRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index 306469d..54bcb1a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 5bbd0a1..be91c9c 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -1,13 +1,11 @@ #include "CLifeTimeRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Lifetimerandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Lifetimerandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value"); return new CLifeTimeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index e6c7435..f1bc8ed 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index 0ef3b8c..66ce76d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -1,13 +1,11 @@ #include "CSizeRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Sizerandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Sizerandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value"); return new CSizeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index afecd47..0c46add 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 11272b6..4db31fa 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -1,13 +1,11 @@ #include "CVelocityRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CVelocityRandom* CVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = jsonFindRequired (&data, "min", "Velocityrandom initializer must have a minimum value"); - auto max_it = jsonFindRequired (&data, "max", "Velocityrandom initializer must have a maximum value"); + auto min_it = jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value"); return new CVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index 131b061..ef06b1d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index fee5d5e..26f5c32 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -1,14 +1,12 @@ #include "CProperty.h" #include "CPropertyColor.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Projects; CProperty* CProperty::fromJSON (json data, const std::string& name) { - auto type = jsonFindRequired (&data, "type", "Project properties must have the type field"); - auto value = jsonFindRequired (&data, "value", "Project properties must have the value field"); + auto type = jsonFindRequired (data, "type", "Project properties must have the type field"); + auto value = jsonFindRequired (data, "value", "Project properties must have the value field"); auto text = data.find ("text"); if (*type == CPropertyColor::Type) diff --git a/src/WallpaperEngine/Core/Projects/CProperty.h b/src/WallpaperEngine/Core/Projects/CProperty.h index 29c4405..651b7c0 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.h +++ b/src/WallpaperEngine/Core/Projects/CProperty.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "WallpaperEngine/Core/Core.h" namespace WallpaperEngine::Core::Projects { diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp index 31e70e6..ea10468 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp @@ -1,5 +1,4 @@ #include "CPropertyColor.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Projects; diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index af4bd76..a3669bd 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -4,6 +4,8 @@ #include "CProperty.h" +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index 28939b6..3055805 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -1,5 +1,4 @@ #include "CCamera.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Scenes; @@ -27,9 +26,9 @@ const irr::core::vector3df& CCamera::getUp () const CCamera* CCamera::fromJSON (json data) { - auto center_it = jsonFindRequired (&data, "center", "Camera must have a center position"); - auto eye_it = jsonFindRequired (&data, "eye", "Camera must have an eye position"); - auto up_it = jsonFindRequired (&data, "up", "Camera must have a up position"); + auto center_it = jsonFindRequired (data, "center", "Camera must have a center position"); + auto eye_it = jsonFindRequired (data, "eye", "Camera must have an eye position"); + auto up_it = jsonFindRequired (data, "up", "Camera must have a up position"); return new CCamera ( WallpaperEngine::Core::ato3vf (*center_it), diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.h b/src/WallpaperEngine/Core/Scenes/CCamera.h index 1e9efce..7465551 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.h +++ b/src/WallpaperEngine/Core/Scenes/CCamera.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Scenes { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index ca81861..92495f3 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -1,5 +1,4 @@ #include "CProjection.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Scenes; @@ -21,8 +20,8 @@ const irr::u32& CProjection::getHeight () const CProjection* CProjection::fromJSON (json data) { - auto width_it = jsonFindRequired (&data, "width", "Projection must have width"); - auto height_it = jsonFindRequired (&data, "height", "Projection must have height"); + auto width_it = jsonFindRequired (data, "width", "Projection must have width"); + auto height_it = jsonFindRequired (data, "height", "Projection must have height"); return new CProjection ( *width_it, diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index 537735f..16f92fc 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Scenes { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 64c49fd..b7bad42 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -8,7 +8,6 @@ // shader compiler #include -#include #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h" @@ -485,8 +484,8 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseComboConfiguration (const std::string& content) { json data = json::parse (content); - auto combo = jsonFindRequired (&data, "combo", "cannot parse combo information"); - auto defvalue = jsonFindRequired (&data, "default", "cannot parse combo information"); + auto combo = jsonFindRequired (data, "combo", "cannot parse combo information"); + auto defvalue = jsonFindRequired (data, "default", "cannot parse combo information"); // add line feed just in case this->m_compiledContent += "\n"; diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 467e553..26a818a 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -4,7 +4,8 @@ #include #include #include -#include + +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" From 838c9499e7bb3847c650b57d4030fc9aade7852f Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 25 Mar 2020 14:36:07 +0100 Subject: [PATCH 28/31] ~ changed missed nlohmann::json::iter_imp to nlohmann::json::iterator from PR #12 Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Core/Core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 2867315..dda3578 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -60,7 +60,7 @@ irr::video::SColor Core::atoSColor (const std::string& str) return Core::atoSColor (str.c_str ()); } -nlohmann::detail::iter_impl Core::jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg) +nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg) { auto value = data.find (key); if (value == data.end ()) From 7f227291d2623dff212e691f0195b5794de49a03 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Thu, 26 Mar 2020 11:00:01 +0100 Subject: [PATCH 29/31] + added missing license for the DXT1 and DXT5 decompressors Signed-off-by: Alexis Maiquez --- .../Irrlicht/CImageLoaderTEX.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp b/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp index 18f86ea..d5e518e 100644 --- a/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp +++ b/src/WallpaperEngine/Irrlicht/CImageLoaderTEX.cpp @@ -372,6 +372,28 @@ namespace WallpaperEngine::Irrlicht // https://github.com/Benjamin-Dobell/s3tc-dxt-decompression // ------------------------------------------------------------------------------------ + /* + * Copyright (c) 2009 Benjamin Dobell, Glass Echidna + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + // unsigned long PackRGBA(): Helper method that packs RGBA channels into a single 4 byte pixel. // // unsigned char r: red channel. From 98e245b4cbc8ddd82632507fde7c72d20a44c44f Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 31 Mar 2020 23:32:46 +0200 Subject: [PATCH 30/31] + added error reporting for SDL initialization Signed-off-by: Alexis Maiquez --- main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 8a76317..4eed0c5 100644 --- a/main.cpp +++ b/main.cpp @@ -150,7 +150,9 @@ int main (int argc, char* argv[]) if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags)) { - IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR); + // Mix_GetError is an alias for SDL_GetError, so calling it directly will yield the correct result + // it doesn't matter if SDL_Init or Mix_Init failed, both report the errors through the same functions + IrrlichtContext->getDevice ()->getLogger ()->log ("Cannot initialize SDL audio system", SDL_GetError(),irr::ELL_ERROR); return 2; } From 5d5ce361fede30e966cf1e726b09fa7e545f9cba Mon Sep 17 00:00:00 2001 From: IceCryptonym <59789660+IceCryptonym@users.noreply.github.com> Date: Tue, 28 Apr 2020 02:50:17 +1000 Subject: [PATCH 31/31] Initial video support without audio (#14) * Adds FFmpeg to CMake * Refactors to allow support for other wallpaper types * Updates README.md for compilation requirements * Initial video support without audio * Properly support different wallpapers * Fixes videos not rendering * Nitpicks * Moves code related to rendering from Core::CVideo to Render::CVideo --- CMakeLists.txt | 13 +- CMakeModules/FindFFmpeg.cmake | 110 +++++++++++++++ README.md | 1 + main.cpp | 28 +++- src/WallpaperEngine/Core/CProject.cpp | 26 +++- src/WallpaperEngine/Core/CProject.h | 11 +- src/WallpaperEngine/Core/CScene.cpp | 14 +- src/WallpaperEngine/Core/CScene.h | 13 +- src/WallpaperEngine/Core/CVideo.cpp | 17 +++ src/WallpaperEngine/Core/CVideo.h | 36 +++++ src/WallpaperEngine/Core/CWallpaper.cpp | 18 +++ src/WallpaperEngine/Core/CWallpaper.h | 33 +++++ src/WallpaperEngine/Irrlicht/CContext.cpp | 11 +- src/WallpaperEngine/Irrlicht/CContext.h | 8 +- src/WallpaperEngine/Render/CScene.cpp | 47 ++---- src/WallpaperEngine/Render/CScene.h | 29 ++-- src/WallpaperEngine/Render/CVideo.cpp | 165 ++++++++++++++++++++++ src/WallpaperEngine/Render/CVideo.h | 52 +++++++ src/WallpaperEngine/Render/CWallpaper.cpp | 40 ++++++ src/WallpaperEngine/Render/CWallpaper.h | 45 ++++++ 20 files changed, 617 insertions(+), 100 deletions(-) create mode 100644 CMakeModules/FindFFmpeg.cmake create mode 100644 src/WallpaperEngine/Core/CVideo.cpp create mode 100644 src/WallpaperEngine/Core/CVideo.h create mode 100644 src/WallpaperEngine/Core/CWallpaper.cpp create mode 100644 src/WallpaperEngine/Core/CWallpaper.h create mode 100644 src/WallpaperEngine/Render/CVideo.cpp create mode 100644 src/WallpaperEngine/Render/CVideo.h create mode 100644 src/WallpaperEngine/Render/CWallpaper.cpp create mode 100644 src/WallpaperEngine/Render/CWallpaper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c5622..ea45fbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,9 @@ find_package(Irrlicht REQUIRED) find_package(SDL REQUIRED) find_package(SDL_mixer REQUIRED) find_package(LZ4 REQUIRED) +find_package(FFmpeg REQUIRED) -include_directories(${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} src include) +include_directories(${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIR} src include) add_executable( wallengine @@ -46,8 +47,12 @@ add_executable( src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp + src/WallpaperEngine/Render/CWallpaper.h + src/WallpaperEngine/Render/CWallpaper.cpp src/WallpaperEngine/Render/CScene.h src/WallpaperEngine/Render/CScene.cpp + src/WallpaperEngine/Render/CVideo.h + src/WallpaperEngine/Render/CVideo.cpp src/WallpaperEngine/Render/CCamera.h src/WallpaperEngine/Render/CCamera.cpp src/WallpaperEngine/Render/CObject.h @@ -83,8 +88,12 @@ add_executable( src/WallpaperEngine/Core/CProject.cpp src/WallpaperEngine/Core/CProject.h + src/WallpaperEngine/Core/CWallpaper.cpp + src/WallpaperEngine/Core/CWallpaper.h src/WallpaperEngine/Core/CScene.cpp src/WallpaperEngine/Core/CScene.h + src/WallpaperEngine/Core/CVideo.cpp + src/WallpaperEngine/Core/CVideo.h src/WallpaperEngine/Core/CObject.cpp src/WallpaperEngine/Core/CObject.h @@ -150,4 +159,4 @@ add_executable( src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h ) -target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES}) \ No newline at end of file +target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES} ${FFMPEG_LIBRARIES}) \ No newline at end of file diff --git a/CMakeModules/FindFFmpeg.cmake b/CMakeModules/FindFFmpeg.cmake new file mode 100644 index 0000000..bfd7b21 --- /dev/null +++ b/CMakeModules/FindFFmpeg.cmake @@ -0,0 +1,110 @@ +# - Try to find ffmpeg libraries (libavcodec, libavformat, libavutil and libswscale) +# Once done this will define +# +# FFMPEG_FOUND - system has ffmpeg or libav +# FFMPEG_INCLUDE_DIR - the ffmpeg include directory +# FFMPEG_LIBRARIES - Link these to use ffmpeg +# FFMPEG_LIBAVCODEC +# FFMPEG_LIBAVFORMAT +# FFMPEG_LIBAVUTIL +# FFMPEG_LIBSWSCALE +# +# Copyright (c) 2008 Andreas Schneider +# Modified for other libraries by Lasse Kärkkäinen +# Modified for Hedgewars by Stepik777 +# Modified for FFmpeg-example Tuukka Pasanen 2018 +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# + +include(FindPackageHandleStandardArgs) + + find_package_handle_standard_args(FFMPEG + FOUND_VAR FFMPEG_FOUND + REQUIRED_VARS + FFMPEG_LIBRARY + FFMPEG_INCLUDE_DIR + VERSION_VAR FFMPEG_VERSION + ) + +if(FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) + # in cache already + set(FFMPEG_FOUND TRUE) +else() + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(_FFMPEG_AVCODEC libavcodec) + pkg_check_modules(_FFMPEG_AVFORMAT libavformat) + pkg_check_modules(_FFMPEG_AVUTIL libavutil) + pkg_check_modules(_FFMPEG_SWSCALE libswscale) + endif() + + find_path(FFMPEG_AVCODEC_INCLUDE_DIR + NAMES libavcodec/avcodec.h + PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS} + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES ffmpeg libav) + + find_library(FFMPEG_LIBAVCODEC + NAMES avcodec + PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib) + + find_library(FFMPEG_LIBAVFORMAT + NAMES avformat + PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib) + + find_library(FFMPEG_LIBAVUTIL + NAMES avutil + PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib) + + find_library(FFMPEG_LIBSWSCALE + NAMES swscale + PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib) + + if(FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT) + set(FFMPEG_FOUND TRUE) + endif() + + if(FFMPEG_FOUND) + set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR}) + set(FFMPEG_LIBRARIES + ${FFMPEG_LIBAVCODEC} + ${FFMPEG_LIBAVFORMAT} + ${FFMPEG_LIBAVUTIL} + ${FFMPEG_LIBSWSCALE}) + endif() + + if(FFMPEG_FOUND) + if(NOT FFMPEG_FIND_QUIETLY) + message(STATUS + "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}") + endif() + else() + if(FFMPEG_FIND_REQUIRED) + message(FATAL_ERROR + "Could not find libavcodec or libavformat or libavutil or libswscale") + endif() + endif() +endif() diff --git a/README.md b/README.md index 8e43d86..fb42c0c 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Wallpaper Engine is a software designed by [Kristjan Skutta](https://store.steam - ZLIB - SDL - SDL_mixer +- FFmpeg - X11 - Xrandr diff --git a/main.cpp b/main.cpp index 4eed0c5..4248094 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,9 @@ #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Irrlicht/CContext.h" +#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CScene.h" +#include "WallpaperEngine/Render/CVideo.h" enum BACKGROUND_RUN_MODE { @@ -161,14 +163,32 @@ int main (int argc, char* argv[]) } WallpaperEngine::Core::CProject* project = WallpaperEngine::Core::CProject::fromFile (project_path); - WallpaperEngine::Render::CScene* scene = new WallpaperEngine::Render::CScene (project, IrrlichtContext); + WallpaperEngine::Render::CWallpaper* wallpaper; + if (project->getType () == "scene") + { + WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as (); + wallpaper = new WallpaperEngine::Render::CScene (scene, IrrlichtContext); + IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight ( + scene->getAmbientColor ().toSColor () + ); + } + else if (project->getType () == "video") + { + wallpaper = new WallpaperEngine::Render::CVideo ( + project->getWallpaper ()->as (), + IrrlichtContext + ); + } + else + { + throw std::runtime_error ("Unsupported wallpaper type"); + } + irr::u32 minimumTime = 1000 / maximumFPS; irr::u32 startTime = 0; irr::u32 endTime = 0; - IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (scene->getScene ()->getAmbientColor ().toSColor ()); - while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) { if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) @@ -176,7 +196,7 @@ int main (int argc, char* argv[]) startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - IrrlichtContext->renderFrame (scene); + IrrlichtContext->renderFrame (wallpaper); endTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index 0fb84f7..4ab0831 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -1,15 +1,17 @@ #include #include "CProject.h" +#include "CScene.h" +#include "CVideo.h" using namespace WallpaperEngine::Core; -CProject::CProject (std::string title, std::string type, CScene *scene) : +CProject::CProject (std::string title, std::string type, CWallpaper* wallpaper) : m_title (std::move (title)), m_type (std::move (type)), - m_scene (scene) + m_wallpaper (wallpaper) { - this->m_scene->setProject (this); + this->m_wallpaper->setProject (this); } CProject* CProject::fromFile (const irr::io::path& filename) @@ -20,11 +22,23 @@ CProject* CProject::fromFile (const irr::io::path& filename) auto type = jsonFindRequired (content, "type", "Project type missing"); auto file = jsonFindRequired (content, "file", "Project's main file missing"); auto general = content.find ("general"); + CWallpaper* wallpaper; + + if (strcmp ((*type).get ().c_str (), "scene") == 0) + { + wallpaper = CScene::fromFile ((*file).get ().c_str ()); + } + else if (strcmp ((*type).get ().c_str (), "video") == 0) + { + wallpaper = new CVideo ((*file).get ().c_str ()); + } + else + throw std::runtime_error ("Unsupported wallpaper type"); CProject* project = new CProject ( *title, *type, - CScene::fromFile ((*file).get ().c_str ()) + wallpaper ); if (general != content.end ()) @@ -48,9 +62,9 @@ CProject* CProject::fromFile (const irr::io::path& filename) return project; } -const CScene* CProject::getScene () const +CWallpaper* CProject::getWallpaper () const { - return this->m_scene; + return this->m_wallpaper; } const std::string& CProject::getTitle () const diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index aee6396..c48db55 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -2,7 +2,7 @@ #include -#include "CScene.h" +#include "CWallpaper.h" #include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Projects/CProperty.h" @@ -10,21 +10,21 @@ namespace WallpaperEngine::Core { using json = nlohmann::json; - class CScene; + class CWallpaper; class CProject { public: static CProject* fromFile (const irr::io::path& filename); - const CScene* getScene () const; + CWallpaper* getWallpaper () const; const std::string& getTitle () const; const std::string& getType () const; const std::vector& getProperties () const; protected: - CProject (std::string title, std::string type, CScene* scene); + CProject (std::string title, std::string type, CWallpaper* wallpaper); void insertProperty (Projects::CProperty* property); private: @@ -32,7 +32,6 @@ namespace WallpaperEngine::Core std::string m_title; std::string m_type; - CScene* m_scene; + CWallpaper* m_wallpaper; }; }; - diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index b1339ff..a0d93b0 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -24,6 +24,7 @@ CScene::CScene ( irr::video::SColorf clearColor, Scenes::CProjection* orthogonalProjection, irr::video::SColorf skylightColor) : + CWallpaper (Type), m_camera (camera), m_ambientColor (ambientColor), m_bloom (bloom), @@ -105,7 +106,6 @@ CScene* CScene::fromFile (const irr::io::path& filename) return scene; } - const std::vector& CScene::getObjects () const { return this->m_objects; @@ -116,16 +116,6 @@ void CScene::insertObject (CObject* object) this->m_objects.push_back (object); } -CProject* CScene::getProject () -{ - return this->m_project; -} - -void CScene::setProject (CProject* project) -{ - this->m_project = project; -} - const Scenes::CCamera* CScene::getCamera () const { return this->m_camera; @@ -215,3 +205,5 @@ const irr::video::SColorf& CScene::getSkylightColor () const { return this->m_skylightColor; } + +const std::string CScene::Type = "scene"; diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index c9a828c..16f901f 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -2,8 +2,8 @@ #include -#include "CProject.h" #include "CObject.h" +#include "CWallpaper.h" #include "Core.h" @@ -14,15 +14,13 @@ namespace WallpaperEngine::Core { using json = nlohmann::json; - class CProject; class CObject; - class CScene + class CScene : public CWallpaper { public: static CScene* fromFile (const irr::io::path& filename); - CProject* getProject (); const std::vector& getObjects () const; const irr::video::SColorf& getAmbientColor() const; @@ -45,9 +43,7 @@ namespace WallpaperEngine::Core const Scenes::CCamera* getCamera () const; protected: - friend class CProject; - - void setProject (CProject* project); + friend class CWallpaper; CScene ( Scenes::CCamera* camera, @@ -70,9 +66,10 @@ namespace WallpaperEngine::Core irr::video::SColorf skylightColor ); + static const std::string Type; + void insertObject (CObject* object); private: - CProject* m_project; Scenes::CCamera* m_camera; // data from general section on the json diff --git a/src/WallpaperEngine/Core/CVideo.cpp b/src/WallpaperEngine/Core/CVideo.cpp new file mode 100644 index 0000000..e7f25d8 --- /dev/null +++ b/src/WallpaperEngine/Core/CVideo.cpp @@ -0,0 +1,17 @@ +#include "CVideo.h" + +using namespace WallpaperEngine::Core; + +CVideo::CVideo ( + const irr::io::path& filename) : + CWallpaper (Type), + m_filename (filename) +{ +} + +const irr::io::path CVideo::getFilename () +{ + return this->m_filename; +} + +const std::string CVideo::Type = "video"; diff --git a/src/WallpaperEngine/Core/CVideo.h b/src/WallpaperEngine/Core/CVideo.h new file mode 100644 index 0000000..2fca344 --- /dev/null +++ b/src/WallpaperEngine/Core/CVideo.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include "Core.h" +#include "CWallpaper.h" + +extern "C" +{ + #include + #include + #include + #include +} + +namespace WallpaperEngine::Core +{ + class CVideo : public CWallpaper + { + public: + CVideo ( + const irr::io::path& filename + ); + + const irr::io::path getFilename (); + + protected: + friend class CWallpaper; + + const irr::io::path m_filename; + + static const std::string Type; + + private: + }; +}; diff --git a/src/WallpaperEngine/Core/CWallpaper.cpp b/src/WallpaperEngine/Core/CWallpaper.cpp new file mode 100644 index 0000000..df455d9 --- /dev/null +++ b/src/WallpaperEngine/Core/CWallpaper.cpp @@ -0,0 +1,18 @@ +#include "CWallpaper.h" + +using namespace WallpaperEngine::Core; + +CWallpaper::CWallpaper (std::string type) : + m_type (type) +{ +} + +CProject* CWallpaper::getProject () +{ + return this->m_project; +} + +void CWallpaper::setProject (CProject* project) +{ + this->m_project = project; +} diff --git a/src/WallpaperEngine/Core/CWallpaper.h b/src/WallpaperEngine/Core/CWallpaper.h new file mode 100644 index 0000000..e08f3b5 --- /dev/null +++ b/src/WallpaperEngine/Core/CWallpaper.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "CProject.h" + +namespace WallpaperEngine::Core +{ + class CProject; + + class CWallpaper + { + public: + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } + + template bool is () { return this->m_type == T::Type; } + + CWallpaper (std::string type); + + CProject* getProject (); + + protected: + friend class CProject; + + void setProject (CProject* project); + + private: + CProject* m_project; + + std::string m_type; + }; +} diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp index 1b2d6fd..83465b3 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ b/src/WallpaperEngine/Irrlicht/CContext.cpp @@ -162,7 +162,7 @@ void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCr irrlichtCreationParameters.WindowId = reinterpret_cast (DefaultRootWindow (display)); } -void CContext::renderFrame (Render::CScene* scene) +void CContext::renderFrame (Render::CWallpaper* wallpaper) { this->m_time = this->getDevice ()->getTimer ()->getTime () / 1000.0f; this->m_pointerPosition.X = this->m_eventReceiver->getPosition ().X / (irr::f32) this->getDevice ()->getVideoDriver ()->getScreenSize ().Width; @@ -170,7 +170,7 @@ void CContext::renderFrame (Render::CScene* scene) if (this->m_viewports.empty () == true) { - this->drawScene (scene, true); + this->drawWallpaper (wallpaper, true); } else { @@ -181,14 +181,15 @@ void CContext::renderFrame (Render::CScene* scene) { // change viewport to render to the correct portion of the display this->getDevice ()->getVideoDriver ()->setViewPort (*cur); - this->drawScene (scene, false); + this->drawWallpaper (wallpaper, false); } } } -void CContext::drawScene (Render::CScene* scene, bool backBuffer) +void CContext::drawWallpaper (Render::CWallpaper* wallpaper, bool backBuffer) { - this->getDevice ()->getVideoDriver ()->beginScene (backBuffer, true, scene->getScene ()->getClearColor ().toSColor()); + // TODO: Get scene clear color + this->getDevice ()->getVideoDriver ()->beginScene (backBuffer, true); this->getDevice ()->getSceneManager ()->drawAll (); this->getDevice ()->getVideoDriver ()->endScene (); } diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h index c456b92..d254f55 100644 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ b/src/WallpaperEngine/Irrlicht/CContext.h @@ -5,7 +5,7 @@ #include -#include "WallpaperEngine/Render/CScene.h" +#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" @@ -13,7 +13,7 @@ namespace WallpaperEngine::Render { - class CScene; + class CWallpaper; }; namespace WallpaperEngine::Irrlicht @@ -29,7 +29,7 @@ namespace WallpaperEngine::Irrlicht void insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable); const std::vector& getShaderVariables () const; - void renderFrame (Render::CScene* scene); + void renderFrame (Render::CWallpaper* wallpaper); irr::IrrlichtDevice* getDevice (); irr::io::path resolveMaterials (const std::string& materialName); @@ -38,7 +38,7 @@ namespace WallpaperEngine::Irrlicht irr::io::path resolveIncludeShader (const std::string& includeShader); private: void initializeViewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters); - void drawScene (Render::CScene* scene, bool backBuffer); + void drawWallpaper (Render::CWallpaper* wallpaper, bool backBuffer); irr::io::path resolveFile (const irr::io::path& file); diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 2f72881..d8f3c08 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -1,5 +1,3 @@ -#include "WallpaperEngine/Irrlicht/CContext.h" - #include "WallpaperEngine/Core/Objects/CImage.h" #include "WallpaperEngine/Core/Objects/CSound.h" @@ -11,23 +9,17 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; -CScene::CScene (const Core::CProject* project, Irrlicht::CContext* context) : - irr::scene::ISceneNode ( - context->getDevice ()->getSceneManager ()->getRootSceneNode (), - context->getDevice ()->getSceneManager () - ), - m_project (project), - m_scene (project->getScene ()), - m_context (context) +CScene::CScene (Core::CScene* scene, Irrlicht::CContext* context) : + CWallpaper (scene, Type, context) { - this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); + this->m_camera = new CCamera (this, scene->getCamera ()); this->m_camera->setOrthogonalProjection ( - this->m_scene->getOrthogonalProjection ()->getWidth (), - this->m_scene->getOrthogonalProjection ()->getHeight () + scene->getOrthogonalProjection ()->getWidth (), + scene->getOrthogonalProjection ()->getHeight () ); - auto cur = this->m_scene->getObjects ().begin (); - auto end = this->m_scene->getObjects ().end (); + auto cur = scene->getObjects ().begin (); + auto end = scene->getObjects ().end (); int highestId = 0; @@ -48,21 +40,6 @@ CScene::CScene (const Core::CProject* project, Irrlicht::CContext* context) : this->m_nextId = ++highestId; this->setAutomaticCulling (irr::scene::EAC_OFF); - this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); -} - -CScene::~CScene () -{ -} - -Irrlicht::CContext* CScene::getContext () -{ - return this->m_context; -} - -const Core::CScene* CScene::getScene () const -{ - return this->m_scene; } CCamera* CScene::getCamera () const @@ -79,13 +56,9 @@ void CScene::render () { } -const irr::core::aabbox3d& CScene::getBoundingBox () const +Core::CScene* CScene::getScene () { - return this->m_boundingBox; + return this->getWallpaperData ()->as (); } -void CScene::OnRegisterSceneNode () -{ - SceneManager->registerNodeForRendering (this); - ISceneNode::OnRegisterSceneNode (); -} \ No newline at end of file +const std::string CScene::Type = "scene"; diff --git a/src/WallpaperEngine/Render/CScene.h b/src/WallpaperEngine/Render/CScene.h index 5307a8d..96f1c86 100644 --- a/src/WallpaperEngine/Render/CScene.h +++ b/src/WallpaperEngine/Render/CScene.h @@ -2,40 +2,35 @@ #include "CCamera.h" -#include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Core/CScene.h" -#include "WallpaperEngine/Irrlicht/CContext.h" +#include "WallpaperEngine/Render/CWallpaper.h" -namespace WallpaperEngine::Irrlicht -{ - class CContext; -}; +#include "WallpaperEngine/Irrlicht/CContext.h" namespace WallpaperEngine::Render { class CCamera; - class CScene : public irr::scene::ISceneNode + class CScene : public CWallpaper { public: - CScene (const Core::CProject* project, Irrlicht::CContext* context); - ~CScene () override; + CScene (Core::CScene* scene, WallpaperEngine::Irrlicht::CContext* context); - Irrlicht::CContext* getContext (); - const Core::CScene* getScene () const; CCamera* getCamera () const; int nextId (); void render () override; - const irr::core::aabbox3d& getBoundingBox() const override; - void OnRegisterSceneNode () override; + + Core::CScene* getScene (); + + protected: + friend class CWallpaper; + + static const std::string Type; + private: - const Core::CProject* m_project; - const Core::CScene* m_scene; CCamera* m_camera; - Irrlicht::CContext* m_context; irr::u32 m_nextId; - irr::core::aabbox3d m_boundingBox; }; } diff --git a/src/WallpaperEngine/Render/CVideo.cpp b/src/WallpaperEngine/Render/CVideo.cpp new file mode 100644 index 0000000..f9d0823 --- /dev/null +++ b/src/WallpaperEngine/Render/CVideo.cpp @@ -0,0 +1,165 @@ +#include "CVideo.h" + +using namespace WallpaperEngine; + +using namespace WallpaperEngine::Render; + +CVideo::CVideo (Core::CVideo* video, WallpaperEngine::Irrlicht::CContext* context) : + CWallpaper (video, Type, context) +{ + if (avformat_open_input (&m_formatCtx, video->getFilename ().c_str (), NULL, NULL) < 0) + throw std::runtime_error ("Failed to open video file"); + + if (avformat_find_stream_info (m_formatCtx, NULL) < 0) + throw std::runtime_error ("Failed to get stream info"); + + // Find first video stream + for (int i = 0; i < m_formatCtx->nb_streams; i++) + { + if (m_formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + { + m_videoStream = i; + break; + } + } + + // Find first audio stream + for (int i = 0; i < m_formatCtx->nb_streams; i++) + { + if (m_formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) + { + m_audioStream = i; + break; + } + } + + // Only video stream is required + if (m_videoStream == -1) + throw std::runtime_error ("Failed to find video stream"); + + AVCodec* codec = avcodec_find_decoder (m_formatCtx->streams[m_videoStream]->codecpar->codec_id); + if (codec == nullptr) + throw std::runtime_error ("Failed to find codec"); + + m_codecCtx = avcodec_alloc_context3 (codec); + if (avcodec_parameters_to_context (m_codecCtx, m_formatCtx->streams[m_videoStream]->codecpar)) + throw std::runtime_error ("Failed to copy codec parameters"); + + if (avcodec_open2 (m_codecCtx, codec, NULL) < 0) + throw std::runtime_error ("Failed to open codec"); + + m_videoFrame = av_frame_alloc (); + m_videoFrameRGB = av_frame_alloc (); + if (m_videoFrameRGB == nullptr) + throw std::runtime_error ("Failed to allocate video frame"); +} + +void CVideo::setSize (int width, int height) +{ + if (m_buffer != nullptr) + av_free (m_buffer); + + if (m_swsCtx != nullptr) + sws_freeContext (m_swsCtx); + + int numBytes = av_image_get_buffer_size (AV_PIX_FMT_RGB24, width, height, 1); + m_buffer = (uint8_t*)av_malloc (numBytes * sizeof (uint8_t)); + + av_image_fill_arrays (m_videoFrameRGB->data, m_videoFrameRGB->linesize, m_buffer, AV_PIX_FMT_RGB24, width, height, 1); + + m_swsCtx = sws_getContext (m_codecCtx->width, m_codecCtx->height, + m_codecCtx->pix_fmt, + width, height, + AV_PIX_FMT_RGB24, + SWS_BILINEAR, NULL, NULL, NULL); +} + +void CVideo::render () +{ + irr::video::IVideoDriver* driver = m_context->getDevice ()->getVideoDriver (); + int width = driver->getScreenSize ().Width; + int height = driver->getScreenSize ().Height; + + m_frameImage = m_context->getDevice ()->getVideoDriver ()->createImage (irr::video::ECOLOR_FORMAT::ECF_R8G8B8, + irr::core::dimension2du(width, height)); + + setSize (width, height); + getNextFrame (); + writeFrameToImage (); + + driver->removeTexture (m_frameTexture); + m_frameTexture = driver->addTexture ("frameTexture", m_frameImage); + m_frameImage->drop (); + + driver->draw2DImage (m_frameTexture, irr::core::vector2di(0)); +} + +void CVideo::getNextFrame () +{ + bool eof = false; + AVPacket packet; + packet.data = nullptr; + + // Find video streams packet + do + { + if (packet.data != nullptr) + av_packet_unref (&packet); + + int readError = av_read_frame (m_formatCtx, &packet); + if (readError == AVERROR_EOF) + { + eof = true; + break; + } + else if (readError < 0) + { + char err[AV_ERROR_MAX_STRING_SIZE]; + throw std::runtime_error (av_make_error_string (err, AV_ERROR_MAX_STRING_SIZE, readError)); + } + + } while (packet.stream_index != m_videoStream); + + // Send video stream packet to codec + if (avcodec_send_packet (m_codecCtx, &packet) < 0) + return; + + // Receive frame from codec + if (avcodec_receive_frame (m_codecCtx, m_videoFrame) < 0) + return; + + sws_scale (m_swsCtx, (uint8_t const* const*)m_videoFrame->data, m_videoFrame->linesize, + 0, m_codecCtx->height, m_videoFrameRGB->data, m_videoFrameRGB->linesize); + + av_packet_unref (&packet); + + if (eof) + restartStream (); +} + +void CVideo::writeFrameToImage () +{ + uint8_t* frameData = m_videoFrameRGB->data[0]; + if (frameData == nullptr) + return; + + irr::u32 imgWidth = m_frameImage->getDimension().Width; + irr::u32 imgHeight = m_frameImage->getDimension().Height; + + unsigned char* data = (unsigned char*)m_frameImage->lock (); + memcpy (data, frameData, imgWidth * imgHeight * 3); + m_frameImage->unlock (); +} + +void CVideo::restartStream () +{ + av_seek_frame (m_formatCtx, m_videoStream, 0, AVSEEK_FLAG_FRAME); + avcodec_flush_buffers (m_codecCtx); +} + +Core::CVideo* CVideo::getVideo () +{ + return this->getWallpaperData ()->as (); +} + +const std::string CVideo::Type = "video"; diff --git a/src/WallpaperEngine/Render/CVideo.h b/src/WallpaperEngine/Render/CVideo.h new file mode 100644 index 0000000..77382fc --- /dev/null +++ b/src/WallpaperEngine/Render/CVideo.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +#include "WallpaperEngine/Core/CVideo.h" + +#include "WallpaperEngine/Render/CWallpaper.h" + +#include "WallpaperEngine/Irrlicht/CContext.h" + +extern "C" +{ + #include + #include + #include + #include +} + +namespace WallpaperEngine::Render +{ + class CVideo : public CWallpaper + { + public: + CVideo (Core::CVideo* video, WallpaperEngine::Irrlicht::CContext* context); + + void render () override; + + Core::CVideo* getVideo (); + + protected: + friend class CWallpaper; + + static const std::string Type; + + private: + void setSize (int width, int height); + void restartStream (); + void getNextFrame (); + void writeFrameToImage (); + + AVFormatContext* m_formatCtx = nullptr; + AVCodecContext* m_codecCtx = nullptr; + AVFrame* m_videoFrame = nullptr; + AVFrame* m_videoFrameRGB = nullptr; + SwsContext* m_swsCtx = nullptr; + uint8_t* m_buffer = nullptr; + int m_videoStream = -1, m_audioStream = -1; + + irr::video::IImage* m_frameImage; + irr::video::ITexture* m_frameTexture; + }; +}; diff --git a/src/WallpaperEngine/Render/CWallpaper.cpp b/src/WallpaperEngine/Render/CWallpaper.cpp new file mode 100644 index 0000000..788e4cd --- /dev/null +++ b/src/WallpaperEngine/Render/CWallpaper.cpp @@ -0,0 +1,40 @@ +#include "CWallpaper.h" + +using namespace WallpaperEngine::Render; + +CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, WallpaperEngine::Irrlicht::CContext* context) : + irr::scene::ISceneNode ( + context->getDevice ()->getSceneManager ()->getRootSceneNode (), + context->getDevice ()->getSceneManager () + ), + m_context (context), + m_wallpaperData (wallpaperData), + m_type (type) +{ +} + +CWallpaper::~CWallpaper () +{ +} + +void CWallpaper::OnRegisterSceneNode () +{ + SceneManager->registerNodeForRendering (this); + + ISceneNode::OnRegisterSceneNode (); +} + +WallpaperEngine::Irrlicht::CContext* CWallpaper::getContext () const +{ + return this->m_context; +} + +const irr::core::aabbox3d& CWallpaper::getBoundingBox () const +{ + return this->m_boundingBox; +} + +WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () +{ + return this->m_wallpaperData; +} diff --git a/src/WallpaperEngine/Render/CWallpaper.h b/src/WallpaperEngine/Render/CWallpaper.h new file mode 100644 index 0000000..8f260a7 --- /dev/null +++ b/src/WallpaperEngine/Render/CWallpaper.h @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include "WallpaperEngine/Core/CWallpaper.h" +#include "WallpaperEngine/Core/CScene.h" +#include "WallpaperEngine/Core/CVideo.h" + +#include "WallpaperEngine/Irrlicht/CContext.h" + +namespace WallpaperEngine::Irrlicht +{ + class CContext; +}; + +namespace WallpaperEngine::Render +{ + class CWallpaper : public irr::scene::ISceneNode + { + public: + template const T* as () const { assert (is ()); return (const T*) this; } + template T* as () { assert (is ()); return (T*) this; } + + template bool is () { return this->m_type == T::Type; } + + CWallpaper (Core::CWallpaper* wallpaperData, std::string type, WallpaperEngine::Irrlicht::CContext* context); + ~CWallpaper () override; + + void OnRegisterSceneNode () override; + + WallpaperEngine::Irrlicht::CContext* getContext () const; + const irr::core::aabbox3d& getBoundingBox () const override; + + protected: + WallpaperEngine::Irrlicht::CContext* m_context; + Core::CWallpaper* m_wallpaperData; + + Core::CWallpaper* getWallpaperData (); + + private: + irr::core::aabbox3d m_boundingBox = irr::core::aabbox3d (0, 0, 0, 0, 0, 0); + + std::string m_type; + }; +}