openscenegraph
MinimalDrawBoundsShadowMap
Go to the documentation of this file.
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
18#ifndef OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP
19#define OSGSHADOW_MINIMALDRAWBOUNDSSHADOWMAP 1
20
21#include <osgShadow/MinimalShadowMap>
22
23namespace osgShadow {
24
25class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap
26 : public MinimalShadowMap
27{
28 public :
29 /** Convenient typedef used in definition of ViewData struct and methods */
30 typedef MinimalDrawBoundsShadowMap ThisClass;
31 /** Convenient typedef used in definition of ViewData struct and methods */
32 typedef MinimalShadowMap BaseClass;
33
34 /** Classic OSG constructor */
35 MinimalDrawBoundsShadowMap();
36
37 /** Classic OSG cloning constructor */
38 MinimalDrawBoundsShadowMap(
39 const MinimalDrawBoundsShadowMap& mdbsm,
40 const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
41
42 /** Declaration of standard OSG object methods */
43 META_Object( osgShadow, MinimalDrawBoundsShadowMap );
44
45 protected:
46 /** Classic protected OSG destructor */
47 virtual ~MinimalDrawBoundsShadowMap(void);
48
49 struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
50 {
51 osg::ref_ptr< osg::RefMatrix > _projection;
52 osg::Vec2s _boundAnalysisSize;
53 osg::ref_ptr< osg::Image > _boundAnalysisImage;
54 osg::ref_ptr< osg::Texture2D > _boundAnalysisTexture;
55 osg::ref_ptr< osg::Camera > _boundAnalysisCamera;
56 osg::observer_ptr< osg::Camera > _mainCamera;
57
58 void setShadowCameraProjectionMatrixPtr( osg::RefMatrix * projection )
59 { _projection = projection; }
60
61 osg::RefMatrix * getShadowCameraProjectionMatrixPtr( void )
62 { return _projection.get(); }
63
64 virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
65
66 virtual void cullShadowReceivingScene( );
67
68 virtual void createDebugHUD( );
69
70 virtual void recordShadowMapParams( );
71
72 virtual void cullBoundAnalysisScene( );
73
74 static osg::BoundingBox scanImage( const osg::Image * image, osg::Matrix m );
75
76 virtual void performBoundAnalysis( const osg::Camera& camera );
77
78 ViewData( void ): _boundAnalysisSize( 64, 64 ) {}
79
80 virtual void resizeGLObjectBuffers(unsigned int maxSize);
81 virtual void releaseGLObjects(osg::State* = 0) const;
82 };
83
84 friend struct ViewData;
85
86 META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData );
87
88
89 struct CameraPostDrawCallback : public osg::Camera::DrawCallback {
90
91 CameraPostDrawCallback( ViewData * vd ): _vd( vd )
92 {
93 }
94
95 virtual void operator ()( const osg::Camera& camera ) const
96 {
97 if( _vd.valid() )
98 _vd->performBoundAnalysis( camera );
99 }
100
101 osg::observer_ptr< ViewData > _vd;
102 };
103
104 struct CameraCullCallback: public osg::Callback {
105
106 CameraCullCallback(ViewData * vd, osg::Callback * nc): _vd(vd), _nc(nc)
107 {
108 }
109
110 virtual bool run(osg::Object* object, osg::Object* data)
111 {
112 osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( data );
113
114 if( _nc.valid() )
115 _nc->run(object, data);
116 else
117 traverse(object, data);
118
119 if( cv )
120 _vd->recordShadowMapParams( );
121
122 return true;
123 }
124
125 protected:
126 osg::observer_ptr< ViewData > _vd;
127 osg::ref_ptr< osg::Callback > _nc;
128 };
129};
130
131} // namespace osgShadow
132
133#endif