1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000,2001,2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
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"
61 StatElemDesc
<StatTimeElem
>
62 RenderActionBase::statTravTime ("RT-TravTime",
63 "time for traversal" );
64 # if defined(__APPLE__)
65 template class DataSlotMixin
< MixinHead
< RenderDataSlotDesc
> >;
69 StatElemDesc<StatIntElem>
70 RenderTraversalActionBase::statCullTestedNodes("rtCullTestedNodes",
73 StatElemDesc<StatIntElem>
74 RenderTraversalActionBase::statCulledNodes ("rtCulledNodes",
75 "nodes culled from frustum");
78 /*-------------------------------------------------------------------------*/
81 RenderActionBase::RenderActionBase(void) :
87 _pTraversalRoot (NULL
),
88 _pGlobalOverride (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 ),
101 _uiFrameTravCount (0 ),
104 _oCurrentRenderProp (0x0000),
105 _bDrawPartPar (false )
107 _pTravValidator
= new TraversalValidator();
110 RenderActionBase::RenderActionBase(const RenderActionBase
&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 /*-------------------------------------------------------------------------*/
145 RenderActionBase::~RenderActionBase(void)
147 OSG::subRef(_pStatistics
);
149 delete _pTravValidator
;
154 Action::ResultE
RenderActionBase::start(void)
156 if(_bFrustumCulling
== true &&
157 _bAutoFrustum
== true &&
159 _pViewarea
!= NULL
&&
163 UInt32 uiPixelHeight
;
165 _pViewarea
->computePixelSizes(_pWindow
,
169 getCamera()->getFrustum(_oFrustum
,
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();
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
)
222 void RenderActionBase::setBackground(Background
*pBackground
)
224 _pBackground
= pBackground
;
227 void RenderActionBase::setWindow(Window
*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?
246 void RenderActionBase::setFrustumCulling(bool val
)
248 _bFrustumCulling
= val
;
251 void RenderActionBase::setCorrectTwoSidedLighting(bool val
)
253 _bCorrectTwoSidedLighting
= val
;
256 // draw the tested volumes
259 void RenderActionBase::setVolumeDrawing(bool val
)
261 _bVolumeDrawing
= val
;
264 void RenderActionBase::setZWriteTrans(bool val
)
269 // automatically calc the frustum at the beginning of the traversal
272 void RenderActionBase::setAutoFrustum(bool val
)
277 // explicitly set the frustum
279 void RenderActionBase::setFrustum(FrustumVolume
&oFrustum
)
281 _oFrustum
= oFrustum
;