Pass.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "Base.h"
  2. #include "Pass.h"
  3. #include "Technique.h"
  4. #include "Material.h"
  5. #include "Node.h"
  6. namespace gameplay
  7. {
  8. Pass::Pass(const char* id, Technique* technique, Effect* effect) :
  9. _id(id ? id : ""), _technique(technique), _effect(effect), _vaBinding(NULL)
  10. {
  11. GP_ASSERT(technique);
  12. RenderState::_parent = _technique;
  13. }
  14. Pass::~Pass()
  15. {
  16. SAFE_RELEASE(_effect);
  17. SAFE_RELEASE(_vaBinding);
  18. }
  19. Pass* Pass::create(const char* id, Technique* technique, const char* vshPath, const char* fshPath, const char* defines)
  20. {
  21. // Attempt to create/load the effect
  22. Effect* effect = Effect::createFromFile(vshPath, fshPath, defines);
  23. GP_ASSERT(effect);
  24. if (effect == NULL)
  25. {
  26. return NULL;
  27. }
  28. // Return the new pass
  29. return new Pass(id, technique, effect);
  30. }
  31. const char* Pass::getId() const
  32. {
  33. return _id.c_str();
  34. }
  35. Effect* Pass::getEffect() const
  36. {
  37. return _effect;
  38. }
  39. void Pass::setVertexAttributeBinding(VertexAttributeBinding* binding)
  40. {
  41. SAFE_RELEASE(_vaBinding);
  42. if (binding)
  43. {
  44. _vaBinding = binding;
  45. binding->addRef();
  46. }
  47. }
  48. void Pass::bind()
  49. {
  50. // Bind our effect
  51. _effect->bind();
  52. // Bind our render state
  53. RenderState::bind(this);
  54. // If we have a vertex attribute binding, bind it
  55. if (_vaBinding)
  56. {
  57. _vaBinding->bind();
  58. }
  59. }
  60. void Pass::unbind()
  61. {
  62. // If we have a vertex attribute binding, unbind it
  63. if (_vaBinding)
  64. {
  65. _vaBinding->unbind();
  66. }
  67. }
  68. Pass* Pass::clone(Technique* technique, NodeCloneContext &context) const
  69. {
  70. Effect* effect = getEffect();
  71. effect->addRef();
  72. Pass* pass = new Pass(getId(), technique, effect);
  73. RenderState::cloneInto(pass, context);
  74. return pass;
  75. }
  76. }