VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
ParticleRendererItem.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PARTICLERENDERERITEM_H
18 #define PARTICLERENDERERITEM_H
19 
20 #include <memory>
21 #include "Graphic.h"
23 #include "renderer/RenderNode.h"
24 
25 struct ParticleRendererItemFboDesc;
26 class b2ParticleSystem;
27 struct b2AABB;
28 
43  float aspectRatio = 0.0f;
47  float alpha = 0.0f;
51  float zoomFactor = 0.0f;
58  float highlightWidth = 0.0f;
62  float highlightAlpha = 0.0f;
74  float shadowAlpha = 0.0f;
87 };
88 
113  Q_OBJECT
114 public:
118  constexpr static const int FBO_SIZE = 1024;
123  constexpr static const int AUX_FBO_SIZE = 384;
132  static const float PARTICLE_SCALE;
133 
134  virtual ~ParticleRendererItem();
135 
136 protected:
142  virtual void render(RenderNode* node) override;
148  virtual void synchronizeForRendering(RenderList* renderList) override;
149 
150 private:
151  constexpr static const float NORMAL_ZOOM_FOV = 8.0f;
152  constexpr static const int FBO_COUNT = 2;
153 
154  void synchronize();
155  void renderFboContents();
156  void renderParticleSystem(b2ParticleSystem* psystem, float scale, const QRectF& worldCullBounds,
157  b2AABB* worldUpdateRegion);
158  void createParticleShader();
159  static void checkExtensions();
160 
161  float mZoomFactor = 0.0f;
162  float mAspectRatio = 1.0f;
163  bool mUpdateRegionEmpty = false;
164  QRectF mUpdateRegion;
165  int mFboIds[FBO_COUNT];
166  int mFboTextureIds[FBO_COUNT];
167  TexturePtr mFboTextures[FBO_COUNT];
168 
169  ShaderPtr mParticleShader;
170  ShaderPtr mAuxFboSpecularShader;
171  MeshInstancePtr mSquareFboToScreenMesh;
172  TexturePtr mParticleTexture;
173  RenderNode mRenderNode;
174  ParticleShaderParams mRenderParams;
175 
176  static const ParticleRendererItemFboDesc FBO_DEFINITIONS[];
177  // Whether or not the current GPU supports extensions allowing us to use the combined shader
178  // rather than multiple stages for performance.
179  static bool sParticleRendererUseCombinedShader;
180 };
181 Q_DECLARE_METATYPE(ParticleRendererItem*)
182 
183 #endif // PARTICLERENDERERITEM_H
Callback set in a RenderNode which can be used to issues draw calls.
Definition: RenderableInterface.h:26
QPointF shadowOffset
Offset of the inner shadow in world coordinates.
Definition: ParticleRendererItem.h:70
QColor tintColor
Base color of the inner shadow effect, which tints colors beneath this effect.
Definition: ParticleRendererItem.h:66
Base class for visual elements which are part of the game scene, and are rendered through Renderer...
Definition: Graphic.h:34
Graphic which renders LiquidFun particles as blobs with a variety of effects.
Definition: ParticleRendererItem.h:112
float highlightAlpha
Transparency of the highlight effect.
Definition: ParticleRendererItem.h:62
float shadowAlpha
Transparency of the inner shadow effect.
Definition: ParticleRendererItem.h:74
float alpha
Overall transparency of the rendered effect.
Definition: ParticleRendererItem.h:47
virtual void synchronizeForRendering(RenderList *renderList) override
Synchronize and queue RenderNodes for rendering.
static const float PARTICLE_SCALE
Visual size of particles, relative to their physical size.
Definition: ParticleRendererItem.h:132
static constexpr const int FBO_SIZE
Width and height of the main frame buffer object used to render particles to.
Definition: ParticleRendererItem.h:118
QRectF updateRegion
Subsection of the frame buffer and viewport which needs to get rendered.
Definition: ParticleRendererItem.h:39
Structure holding the state for shaders used in ParticleRenderItem.
Definition: ParticleRendererItem.h:35
std::shared_ptr< Texture > TexturePtr
Shared pointer typedef for Texture.
Definition: PointerDeclarations.h:173
float aspectRatio
Aspect ratio of the viewport.
Definition: ParticleRendererItem.h:43
std::shared_ptr< Shader > ShaderPtr
Shared pointer typedef for Shader.
Definition: PointerDeclarations.h:143
static constexpr const int AUX_FBO_SIZE
Width and height of the secondary frame buffer object used to render fake specular lighting to...
Definition: ParticleRendererItem.h:123
Node which queues a callback (RenderableInterface) or MeshInstance for rendering. ...
Definition: RenderNode.h:33
float highlightWidth
Width of the highlight produced by the inner bevel effect.
Definition: ParticleRendererItem.h:58
qreal scale() const
File containing forward declarations for renderer types and smart pointers.
std::shared_ptr< MeshInstance > MeshInstancePtr
Shared pointer typedef for MeshInstance.
Definition: PointerDeclarations.h:113
List of RenderNodes, sorted by z-depth for rendering.
Definition: RenderList.h:36
float zoomFactor
Amount of zoom relative to a reference zoom amount.
Definition: ParticleRendererItem.h:51
virtual void render(RenderNode *node) override
Implementation of RenderableInterface blending our frame buffers onto the current scene...
TexturePtr texture
Texture referencing the main FBO.
Definition: ParticleRendererItem.h:82
QColor shadowColor
Color of the shadowed parts of the inner shadow effect.
Definition: ParticleRendererItem.h:78
TexturePtr specularTexture
Texture referencing the secondary FBO containing the fake specular lighting.
Definition: ParticleRendererItem.h:86