changed: gcc8 base update
[opensg.git] / Source / System / State / Shader / Base / OSGShaderCacheTree.h
blobdf3f149d2a07f1480abaeabf9df5fb9e14c0df35
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 const VariantPtr &operator =(Object1T * const rhs);
400 const VariantPtr &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];
514 private:
516 TreeNode(const TreeNode &other);
517 void operator =(const TreeNode &rhs);
520 #ifdef OSG_DEBUG
521 UInt32 _uiNodeCount;
522 #endif
523 TreeNode *_pRoot;
524 std::vector<TreeNode *> _vLevelEntries;
525 std::deque <TreeNode *> _qFreeElements;
527 /*---------------------------------------------------------------------*/
528 /*! \name Destructor */
529 /*! \{ */
531 TreeNode *allocateNode(void );
532 void eraseNode (TreeNode *pNode);
534 template <typename ElemDestFunc>
535 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
537 void dumpDotNode(TreeNode *pNode,
538 FILE *pOut,
539 std::vector< std::vector<TreeNode *> > &vLevelStore,
540 UInt32 uiLevel );
542 /*! \} */
543 /*========================== PRIVATE ================================*/
545 private:
547 ShaderCacheTreeV1(const ShaderCacheTreeV1 &other);
548 void operator =(const ShaderCacheTreeV1 &rhs);
551 #ifdef OSG_SHC_MODE_3
552 typedef ShaderCacheTreeV1<ShaderExecutableChunk,
553 3 > ActiveShaderExeTree;
554 typedef ShaderCacheTreeV1<ShaderExecutableVarChunk,
555 6 > ActiveShaderVarTree;
556 #endif
558 /*! \ingroup GrpSystemShaderBase
559 \ingroup GrpLibOSGSystem
560 \nohierarchy
563 template<class ObjectT, UInt32 LevelBits>
564 class ShaderCacheTreeV2
566 /*========================== PUBLIC =================================*/
568 public:
570 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
572 typedef UInt16 IdType;
573 typedef std::vector<IdType > IdStore;
575 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
576 #if !defined(WIN32) && !defined(__APPLE__) && \
577 !defined(__GXX_EXPERIMENTAL_CXX0X__)
578 static const Real32 LevelFactor = 1.f / (LevelBits);
579 #else
580 static const Real32 LevelFactor;
581 #endif
583 /*---------------------------------------------------------------------*/
584 /*! \name Statistic */
585 /*! \{ */
587 ObjectT *find(const IdStore &vIds );
588 bool add (const IdStore &vIds,
589 ObjectT *pObject);
590 void sub ( UInt32 uiIdx );
592 /*! \} */
593 /*---------------------------------------------------------------------*/
594 /*! \name Constructors */
595 /*! \{ */
597 void dumpDot(const Char8 *szFilename);
599 /*! \} */
600 /*---------------------------------------------------------------------*/
601 /*! \name Constructors */
602 /*! \{ */
604 template <typename ElemDestFunc>
605 void destroy(ElemDestFunc destFunc);
607 /*! \} */
608 /*---------------------------------------------------------------------*/
609 /*! \name Constructors */
610 /*! \{ */
612 ShaderCacheTreeV2(void);
614 /*! \} */
615 /*---------------------------------------------------------------------*/
616 /*! \name Destructor */
617 /*! \{ */
619 ~ShaderCacheTreeV2(void);
621 /*! \} */
622 /*========================= PROTECTED ===============================*/
624 protected:
626 /*! \nohierarchy
629 struct TreeNode
631 typedef VariantPtr<ObjectT, UnrecordedRefCountPolicy,
632 TreeNode, NoRefCountPolicy > ChildPtr;
634 TreeNode(void);
635 ~TreeNode(void);
637 void clear(void);
639 #ifdef OSG_DEBUG
640 UInt32 _uiNodeId;
641 #endif
642 ObjectUnrecPtr _pObject;
643 TreeNode *_pPrev;
644 TreeNode *_pNext;
645 UInt16 _vJumps[LevelSize];
646 ChildPtr _vChildren[LevelSize];
648 private:
650 TreeNode(const TreeNode &other);
651 void operator =(const TreeNode &rhs);
654 #ifdef OSG_DEBUG
655 UInt32 _uiNodeCount;
656 #endif
657 TreeNode *_pRoot;
658 std::vector<TreeNode *> _vLevelEntries;
659 std::deque <TreeNode *> _qFreeElements;
661 /*---------------------------------------------------------------------*/
662 /*! \name Destructor */
663 /*! \{ */
665 TreeNode *allocateNode(void );
666 void eraseNode (TreeNode *pNode);
668 template <typename ElemDestFunc>
669 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
671 void dumpDotNode(TreeNode *pNode,
672 FILE *pOut,
673 std::vector< std::vector<TreeNode *> > &vLevelStore,
674 UInt32 uiLevel );
676 /*! \} */
677 /*========================== PRIVATE ================================*/
679 private:
681 ShaderCacheTreeV2(const ShaderCacheTreeV2 &other);
682 void operator =(const ShaderCacheTreeV2 &rhs);
685 #ifdef OSG_SHC_MODE_4
686 typedef ShaderCacheTreeV2<ShaderExecutableChunk,
687 3 > ActiveShaderExeTree;
688 typedef ShaderCacheTreeV2<ShaderExecutableVarChunk,
689 6 > ActiveShaderVarTree;
690 #endif
693 /*! \ingroup GrpSystemShaderBase
694 \ingroup GrpLibOSGSystem
695 \nohierarchy
698 template<class ObjectT, UInt32 LevelBits>
699 class ShaderCacheTreeV3
701 /*========================== PUBLIC =================================*/
703 public:
705 typedef typename ObjectT::ObjUnrecPtr ObjectUnrecPtr;
707 typedef UInt16 IdType;
708 typedef std::vector<IdType > IdStore;
710 static const UInt32 LevelSize = osgPow_s<2u, LevelBits>::result;
711 #if !defined(WIN32) && !defined(__APPLE__) && \
712 !defined(__GXX_EXPERIMENTAL_CXX0X__)
713 static const Real32 LevelFactor = 1.f / (LevelBits);
714 #else
715 static const Real32 LevelFactor;
716 #endif
718 /*---------------------------------------------------------------------*/
719 /*! \name Statistic */
720 /*! \{ */
722 ObjectT *find(const IdStore &vIds );
723 bool add (const IdStore &vIds,
724 ObjectT *pObject);
725 void sub ( UInt32 uiIdx );
727 /*! \} */
728 /*---------------------------------------------------------------------*/
729 /*! \name Constructors */
730 /*! \{ */
732 void dumpDot(const Char8 *szFilename,
733 bool dumpEmptyLevelEntries = false);
735 /*! \} */
736 /*---------------------------------------------------------------------*/
737 /*! \name Constructors */
738 /*! \{ */
740 template <typename ElemDestFunc>
741 void destroy(ElemDestFunc destFunc);
743 /*! \} */
744 /*---------------------------------------------------------------------*/
745 /*! \name Constructors */
746 /*! \{ */
748 ShaderCacheTreeV3(void);
750 /*! \} */
751 /*---------------------------------------------------------------------*/
752 /*! \name Destructor */
753 /*! \{ */
755 ~ShaderCacheTreeV3(void);
757 /*! \} */
758 /*========================= PROTECTED ===============================*/
760 protected:
762 /*! \nohierarchy
764 struct TreeNode
766 typedef VariantPtr<ObjectT, UnrecordedRefCountPolicy,
767 TreeNode, NoRefCountPolicy > ChildPtr;
769 TreeNode(void);
770 ~TreeNode(void);
772 void clear(void);
774 #ifdef OSG_DEBUG
775 UInt32 _uiNodeId;
776 #endif
777 ObjectUnrecPtr _pObject;
778 TreeNode *_pPrev;
779 TreeNode *_pNext;
780 UInt16 _vJumps[LevelSize];
781 ChildPtr _vChildren[LevelSize];
783 private:
785 TreeNode(const TreeNode &other);
786 void operator =(const TreeNode &rhs);
789 #ifdef OSG_DEBUG
790 UInt32 _uiNodeCount;
791 #endif
792 TreeNode *_pRoot;
793 std::vector<TreeNode *> _vLevelEntries;
794 std::deque <TreeNode *> _qFreeElements;
796 typedef typename std::vector<TreeNode *>:: iterator TreeNodeVecIt;
797 typedef typename std::vector<TreeNode *>::const_iterator TreeNodeVecConstIt;
799 /*---------------------------------------------------------------------*/
800 /*! \name Destructor */
801 /*! \{ */
803 TreeNode *allocateNode(void );
804 void eraseNode (TreeNode *pNode);
806 template <typename ElemDestFunc>
807 void destroyNode(TreeNode *pNode, ElemDestFunc destFunc);
809 void dumpDotNode(TreeNode *pNode,
810 FILE *pOut,
811 std::vector< std::vector<TreeNode *> > &vLevelStore,
812 UInt32 uiLevel );
814 /*! \} */
815 /*========================== PRIVATE ================================*/
817 private:
819 ShaderCacheTreeV3(const ShaderCacheTreeV3 &other);
820 void operator =(const ShaderCacheTreeV3 &rhs);
823 #ifdef OSG_SHC_MODE_5
824 typedef ShaderCacheTreeV3<ShaderExecutableChunk,
825 3 > ActiveShaderExeTree;
826 typedef ShaderCacheTreeV3<ShaderExecutableVarChunk,
827 6 > ActiveShaderVarTree;
828 #endif
830 OSG_END_NAMESPACE
832 #include "OSGShaderCacheTree.inl"
834 #endif /* _OSGSHADERCACHETREE_H_ */