passes.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Created by almamu on 13/08/19.
  3. //
  4. #include <nlohmann/json.hpp>
  5. #include <utility>
  6. #include "passes.h"
  7. using namespace wp::core::objects::images::materials;
  8. passes::passes (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader) :
  9. m_blending (std::move(blending)),
  10. m_cullmode (std::move(cullmode)),
  11. m_depthtest (std::move(depthtest)),
  12. m_depthwrite (std::move(depthwrite)),
  13. m_shader (std::move(shader))
  14. {
  15. }
  16. std::vector<std::string>* passes::getTextures ()
  17. {
  18. return &this->m_textures;
  19. }
  20. passes* passes::fromJSON (json data)
  21. {
  22. json::const_iterator blending_it = data.find ("blending");
  23. json::const_iterator cullmode_it = data.find ("cullmode");
  24. json::const_iterator depthtest_it = data.find ("depthtest");
  25. json::const_iterator depthwrite_it = data.find ("depthwrite");
  26. json::const_iterator shader_it = data.find ("shader");
  27. json::const_iterator textures_it = data.find ("textures");
  28. if (blending_it == data.end ())
  29. {
  30. throw std::runtime_error ("Material pass must have blending specified");
  31. }
  32. if (cullmode_it == data.end ())
  33. {
  34. throw std::runtime_error ("Material pass must have cullmode specified");
  35. }
  36. if (depthtest_it == data.end ())
  37. {
  38. throw std::runtime_error ("Material pass must have depthtest specified");
  39. }
  40. if (depthwrite_it == data.end ())
  41. {
  42. throw std::runtime_error ("Material pass must have depthwrite specified");
  43. }
  44. if (shader_it == data.end ())
  45. {
  46. throw std::runtime_error ("Material pass must have shader specified");
  47. }
  48. if (textures_it == data.end ())
  49. {
  50. throw std::runtime_error ("Material pass must have textures specified");
  51. }
  52. if ((*textures_it).is_array () == false)
  53. {
  54. throw std::runtime_error ("Textures for material must be a list");
  55. }
  56. passes* pass = new passes (
  57. *blending_it,
  58. *cullmode_it,
  59. *depthtest_it,
  60. *depthwrite_it,
  61. *shader_it
  62. );
  63. json::const_iterator cur = (*textures_it).begin ();
  64. json::const_iterator end = (*textures_it).end ();
  65. for (;cur != end; cur ++)
  66. {
  67. if ((*cur).is_null () == true)
  68. {
  69. pass->insertTexture ("");
  70. }
  71. else
  72. {
  73. pass->insertTexture (*cur);
  74. }
  75. }
  76. return pass;
  77. }
  78. void passes::insertTexture (std::string texture)
  79. {
  80. this->m_textures.push_back (texture);
  81. }