Fillwave  10.0.0
EmiterPointGPU.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/flf/models/base/IEmiterPoint.h>
25 #include <flw/flc/extended/pipeline/Fence.h>
26 #include <flw/flc/extended/buffers/VertexBufferParticlesGPU.h>
27 
28 namespace flw {
29 class Engine;
30 namespace flf {
31 
38 class EmiterPointGPU : public IReloadable, public Entity, public IEmiterPoint {
39 public:
40  EmiterPointGPU(Engine *engine,
41  GLfloat emitingSourceRate,
42  GLuint howMany,
43  glm::vec4 color,
44  glm::vec3 acceleration,
45  glm::vec3 startVelocity,
46  glm::vec3 robustnessVelocity,
47  glm::vec3 startPosition,
48  glm::vec3 robustnessPosition,
49  GLfloat startSize,
50  GLfloat lifetime,
51  flc::Texture2D* texture,
52  GLenum blendingSource,
53  GLenum blendingDestination,
54  GLboolean depthTesting,
55  GLfloat alphaCutOffLevel = 0.0f);
56 
57  ~EmiterPointGPU() override = default;
58 
59  /* IEmiterPoint */
60  void update(GLfloat timeElapsedSec) override;
61 
62  /* IRenderable */
63  void drawFR(ICamera &camera) override;
64  void drawPBRP(ICamera &camera) override;
65  bool getRenderItem(flc::RenderItem &item) override;
66 
67  /* IRenderable */
68  void updateRenderer(flc::IRenderer &renderer) override;
69 
70  private:
71  static const GLint mPingPongBuffers = 2;
72  GLuint mSrcIndex;
73  GLuint mNoiseTextureHandle;
74  GLfloat mEmmisingSourceRate;
75  glm::vec3 mAcceleration;
76  glm::vec3 mStartVelocity;
77  glm::vec3 mRobustnessVelocity;
78  glm::vec3 mStartPosition;
79  glm::vec3 mRobustnessPosition;
80  glm::vec3 mCameraPosition;
81  GLfloat mTimeDeltaEmiter;
82  flc::Program *mProgramEmiter;
83  pu<flc::Fence> mFence;
84 
85  flc::VertexBufferParticlesGPU* mVBOGPU[mPingPongBuffers];
86 
87  GLint mULCTimeEmiter, mULCEmissionRateEmiter, mULCModelMatrixEmiter, mULCCameraPositionEmiter, mULCHowManyEmiter, mULCAccelerationEmiter, mULCStartVelocityEmiter, mULCStartPositionEmiter, mULCLifeTimeEmiter, mULCRobustnessVelocityEmiter, mULCRobustnessPositionEmiter, mULCNoiseSamplerEmiter;
88 
89  GLint mULCModelMatrix, mULCViewProjectionMatrix, mULCCameraPosition, mULCTextureUnit, mULCTime, mULCAcceleration, mULCColor, mULCAlphaCutOff, mULCStartSize;
90 
91  void initBuffers() override;
92 
93  void initPipeline() override;
94 
95  void initVBO() override;
96 
97  void initVAO() override;
98 
99  void initUniformsCache() override;
100 
101  void coreDraw();
102 
103  void sort(glm::vec3 cameraPosition);
104 };
105 
106 } /* flf */
107 } /* flw */
Definition: Aliases.h:30
Encapsulates reloadable objects.
Definition: IReloadable.h:35
Drawable Entity which emits particles.
Definition: IEmiterPoint.h:40
Base for all renderers.
Definition: IRenderer.h:42
Single GLSL 2D Texture object.
Definition: Texture2D.h:36
Fillwave engine core.
Definition: Engine.h:85
Base for all Scene nodes.
Definition: Entity.h:48
Vertex buffer specialized with VertexParticleGPU data structure.
Definition: VertexBufferParticlesGPU.h:49
Single GLSL program object.
Definition: Program.h:37
Polynomial particle Emiter entirely computed on GPU. Can generate a particles with velocity...
Definition: EmiterPointGPU.h:38
Single draw item structure.
Definition: RenderItem.h:33
Stores camera view parameters.
Definition: ICamera.h:32