fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Action / RenderAction / OSGRenderAction.h
blob156c3921d31b9f87a120f7e144999180d3c2e11c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-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 #ifndef _OSGRENDERACTION_H_
40 #define _OSGRENDERACTION_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 //---------------------------------------------------------------------------
46 // Includes
47 //---------------------------------------------------------------------------
49 #include <stack>
51 #include "OSGRenderActionFwd.h"
52 #include "OSGRenderActionBase.h"
53 #include "OSGRenderPartition.h"
54 #include "OSGDrawEnv.h"
55 #include "OSGMaterial.h"
56 #include "OSGRenderActionTask.h"
58 OSG_BEGIN_NAMESPACE
60 //---------------------------------------------------------------------------
61 // Forward References
62 //---------------------------------------------------------------------------
64 class State;
65 class MultiCore;
67 //---------------------------------------------------------------------------
68 // Types
69 //---------------------------------------------------------------------------
71 //---------------------------------------------------------------------------
72 // Class
73 //---------------------------------------------------------------------------
75 /*! \brief RenderAction class
76 \ingroup GrpSystemRenderAction
77 \ingroup GrpLibOSGSystem
80 class OSG_SYSTEM_DLLMAPPING RenderAction : public RenderActionBase
82 public:
84 OSG_GEN_INTERNAL_MEMOBJPTR(RenderAction);
86 //-----------------------------------------------------------------------
87 // constants
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 //-----------------------------------------------------------------------
98 // enums
99 //-----------------------------------------------------------------------
101 //-----------------------------------------------------------------------
102 // types
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 //-----------------------------------------------------------------------
111 // class functions
112 //-----------------------------------------------------------------------
114 static ObjTransitPtr create (void );
116 static void setPrototype(RenderAction *pPrototype);
117 static RenderAction *getPrototype(void );
119 //-----------------------------------------------------------------------
120 // class functions
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,
145 State *pState,
146 UInt32 uiSortKey,
147 bool bIgnoreOverrides = false);
149 void dropFunctor(DrawEnv::DrawFunctor &func,
150 Material *pMat,
151 bool bIgnoreOverrides = false);
153 /*---------------------------- state ------------------------------------*/
155 void pushState (void );
156 void popState (void );
158 void addOverride (UInt32 uiSlot,
159 StateChunk *pChunk);
160 void subOverride (UInt32 uiSlot,
161 StateChunk *pChunk);
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 );
185 // visibility levels
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,
248 const UInt32 culled,
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 );
282 protected:
284 //-----------------------------------------------------------------------
285 // enums
286 //-----------------------------------------------------------------------
288 //-----------------------------------------------------------------------
289 // types
290 //-----------------------------------------------------------------------
292 typedef RenderActionBase Inherited;
294 //-----------------------------------------------------------------------
295 // class variables
296 //-----------------------------------------------------------------------
298 static RenderAction *_pPrototype;
300 static Action::FunctorStore *_vDefaultEnterFunctors;
301 static Action::FunctorStore *_vDefaultLeaveFunctors;
304 //-----------------------------------------------------------------------
305 // class functions
306 //-----------------------------------------------------------------------
308 static bool terminateEnter(void);
309 static bool terminateLeave(void);
311 //-----------------------------------------------------------------------
312 // instance variables
313 //-----------------------------------------------------------------------
315 bool _doCullOnly;
316 UInt32 _numBuffers;
317 UInt32 _currentBuffer;
319 UInt32 _uiKeyGen;
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;
340 // Occlusion Culling
341 bool _occlusionCulling;
342 bool _occlusionCullingDebug;
343 UInt32 _occDMTested;
344 UInt32 _occDMCulled;
345 UInt32 _occDMVisible;
346 UInt32 _occMinFeatureSize;
347 UInt32 _occVisibilityThreshold;
348 Real32 _occCoveredThreshold;
349 UInt32 _occQueryBufferSize;
350 UInt32 _occMinimumTriangleCount;
352 // Screen LOD
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)
365 RenderAction(void);
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 );
387 private:
389 //-----------------------------------------------------------------------
390 // enums
391 //-----------------------------------------------------------------------
393 //-----------------------------------------------------------------------
394 // types
395 //-----------------------------------------------------------------------
397 //-----------------------------------------------------------------------
398 // friend classes
399 //-----------------------------------------------------------------------
401 template <class ParentT>
402 friend class StageHandlerMixin;
404 //-----------------------------------------------------------------------
405 // friend functions
406 //-----------------------------------------------------------------------
408 //-----------------------------------------------------------------------
409 // class variables
410 //-----------------------------------------------------------------------
413 //-----------------------------------------------------------------------
414 // class functions
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 //---------------------------------------------------------------------------
430 // Exported Types
431 //---------------------------------------------------------------------------
433 #if 0
434 Action::ResultE MaterialDrawableRenderEnter(NodeCore * const pCore,
435 Action * action);
437 Action::ResultE MaterialDrawableRenderLeave(NodeCore * const pCore,
438 Action * action);
439 #endif
441 OSG_GEN_MEMOBJPTR(RenderAction);
443 OSG_END_NAMESPACE
445 #include "OSGRenderAction.inl"
447 #endif /* _OSGRENDERACTION_H_ */