AGXDynamics  2.35.0.3
ParticleSystemDrawable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, is 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 
116 
118 }
119 
120 #endif /* AGXOSG_PARTICLE_SYSTEMDRAWABLE_H */
agxOSG::ParticleSystemDrawable::clone
virtual osg::Object * clone(const osg::CopyOp &) const
Definition: ParticleSystemDrawable.h:74
Task.h
agxOSG::ParticleSystemDrawable::cloneType
virtual osg::Object * cloneType() const
Definition: ParticleSystemDrawable.h:73
agxOSG::ParticleSystemDrawable::ParticleShaderMode
ParticleShaderMode
Definition: ParticleSystemDrawable.h:56
DEFAULT_PARTICLE_RENDERING_MODE
#define DEFAULT_PARTICLE_RENDERING_MODE
Definition: ParticleSystemDrawable.h:38
ParticleSystem.h
agxOSG::ParticleSystemDrawable::m_renderMode
ParticleRenderingMode m_renderMode
Definition: ParticleSystemDrawable.h:109
agxOSG::ParticleSystemDrawable::setEnable
void setEnable(bool enable)
Definition: ParticleSystemDrawable.h:117
agx::observer_ptr< ParticleSystem >
agxOSG::ParticleSystemDrawable::getEnable
bool getEnable() const
Definition: ParticleSystemDrawable.h:115
agxOSG::ParticleSystemDrawable::SPRITES
@ SPRITES
Definition: ParticleSystemDrawable.h:48
agx::ParticleSystem
A basic particle system that contains all the storages and buffers required for basic operation and a...
Definition: ParticleSystem.h:67
agx::ref_ptr< TaskGroup >
agxOSG::ParticleSystemDrawable::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: ParticleSystemDrawable.h:75
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
PushDisableWarnings.h
agxOSG::ParticleSystemDrawable
Definition: ParticleSystemDrawable.h:44
observer_ptr.h
agxOSG::ParticleSystemDrawable::ParticleRenderingMode
ParticleRenderingMode
Definition: ParticleSystemDrawable.h:47
agxOSG::ParticleSystemDrawable::libraryName
virtual const char * libraryName() const
Definition: ParticleSystemDrawable.h:76
agxOSG::ParticleSystemDrawable::className
virtual const char * className() const
Definition: ParticleSystemDrawable.h:77
agxOSG::ParticleSystemDrawable::QUAD_SPRITES
@ QUAD_SPRITES
Definition: ParticleSystemDrawable.h:49
export.h
agxOSG::ParticleSystemDrawable::SIMPLE_SPRITES
@ SIMPLE_SPRITES
Definition: ParticleSystemDrawable.h:58
agxOSG::ParticleSystemDrawable::ALPHA_SPRITES
@ ALPHA_SPRITES
Definition: ParticleSystemDrawable.h:60
agxOSG::ParticleSystemDrawable::m_enable
bool m_enable
Definition: ParticleSystemDrawable.h:110
agxOSG::ParticleSystemDrawable::m_particleShaderMode
ParticleShaderMode m_particleShaderMode
Definition: ParticleSystemDrawable.h:108
agxOSG::ParticleSystemDrawable::m_renderTask
agx::TaskGroupRef m_renderTask
Definition: ParticleSystemDrawable.h:107
agxOSG::ParticleSystemDrawable::ROTATION_SPRITES
@ ROTATION_SPRITES
Definition: ParticleSystemDrawable.h:59
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
AGXOSG_EXPORT
#define AGXOSG_EXPORT
agxOSG::ParticleSystemDrawable::m_particleSystem
agx::ParticleSystemObserver m_particleSystem
Definition: ParticleSystemDrawable.h:106
PopDisableWarnings.h