CPass.cpp 3.7 KB

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