瀏覽代碼

~ added proper texture input/output

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 7 年之前
父節點
當前提交
8d2f2adcfa

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

+ 19 - 5
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);
     }
 }

+ 2 - 2
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;

+ 12 - 3
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;

+ 2 - 2
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;