fixed: c++11 build problems ("" operator)
[opensg.git] / Source / System / State / Shader / Base / OSGShaderCacheTree.h
blob69121a89752f5d836cb210105f26b57cb32db38c
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 _OSGSHADERCACHETREE_H_
40 #define _OSGSHADERCACHETREE_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGBaseTypes.h"
47 #include "OSGSystemDef.h"
49 #include "OSGShaderExecutableChunk.h"
50 #include "OSGShaderExecutableVarChunk.h"
52 OSG_BEGIN_NAMESPACE
54 /*! \ingroup GrpSystemShaderBase
55 \ingroup GrpLibOSGSystem
56 \nohierarchy
59 template<class ObjectT>
60 class ShaderMapCache
62 /*========================== PUBLIC =================================*/
64 public:
66 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
68 typedef UInt16 IdType;
69 typedef std::vector<IdType > IdStore;
71 typedef std::map<IdStore, ObjectUnrecPtr > ObjectStore;
73 /*---------------------------------------------------------------------*/
74 /*! \name Statistic */
75 /*! \{ */
77 ObjectT *find(const IdStore &vIds );
78 bool add (const IdStore &vIds,
79 ObjectT *pObject);
80 void sub ( UInt32 uiIdx );
82 /*! \} */
83 /*---------------------------------------------------------------------*/
84 /*! \name Constructors */
85 /*! \{ */
87 void dumpDot(const Char8 *szFilename);
89 /*! \} */
90 /*---------------------------------------------------------------------*/
91 /*! \name Constructors */
92 /*! \{ */
94 template <typename ElemDestFunc>
95 void destroy(ElemDestFunc destFunc);
97 /*! \} */
98 /*---------------------------------------------------------------------*/
99 /*! \name Constructors */
100 /*! \{ */
102 ShaderMapCache(void);
104 /*! \} */
105 /*---------------------------------------------------------------------*/
106 /*! \name Destructor */
107 /*! \{ */
109 ~ShaderMapCache(void);
111 /*! \} */
112 /*========================= PROTECTED ===============================*/
114 protected:
116 ObjectStore _vObjectStore;
118 /*---------------------------------------------------------------------*/
119 /*! \name Destructor */
120 /*! \{ */
122 /*! \} */
123 /*========================== PRIVATE ================================*/
125 private:
128 typedef ShaderMapCache<ShaderExecutableChunk > ShaderExeMap;
129 typedef ShaderMapCache<ShaderExecutableVarChunk> ShaderVarMap;
131 #ifdef OSG_SHC_MODE_0
132 typedef ShaderMapCache<ShaderExecutableChunk > ActiveShaderExeTree;
133 typedef ShaderMapCache<ShaderExecutableVarChunk> ActiveShaderVarTree;
134 #endif
138 /*! \ingroup GrpSystemShaderBase
139 \ingroup GrpLibOSGSystem
140 \nohierarchy
143 template<class ObjectT>
144 class ShaderVectorCache
146 /*========================== PUBLIC =================================*/
148 public:
150 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
152 typedef UInt16 IdType;
153 typedef std::vector<IdType > IdStore;
155 typedef std::pair <IdStore,
156 ObjectUnrecPtr > StoreElement;
158 typedef std::vector<StoreElement > ObjectStore;
160 /*---------------------------------------------------------------------*/
161 /*! \name Statistic */
162 /*! \{ */
164 ObjectT *find(const IdStore &vIds );
165 bool add (const IdStore &vIds,
166 ObjectT *pObject);
167 void sub ( UInt32 uiIdx );
169 /*! \} */
170 /*---------------------------------------------------------------------*/
171 /*! \name Constructors */
172 /*! \{ */
174 void dumpDot(const Char8 *szFilename);
176 /*! \} */
177 /*---------------------------------------------------------------------*/
178 /*! \name Constructors */
179 /*! \{ */
181 template <typename ElemDestFunc>
182 void destroy(ElemDestFunc destFunc);
184 /*! \} */
185 /*---------------------------------------------------------------------*/
186 /*! \name Constructors */
187 /*! \{ */
189 ShaderVectorCache(void);
191 /*! \} */
192 /*---------------------------------------------------------------------*/
193 /*! \name Destructor */
194 /*! \{ */
196 ~ShaderVectorCache(void);
198 /*! \} */
199 /*========================= PROTECTED ===============================*/
201 protected:
203 ObjectStore _vObjectStore;
205 /*---------------------------------------------------------------------*/
206 /*! \name Destructor */
207 /*! \{ */
209 /*! \} */
210 /*========================== PRIVATE ================================*/
212 private:
215 #ifdef OSG_SHC_MODE_1
216 typedef ShaderVectorCache<ShaderExecutableChunk > ActiveShaderExeTree;
217 typedef ShaderVectorCache<ShaderExecutableVarChunk> ActiveShaderVarTree;
218 #endif
220 typedef ShaderVectorCache<ShaderExecutableChunk > ShaderExeVector;
221 typedef ShaderVectorCache<ShaderExecutableVarChunk> ShaderVarVector;
223 inline
224 bool operator < (const ShaderExeVector::StoreElement &rhs,
225 const ShaderExeVector::IdStore &lhs)
227 return rhs.first < lhs;
230 inline
231 bool operator < (const ShaderVarVector::StoreElement &rhs,
232 const ShaderVarVector::IdStore &lhs)
234 return rhs.first < lhs;
239 /*! \nohierarchy
242 template<UInt32 Base, UInt32 Exponent>
243 struct osgPow_s
245 static const UInt32 result = Base * osgPow_s<Base, Exponent - 1>::result;
248 /*! \nohierarchy
251 template<UInt32 Base>
252 struct osgPow_s<Base, 1>
254 static const UInt32 result = Base;
257 /*! \ingroup GrpSystemShaderBase
258 \ingroup GrpLibOSGSystem
259 \nohierarchy
262 template<class ObjectT, UInt32 LevelBits>
263 class ShaderCacheTreeV0
265 /*========================== PUBLIC =================================*/
267 public:
269 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
271 typedef UInt16 IdType;
272 typedef std::vector<IdType > IdStore;
274 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
275 #if !defined(WIN32) && !defined(__APPLE__) && \
276 !defined(__GXX_EXPERIMENTAL_CXX0X__)
277 static const Real32 LevelFactor = 1.f / (LevelBits);
278 #else
279 static const Real32 LevelFactor;
280 #endif
282 /*---------------------------------------------------------------------*/
283 /*! \name Statistic */
284 /*! \{ */
286 ObjectT *find(const IdStore &vIds );
287 bool add (const IdStore &vIds,
288 ObjectT *pObject);
289 void sub ( UInt32 uiIdx );
291 /*! \} */
292 /*---------------------------------------------------------------------*/
293 /*! \name Constructors */
294 /*! \{ */
296 void dumpDot(const Char8 *szFilename);
298 /*! \} */
299 /*---------------------------------------------------------------------*/
300 /*! \name Constructors */
301 /*! \{ */
303 template <typename ElemDestFunc>
304 void destroy(ElemDestFunc destFunc);
306 /*! \} */
307 /*---------------------------------------------------------------------*/
308 /*! \name Constructors */
309 /*! \{ */
311 ShaderCacheTreeV0(void);
313 /*! \} */
314 /*---------------------------------------------------------------------*/
315 /*! \name Destructor */
316 /*! \{ */
318 ~ShaderCacheTreeV0(void);
320 /*! \} */
321 /*========================= PROTECTED ===============================*/
323 protected:
325 /*! \nohierarchy
327 struct TreeNode
329 TreeNode(void);
330 ~TreeNode(void);
332 void clear(void);
334 #ifdef OSG_DEBUG
335 UInt32 _uiNodeId;
336 #endif
337 ObjectUnrecPtr _pObject;
338 TreeNode *_pPrev;
339 TreeNode *_pNext;
340 TreeNode *_vChildren[LevelSize];
343 #ifdef OSG_DEBUG
344 UInt32 _uiNodeCount;
345 #endif
346 TreeNode *_pRoot;
347 std::vector<TreeNode *> _vLevelEntries;
348 std::deque <TreeNode *> _qFreeElements;
350 /*---------------------------------------------------------------------*/
351 /*! \name Destructor */
352 /*! \{ */
354 TreeNode *allocateNode(void );
355 void eraseNode (TreeNode *pNode);
357 template <typename ElemDestFunc>
358 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
360 void dumpDotNode(TreeNode *pNode,
361 FILE *pOut,
362 std::vector< std::vector<TreeNode *> > &vLevelStore,
363 UInt32 uiLevel );
365 /*! \} */
366 /*========================== PRIVATE ================================*/
368 private:
371 #ifdef OSG_SHC_MODE_2
372 typedef ShaderCacheTreeV0<ShaderExecutableChunk,
373 3 > ActiveShaderExeTree;
374 typedef ShaderCacheTreeV0<ShaderExecutableVarChunk,
375 6 > ActiveShaderVarTree;
376 #endif
379 /*! \ingroup GrpSystemShaderBase
380 \ingroup GrpLibOSGSystem
381 \nohierarchy
384 template<typename Object1T, typename RefCountPol1,
385 typename Object2T, typename RefCountPol2>
386 class VariantPtr
388 public:
390 VariantPtr(void);
391 ~VariantPtr(void);
393 Object1T *asT1(void) const;
394 Object2T *asT2(void) const;
396 void setAsT1(Object1T * const rhs);
397 void setAsT2(Object2T * const rhs);
399 void operator =(Object1T * const rhs);
400 void operator =(Object2T * const rhs);
402 Object2T *operator ->(void) const;
404 protected:
406 static const UIntPointer UIMaskChoice = 0x0001;
407 static const UIntPointer UIMaskPtr = ~0x0001;
409 /*! \nohierarchy
411 union MemberU
413 UIntPointer _uiIntVal;
414 Object1T *_pObj1;
415 Object2T *_pObj2;
418 MemberU _val;
420 private:
422 VariantPtr(const VariantPtr &source);
423 void operator =(const VariantPtr &rhs);
426 /*! \ingroup GrpSystemShaderBase
427 \ingroup GrpLibOSGSystem
428 \nohierarchy
431 template<class ObjectT, UInt32 LevelBits>
432 class ShaderCacheTreeV1
434 /*========================== PUBLIC =================================*/
436 public:
438 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
440 typedef UInt16 IdType;
441 typedef std::vector<IdType > IdStore;
443 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
444 #if !defined(WIN32) && !defined(__APPLE__) && \
445 !defined(__GXX_EXPERIMENTAL_CXX0X__)
446 static const Real32 LevelFactor = 1.f / (LevelBits);
447 #else
448 static const Real32 LevelFactor;
449 #endif
451 /*---------------------------------------------------------------------*/
452 /*! \name Statistic */
453 /*! \{ */
455 ObjectT *find(const IdStore &vIds );
456 bool add (const IdStore &vIds,
457 ObjectT *pObject);
458 void sub ( UInt32 uiIdx );
460 /*! \} */
461 /*---------------------------------------------------------------------*/
462 /*! \name Constructors */
463 /*! \{ */
465 void dumpDot(const Char8 *szFilename);
467 /*! \} */
468 /*---------------------------------------------------------------------*/
469 /*! \name Constructors */
470 /*! \{ */
472 template <typename ElemDestFunc>
473 void destroy(ElemDestFunc destFunc);
475 /*! \} */
476 /*---------------------------------------------------------------------*/
477 /*! \name Constructors */
478 /*! \{ */
480 ShaderCacheTreeV1(void);
482 /*! \} */
483 /*---------------------------------------------------------------------*/
484 /*! \name Destructor */
485 /*! \{ */
487 ~ShaderCacheTreeV1(void);
489 /*! \} */
490 /*========================= PROTECTED ===============================*/
492 protected:
494 /*! \nohierarchy
496 struct TreeNode
498 typedef VariantPtr<ObjectT, UnrecordedRefCountPolicy,
499 TreeNode, NoRefCountPolicy > ChildPtr;
501 TreeNode(void);
502 ~TreeNode(void);
504 void clear(void);
506 #ifdef OSG_DEBUG
507 UInt32 _uiNodeId;
508 #endif
509 ObjectUnrecPtr _pObject;
510 TreeNode *_pPrev;
511 TreeNode *_pNext;
512 ChildPtr _vChildren[LevelSize];
515 #ifdef OSG_DEBUG
516 UInt32 _uiNodeCount;
517 #endif
518 TreeNode *_pRoot;
519 std::vector<TreeNode *> _vLevelEntries;
520 std::deque <TreeNode *> _qFreeElements;
522 /*---------------------------------------------------------------------*/
523 /*! \name Destructor */
524 /*! \{ */
526 TreeNode *allocateNode(void );
527 void eraseNode (TreeNode *pNode);
529 template <typename ElemDestFunc>
530 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
532 void dumpDotNode(TreeNode *pNode,
533 FILE *pOut,
534 std::vector< std::vector<TreeNode *> > &vLevelStore,
535 UInt32 uiLevel );
537 /*! \} */
538 /*========================== PRIVATE ================================*/
540 private:
543 #ifdef OSG_SHC_MODE_3
544 typedef ShaderCacheTreeV1<ShaderExecutableChunk,
545 3 > ActiveShaderExeTree;
546 typedef ShaderCacheTreeV1<ShaderExecutableVarChunk,
547 6 > ActiveShaderVarTree;
548 #endif
550 /*! \ingroup GrpSystemShaderBase
551 \ingroup GrpLibOSGSystem
552 \nohierarchy
555 template<class ObjectT, UInt32 LevelBits>
556 class ShaderCacheTreeV2
558 /*========================== PUBLIC =================================*/
560 public:
562 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
564 typedef UInt16 IdType;
565 typedef std::vector<IdType > IdStore;
567 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
568 #if !defined(WIN32) && !defined(__APPLE__) && \
569 !defined(__GXX_EXPERIMENTAL_CXX0X__)
570 static const Real32 LevelFactor = 1.f / (LevelBits);
571 #else
572 static const Real32 LevelFactor;
573 #endif
575 /*---------------------------------------------------------------------*/
576 /*! \name Statistic */
577 /*! \{ */
579 ObjectT *find(const IdStore &vIds );
580 bool add (const IdStore &vIds,
581 ObjectT *pObject);
582 void sub ( UInt32 uiIdx );
584 /*! \} */
585 /*---------------------------------------------------------------------*/
586 /*! \name Constructors */
587 /*! \{ */
589 void dumpDot(const Char8 *szFilename);
591 /*! \} */
592 /*---------------------------------------------------------------------*/
593 /*! \name Constructors */
594 /*! \{ */
596 template <typename ElemDestFunc>
597 void destroy(ElemDestFunc destFunc);
599 /*! \} */
600 /*---------------------------------------------------------------------*/
601 /*! \name Constructors */
602 /*! \{ */
604 ShaderCacheTreeV2(void);
606 /*! \} */
607 /*---------------------------------------------------------------------*/
608 /*! \name Destructor */
609 /*! \{ */
611 ~ShaderCacheTreeV2(void);
613 /*! \} */
614 /*========================= PROTECTED ===============================*/
616 protected:
618 /*! \nohierarchy
621 struct TreeNode
623 typedef VariantPtr<ObjectT, UnrecordedRefCountPolicy,
624 TreeNode, NoRefCountPolicy > ChildPtr;
626 TreeNode(void);
627 ~TreeNode(void);
629 void clear(void);
631 #ifdef OSG_DEBUG
632 UInt32 _uiNodeId;
633 #endif
634 ObjectUnrecPtr _pObject;
635 TreeNode *_pPrev;
636 TreeNode *_pNext;
637 UInt16 _vJumps[LevelSize];
638 ChildPtr _vChildren[LevelSize];
641 #ifdef OSG_DEBUG
642 UInt32 _uiNodeCount;
643 #endif
644 TreeNode *_pRoot;
645 std::vector<TreeNode *> _vLevelEntries;
646 std::deque <TreeNode *> _qFreeElements;
648 /*---------------------------------------------------------------------*/
649 /*! \name Destructor */
650 /*! \{ */
652 TreeNode *allocateNode(void );
653 void eraseNode (TreeNode *pNode);
655 template <typename ElemDestFunc>
656 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
658 void dumpDotNode(TreeNode *pNode,
659 FILE *pOut,
660 std::vector< std::vector<TreeNode *> > &vLevelStore,
661 UInt32 uiLevel );
663 /*! \} */
664 /*========================== PRIVATE ================================*/
666 private:
669 #ifdef OSG_SHC_MODE_4
670 typedef ShaderCacheTreeV2<ShaderExecutableChunk,
671 3 > ActiveShaderExeTree;
672 typedef ShaderCacheTreeV2<ShaderExecutableVarChunk,
673 6 > ActiveShaderVarTree;
674 #endif
677 /*! \ingroup GrpSystemShaderBase
678 \ingroup GrpLibOSGSystem
679 \nohierarchy
682 template<class ObjectT, UInt32 LevelBits>
683 class ShaderCacheTreeV3
685 /*========================== PUBLIC =================================*/
687 public:
689 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
691 typedef UInt16 IdType;
692 typedef std::vector<IdType > IdStore;
694 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
695 #if !defined(WIN32) && !defined(__APPLE__) && \
696 !defined(__GXX_EXPERIMENTAL_CXX0X__)
697 static const Real32 LevelFactor = 1.f / (LevelBits);
698 #else
699 static const Real32 LevelFactor;
700 #endif
702 /*---------------------------------------------------------------------*/
703 /*! \name Statistic */
704 /*! \{ */
706 ObjectT *find(const IdStore &vIds );
707 bool add (const IdStore &vIds,
708 ObjectT *pObject);
709 void sub ( UInt32 uiIdx );
711 /*! \} */
712 /*---------------------------------------------------------------------*/
713 /*! \name Constructors */
714 /*! \{ */
716 void dumpDot(const Char8 *szFilename,
717 bool dumpEmptyLevelEntries = false);
719 /*! \} */
720 /*---------------------------------------------------------------------*/
721 /*! \name Constructors */
722 /*! \{ */
724 template <typename ElemDestFunc>
725 void destroy(ElemDestFunc destFunc);
727 /*! \} */
728 /*---------------------------------------------------------------------*/
729 /*! \name Constructors */
730 /*! \{ */
732 ShaderCacheTreeV3(void);
734 /*! \} */
735 /*---------------------------------------------------------------------*/
736 /*! \name Destructor */
737 /*! \{ */
739 ~ShaderCacheTreeV3(void);
741 /*! \} */
742 /*========================= PROTECTED ===============================*/
744 protected:
746 /*! \nohierarchy
748 struct TreeNode
750 typedef VariantPtr<ObjectT, UnrecordedRefCountPolicy,
751 TreeNode, NoRefCountPolicy > ChildPtr;
753 TreeNode(void);
754 ~TreeNode(void);
756 void clear(void);
758 #ifdef OSG_DEBUG
759 UInt32 _uiNodeId;
760 #endif
761 ObjectUnrecPtr _pObject;
762 TreeNode *_pPrev;
763 TreeNode *_pNext;
764 UInt16 _vJumps[LevelSize];
765 ChildPtr _vChildren[LevelSize];
768 #ifdef OSG_DEBUG
769 UInt32 _uiNodeCount;
770 #endif
771 TreeNode *_pRoot;
772 std::vector<TreeNode *> _vLevelEntries;
773 std::deque <TreeNode *> _qFreeElements;
775 typedef typename std::vector<TreeNode *>:: iterator TreeNodeVecIt;
776 typedef typename std::vector<TreeNode *>::const_iterator TreeNodeVecConstIt;
778 /*---------------------------------------------------------------------*/
779 /*! \name Destructor */
780 /*! \{ */
782 TreeNode *allocateNode(void );
783 void eraseNode (TreeNode *pNode);
785 template <typename ElemDestFunc>
786 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
788 void dumpDotNode(TreeNode *pNode,
789 FILE *pOut,
790 std::vector< std::vector<TreeNode *> > &vLevelStore,
791 UInt32 uiLevel );
793 /*! \} */
794 /*========================== PRIVATE ================================*/
796 private:
799 #ifdef OSG_SHC_MODE_5
800 typedef ShaderCacheTreeV3<ShaderExecutableChunk,
801 3 > ActiveShaderExeTree;
802 typedef ShaderCacheTreeV3<ShaderExecutableVarChunk,
803 6 > ActiveShaderVarTree;
804 #endif
806 OSG_END_NAMESPACE
808 #include "OSGShaderCacheTree.inl"
810 #endif /* _OSGSHADERCACHETREE_H_ */