Renderable.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "anki/scene/Renderable.h"
  2. #include "anki/resource/Material.h"
  3. #include "anki/resource/TextureResource.h"
  4. namespace anki {
  5. //==============================================================================
  6. // CreateNewPropertyVisitor =
  7. //==============================================================================
  8. /// Create a new property given a material variable
  9. struct CreateNewPropertyVisitor
  10. {
  11. const MaterialVariable* mvar = nullptr;
  12. PropertyMap* pmap = nullptr;
  13. Renderable::MaterialVariableProperties* rprops = nullptr;
  14. template<typename T>
  15. void visit(const T&) const
  16. {
  17. MaterialVariableProperty<T>* prop = new MaterialVariableProperty<T>(
  18. mvar->getName().c_str(),
  19. &(mvar->getValue<T>()),
  20. mvar);
  21. pmap->addNewProperty(prop);
  22. rprops->push_back(prop);
  23. }
  24. };
  25. //==============================================================================
  26. // Renderable =
  27. //==============================================================================
  28. //==============================================================================
  29. Renderable::~Renderable()
  30. {}
  31. //==============================================================================
  32. void Renderable::init(PropertyMap& pmap)
  33. {
  34. const Material& mtl = getMaterial();
  35. CreateNewPropertyVisitor vis;
  36. vis.pmap = &pmap;
  37. vis.rprops = &props;
  38. for(const MaterialVariable* mv : mtl.getVariables())
  39. {
  40. vis.mvar = mv;
  41. mv->acceptVisitor(vis);
  42. }
  43. // FUTURE if the material is simple (only viewprojection matrix and samlers)
  44. // then use a common UBO. It will save the copying to the UBO and the
  45. // binding
  46. // Init the UBO
  47. const ShaderProgramUniformBlock* block = mtl.getUniformBlock();
  48. if(block)
  49. {
  50. ubo.create(block->getSize());
  51. }
  52. }
  53. } // end namespace anki