fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Action / Base / OSGRenderActionBase.cpp
blob7aa55bcca513b7ee8fc446d3a50d8eabfec61e6b
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000,2001,2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGRenderActionBase.h"
49 //#include "OSGRenderTraversalAction.h"
51 #include "OSGStatCollector.h"
52 #include "OSGDrawable.h"
53 #include "OSGVolumeDraw.h"
54 #include "OSGTraversalValidator.h"
55 #include "OSGWindow.h"
56 #include "OSGCamera.h"
57 #include "OSGViewarea.h"
59 OSG_BEGIN_NAMESPACE
61 StatElemDesc<StatTimeElem>
62 RenderActionBase::statTravTime ("RT-TravTime",
63 "time for traversal" );
64 # if defined(__APPLE__)
65 template class DataSlotMixin< MixinHead < RenderDataSlotDesc > >;
66 #endif
69 StatElemDesc<StatIntElem>
70 RenderTraversalActionBase::statCullTestedNodes("rtCullTestedNodes",
71 "nodes tested" );
73 StatElemDesc<StatIntElem>
74 RenderTraversalActionBase::statCulledNodes ("rtCulledNodes",
75 "nodes culled from frustum");
78 /*-------------------------------------------------------------------------*/
79 /* Constructors */
81 RenderActionBase::RenderActionBase(void) :
82 Inherited ( ),
83 _pCamera (NULL ),
84 _pBackground (NULL ),
85 _pWindow (NULL ),
86 _pViewarea (NULL ),
87 _pTraversalRoot (NULL ),
88 _pGlobalOverride (NULL ),
89 _pStatistics (NULL ),
90 _pTravValidator (NULL ),
92 _bResetStatistics (true ),
93 _bUseGLFinish (false ),
95 _bFrustumCulling (true ),
96 _bVolumeDrawing (false ),
97 _bZWriteTrans (false ),
98 _bAutoFrustum (true ),
99 _bCorrectTwoSidedLighting (false ),
100 _oFrustum ( ),
101 _uiFrameTravCount (0 ),
102 _iDrawerId (-1 ),
103 _iDrawableId (-1 ),
104 _oCurrentRenderProp (0x0000),
105 _bDrawPartPar (false )
107 _pTravValidator = new TraversalValidator();
110 RenderActionBase::RenderActionBase(const RenderActionBase &source) :
112 Inherited (source ),
113 _pCamera (source._pCamera ),
114 _pBackground (source._pBackground ),
115 _pWindow (source._pWindow ),
116 _pViewarea (source._pViewarea ),
117 _pTraversalRoot (source._pTraversalRoot ),
118 _pGlobalOverride (source._pGlobalOverride ),
119 _pStatistics (NULL ),
120 _pTravValidator (NULL ),
122 _bResetStatistics (source._bResetStatistics ),
123 _bUseGLFinish (source._bUseGLFinish ),
125 _bFrustumCulling (source._bFrustumCulling ),
126 _bVolumeDrawing (source._bVolumeDrawing ),
127 _bZWriteTrans (source._bZWriteTrans ),
128 _bAutoFrustum (source._bAutoFrustum ),
129 _bCorrectTwoSidedLighting(source._bCorrectTwoSidedLighting),
130 _oFrustum (source._oFrustum ),
131 _uiFrameTravCount (source._uiFrameTravCount ),
132 _iDrawerId (source._iDrawerId ),
133 _iDrawableId (source._iDrawableId ),
134 _oCurrentRenderProp (0x0000 ),
135 _bDrawPartPar (false )
137 OSG::setRefd(_pStatistics, source._pStatistics);
139 _pTravValidator = new TraversalValidator();
142 /*-------------------------------------------------------------------------*/
143 /* Destructor */
145 RenderActionBase::~RenderActionBase(void)
147 OSG::subRef(_pStatistics);
149 delete _pTravValidator;
154 Action::ResultE RenderActionBase::start(void)
156 if(_bFrustumCulling == true &&
157 _bAutoFrustum == true &&
158 _pCamera != NULL &&
159 _pViewarea != NULL &&
160 _pWindow != NULL )
162 UInt32 uiPixelWidth;
163 UInt32 uiPixelHeight;
165 _pViewarea->computePixelSizes(_pWindow,
166 uiPixelWidth,
167 uiPixelHeight);
169 getCamera()->getFrustum(_oFrustum,
170 uiPixelWidth,
171 uiPixelHeight);
174 if(_pStatistics != NULL)
176 if(_bResetStatistics == true)
177 _pStatistics->reset();
179 _pStatistics->getElem(statTravTime)->start();
182 _pTravValidator->incEventCounter();
184 // _iDrawerId = (_pWindow != NULL) ? _pWindow ->getDrawerId () : 0;
185 // _iDrawableId = (_pViewarea != NULL) ? _pViewarea->getDrawableId() : 0;
187 return Action::Continue;
190 Action::ResultE RenderActionBase::stop(Action::ResultE res)
192 if(_pStatistics != NULL)
194 _pStatistics->getElem(statTravTime)->stop();
197 ++_uiFrameTravCount;
199 return res;
202 void RenderActionBase::frameInit(void)
204 _uiFrameTravCount = 0;
207 void RenderActionBase::setViewarea(Viewarea *pViewarea)
209 _pViewarea = pViewarea;
212 void RenderActionBase::setTraversalRoot(Node *pTravRoot)
214 _pTraversalRoot = pTravRoot;
217 void RenderActionBase::setCamera(Camera *pCamera)
219 _pCamera = pCamera;
222 void RenderActionBase::setBackground(Background *pBackground)
224 _pBackground = pBackground;
227 void RenderActionBase::setWindow(Window *pWindow)
229 _pWindow = pWindow;
232 void RenderActionBase::setStatCollector(StatCollector *pStatistics)
234 OSG::setRefd(_pStatistics, pStatistics);
237 void RenderActionBase::setGlobalOverride(Material *pMat)
239 _pGlobalOverride = pMat;
243 // do frustum culling at all?
244 // default true
246 void RenderActionBase::setFrustumCulling(bool val)
248 _bFrustumCulling = val;
251 void RenderActionBase::setCorrectTwoSidedLighting(bool val)
253 _bCorrectTwoSidedLighting = val;
256 // draw the tested volumes
257 // default false
259 void RenderActionBase::setVolumeDrawing(bool val)
261 _bVolumeDrawing = val;
264 void RenderActionBase::setZWriteTrans(bool val)
266 _bZWriteTrans = val;
269 // automatically calc the frustum at the beginning of the traversal
270 // default true
272 void RenderActionBase::setAutoFrustum(bool val)
274 _bAutoFrustum = val;
277 // explicitly set the frustum
279 void RenderActionBase::setFrustum(FrustumVolume &oFrustum)
281 _oFrustum = oFrustum;
285 OSG_END_NAMESPACE