CMaterial.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "CMaterial.h"
  2. using namespace WallpaperEngine::Render::Objects;
  3. using namespace WallpaperEngine::Render::Objects::Effects;
  4. CMaterial::CMaterial (const Render::Objects::CImage* image, const Core::Objects::Images::CMaterial* material) :
  5. m_image (image),
  6. m_material (material)
  7. {
  8. // TODO: REWRITE THIS
  9. /*this->m_outputTexture = this->m_context->getDevice ()->getVideoDriver ()->addRenderTargetTexture (
  10. this->m_inputTexture->getSize (),
  11. (
  12. "_rt_WALLENGINELINUX_OUTPUT_" +
  13. std::to_string (this->m_image->getImage ()->getId ()) + "_" +
  14. std::to_string (this->m_image->getEffects ().size ()) +
  15. "_material_output"
  16. ).c_str ()
  17. );*/
  18. this->generatePasses ();
  19. }
  20. const std::vector<CPass*>& CMaterial::getPasses () const
  21. {
  22. return this->m_passes;
  23. }
  24. const CImage* CMaterial::getImage () const
  25. {
  26. return this->m_image;
  27. }
  28. void CMaterial::generatePasses ()
  29. {
  30. auto cur = this->m_material->getPasses ().begin ();
  31. auto end = this->m_material->getPasses ().end ();
  32. // these are simple now, just create the entries and done
  33. for (; cur != end; cur ++)
  34. this->m_passes.emplace_back (new CPass (this, *cur));
  35. }
  36. // TODO: REWRITE THIS
  37. /*
  38. void CMaterial::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData)
  39. {
  40. irr::s32 g_Texture0 = 0;
  41. irr::video::IVideoDriver* driver = services->getVideoDriver ();
  42. irr::core::matrix4 worldViewProj;
  43. worldViewProj = driver->getTransform (irr::video::ETS_PROJECTION);
  44. worldViewProj *= driver->getTransform (irr::video::ETS_VIEW);
  45. worldViewProj *= driver->getTransform (irr::video::ETS_WORLD);
  46. services->setPixelShaderConstant ("TextureSampler", &g_Texture0, 1);
  47. services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16);
  48. }
  49. */
  50. void CMaterial::render (GLuint drawTo, GLuint inputTexture)
  51. {
  52. // get the orthogonal projection
  53. auto projection = this->getImage ()->getScene ()->getScene ()->getOrthogonalProjection ();
  54. auto begin = this->getPasses ().begin ();
  55. auto cur = this->getPasses ().begin ();
  56. auto end = this->getPasses ().end ();
  57. for (; cur != end; cur ++)
  58. {
  59. // get the current framebuffer to use (only after the first iteration)
  60. if (cur != begin)
  61. this->getImage ()->getScene ()->pinpongFramebuffer (&drawTo, &inputTexture);
  62. // bind to this new framebuffer
  63. glBindFramebuffer (GL_FRAMEBUFFER, drawTo);
  64. // set the viewport, for now use the scene width/height but we might want to use image's size TODO: INVESTIGATE THAT
  65. glViewport (0, 0, projection->getWidth (), projection->getHeight ());
  66. // render the pass
  67. (*cur)->render (drawTo, inputTexture);
  68. }
  69. // TODO: REWRITE THIS
  70. /*
  71. uint16_t indices [] =
  72. {
  73. 3, 2, 1, 0
  74. };
  75. irr::video::IVideoDriver* driver = this->getImage ()->getSceneManager ()->getVideoDriver ();
  76. auto mainCur = this->getPasses ().begin ();
  77. auto mainEnd = this->getPasses ().end ();
  78. for (; mainCur != mainEnd; mainCur ++)
  79. {
  80. // set the proper render target
  81. driver->setRenderTarget ((*mainCur)->getOutputTexture (), true, true, IntegerColor (0, 0, 0, 0));
  82. // set the material
  83. driver->setMaterial ((*mainCur)->getMaterial ());
  84. // draw it
  85. driver->drawVertexPrimitiveList (
  86. this->m_image->getVertex (), 4, indices, 1,
  87. irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
  88. );
  89. }
  90. // render last pass' output into our output
  91. // set the proper render target
  92. driver->setRenderTarget (this->getOutputTexture (), true, true, IntegerColor (0, 0, 0, 0));
  93. // set the material
  94. driver->setMaterial (this->m_outputMaterial);
  95. // draw it
  96. driver->drawVertexPrimitiveList (
  97. this->m_image->getVertex (), 4, indices, 1,
  98. irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
  99. );
  100. */
  101. }