CPass.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "common.h"
  2. #include "CPass.h"
  3. #include <utility>
  4. using namespace WallpaperEngine::Core::Objects::Effects::Constants;
  5. using namespace WallpaperEngine::Core::Objects::Images::Materials;
  6. CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) :
  7. m_blending (std::move(blending)),
  8. m_cullmode (std::move(cullmode)),
  9. m_depthtest (std::move(depthtest)),
  10. m_depthwrite (std::move(depthwrite)),
  11. m_shader (std::move(shader))
  12. {
  13. }
  14. CPass* CPass::fromJSON (json data)
  15. {
  16. // TODO: FIGURE OUT DEFAULT BLENDING MODE
  17. auto blending = jsonFindDefault <std::string> (data, "blending", "normal");
  18. auto cullmode = jsonFindDefault <std::string> (data, "cullmode", "nocull");
  19. auto depthtest_it = jsonFindRequired (data, "depthtest", "Material pass must have depthtest specified");
  20. auto depthwrite_it = jsonFindRequired (data, "depthwrite", "Material pass must have depthwrite specified");
  21. auto shader_it = jsonFindRequired (data, "shader", "Material pass must have shader specified");
  22. auto textures_it = data.find ("textures");
  23. auto combos_it = data.find ("combos");
  24. if (textures_it != data.end ())
  25. {
  26. // TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
  27. if (!(*textures_it).is_array ())
  28. sLog.exception ("Material's textures must be a list");
  29. }
  30. auto* pass = new CPass (
  31. blending,
  32. cullmode,
  33. *depthtest_it,
  34. *depthwrite_it,
  35. *shader_it
  36. );
  37. if (textures_it != data.end ())
  38. for (const auto& cur : (*textures_it))
  39. pass->insertTexture (cur.is_null () ? "" : cur);
  40. if (combos_it != data.end ())
  41. {
  42. for (const auto& cur : (*combos_it).items ())
  43. {
  44. if (cur.value ().is_number_integer ())
  45. pass->insertCombo (cur.key (), cur.value ());
  46. else
  47. sLog.exception ("unexpected non-integer combo on pass");
  48. }
  49. }
  50. return pass;
  51. }
  52. void CPass::insertTexture (const std::string& texture)
  53. {
  54. this->m_textures.push_back (texture);
  55. }
  56. void CPass::setTexture (int index, const std::string& texture)
  57. {
  58. this->m_textures.at (index) = texture;
  59. }
  60. void CPass::insertCombo (const std::string& name, int value)
  61. {
  62. std::string uppercase = std::string (name);
  63. std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
  64. this->m_combos.insert (std::pair <std::string, int> (uppercase, value));
  65. }
  66. const std::vector<std::string>& CPass::getTextures () const
  67. {
  68. return this->m_textures;
  69. }
  70. const std::map<std::string, CShaderConstant*>& CPass::getConstants () const
  71. {
  72. return this->m_constants;
  73. }
  74. std::map<std::string, int>* CPass::getCombos ()
  75. {
  76. return &this->m_combos;
  77. }
  78. const std::string& CPass::getShader () const
  79. {
  80. return this->m_shader;
  81. }
  82. const std::string& CPass::getBlendingMode () const
  83. {
  84. return this->m_blending;
  85. }
  86. const std::string& CPass::getCullingMode () const
  87. {
  88. return this->m_cullmode;
  89. }
  90. const std::string& CPass::getDepthTest () const
  91. {
  92. return this->m_depthtest;
  93. }
  94. const std::string& CPass::getDepthWrite ()const
  95. {
  96. return this->m_depthwrite;
  97. }
  98. void CPass::setBlendingMode (const std::string& mode)
  99. {
  100. this->m_blending = mode;
  101. }
  102. void CPass::insertConstant (const std::string& name, CShaderConstant* constant)
  103. {
  104. this->m_constants.insert (std::pair <std::string, CShaderConstant*> (name, constant));
  105. }