Pass.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef PASS_H_
  2. #define PASS_H_
  3. #include "RenderState.h"
  4. #include "VertexAttributeBinding.h"
  5. namespace gameplay
  6. {
  7. class Technique;
  8. class NodeCloneContext;
  9. /**
  10. * Defines a pass for an object to be rendered.
  11. *
  12. * This class encapsulates the parameters and logic required to apply a shader
  13. * to an object to be rendered. This includes specifying both a vertex and fragment
  14. * shader, as well as any uniforms and vertex attributes to be applied to these.
  15. */
  16. class Pass : public RenderState
  17. {
  18. friend class Technique;
  19. friend class Material;
  20. friend class RenderState;
  21. public:
  22. /**
  23. * Returns the Id of this pass.
  24. */
  25. const char* getId() const;
  26. /**
  27. * Returns the effect for this Pass.
  28. */
  29. Effect* getEffect() const;
  30. /**
  31. * Sets a vertex attribute binding for this pass.
  32. *
  33. * When a mesh binding is set, the VertexAttributeBinding will be automatically
  34. * bound when the bind() method is called for the pass.
  35. *
  36. * @param binding The VertexAttributeBinding to set (or NULL to remove an existing binding).
  37. */
  38. void setVertexAttributeBinding(VertexAttributeBinding* binding);
  39. /**
  40. * Sets a vertex attribute binding for this pass.
  41. *
  42. * @return The vertex attribute binding for this pass.
  43. */
  44. VertexAttributeBinding* getVertexAttributeBinding() const;
  45. /**
  46. * Binds the render state for this pass.
  47. *
  48. * This method should be called before executing any drawing code that should
  49. * use this pass. When drawing code is complete, the unbind() method should be called.
  50. */
  51. void bind();
  52. /**
  53. * Unbinds the render state for this pass.
  54. *
  55. * This method should always be called when rendering for a pass is complete, to
  56. * restore the render state to the state it was in previous to calling bind().
  57. */
  58. void unbind();
  59. private:
  60. /**
  61. * Constructor.
  62. */
  63. Pass(const char* id, Technique* technique, Effect* effect);
  64. /**
  65. * Hidden copy constructor.
  66. */
  67. Pass(const Pass& copy);
  68. /**
  69. * Destructor.
  70. */
  71. ~Pass();
  72. /**
  73. * Creates a new pass for the given shaders.
  74. */
  75. static Pass* create(const char* id, Technique* technique, const char* vshPath, const char* fshPath, const char* defines);
  76. /**
  77. * Hidden copy assignment operator.
  78. */
  79. Pass& operator=(const Pass&);
  80. /**
  81. * Clones the Pass and assigns it the given Technique.
  82. *
  83. * @param technique The technique to assign to the new Pass.
  84. * @param context The clone context.
  85. *
  86. * @return The newly created Pass.
  87. */
  88. Pass* clone(Technique* technique, NodeCloneContext &context) const;
  89. std::string _id;
  90. Technique* _technique;
  91. Effect* _effect;
  92. VertexAttributeBinding* _vaBinding;
  93. };
  94. }
  95. #endif