| 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 | |
|---|
| 14 | #ifndef OSGSHADOW_SHADOWEDTECHNIQUE |
|---|
| 15 | #define OSGSHADOW_SHADOWEDTECHNIQUE 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/buffered_value> |
|---|
| 18 | #include <osg/Camera> |
|---|
| 19 | #include <osg/Texture2D> |
|---|
| 20 | #include <osg/TexGenNode> |
|---|
| 21 | #include <osgUtil/CullVisitor> |
|---|
| 22 | |
|---|
| 23 | #include <osgShadow/Export> |
|---|
| 24 | |
|---|
| 25 | namespace osgShadow { |
|---|
| 26 | |
|---|
| 27 | // forward declare ShadowedScene |
|---|
| 28 | class ShadowedScene; |
|---|
| 29 | |
|---|
| 30 | /** ShadowedScene provides a mechanism for decorating a scene that the needs to have shadows cast upon it.*/ |
|---|
| 31 | class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object |
|---|
| 32 | { |
|---|
| 33 | public : |
|---|
| 34 | ShadowTechnique(); |
|---|
| 35 | |
|---|
| 36 | ShadowTechnique(const ShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 37 | |
|---|
| 38 | META_Object(osgShadow, ShadowTechnique); |
|---|
| 39 | |
|---|
| 40 | ShadowedScene* getShadowedScene() { return _shadowedScene; } |
|---|
| 41 | |
|---|
| 42 | const ShadowedScene* getShadowedScene() const { return _shadowedScene; } |
|---|
| 43 | |
|---|
| 44 | /** initialize the ShadowedScene and local cached data structures.*/ |
|---|
| 45 | virtual void init(); |
|---|
| 46 | |
|---|
| 47 | /** run the update traversal of the ShadowedScene and update any local cached data structures.*/ |
|---|
| 48 | virtual void update(osg::NodeVisitor& nv); |
|---|
| 49 | |
|---|
| 50 | /** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/ |
|---|
| 51 | virtual void cull(osgUtil::CullVisitor& cv); |
|---|
| 52 | |
|---|
| 53 | /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ |
|---|
| 54 | virtual void cleanSceneGraph(); |
|---|
| 55 | |
|---|
| 56 | virtual void traverse(osg::NodeVisitor& nv); |
|---|
| 57 | |
|---|
| 58 | /** Dirty so that cached data structures are updated.*/ |
|---|
| 59 | virtual void dirty() { _dirty = true; } |
|---|
| 60 | |
|---|
| 61 | protected : |
|---|
| 62 | |
|---|
| 63 | class OSGSHADOW_EXPORT CameraCullCallback : public osg::NodeCallback |
|---|
| 64 | { |
|---|
| 65 | public: |
|---|
| 66 | |
|---|
| 67 | CameraCullCallback(ShadowTechnique* st); |
|---|
| 68 | |
|---|
| 69 | virtual void operator()(osg::Node*, osg::NodeVisitor* nv); |
|---|
| 70 | |
|---|
| 71 | protected: |
|---|
| 72 | |
|---|
| 73 | ShadowTechnique* _shadowTechnique; |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | osg::Vec3 computeOrthogonalVector(const osg::Vec3& direction) const; |
|---|
| 77 | |
|---|
| 78 | virtual ~ShadowTechnique(); |
|---|
| 79 | |
|---|
| 80 | friend class ShadowedScene; |
|---|
| 81 | |
|---|
| 82 | ShadowedScene* _shadowedScene; |
|---|
| 83 | bool _dirty; |
|---|
| 84 | |
|---|
| 85 | }; |
|---|
| 86 | |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | #endif |
|---|