Technique.cpp 1.6 KB

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