Blame view

ios/cocos2d/extensions/Particle3D/CCParticle3DRender.h 5.14 KB
520389e3   xiaoyu   接入cocos源码,编译未通过,继续修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  /****************************************************************************
   Copyright (c) 2015-2016 Chukong Technologies Inc.
   Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
   
   http://www.cocos2d-x.org
   
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
   
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
  
  #pragma once
  
  #include <vector>
  
  #include "renderer/CCRenderState.h"
  #include "renderer/backend/Types.h"
  #include "renderer/CCMeshCommand.h"
  #include "renderer/CCCallbackCommand.h"
  #include "renderer/backend/Buffer.h"
  #include "base/CCRef.h"
  #include "math/CCMath.h"
  
  
  
  NS_CC_BEGIN
  
  class ParticleSystem3D;
  class Renderer;
  class MeshCommand;
  class Sprite3D;
  class GLProgramState;
  class IndexBuffer;
  class VertexBuffer;
  class Texture2D;
  
  /**
   * 3d particle render
   */
  class CC_DLL Particle3DRender : public Ref
  {
      friend class ParticleSystem3D;
  public:
  
      virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) = 0;
  
      /** Perform activities when a Renderer is started.
      */
      virtual void notifyStart();
      /** Perform activities when a Renderer is stopped.
      */
      virtual void notifyStop();
      /** Notify that the Particle System is rescaled.
      */
      virtual void notifyRescaled(const Vec3& scale);
      
      void setVisible(bool isVisible) { _isVisible = isVisible; }
      
      bool isVisible() const { return _isVisible; }
  
      void setDepthTest(bool isDepthTest);
      void setDepthWrite(bool isDepthWrite);
      void setBlendFunc(const BlendFunc& blendFunc);
  
      void copyAttributesTo (Particle3DRender *render);
  
      virtual void reset(){}
  
  CC_CONSTRUCTOR_ACCESS:
      Particle3DRender();
      virtual ~Particle3DRender();
      
  protected:
      ParticleSystem3D *_particleSystem;
      RenderState::StateBlock _stateBlock;
      bool  _isVisible;
      Vec3 _rendererScale;
      bool _depthTest;
      bool _depthWrite;
  };
  
  // particle render for quad
  class CC_DLL Particle3DQuadRender : public Particle3DRender
  {
  public:
      static Particle3DQuadRender* create(const std::string& texFile = "");
      
      virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  
      virtual void reset()override;
  CC_CONSTRUCTOR_ACCESS:
      Particle3DQuadRender();
      virtual ~Particle3DQuadRender();
  
  protected:
  
      bool initQuadRender(const std::string& texFile);
  
      void onBeforeDraw();
      void onAfterDraw();
      
  protected:
      MeshCommand             _meshCommand;
      CallbackCommand         _beforeCommand;
      CallbackCommand         _afterCommand;
      Texture2D*              _texture         = nullptr;
      backend::ProgramState*  _programState    = nullptr;
      backend::Buffer*        _indexBuffer     = nullptr; //index buffer
      backend::Buffer*        _vertexBuffer    = nullptr; // vertex buffer
      
      struct posuvcolor
      {
          Vec3 position;
          Vec2 uv;
          Vec4 color;
      };
  
      std::vector<posuvcolor> _posuvcolors;   //vertex data
      std::vector<uint16_t> _indexData; //index data
      std::string _texFile;
  
      backend::UniformLocation    _locColor;
      backend::UniformLocation    _locTexture;
      backend::UniformLocation    _locPMatrix;
  
      //renderer state cache variables
      bool                        _rendererDepthTestEnabled   = true;
      backend::CompareFunction    _rendererDepthCmpFunc       = backend::CompareFunction::LESS;
      backend::CullMode           _rendererCullMode           = backend::CullMode::BACK;
      backend::Winding            _rendererWinding            = backend::Winding::COUNTER_CLOCK_WISE;
      bool                        _rendererDepthWrite         = false;
  };
  
  // particle render for Sprite3D
  class CC_DLL Particle3DModelRender : public Particle3DRender
  {
  public:
      static Particle3DModelRender* create(const std::string& modelFile, const std::string &texFile = "");
  
      virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
      
      virtual void reset()override;
  CC_CONSTRUCTOR_ACCESS:
      Particle3DModelRender();
      virtual ~Particle3DModelRender();
      
  protected:
      std::vector<Sprite3D *> _spriteList;
      std::string _modelFile;
      std::string _texFile;
      Vec3 _spriteSize;
  };
  
  NS_CC_END