CPassess.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "CPassess.h"
  2. using namespace WallpaperEngine::Core::Objects::Effects::Constants;
  3. using namespace WallpaperEngine::Core::Objects::Images::Materials;
  4. CPassess::CPassess (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) :
  5. m_blending (std::move(blending)),
  6. m_cullmode (std::move(cullmode)),
  7. m_depthtest (std::move(depthtest)),
  8. m_depthwrite (std::move(depthwrite)),
  9. m_shader (std::move(shader))
  10. {
  11. }
  12. CPassess* CPassess::fromJSON (json data)
  13. {
  14. auto blending_it = data.find ("blending");
  15. auto cullmode_it = data.find ("cullmode");
  16. auto depthtest_it = data.find ("depthtest");
  17. auto depthwrite_it = data.find ("depthwrite");
  18. auto shader_it = data.find ("shader");
  19. auto textures_it = data.find ("textures");
  20. auto combos_it = data.find ("combos");
  21. if (blending_it == data.end ())
  22. {
  23. throw std::runtime_error ("Material pass must have blending specified");
  24. }
  25. if (cullmode_it == data.end ())
  26. {
  27. throw std::runtime_error ("Material pass must have cullmode specified");
  28. }
  29. if (depthtest_it == data.end ())
  30. {
  31. throw std::runtime_error ("Material pass must have depthtest specified");
  32. }
  33. if (depthwrite_it == data.end ())
  34. {
  35. throw std::runtime_error ("Material pass must have depthwrite specified");
  36. }
  37. if (shader_it == data.end ())
  38. {
  39. throw std::runtime_error ("Material pass must have shader specified");
  40. }
  41. if (textures_it != data.end ())
  42. {
  43. // TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
  44. if ((*textures_it).is_array () == false)
  45. {
  46. throw std::runtime_error ("Textures for material must be a list");
  47. }
  48. }
  49. CPassess* pass = new CPassess (
  50. *blending_it,
  51. *cullmode_it,
  52. *depthtest_it,
  53. *depthwrite_it,
  54. *shader_it
  55. );
  56. if (textures_it != data.end ())
  57. {
  58. auto cur = (*textures_it).begin ();
  59. auto end = (*textures_it).end ();
  60. for (;cur != end; cur ++)
  61. {
  62. if ((*cur).is_null () == true)
  63. {
  64. pass->insertTexture ("");
  65. }
  66. else
  67. {
  68. pass->insertTexture (*cur);
  69. }
  70. }
  71. }
  72. if (combos_it != data.end ())
  73. {
  74. auto cur = (*combos_it).begin ();
  75. auto end = (*combos_it).end ();
  76. for (; cur != end; cur ++)
  77. {
  78. std::string name = cur.key ();
  79. if ((*cur).is_number_integer () == true)
  80. {
  81. pass->insertCombo (name, *cur);
  82. }
  83. else
  84. {
  85. throw std::runtime_error ("unexpected non-integer combo");
  86. }
  87. }
  88. }
  89. return pass;
  90. }
  91. void CPassess::insertTexture (const std::string& texture)
  92. {
  93. this->m_textures.push_back (texture);
  94. }
  95. void CPassess::setTexture (int index, const std::string& texture)
  96. {
  97. this->m_textures.at (index) = texture;
  98. }
  99. void CPassess::insertCombo (const std::string& name, int value)
  100. {
  101. this->m_combos.insert (std::pair <std::string, int> (name, value));
  102. }
  103. const std::vector<std::string>& CPassess::getTextures () const
  104. {
  105. return this->m_textures;
  106. }
  107. const std::map<std::string, CShaderConstant*>& CPassess::getConstants () const
  108. {
  109. return this->m_constants;
  110. }
  111. const std::map<std::string, int>& CPassess::getCombos () const
  112. {
  113. return this->m_combos;
  114. }
  115. const std::string& CPassess::getShader () const
  116. {
  117. return this->m_shader;
  118. }
  119. const std::string& CPassess::getBlendingMode () const
  120. {
  121. return this->m_blending;
  122. }
  123. const std::string& CPassess::getCullingMode () const
  124. {
  125. return this->m_cullmode;
  126. }
  127. const std::string& CPassess::getDepthTest () const
  128. {
  129. return this->m_depthtest;
  130. }
  131. const std::string& CPassess::getDepthWrite ()const
  132. {
  133. return this->m_depthwrite;
  134. }
  135. void CPassess::insertConstant (const std::string& name, CShaderConstant* constant)
  136. {
  137. this->m_constants.insert (std::pair <std::string, CShaderConstant*> (name, constant));
  138. }