MaterialRuntime.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "anki/scene/MaterialRuntime.h"
  2. #include "anki/resource/Material.h"
  3. #include "anki/scene/MaterialRuntimeVariable.h"
  4. #include <boost/foreach.hpp>
  5. namespace anki {
  6. //==============================================================================
  7. MaterialRuntime::MaterialRuntime(const Material& mtl_)
  8. : mtl(mtl_)
  9. {
  10. // Copy props
  11. MaterialProperties& me = *this;
  12. const MaterialProperties& he = mtl.getBaseClass();
  13. me = he;
  14. // Create vars
  15. BOOST_FOREACH(const MaterialVariable& var, mtl.getVariables())
  16. {
  17. MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
  18. vars.push_back(varr);
  19. varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;
  20. }
  21. }
  22. //==============================================================================
  23. MaterialRuntime::~MaterialRuntime()
  24. {}
  25. //==============================================================================
  26. MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
  27. const char* name)
  28. {
  29. VariablesHashMap::iterator it = varNameToVar.find(name);
  30. if(it == varNameToVar.end())
  31. {
  32. throw ANKI_EXCEPTION("Cannot get material runtime variable "
  33. "with name \"" + name + '\"');
  34. }
  35. return *(it->second);
  36. }
  37. //==============================================================================
  38. const MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
  39. const char* name) const
  40. {
  41. VariablesHashMap::const_iterator it = varNameToVar.find(name);
  42. if(it == varNameToVar.end())
  43. {
  44. throw ANKI_EXCEPTION("Cannot get material runtime variable "
  45. "with name \"" + name + '\"');
  46. }
  47. return *(it->second);
  48. }
  49. } // end namespace