CCParticle3DRender.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. ****************************************************************************/
  21. #ifndef __CC_PARTICLE_3D_RENDER_H__
  22. #define __CC_PARTICLE_3D_RENDER_H__
  23. #include <vector>
  24. #include "renderer/CCRenderState.h"
  25. #include "base/CCRef.h"
  26. #include "math/CCMath.h"
  27. NS_CC_BEGIN
  28. class ParticleSystem3D;
  29. class Renderer;
  30. class MeshCommand;
  31. class Sprite3D;
  32. class GLProgramState;
  33. class IndexBuffer;
  34. class VertexBuffer;
  35. class Texture2D;
  36. /**
  37. * 3d particle render
  38. */
  39. class CC_DLL Particle3DRender : public Ref
  40. {
  41. friend class ParticleSystem3D;
  42. public:
  43. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) = 0;
  44. /** Perform activities when a Renderer is started.
  45. */
  46. virtual void notifyStart();
  47. /** Perform activities when a Renderer is stopped.
  48. */
  49. virtual void notifyStop();
  50. /** Notify that the Particle System is rescaled.
  51. */
  52. virtual void notifyRescaled(const Vec3& scale);
  53. void setVisible(bool isVisible) { _isVisible = isVisible; }
  54. bool isVisible() const { return _isVisible; }
  55. void setDepthTest(bool isDepthTest);
  56. void setDepthWrite(bool isDepthWrite);
  57. void setBlendFunc(const BlendFunc& blendFunc);
  58. void copyAttributesTo (Particle3DRender *render);
  59. virtual void reset(){}
  60. CC_CONSTRUCTOR_ACCESS:
  61. Particle3DRender();
  62. virtual ~Particle3DRender();
  63. protected:
  64. ParticleSystem3D *_particleSystem;
  65. RenderState::StateBlock* _stateBlock;
  66. bool _isVisible;
  67. Vec3 _rendererScale;
  68. bool _depthTest;
  69. bool _depthWrite;
  70. };
  71. // particle render for quad
  72. class CC_DLL Particle3DQuadRender : public Particle3DRender
  73. {
  74. public:
  75. static Particle3DQuadRender* create(const std::string& texFile = "");
  76. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  77. virtual void reset()override;
  78. CC_CONSTRUCTOR_ACCESS:
  79. Particle3DQuadRender();
  80. virtual ~Particle3DQuadRender();
  81. protected:
  82. bool initQuadRender(const std::string& texFile);
  83. protected:
  84. MeshCommand* _meshCommand;
  85. Texture2D* _texture;
  86. GLProgramState* _glProgramState;
  87. IndexBuffer* _indexBuffer; //index buffer
  88. VertexBuffer* _vertexBuffer; // vertex buffer
  89. struct posuvcolor
  90. {
  91. Vec3 position;
  92. Vec2 uv;
  93. Vec4 color;
  94. };
  95. std::vector<posuvcolor> _posuvcolors; //vertex data
  96. std::vector<unsigned short> _indexData; //index data
  97. std::string _texFile;
  98. };
  99. // particle render for Sprite3D
  100. class CC_DLL Particle3DModelRender : public Particle3DRender
  101. {
  102. public:
  103. static Particle3DModelRender* create(const std::string& modelFile, const std::string &texFile = "");
  104. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  105. virtual void reset()override;
  106. CC_CONSTRUCTOR_ACCESS:
  107. Particle3DModelRender();
  108. virtual ~Particle3DModelRender();
  109. protected:
  110. std::vector<Sprite3D *> _spriteList;
  111. std::string _modelFile;
  112. std::string _texFile;
  113. Vec3 _spriteSize;
  114. };
  115. NS_CC_END
  116. #endif