Pass.cpp 1.6 KB

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