1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGSHADOW_SHADOWEDTECHNIQUE
15#define OSGSHADOW_SHADOWEDTECHNIQUE 1
17#include <osg/buffered_value>
19#include <osg/Texture2D>
20#include <osg/TexGenNode>
21#include <osgUtil/CullVisitor>
23#include <osgShadow/Export>
27// forward declare ShadowedScene
30/** ShadowTechnique is the base class for different shadow implementations.*/
31class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object
36 ShadowTechnique(const ShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
38 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ShadowTechnique*>(obj)!=NULL; } \
39 virtual const char* libraryName() const { return "osgShadow"; }\
40 virtual const char* className() const { return "ShadowTechnique"; }
42 virtual void setShadowedScene(ShadowedScene* ss);
44 ShadowedScene* getShadowedScene() { return _shadowedScene; }
46 const ShadowedScene* getShadowedScene() const { return _shadowedScene; }
48 /** initialize the ShadowedScene and local cached data structures.*/
51 /** run the update traversal of the ShadowedScene and update any local cached data structures.*/
52 virtual void update(osg::NodeVisitor& nv);
54 /** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/
55 virtual void cull(osgUtil::CullVisitor& cv);
57 /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
58 virtual void cleanSceneGraph();
60 virtual void traverse(osg::NodeVisitor& nv);
62 /** Dirty so that cached data structures are updated.*/
63 virtual void dirty() { _dirty = true; }
65 /** Resize any per context GLObject buffers to specified size. */
66 virtual void resizeGLObjectBuffers(unsigned int maxSize) = 0;
68 /** If State is non-zero, this function releases any associated OpenGL objects for
69 * the specified graphics context. Otherwise, releases OpenGL objects
70 * for all graphics contexts. */
71 virtual void releaseGLObjects(osg::State* = 0) const = 0;
75 class OSGSHADOW_EXPORT CameraCullCallback : public osg::NodeCallback
79 CameraCullCallback(ShadowTechnique* st);
81 virtual void operator()(osg::Node*, osg::NodeVisitor* nv);
85 ShadowTechnique* _shadowTechnique;
88 osg::Vec3 computeOrthogonalVector(const osg::Vec3& direction) const;
90 virtual ~ShadowTechnique();
92 friend class ShadowedScene;
94 ShadowedScene* _shadowedScene;