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 #include <osg/Texture2D>
15 #include <osg/CoordinateSystemNode>
16 #include <osg/TexEnv>
17 #include <osg/io_utils>
18 
19 #include <osgUtil/CullVisitor>
20 #include <osgShadow/ShadowedScene>
21 
22 using namespace osgShadow;
23 
24 ShadowedScene::ShadowedScene(ShadowTechnique* st)
25 {
26     setNumChildrenRequiringUpdateTraversal(1);
27 
28     setShadowSettings(new ShadowSettings);
29 
30     if (st) setShadowTechnique(st);
31 }
32 
33 ShadowedScene::ShadowedScene(const ShadowedScene& ss, const osg::CopyOp& copyop):
34     osg::Group(ss,copyop)
35 {
36     setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
37 
38     if (ss._shadowTechnique.valid())
39     {
40         setShadowTechnique( dynamic_cast<osgShadow::ShadowTechnique*>(ss._shadowTechnique->clone(copyop)) );
41     }
42 
43     if (ss._shadowSettings)
44     {
45         setShadowSettings(ss._shadowSettings.get());
46     }
47     else
48     {
49         setShadowSettings(new ShadowSettings);
50     }
51 
52 }
53 
54 ShadowedScene::~ShadowedScene()
55 {
56     setShadowTechnique(0);
57 }
58 
59 void ShadowedScene::traverse(osg::NodeVisitor& nv)
60 {
61     if (_shadowTechnique.valid())
62     {
63         _shadowTechnique->traverse(nv);
64     }
65     else
66     {
67         osg::Group::traverse(nv);
68     }
69 }
70 
71 void ShadowedScene::setShadowSettings(ShadowSettings* ss)
72 {
73     _shadowSettings = ss;
74 }
75 
76 void ShadowedScene::setShadowTechnique(ShadowTechnique* technique)
77 {
78     if (_shadowTechnique == technique) return;
79 
80     if (_shadowTechnique.valid())
81     {
82         _shadowTechnique->cleanSceneGraph();
83         _shadowTechnique->_shadowedScene = 0;
84     }
85 
86     _shadowTechnique = technique;
87 
88     if (_shadowTechnique.valid())
89     {
90         _shadowTechnique->_shadowedScene = this;
91         _shadowTechnique->dirty();
92     }
93 }
94 
95 void ShadowedScene::cleanSceneGraph()
96 {
97     if (_shadowTechnique.valid())
98     {
99         _shadowTechnique->cleanSceneGraph();
100     }
101 }
102 
103 
104 void ShadowedScene::dirty()
105 {
106     if (_shadowTechnique.valid())
107     {
108         _shadowTechnique->dirty();
109     }
110 }
111 
112 void ShadowedScene::resizeGLObjectBuffers(unsigned int maxSize)
113 {
114     if (_shadowTechnique.valid()) _shadowTechnique->resizeGLObjectBuffers(maxSize);
115     Group::resizeGLObjectBuffers(maxSize);
116 }
117 
118 void ShadowedScene::releaseGLObjects(osg::State* state) const
119 {
120     if (_shadowTechnique.valid()) _shadowTechnique->releaseGLObjects(state);
121     Group::releaseGLObjects(state);
122 }
123