ShadowTechnique 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_SHADOWEDTECHNIQUE
  14. #define OSGSHADOW_SHADOWEDTECHNIQUE 1
  15. #include <osg/buffered_value>
  16. #include <osg/Camera>
  17. #include <osg/Texture2D>
  18. #include <osg/TexGenNode>
  19. #include <osgUtil/CullVisitor>
  20. #include <osgShadow/Export>
  21. namespace osgShadow {
  22. // forward declare ShadowedScene
  23. class ShadowedScene;
  24. /** ShadowTechnique is the base class for different shadow implementations.*/
  25. class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object
  26. {
  27. public :
  28. ShadowTechnique();
  29. ShadowTechnique(const ShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  30. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ShadowTechnique*>(obj)!=NULL; } \
  31. virtual const char* libraryName() const { return "osgShadow"; }\
  32. virtual const char* className() const { return "ShadowTechnique"; }
  33. virtual void setShadowedScene(ShadowedScene* ss);
  34. ShadowedScene* getShadowedScene() { return _shadowedScene; }
  35. const ShadowedScene* getShadowedScene() const { return _shadowedScene; }
  36. /** initialize the ShadowedScene and local cached data structures.*/
  37. virtual void init();
  38. /** run the update traversal of the ShadowedScene and update any local cached data structures.*/
  39. virtual void update(osg::NodeVisitor& nv);
  40. /** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/
  41. virtual void cull(osgUtil::CullVisitor& cv);
  42. /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
  43. virtual void cleanSceneGraph();
  44. virtual void traverse(osg::NodeVisitor& nv);
  45. /** Dirty so that cached data structures are updated.*/
  46. virtual void dirty() { _dirty = true; }
  47. /** Resize any per context GLObject buffers to specified size. */
  48. virtual void resizeGLObjectBuffers(unsigned int maxSize) = 0;
  49. /** If State is non-zero, this function releases any associated OpenGL objects for
  50. * the specified graphics context. Otherwise, releases OpenGL objects
  51. * for all graphics contexts. */
  52. virtual void releaseGLObjects(osg::State* = 0) const = 0;
  53. protected :
  54. class OSGSHADOW_EXPORT CameraCullCallback : public osg::NodeCallback
  55. {
  56. public:
  57. CameraCullCallback(ShadowTechnique* st);
  58. virtual void operator()(osg::Node*, osg::NodeVisitor* nv);
  59. protected:
  60. ShadowTechnique* _shadowTechnique;
  61. };
  62. osg::Vec3 computeOrthogonalVector(const osg::Vec3& direction) const;
  63. virtual ~ShadowTechnique();
  64. friend class ShadowedScene;
  65. ShadowedScene* _shadowedScene;
  66. bool _dirty;
  67. };
  68. }
  69. #endif