Renderable.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "anki/scene/Renderable.h"
  2. #include "anki/resource/Material.h"
  3. #include "anki/resource/TextureResource.h"
  4. #include <boost/variant.hpp>
  5. namespace anki {
  6. //==============================================================================
  7. // CreateNewPropertyVisitor =
  8. //==============================================================================
  9. /// Create a new property given a material variable
  10. struct CreateNewPropertyVisitor: boost::static_visitor<void>
  11. {
  12. const MaterialVariable* mvar;
  13. PropertyMap* pmap;
  14. Renderable::Properties* rprops;
  15. template<typename T>
  16. void operator()(const T&) const
  17. {
  18. MaterialVariableProperty<T>* prop = new MaterialVariableProperty<T>(
  19. mvar->getName().c_str(),
  20. &(mvar->getValue<T>()),
  21. !mvar->getInitialized());
  22. pmap->addNewProperty(prop);
  23. rprops->push_back(prop);
  24. }
  25. };
  26. //==============================================================================
  27. // Renderable =
  28. //==============================================================================
  29. //==============================================================================
  30. void Renderable::init(PropertyMap& pmap)
  31. {
  32. const Material& mtl = getMaterial();
  33. CreateNewPropertyVisitor vis;
  34. vis.pmap = &pmap;
  35. vis.rprops = &props;
  36. for(const MaterialVariable& mv : mtl.getVariables())
  37. {
  38. vis.mvar = &mv;
  39. boost::apply_visitor(vis, mv.getVariant());
  40. }
  41. }
  42. } // namespace anki