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
40
resizeGLObjectBuffers(unsigned int maxSize)41 void ViewDependentShadowTechnique::resizeGLObjectBuffers(unsigned int maxSize)
42 {
43 for(ViewDataMap::iterator itr = _viewDataMap.begin();
44 itr != _viewDataMap.end();
45 ++itr)
46 {
47 itr->second->resizeGLObjectBuffers(maxSize);
48 }
49 }
50
releaseGLObjects(osg::State * state) const51 void ViewDependentShadowTechnique::releaseGLObjects(osg::State* state) const
52 {
53 for(ViewDataMap::const_iterator itr = _viewDataMap.begin();
54 itr != _viewDataMap.end();
55 ++itr)
56 {
57 itr->second->releaseGLObjects(state);
58 }
59 }
60
traverse(osg::NodeVisitor & nv)61 void ViewDependentShadowTechnique::traverse(osg::NodeVisitor& nv)
62 {
63 osgShadow::ShadowTechnique::traverse(nv);
64 }
65
dirty()66 void ViewDependentShadowTechnique::dirty()
67 {
68 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
69
70 osgShadow::ShadowTechnique::_dirty = true;
71
72 for( ViewDataMap::iterator mitr = _viewDataMap.begin();
73 mitr != _viewDataMap.end();
74 ++mitr )
75 {
76 mitr->second->dirty( true );
77 }
78 }
79
init()80 void ViewDependentShadowTechnique::init()
81 {
82 //osgShadow::ShadowTechnique::init( );
83 osgShadow::ShadowTechnique::_dirty = false;
84 }
85
update(osg::NodeVisitor & nv)86 void ViewDependentShadowTechnique::update(osg::NodeVisitor& nv)
87 {
88 //osgShadow::ShadowTechnique::update( nv );
89 osgShadow::ShadowTechnique::_shadowedScene->osg::Group::traverse(nv);
90 }
91
cull(osgUtil::CullVisitor & cv)92 void ViewDependentShadowTechnique::cull(osgUtil::CullVisitor& cv)
93 {
94 //osgShadow::ShadowTechnique::cull( cv );
95
96 ViewData * vd = getViewDependentData( &cv );
97
98 if ( !vd || vd->_dirty || vd->_cv != &cv || vd->_st != this ) {
99 vd = initViewDependentData( &cv, vd );
100 setViewDependentData( &cv, vd );
101 }
102
103 if( vd ) {
104 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(vd->_mutex);
105 vd->cull();
106 } else {
107 osgShadow::ShadowTechnique::_shadowedScene->osg::Group::traverse(cv);
108 }
109 }
110
cleanSceneGraph()111 void ViewDependentShadowTechnique::cleanSceneGraph()
112 {
113 //osgShadow::ShadowTechnique::cleanSceneGraph( );
114 }
115
116 ViewDependentShadowTechnique::ViewData *
getViewDependentData(osgUtil::CullVisitor * cv)117 ViewDependentShadowTechnique::getViewDependentData( osgUtil::CullVisitor * cv )
118 {
119 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
120 return _viewDataMap[ osg::Identifier::get(cv) ].get();
121 }
122
setViewDependentData(osgUtil::CullVisitor * cv,ViewData * data)123 void ViewDependentShadowTechnique::setViewDependentData
124 ( osgUtil::CullVisitor * cv, ViewData * data )
125 {
126 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDataMapMutex);
127 _viewDataMap[ osg::Identifier::get(cv) ] = data;
128 }
129
dirty(bool flag)130 void ViewDependentShadowTechnique::ViewData::dirty( bool flag )
131 {
132 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
133 _dirty = flag;
134 }
135
init(ViewDependentShadowTechnique * st,osgUtil::CullVisitor * cv)136 void ViewDependentShadowTechnique::ViewData::init
137 ( ViewDependentShadowTechnique *st, osgUtil::CullVisitor * cv )
138 {
139 _cv = cv;
140 _st = st;
141 dirty( false );
142 }
143
cull(void)144 void ViewDependentShadowTechnique::ViewData::cull( void )
145 {
146
147 }
148
149