Pass.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * Get a list of properties to be auto-bound.
  32. */
  33. const std::vector<std::string>* getAutoBindProperties() const;
  34. /**
  35. * Stores a vertex attribute binding for this pass.
  36. *
  37. * When a mesh binding is set, the VertexAttributeBinding will be automatically
  38. * bound when the bind() method is called for the pass.
  39. *
  40. * @param binding The VertexAttributeBinding to set (or NULL to remove an existing binding).
  41. */
  42. void setVertexAttributeBinding(VertexAttributeBinding* binding);
  43. /**
  44. * Binds the render state for this pass.
  45. *
  46. * This method should be called before executing any drawing code that should
  47. * use this pass. When drawing code is complete, the unbind() method should be called.
  48. */
  49. void bind();
  50. /**
  51. * Unbinds the render state for this pass.
  52. *
  53. * This method should always be called when rendering for a pass is complete, to
  54. * restore the render state to the state it was in previous to calling bind().
  55. */
  56. void unbind();
  57. private:
  58. /**
  59. * Constructor.
  60. */
  61. Pass(const char* id, Technique* technique, Effect* effect);
  62. /**
  63. * Hidden copy constructor.
  64. */
  65. Pass(const Pass& copy);
  66. /**
  67. * Destructor.
  68. */
  69. ~Pass();
  70. /**
  71. * Creates a new pass for the given shaders.
  72. */
  73. static Pass* create(const char* id, Technique* technique, const char* vshPath, const char* fshPath, const char* defines);
  74. /**
  75. * Hidden copy assignment operator.
  76. */
  77. Pass& operator=(const Pass&);
  78. /**
  79. * Clones the Pass and assigns it the given Technique.
  80. *
  81. * @param technique The technique to assign to the new Pass.
  82. * @param context The clone context.
  83. *
  84. * @return The newly created Pass.
  85. */
  86. Pass* clone(Technique* technique, NodeCloneContext &context) const;
  87. std::string _id;
  88. Technique* _technique;
  89. Effect* _effect;
  90. VertexAttributeBinding* _vaBinding;
  91. };
  92. }
  93. #endif