CPass.cpp 3.6 KB

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