CCPass.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. Copyright (c) 2015-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. Ideas taken from:
  21. - GamePlay3D: http://gameplay3d.org/
  22. - OGRE3D: http://www.ogre3d.org/
  23. - Qt3D: http://qt-project.org/
  24. ****************************************************************************/
  25. #ifndef __cocos2d_libs__CCPass__
  26. #define __cocos2d_libs__CCPass__
  27. #include <stdio.h>
  28. #include "platform/CCPlatformMacros.h"
  29. #include "renderer/CCRenderState.h"
  30. NS_CC_BEGIN
  31. class GLProgramState;
  32. class Technique;
  33. class Node;
  34. class VertexAttribBinding;
  35. class CC_DLL Pass : public RenderState
  36. {
  37. friend class Material;
  38. public:
  39. /** Creates a Pass with a GLProgramState.
  40. */
  41. static Pass* createWithGLProgramState(Technique* parent, GLProgramState* programState);
  42. static Pass* create(Technique* parent);
  43. /** Returns the GLProgramState */
  44. GLProgramState* getGLProgramState() const;
  45. /** Binds the GLProgramState and the RenderState.
  46. This method must be called before call the actual draw call.
  47. */
  48. void bind(const Mat4& modelView);
  49. void bind(const Mat4& modelView, bool bindAttributes);
  50. /** Unbinds the Pass.
  51. This method must be called AFTER calling the actual draw call
  52. */
  53. void unbind();
  54. /**
  55. * Sets a vertex attribute binding for this pass.
  56. *
  57. * When a mesh binding is set, the VertexAttribBinding will be automatically
  58. * bound when the bind() method is called for the pass.
  59. *
  60. * @param binding The VertexAttribBinding to set (or NULL to remove an existing binding).
  61. */
  62. void setVertexAttribBinding(VertexAttribBinding* binding);
  63. /**
  64. * Returns the vertex attribute binding for this pass.
  65. *
  66. * @return The vertex attribute binding for this pass.
  67. */
  68. VertexAttribBinding* getVertexAttributeBinding() const;
  69. uint32_t getHash() const;
  70. /**
  71. * Returns a clone (deep-copy) of this instance */
  72. Pass* clone() const;
  73. protected:
  74. Pass();
  75. ~Pass();
  76. bool init(Technique* parent);
  77. bool initWithGLProgramState(Technique* parent, GLProgramState *glProgramState);
  78. void setGLProgramState(GLProgramState* glProgramState);
  79. Node* getTarget() const;
  80. GLProgramState* _glProgramState;
  81. VertexAttribBinding* _vertexAttribBinding;
  82. };
  83. NS_CC_END
  84. #endif /* defined(__cocos2d_libs__CCPass__) */