CollectOccludersVisitor 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 OSG_COLLECTOCCLUDERSVISITOR
  14. #define OSG_COLLECTOCCLUDERSVISITOR 1
  15. #include <osg/NodeVisitor>
  16. #include <osg/CullStack>
  17. #include <set>
  18. namespace osg {
  19. class OSG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::CullStack
  20. {
  21. public:
  22. typedef std::set<ShadowVolumeOccluder> ShadowVolumeOccluderSet;
  23. CollectOccludersVisitor();
  24. virtual ~CollectOccludersVisitor();
  25. META_NodeVisitor(osg, CollectOccludersVisitor)
  26. virtual Object* cloneType() const { return new CollectOccludersVisitor(); }
  27. virtual void reset();
  28. virtual float getDistanceToEyePoint(const Vec3& pos, bool withLODScale) const;
  29. virtual float getDistanceToViewPoint(const Vec3& pos, bool withLODScale) const;
  30. virtual float getDistanceFromEyePoint(const Vec3& pos, bool withLODScale) const;
  31. virtual void apply(osg::Node&);
  32. virtual void apply(osg::Transform& node);
  33. virtual void apply(osg::Projection& node);
  34. virtual void apply(osg::Switch& node);
  35. virtual void apply(osg::LOD& node);
  36. virtual void apply(osg::OccluderNode& node);
  37. /** Sets the minimum shadow occluder volume that an active occluder
  38. * must have. vol is units relative the clip space volume where 1.0
  39. * is the whole clip space. */
  40. void setMinimumShadowOccluderVolume(float vol) { _minimumShadowOccluderVolume = vol; }
  41. float getMinimumShadowOccluderVolume() const { return _minimumShadowOccluderVolume; }
  42. /** Sets the maximum number of occluders to have active for culling
  43. * purposes. */
  44. void setMaximumNumberOfActiveOccluders(unsigned int num) { _maximumNumberOfActiveOccluders = num; }
  45. unsigned int getMaximumNumberOfActiveOccluders() const { return _maximumNumberOfActiveOccluders; }
  46. void setCreateDrawablesOnOccludeNodes(bool flag) { _createDrawables=flag; }
  47. bool getCreateDrawablesOnOccludeNodes() const { return _createDrawables; }
  48. void setCollectedOccluderSet(const ShadowVolumeOccluderSet& svol) { _occluderSet = svol; }
  49. ShadowVolumeOccluderSet& getCollectedOccluderSet() { return _occluderSet; }
  50. const ShadowVolumeOccluderSet& getCollectedOccluderSet() const { return _occluderSet; }
  51. /** Removes occluded occluders for the collected occluders list, then
  52. * discards all but MaximumNumberOfActiveOccluders of occluders,
  53. * discarding the occluders with the lowest shadow occluder volume. */
  54. void removeOccludedOccluders();
  55. protected:
  56. /** Prevents unwanted copy construction. */
  57. //CollectOccludersVisitor(const CollectOccludersVisitor&):osg::NodeVisitor(),osg::CullStack() {}
  58. /** Prevents unwanted copy operator. */
  59. CollectOccludersVisitor& operator = (const CollectOccludersVisitor&) { return *this; }
  60. inline void handle_cull_callbacks_and_traverse(osg::Node& node)
  61. {
  62. /*osg::NodeCallback* callback = node.getCullCallback();
  63. if (callback) (*callback)(&node,this);
  64. else*/ if (node.getNumChildrenWithOccluderNodes()>0) traverse(node);
  65. }
  66. inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
  67. {
  68. /*osg::NodeCallback* callback = node.getCullCallback();
  69. if (callback) (*callback)(&node,this);
  70. else*/ if (node.getNumChildrenWithOccluderNodes()>0) acceptNode->accept(*this);
  71. }
  72. float _minimumShadowOccluderVolume;
  73. unsigned _maximumNumberOfActiveOccluders;
  74. bool _createDrawables;
  75. ShadowVolumeOccluderSet _occluderSet;
  76. };
  77. }
  78. #endif