1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-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 #ifndef _OSGRENDERACTION_H_
40 #define _OSGRENDERACTION_H_
45 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
51 #include "OSGRenderActionFwd.h"
52 #include "OSGRenderActionBase.h"
53 #include "OSGRenderPartition.h"
54 #include "OSGDrawEnv.h"
55 #include "OSGMaterial.h"
56 #include "OSGRenderActionTask.h"
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
67 //---------------------------------------------------------------------------
69 //---------------------------------------------------------------------------
71 //---------------------------------------------------------------------------
73 //---------------------------------------------------------------------------
75 /*! \brief RenderAction class
76 \ingroup GrpSystemRenderAction
77 \ingroup GrpLibOSGSystem
80 class OSG_SYSTEM_DLLMAPPING RenderAction
: public RenderActionBase
84 OSG_GEN_INTERNAL_MEMOBJPTR(RenderAction
);
86 //-----------------------------------------------------------------------
88 //-----------------------------------------------------------------------
90 static StatElemDesc
<StatTimeElem
> statDrawTime
;
91 static StatElemDesc
<StatIntElem
> statNMatrices
;
92 static StatElemDesc
<StatIntElem
> statNStates
;
93 static StatElemDesc
<StatIntElem
> statNChunks
;
94 static StatElemDesc
<StatIntElem
> statNShaders
;
95 static StatElemDesc
<StatIntElem
> statNShaderParams
;
97 //-----------------------------------------------------------------------
99 //-----------------------------------------------------------------------
101 //-----------------------------------------------------------------------
103 //-----------------------------------------------------------------------
105 typedef std::vector
<RenderPartition
*> RenderPartitionStore
;
106 typedef std::stack
<RenderPartition
*> RenderPartitionStack
;
107 typedef std::stack
<Int32
> RenderPartitionIdxStack
;
108 typedef std::stack
<bool > RenderPartitionGrpStack
;
110 //-----------------------------------------------------------------------
112 //-----------------------------------------------------------------------
114 static ObjTransitPtr
create (void );
116 static void setPrototype(RenderAction
*pPrototype
);
117 static RenderAction
*getPrototype(void );
119 //-----------------------------------------------------------------------
121 //-----------------------------------------------------------------------
123 static void registerEnterDefault (const FieldContainerType
&type
,
124 const Action::Functor
&func
);
126 static void registerLeaveDefault (const FieldContainerType
&type
,
127 const Action::Functor
&func
);
129 //-----------------------------------------------------------------------
130 // instance functions
131 //-----------------------------------------------------------------------
133 /*------------------------- your_category -------------------------------*/
135 /*------------------------- your_operators ------------------------------*/
137 virtual Action::ResultE
start (void );
138 virtual Action::ResultE
stop (ResultE res
);
140 virtual void frameInit(void );
142 /*------------------------- your_operators ------------------------------*/
144 void dropFunctor(DrawEnv::DrawFunctor
&func
,
147 bool bIgnoreOverrides
= false);
149 void dropFunctor(DrawEnv::DrawFunctor
&func
,
151 bool bIgnoreOverrides
= false);
153 /*---------------------------- state ------------------------------------*/
155 void pushState (void );
156 void popState (void );
158 void addOverride (UInt32 uiSlot
,
160 void subOverride (UInt32 uiSlot
,
163 const StateOverride
*getCurrentOverrides(void ) const;
165 /*---------------------------- state ------------------------------------*/
167 Int32
allocateLightIndex(void);
168 void releaseLightIndex (void);
169 UInt32
getLightState (void) const;
171 /*--------------------------- matrix ------------------------------------*/
173 template<class MatrixType
>
174 void pushMatrix (const MatrixType
&matrix
);
175 void popMatrix ( void );
177 const Matrix
&topMatrix ( void );
179 /*------------------------- visibility ---------------------------------*/
181 // test a single node
182 virtual bool isVisible (Node
*node
);
183 UInt32
selectVisibles (void );
186 bool pushVisibility (void );
187 void popVisibility (void );
189 virtual void setFrustumCulling(bool val
= true);
191 /*------------------------- comparison ----------------------------------*/
193 void overrideMaterial(Material
* pMaterial
,
194 Node
* const pNode
);
196 Material
*getMaterial ( void );
198 /*------------------------- comparison ----------------------------------*/
200 void setKeyGen(UInt32 uiKeyGen
);
202 /*------------------------- comparison ----------------------------------*/
204 Int32
getActivePartitionIdx (void );
205 Int32
getLastPartitionIdx (void );
207 void readdPartitionByIndex (UInt32 uiPartIdx
);
209 void dumpPartitionList (void );
211 void disableDefaultPartition(void );
213 /*------------------------- comparison ----------------------------------*/
215 /*------------------------- comparison ----------------------------------*/
217 RenderPartition
*getActivePartition(void);
219 /*----------- multi-frame buffering / split cull/draw -------------------*/
221 void addPassMask(BitVector bvMask
);
222 void subPassMask(BitVector bvMask
);
223 BitVector
getPassMask(void );
225 /*----------- multi-frame buffering / split cull/draw -------------------*/
227 void setDoCullOnly (bool val
);
228 bool getDoCullOnly (void );
230 void setNumBuffers (UInt32 n
);
231 UInt32
getNumBuffers (void );
233 void setCurrentBuffer(UInt32 b
);
234 UInt32
getCurrentBuffer(void );
236 // use with care. Should probably be more protected
237 void drawBuffer (UInt32 buf
);
239 /*------------------ Occlusion Culling control --------------------------*/
241 void setOcclusionCulling (const bool bVal
);
242 bool getOcclusionCulling ( void );
244 void setOcclusionCullingDebug (const bool bVal
);
245 bool getOcclusionCullingDebug ( void );
247 void setOcclusionDebugMasks (const UInt32 tested
,
249 const UInt32 visible
);
251 UInt32
getOcclusionTestedDebugMask ( void );
252 UInt32
getOcclusionCulledDebugMask ( void );
253 UInt32
getOcclusionVisibleDebugMask ( void );
255 void setOcclusionCullingMinimumFeatureSize (const UInt32 pixels
);
256 UInt32
getOcclusionCullingMinimumFeatureSize ( void );
258 void setOcclusionCullingVisibilityThreshold (const UInt32 pixels
);
259 UInt32
getOcclusionCullingVisibilityThreshold ( void );
261 void setOcclusionCullingCoveredThreshold (const Real32 percent
);
262 Real32
getOcclusionCullingCoveredThreshold ( void );
264 void setOcclusionCullingQueryBufferSize (const UInt32 size
);
265 UInt32
getOcclusionCullingQueryBufferSize ( void );
267 void setOcclusionCullingMinimumTriangleCount(const UInt32 count
);
268 UInt32
getOcclusionCullingMinimumTriangleCount( void );
270 /*------------------- ScreenLOD Control -------------------------------*/
272 void setScreenLODCoverageThreshold(const Real32 percent
);
273 Real32
getScreenLODCoverageThreshold( void );
275 void setScreenLODNumLevels (const UInt32 levels
);
276 UInt32
getScreenLODNumLevels ( void );
278 void setScreenLODDegradationFactor(const Real32 percent
);
279 Real32
getScreenLODDegradationFactor( void );
284 //-----------------------------------------------------------------------
286 //-----------------------------------------------------------------------
288 //-----------------------------------------------------------------------
290 //-----------------------------------------------------------------------
292 typedef RenderActionBase Inherited
;
294 //-----------------------------------------------------------------------
296 //-----------------------------------------------------------------------
298 static RenderAction
*_pPrototype
;
300 static Action::FunctorStore
*_vDefaultEnterFunctors
;
301 static Action::FunctorStore
*_vDefaultLeaveFunctors
;
304 //-----------------------------------------------------------------------
306 //-----------------------------------------------------------------------
308 static bool terminateEnter(void);
309 static bool terminateLeave(void);
311 //-----------------------------------------------------------------------
312 // instance variables
313 //-----------------------------------------------------------------------
317 UInt32 _currentBuffer
;
321 // Multi-buffered pools for cull/draw separation
322 std::vector
<RenderPartitionPool
*> _pPartitionPools
;
323 std::vector
<RenderTreeNodePool
*> _pNodePools
;
324 std::vector
<StateOverridePool
*> _pStatePools
;
325 std::vector
<TreeBuilderPool
*> _pTreeBuilderPools
;
327 std::vector
<RenderPartitionStore
> _vRenderPartitions
;
329 Int32 _iActivePartitionIdx
;
330 bool _bInPartitionGroup
;
331 bool _bDefaultPartHandled
;
332 RenderPartition
*_pActivePartition
;
334 RenderPartitionStack _sRenderPartitionStack
;
335 RenderPartitionIdxStack _sRenderPartitionIdxStack
;
336 RenderPartitionGrpStack _sRenderPartitionGrpStack
;
338 BitVector _bvPassMask
;
341 bool _occlusionCulling
;
342 bool _occlusionCullingDebug
;
345 UInt32 _occDMVisible
;
346 UInt32 _occMinFeatureSize
;
347 UInt32 _occVisibilityThreshold
;
348 Real32 _occCoveredThreshold
;
349 UInt32 _occQueryBufferSize
;
350 UInt32 _occMinimumTriangleCount
;
353 Real32 _scrlodCoverageThreshold
;
354 UInt32 _scrlodNumLODsToUse
;
355 Real32 _scrlodDegradationFactor
;
357 RenderActionTaskRefPtr _pGLFinishTask
;
359 //-----------------------------------------------------------------------
360 // instance functions
361 //-----------------------------------------------------------------------
363 // prohibit default functions (move to 'public' if you need one)
366 RenderAction(const RenderAction
&source
);
368 virtual ~RenderAction(void);
370 // access default functors
372 virtual Action::FunctorStore
*getDefaultEnterFunctors(void);
373 virtual Action::FunctorStore
*getDefaultLeaveFunctors(void);
375 // void dump(DrawTreeNode *pRoot, UInt32 uiIndent);
376 // virtual void draw(DrawTreeNode *pRoot);
378 void pushPartition (UInt32 uiCopyOnPush
= 0x0000,
379 RenderPartition::Mode eMode
=
380 RenderPartition::StateSorting
);
382 void popPartition (void );
384 void beginPartitionGroup (void );
385 void endPartitionGroup (void );
389 //-----------------------------------------------------------------------
391 //-----------------------------------------------------------------------
393 //-----------------------------------------------------------------------
395 //-----------------------------------------------------------------------
397 //-----------------------------------------------------------------------
399 //-----------------------------------------------------------------------
401 template <class ParentT
>
402 friend class StageHandlerMixin
;
404 //-----------------------------------------------------------------------
406 //-----------------------------------------------------------------------
408 //-----------------------------------------------------------------------
410 //-----------------------------------------------------------------------
413 //-----------------------------------------------------------------------
415 //-----------------------------------------------------------------------
417 //-----------------------------------------------------------------------
418 // instance variables
419 //-----------------------------------------------------------------------
421 //-----------------------------------------------------------------------
422 // instance functions
423 //-----------------------------------------------------------------------
425 /*!\brief prohibit default function (move to 'public' if needed) */
426 void operator =(const RenderAction
&source
);
429 //---------------------------------------------------------------------------
431 //---------------------------------------------------------------------------
434 Action::ResultE
MaterialDrawableRenderEnter(NodeCore
* const pCore
,
437 Action::ResultE
MaterialDrawableRenderLeave(NodeCore
* const pCore
,
441 OSG_GEN_MEMOBJPTR(RenderAction
);
445 #include "OSGRenderAction.inl"
447 #endif /* _OSGRENDERACTION_H_ */