CCMeshCommand.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /****************************************************************************
  2. Copyright (c) 2013-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. ****************************************************************************/
  21. #ifndef _CC_MESHCOMMAND_H_
  22. #define _CC_MESHCOMMAND_H_
  23. #include <unordered_map>
  24. #include "renderer/CCRenderCommand.h"
  25. #include "renderer/CCGLProgram.h"
  26. #include "renderer/CCRenderState.h"
  27. #include "math/CCMath.h"
  28. NS_CC_BEGIN
  29. class GLProgramState;
  30. class EventListenerCustom;
  31. class EventCustom;
  32. class Material;
  33. //it is a common mesh
  34. class CC_DLL MeshCommand : public RenderCommand
  35. {
  36. public:
  37. MeshCommand();
  38. virtual ~MeshCommand();
  39. void init(float globalZOrder, Material* material, GLuint vertexBuffer, GLuint indexBuffer, GLenum primitive, GLenum indexFormat, ssize_t indexCount, const Mat4 &mv, uint32_t flags);
  40. void init(float globalZOrder, GLuint textureID, GLProgramState* glProgramState, RenderState::StateBlock* stateBlock, GLuint vertexBuffer, GLuint indexBuffer, GLenum primitive, GLenum indexFormat, ssize_t indexCount, const Mat4 &mv, uint32_t flags);
  41. void setDisplayColor(const Vec4& color);
  42. void setMatrixPalette(const Vec4* matrixPalette);
  43. void setMatrixPaletteSize(int size);
  44. void setLightMask(unsigned int lightmask);
  45. void execute();
  46. //used for batch
  47. void preBatchDraw();
  48. void batchDraw();
  49. void postBatchDraw();
  50. void genMaterialID(GLuint texID, void* glProgramState, GLuint vertexBuffer, GLuint indexBuffer, BlendFunc blend);
  51. uint32_t getMaterialID() const;
  52. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  53. void listenRendererRecreated(EventCustom* event);
  54. #endif
  55. protected:
  56. //build & release vao
  57. void buildVAO();
  58. void releaseVAO();
  59. // apply renderstate, not used when using material
  60. void applyRenderState();
  61. Vec4 _displayColor; // in order to support tint and fade in fade out
  62. // used for skin
  63. const Vec4* _matrixPalette;
  64. int _matrixPaletteSize;
  65. uint32_t _materialID; //material ID
  66. GLuint _vao; //use vao if possible
  67. GLuint _vertexBuffer;
  68. GLuint _indexBuffer;
  69. GLenum _primitive;
  70. GLenum _indexFormat;
  71. ssize_t _indexCount;
  72. // States, default value all false
  73. // ModelView transform
  74. Mat4 _mv;
  75. // Mode A: Material
  76. // weak ref
  77. Material* _material;
  78. // Mode B: StateBlock
  79. // weak ref
  80. GLProgramState* _glProgramState;
  81. RenderState::StateBlock* _stateBlock;
  82. GLuint _textureID;
  83. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  84. EventListenerCustom* _rendererRecreatedListener;
  85. #endif
  86. };
  87. NS_CC_END
  88. #endif //_CC_MESHCOMMAND_H_