Technique.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "Base.h"
  2. #include "Technique.h"
  3. #include "Material.h"
  4. #include "Node.h"
  5. namespace gameplay
  6. {
  7. Technique::Technique(const char* id, Material* material)
  8. : _id(id ? id : ""), _material(material)
  9. {
  10. assert(material);
  11. RenderState::_parent = material;
  12. }
  13. Technique::~Technique()
  14. {
  15. // Destroy all the passes.
  16. for (unsigned int i = 0, count = _passes.size(); i < count; ++i)
  17. {
  18. SAFE_RELEASE(_passes[i]);
  19. }
  20. }
  21. const char* Technique::getId() const
  22. {
  23. return _id.c_str();
  24. }
  25. unsigned int Technique::getPassCount() const
  26. {
  27. return _passes.size();
  28. }
  29. Pass* Technique::getPass(unsigned int index) const
  30. {
  31. assert(index < _passes.size());
  32. return _passes[index];
  33. }
  34. Pass* Technique::getPass(const char* id) const
  35. {
  36. for (unsigned int i = 0, count = _passes.size(); i < count; ++i)
  37. {
  38. Pass* pass = _passes[i];
  39. if (strcmp(pass->getId(), id) == 0)
  40. {
  41. return pass;
  42. }
  43. }
  44. return NULL;
  45. }
  46. Technique* Technique::clone(Material* material, NodeCloneContext &context) const
  47. {
  48. Technique* technique = new Technique(getId(), material);
  49. technique->_material = material;
  50. for (std::vector<Pass*>::const_iterator it = _passes.begin(); it != _passes.end(); ++it)
  51. {
  52. Pass* pass = *it;
  53. Pass* passCopy = pass->clone(technique, context);
  54. technique->_passes.push_back(passCopy);
  55. }
  56. RenderState::cloneInto(technique, context);
  57. return technique;
  58. }
  59. }