AGX Dynamics  2.37.3.2
ParticleSystemDrawable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXOSG_PARTICLE_SYSTEMDRAWABLE_H
18 #define AGXOSG_PARTICLE_SYSTEMDRAWABLE_H
19 
20 #include <agx/config/AGX_USE_OPENGL_INSTANCING.h>
21 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
22 #include <osg/Drawable>
23 #include <osgViewer/Viewer>
24 #include <osg/Version>
25 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
26 
27 #include <agxOSG/export.h>
28 #include <agx/Task.h>
29 #include <agx/observer_ptr.h>
30 #include <agx/ParticleSystem.h>
31 
32 #ifndef DEFAULT_PARTICLE_RENDERING_MODE
33  #if defined(__APPLE__)
34  // The shader for quad sprites does not compile on macOS, since OpenGL 2.1 is used.
35  // It should be updated to OpenGL 3.x, but that requires setting up the context a bit differently.
36  #define DEFAULT_PARTICLE_RENDERING_MODE agxOSG::ParticleSystemDrawable::SPRITES
37  #else
38  #define DEFAULT_PARTICLE_RENDERING_MODE agxOSG::ParticleSystemDrawable::QUAD_SPRITES
39  #endif
40 #endif
41 
42 namespace agxOSG
43 {
44  class AGXOSG_EXPORT ParticleSystemDrawable : public osg::Drawable
45  {
46  public:
50  TRIANGLES
51  #if AGX_USE_OPENGL_INSTANCING()
52  , INSTANCES
53  #endif
54  };
55 
57  {
61  };
62 
63  public:
64 
65  ParticleSystemDrawable( agx::ParticleSystem *particleSystem, ParticleRenderingMode renderMode = DEFAULT_PARTICLE_RENDERING_MODE, ParticleShaderMode particleShaderMode = ROTATION_SPRITES);
66  // ParticleSystemDrawable( const ParticleSystemDrawable&c, const osg::CopyOp& copyOp );
67 
68 
69  ParticleShaderMode getParticleShaderMode() const;
70  void setParticleShaderMode(ParticleShaderMode flag);
71 
72 
73  virtual osg::Object* cloneType() const { return new ParticleSystemDrawable ( m_particleSystem.get() ); }
74  virtual osg::Object* clone(const osg::CopyOp&) const { return new ParticleSystemDrawable (*this); }
75  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleSystemDrawable *>(obj)!=nullptr; }
76  virtual const char* libraryName() const { return "agxOSG"; }
77  virtual const char* className() const { return "ParticleSystemDrawable"; }
78 
79 
81 # if OSG_VERSION_GREATER_OR_EQUAL(3,4,0)
82  virtual osg::BoundingSphere computeBound() const;
83  virtual osg::BoundingBox computeBoundingBox() const;
84 #else
85  virtual osg::BoundingBox computeBound() const;
86 #endif
87 
89  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
90 
91  void setEnable(bool enable);
92 
93  bool getEnable() const;
94 
95  agx::ParticleSystem* getParticleSystem();
96 
98  static void setAllowedRenderMode(ParticleRenderingMode mode);
99 
101  static ParticleRenderingMode getAllowedRenderMode();
102 
103  protected:
104  virtual ~ParticleSystemDrawable();
105 
110  bool m_enable;
111  private:
112  static ParticleRenderingMode s_allowedRenderMode;
113  };
114 
115  AGX_FORCE_INLINE bool ParticleSystemDrawable::getEnable() const { return m_enable; }
116 
117  AGX_FORCE_INLINE void ParticleSystemDrawable::setEnable(bool enable) { m_enable = enable; }
118 }
119 
120 #endif /* AGXOSG_PARTICLE_SYSTEMDRAWABLE_H */
#define AGXOSG_EXPORT
virtual const char * className() const
virtual osg::Object * clone(const osg::CopyOp &) const
#define DEFAULT_PARTICLE_RENDERING_MODE
#define AGX_FORCE_INLINE
Definition: Object.h:59
A basic particle system that contains all the storages and buffers required for basic operation and a...
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
virtual bool isSameKindAs(const osg::Object *obj) const
agx::ParticleSystemObserver m_particleSystem
virtual osg::Object * cloneType() const
virtual const char * libraryName() const