CPassess.cpp 2.4 KB

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