ShadowedScene 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 OSGSHADOW_SHADOWEDSCENE
  14. #define OSGSHADOW_SHADOWEDSCENE 1
  15. #include <osg/buffered_value>
  16. #include <osg/Camera>
  17. #include <osg/Texture2D>
  18. #include <osg/TexGenNode>
  19. #include <osgShadow/ShadowTechnique>
  20. #include <osgShadow/ShadowSettings>
  21. namespace osgShadow {
  22. /** ShadowedScene provides a mechansim for decorating a scene that the needs to have shadows cast upon it.*/
  23. class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
  24. {
  25. public:
  26. ShadowedScene(ShadowTechnique* st=0);
  27. ShadowedScene(const ShadowedScene& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  28. META_Node(osgShadow, ShadowedScene);
  29. virtual void traverse(osg::NodeVisitor& nv);
  30. void setShadowSettings(ShadowSettings* ss);
  31. template<class T> void setShadowSettings(const osg::ref_ptr<T>& ss) { setShadowSettings(ss.get()); }
  32. ShadowSettings* getShadowSettings() { return _shadowSettings.get(); }
  33. const ShadowSettings* getShadowSettings() const { return _shadowSettings.get(); }
  34. void setShadowTechnique(ShadowTechnique* technique);
  35. template<class T> void setShadowTechnique(const osg::ref_ptr<T>& ss) { setShadowTechnique(ss.get()); }
  36. ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); }
  37. const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); }
  38. /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
  39. void cleanSceneGraph();
  40. /** Dirty any cache data structures held in the attached ShadowTechnqiue.*/
  41. void dirty();
  42. /** Resize any per context GLObject buffers to specified size. */
  43. virtual void resizeGLObjectBuffers(unsigned int maxSize);
  44. /** If State is non-zero, this function releases any associated OpenGL objects for
  45. * the specified graphics context. Otherwise, releases OpenGL objects
  46. * for all graphics contexts. */
  47. virtual void releaseGLObjects(osg::State* = 0) const;
  48. public:
  49. /** deprecated, moved to ShadowSettings.*/
  50. void setReceivesShadowTraversalMask(unsigned int mask) { if (_shadowSettings.valid()) _shadowSettings->setReceivesShadowTraversalMask(mask); }
  51. /** deprecated, moved to ShadowSettings.*/
  52. unsigned int getReceivesShadowTraversalMask() const { return _shadowSettings.valid() ? _shadowSettings->getReceivesShadowTraversalMask() : 0xffffffff; }
  53. /** deprecated, moved to ShadowSettings.*/
  54. void setCastsShadowTraversalMask(unsigned int mask) { if (_shadowSettings.valid()) _shadowSettings->setCastsShadowTraversalMask(mask); }
  55. /** deprecated, moved to ShadowSettings.*/
  56. unsigned int getCastsShadowTraversalMask() const { return _shadowSettings.valid() ? _shadowSettings->getCastsShadowTraversalMask() : 0xffffffff; }
  57. protected:
  58. virtual ~ShadowedScene();
  59. osg::ref_ptr<ShadowSettings> _shadowSettings;
  60. osg::ref_ptr<ShadowTechnique> _shadowTechnique;
  61. };
  62. }
  63. #endif