CEffect.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "CEffect.h"
  2. using namespace WallpaperEngine::Render::Objects;
  3. CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect, Irrlicht::CContext* context, irr::video::ITexture* input) :
  4. m_context (context),
  5. m_image (image),
  6. m_effect (effect),
  7. m_inputTexture (input)
  8. {
  9. irr::core::dimension2du size = irr::core::dimension2du (
  10. this->m_image->getImage ()->getSize ().X,
  11. this->m_image->getImage ()->getSize ().Y
  12. );
  13. this->m_outputTexture = this->m_context->getDevice ()->getVideoDriver ()->addRenderTargetTexture (
  14. size,
  15. (
  16. "_rt_WALLENGINELINUX_OUTPUT_" +
  17. std::to_string (image->getImage ()->getId ()) + "_" +
  18. std::to_string (this->m_image->getEffects ().size ()) +
  19. "_effect_output"
  20. ).c_str ()
  21. );
  22. this->generateFBOs ();
  23. this->generatePasses ();
  24. }
  25. const irr::video::ITexture* CEffect::getInputTexture () const
  26. {
  27. return this->m_inputTexture;
  28. }
  29. const irr::video::ITexture* CEffect::getOutputTexture () const
  30. {
  31. return this->m_outputTexture;
  32. }
  33. const CImage* CEffect::getImage () const
  34. {
  35. return this->m_image;
  36. }
  37. const std::vector<Effects::CMaterial*>& CEffect::getMaterials () const
  38. {
  39. return this->m_materials;
  40. }
  41. Effects::CFBO* CEffect::findFBO (const std::string& name)
  42. {
  43. auto cur = this->m_fbos.begin ();
  44. auto end = this->m_fbos.end ();
  45. for (; cur != end; cur ++)
  46. {
  47. if ((*cur)->getName () == name)
  48. {
  49. return *cur;
  50. }
  51. }
  52. return nullptr;
  53. }
  54. void CEffect::generatePasses ()
  55. {
  56. auto cur = this->m_effect->getMaterials ().begin ();
  57. auto end = this->m_effect->getMaterials ().end ();
  58. const irr::video::ITexture* inputTexture = this->getInputTexture ();
  59. for (; cur != end; cur ++)
  60. {
  61. Effects::CMaterial* material = new Effects::CMaterial (this->m_context, this, *cur, inputTexture);
  62. // next input texture will be the output texture of the material
  63. inputTexture = material->getOutputTexture ();
  64. this->m_materials.push_back (material);
  65. }
  66. }
  67. void CEffect::generateFBOs ()
  68. {
  69. auto cur = this->m_effect->getFbos ().begin ();
  70. auto end = this->m_effect->getFbos ().end ();
  71. for (; cur != end; cur ++)
  72. {
  73. this->m_fbos.push_back (
  74. new Effects::CFBO (*cur, this->m_image->getImage (), this->m_context)
  75. );
  76. }
  77. }