VolumeTechnique 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGVOLUME_VOLUMETECHNIQUE
  14. #define OSGVOLUME_VOLUMETECHNIQUE 1
  15. #include <osg/Object>
  16. #include <osgUtil/UpdateVisitor>
  17. #include <osgUtil/CullVisitor>
  18. #include <osgVolume/Export>
  19. namespace osgVolume {
  20. class VolumeTile;
  21. /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/
  22. struct TileData : public osg::Referenced
  23. {
  24. TileData() : active(false) {}
  25. virtual void update(osgUtil::CullVisitor* cv) = 0;
  26. bool active;
  27. osg::NodePath nodePath;
  28. osg::ref_ptr<osg::RefMatrix> projectionMatrix;
  29. osg::ref_ptr<osg::RefMatrix> modelviewMatrix;
  30. osg::ref_ptr<osg::StateSet> stateset;
  31. };
  32. class OSGVOLUME_EXPORT VolumeTechnique : public osg::Object
  33. {
  34. public:
  35. VolumeTechnique();
  36. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  37. VolumeTechnique(const VolumeTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  38. META_Object(osgVolume, VolumeTechnique);
  39. VolumeTile* getVolumeTile() { return _volumeTile; }
  40. const VolumeTile* getVolumeTile() const { return _volumeTile; }
  41. virtual void init();
  42. virtual void update(osgUtil::UpdateVisitor* nv);
  43. virtual bool isMoving(osgUtil::CullVisitor* nv);
  44. virtual void cull(osgUtil::CullVisitor* nv);
  45. /** Clean scene graph from any terrain technique specific nodes.*/
  46. virtual void cleanSceneGraph();
  47. /** Traverse the terrain subgraph.*/
  48. virtual void traverse(osg::NodeVisitor& nv);
  49. /** Called from VolumeScene to create the TileData container when a multi-pass technique is being used.
  50. * The TileData container caches any render to texture objects that are required. */
  51. virtual TileData* createTileData(osgUtil::CullVisitor* /*cv*/) { return 0; }
  52. protected:
  53. void setDirty(bool dirty);
  54. virtual ~VolumeTechnique();
  55. friend class osgVolume::VolumeTile;
  56. VolumeTile* _volumeTile;
  57. typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
  58. OpenThreads::Mutex _mutex;
  59. ModelViewMatrixMap _modelViewMatrixMap;
  60. };
  61. }
  62. #endif