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  * ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
14  * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
15 */
16 
17 #include <osgShadow/ViewDependentShadowTechnique>
18 #include <osgShadow/ShadowedScene>
19 
20 using namespace osgShadow;
21 
22 
ViewDependentShadowTechnique()23 ViewDependentShadowTechnique::ViewDependentShadowTechnique()
24 {
25     dirty();
26 }
27 
ViewDependentShadowTechnique(const ViewDependentShadowTechnique & copy,const osg::CopyOp & copyop)28 ViewDependentShadowTechnique::ViewDependentShadowTechnique
29     (const ViewDependentShadowTechnique& copy, const osg::CopyOp& copyop):
30         ShadowTechnique(copy,copyop)
31 {
32     dirty();
33 }
34 
~ViewDependentShadowTechnique(void)35 ViewDependentShadowTechnique::~ViewDependentShadowTechnique(void)
36 {
37 
38 }
39 
traverse(osg::NodeVisitor & nv)40 void ViewDependentShadowTechnique::traverse(osg::NodeVisitor& nv)
41 {
42     osgShadow::ShadowTechnique::traverse(nv);
43 }
44 
dirty()45 void ViewDependentShadowTechnique::dirty()
46 {
47     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
48 
49     osgShadow::ShadowTechnique::_dirty = true;
50 
51     for( ViewDataMap::iterator mitr = _viewDataMap.begin();
52          mitr != _viewDataMap.end();
53          ++mitr )
54     {
55         mitr->second->dirty( true );
56     }
57 }
58 
init()59 void ViewDependentShadowTechnique::init()
60 {
61     //osgShadow::ShadowTechnique::init( );
62     osgShadow::ShadowTechnique::_dirty = false;
63 }
64 
update(osg::NodeVisitor & nv)65 void ViewDependentShadowTechnique::update(osg::NodeVisitor& nv)
66 {
67     //osgShadow::ShadowTechnique::update( nv );
68     osgShadow::ShadowTechnique::_shadowedScene->osg::Group::traverse(nv);
69 }
70 
cull(osgUtil::CullVisitor & cv)71 void ViewDependentShadowTechnique::cull(osgUtil::CullVisitor& cv)
72 {
73     //osgShadow::ShadowTechnique::cull( cv );
74 
75     ViewData * vd = getViewDependentData( &cv );
76 
77     if ( !vd || vd->_dirty || vd->_cv != &cv || vd->_st != this ) {
78         vd = initViewDependentData( &cv, vd );
79         setViewDependentData( &cv, vd );
80     }
81 
82     if( vd ) {
83         OpenThreads::ScopedLock<OpenThreads::Mutex> lock(vd->_mutex);
84         vd->cull();
85     } else {
86         osgShadow::ShadowTechnique::_shadowedScene->osg::Group::traverse(cv);
87     }
88 }
89 
cleanSceneGraph()90 void ViewDependentShadowTechnique::cleanSceneGraph()
91 {
92     //osgShadow::ShadowTechnique::cleanSceneGraph( );
93 }
94 
95 ViewDependentShadowTechnique::ViewData *
getViewDependentData(osgUtil::CullVisitor * cv)96 ViewDependentShadowTechnique::getViewDependentData( osgUtil::CullVisitor * cv )
97 {
98     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
99     return _viewDataMap[ cv ].get();
100 }
101 
setViewDependentData(osgUtil::CullVisitor * cv,ViewData * data)102 void ViewDependentShadowTechnique::setViewDependentData
103     ( osgUtil::CullVisitor * cv, ViewData * data )
104 {
105     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
106     _viewDataMap[ cv ] = data;
107 }
108 
dirty(bool flag)109 void ViewDependentShadowTechnique::ViewData::dirty( bool flag )
110 {
111     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
112     _dirty = flag;
113 }
114 
init(ViewDependentShadowTechnique * st,osgUtil::CullVisitor * cv)115 void ViewDependentShadowTechnique::ViewData::init
116     (  ViewDependentShadowTechnique *st, osgUtil::CullVisitor * cv )
117 {
118     _cv = cv;
119     _st = st;
120     dirty( false );
121 }
122 
cull(void)123 void ViewDependentShadowTechnique::ViewData::cull( void )
124 {
125 
126 }
127 
128