1
0

CCParticle3DRender.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /****************************************************************************
  2. Copyright (c) 2015-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CC_PARTICLE_3D_RENDER_H__
  21. #define __CC_PARTICLE_3D_RENDER_H__
  22. #include <vector>
  23. #include "renderer/CCRenderState.h"
  24. #include "base/CCRef.h"
  25. #include "math/CCMath.h"
  26. NS_CC_BEGIN
  27. class ParticleSystem3D;
  28. class Renderer;
  29. class MeshCommand;
  30. class Sprite3D;
  31. class GLProgramState;
  32. class IndexBuffer;
  33. class VertexBuffer;
  34. class Texture2D;
  35. /**
  36. * 3d particle render
  37. */
  38. class CC_DLL Particle3DRender : public Ref
  39. {
  40. friend class ParticleSystem3D;
  41. public:
  42. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) = 0;
  43. /** Perform activities when a Renderer is started.
  44. */
  45. virtual void notifyStart();
  46. /** Perform activities when a Renderer is stopped.
  47. */
  48. virtual void notifyStop();
  49. /** Notify that the Particle System is rescaled.
  50. */
  51. virtual void notifyRescaled(const Vec3& scale);
  52. void setVisible(bool isVisible) { _isVisible = isVisible; }
  53. bool isVisible() const { return _isVisible; }
  54. void setDepthTest(bool isDepthTest);
  55. void setDepthWrite(bool isDepthWrite);
  56. void setBlendFunc(const BlendFunc& blendFunc);
  57. void copyAttributesTo (Particle3DRender *render);
  58. virtual void reset(){}
  59. CC_CONSTRUCTOR_ACCESS:
  60. Particle3DRender();
  61. virtual ~Particle3DRender();
  62. protected:
  63. ParticleSystem3D *_particleSystem;
  64. RenderState::StateBlock* _stateBlock;
  65. bool _isVisible;
  66. Vec3 _rendererScale;
  67. bool _depthTest;
  68. bool _depthWrite;
  69. };
  70. // particle render for quad
  71. class CC_DLL Particle3DQuadRender : public Particle3DRender
  72. {
  73. public:
  74. static Particle3DQuadRender* create(const std::string& texFile = "");
  75. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  76. virtual void reset()override;
  77. CC_CONSTRUCTOR_ACCESS:
  78. Particle3DQuadRender();
  79. virtual ~Particle3DQuadRender();
  80. protected:
  81. bool initQuadRender(const std::string& texFile);
  82. protected:
  83. MeshCommand* _meshCommand;
  84. Texture2D* _texture;
  85. GLProgramState* _glProgramState;
  86. IndexBuffer* _indexBuffer; //index buffer
  87. VertexBuffer* _vertexBuffer; // vertex buffer
  88. struct posuvcolor
  89. {
  90. Vec3 position;
  91. Vec2 uv;
  92. Vec4 color;
  93. };
  94. std::vector<posuvcolor> _posuvcolors; //vertex data
  95. std::vector<unsigned short> _indexData; //index data
  96. std::string _texFile;
  97. };
  98. // particle render for Sprite3D
  99. class CC_DLL Particle3DModelRender : public Particle3DRender
  100. {
  101. public:
  102. static Particle3DModelRender* create(const std::string& modelFile, const std::string &texFile = "");
  103. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  104. virtual void reset()override;
  105. CC_CONSTRUCTOR_ACCESS:
  106. Particle3DModelRender();
  107. virtual ~Particle3DModelRender();
  108. protected:
  109. std::vector<Sprite3D *> _spriteList;
  110. std::string _modelFile;
  111. std::string _texFile;
  112. Vec3 _spriteSize;
  113. };
  114. NS_CC_END
  115. #endif