/
RenderableParticle.h
102 lines (74 loc) · 3.05 KB
/
RenderableParticle.h
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
#pragma once
#include "RenderableParticleStage.h"
#include "iparticles.h"
#include "irender.h"
#include "math/AABB.h"
#include "render.h"
#include <map>
#include <boost/random/linear_congruential.hpp>
#include <sigc++/connection.h>
namespace particles
{
/// Implementation of IRenderableParticle
class RenderableParticle : public IRenderableParticle,
public sigc::trackable
{
// The particle definition containing the stage info
IParticleDefPtr _particleDef;
// Signal connection from the particle def
sigc::connection _defConnection;
typedef std::vector<RenderableParticleStagePtr> RenderableParticleStageList;
// Particle stages using the same shader get grouped
struct ParticleStageGroup
{
ShaderPtr shader;
RenderableParticleStageList stages;
};
// Each captured shader can have one or more particle stages assigned to it
typedef std::map<std::string, ParticleStageGroup> ShaderMap;
ShaderMap _shaderMap;
// The random number generator, this is used to generate "constant"
// starting values for each bunch of particles. This enables us
// to go back in time when rendering the particle stage.
boost::rand48 _random;
// The particle direction, usually set by the emitter entity or the preview
Vector3 _direction;
// Holds the bounds of all stages at the current time. Will be updated
// by calls to getBounds(), otherwise might hold outdated bounds information.
AABB _bounds;
// The colour used when "use entity colour" is activated.
Vector3 _entityColour;
// The associated rendersystem, needed to get time an shaders
RenderSystemWeakPtr _renderSystem;
public:
RenderableParticle(const IParticleDefPtr& particleDef);
~RenderableParticle();
// Time is in msecs
void update(const Matrix4& viewRotation) override;
// Front-end render methods
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderSolid(RenderableCollector& collector, const VolumeTest& volume,
const Matrix4& localToWorld, const IRenderEntity* entity) const;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume,
const Matrix4& localToWorld, const IRenderEntity* entity) const;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;
std::size_t getHighlightFlags() override
{
return Highlight::NoHighlight; // never highlighted
}
const IParticleDefPtr& getParticleDef() const override;
void setParticleDef(const IParticleDefPtr& def) override;
void setMainDirection(const Vector3& direction) override;
void setEntityColour(const Vector3& colour) override;
// Updates bounds from stages and returns the value
const AABB& getBounds() override;
private:
void calculateBounds();
// Sort stages into groups sharing a material, without capturing the shader yet
void setupStages();
// Capture all shaders, if necessary
void ensureShaders(RenderSystem& renderSystem);
};
typedef std::shared_ptr<RenderableParticle> RenderableParticlePtr;
} // namespace