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 _OSGSHADERCACHETREE_H_
40 #define _OSGSHADERCACHETREE_H_
46 #include "OSGBaseTypes.h"
47 #include "OSGSystemDef.h"
49 #include "OSGShaderExecutableChunk.h"
50 #include "OSGShaderExecutableVarChunk.h"
54 /*! \ingroup GrpSystemShaderBase
55 \ingroup GrpLibOSGSystem
59 template<class ObjectT
>
62 /*========================== 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 */
77 ObjectT
*find(const IdStore
&vIds
);
78 bool add (const IdStore
&vIds
,
80 void sub ( UInt32 uiIdx
);
83 /*---------------------------------------------------------------------*/
84 /*! \name Constructors */
87 void dumpDot(const Char8
*szFilename
);
90 /*---------------------------------------------------------------------*/
91 /*! \name Constructors */
94 template <typename ElemDestFunc
>
95 void destroy(ElemDestFunc destFunc
);
98 /*---------------------------------------------------------------------*/
99 /*! \name Constructors */
102 ShaderMapCache(void);
105 /*---------------------------------------------------------------------*/
106 /*! \name Destructor */
109 ~ShaderMapCache(void);
112 /*========================= PROTECTED ===============================*/
116 ObjectStore _vObjectStore
;
118 /*---------------------------------------------------------------------*/
119 /*! \name Destructor */
123 /*========================== 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
;
138 /*! \ingroup GrpSystemShaderBase
139 \ingroup GrpLibOSGSystem
143 template<class ObjectT
>
144 class ShaderVectorCache
146 /*========================== 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 */
164 ObjectT
*find(const IdStore
&vIds
);
165 bool add (const IdStore
&vIds
,
167 void sub ( UInt32 uiIdx
);
170 /*---------------------------------------------------------------------*/
171 /*! \name Constructors */
174 void dumpDot(const Char8
*szFilename
);
177 /*---------------------------------------------------------------------*/
178 /*! \name Constructors */
181 template <typename ElemDestFunc
>
182 void destroy(ElemDestFunc destFunc
);
185 /*---------------------------------------------------------------------*/
186 /*! \name Constructors */
189 ShaderVectorCache(void);
192 /*---------------------------------------------------------------------*/
193 /*! \name Destructor */
196 ~ShaderVectorCache(void);
199 /*========================= PROTECTED ===============================*/
203 ObjectStore _vObjectStore
;
205 /*---------------------------------------------------------------------*/
206 /*! \name Destructor */
210 /*========================== PRIVATE ================================*/
215 #ifdef OSG_SHC_MODE_1
216 typedef ShaderVectorCache
<ShaderExecutableChunk
> ActiveShaderExeTree
;
217 typedef ShaderVectorCache
<ShaderExecutableVarChunk
> ActiveShaderVarTree
;
220 typedef ShaderVectorCache
<ShaderExecutableChunk
> ShaderExeVector
;
221 typedef ShaderVectorCache
<ShaderExecutableVarChunk
> ShaderVarVector
;
224 bool operator < (const ShaderExeVector::StoreElement
&rhs
,
225 const ShaderExeVector::IdStore
&lhs
)
227 return rhs
.first
< lhs
;
231 bool operator < (const ShaderVarVector::StoreElement
&rhs
,
232 const ShaderVarVector::IdStore
&lhs
)
234 return rhs
.first
< lhs
;
242 template<UInt32 Base
, UInt32 Exponent
>
245 static const UInt32 result
= Base
* osgPow_s
<Base
, Exponent
- 1>::result
;
251 template<UInt32 Base
>
252 struct osgPow_s
<Base
, 1>
254 static const UInt32 result
= Base
;
257 /*! \ingroup GrpSystemShaderBase
258 \ingroup GrpLibOSGSystem
262 template<class ObjectT
, UInt32 LevelBits
>
263 class ShaderCacheTreeV0
265 /*========================== 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
);
279 static const Real32 LevelFactor
;
282 /*---------------------------------------------------------------------*/
283 /*! \name Statistic */
286 ObjectT
*find(const IdStore
&vIds
);
287 bool add (const IdStore
&vIds
,
289 void sub ( UInt32 uiIdx
);
292 /*---------------------------------------------------------------------*/
293 /*! \name Constructors */
296 void dumpDot(const Char8
*szFilename
);
299 /*---------------------------------------------------------------------*/
300 /*! \name Constructors */
303 template <typename ElemDestFunc
>
304 void destroy(ElemDestFunc destFunc
);
307 /*---------------------------------------------------------------------*/
308 /*! \name Constructors */
311 ShaderCacheTreeV0(void);
314 /*---------------------------------------------------------------------*/
315 /*! \name Destructor */
318 ~ShaderCacheTreeV0(void);
321 /*========================= PROTECTED ===============================*/
337 ObjectUnrecPtr _pObject
;
340 TreeNode
*_vChildren
[LevelSize
];
347 std::vector
<TreeNode
*> _vLevelEntries
;
348 std::deque
<TreeNode
*> _qFreeElements
;
350 /*---------------------------------------------------------------------*/
351 /*! \name Destructor */
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
,
362 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
366 /*========================== PRIVATE ================================*/
371 #ifdef OSG_SHC_MODE_2
372 typedef ShaderCacheTreeV0
<ShaderExecutableChunk
,
373 3 > ActiveShaderExeTree
;
374 typedef ShaderCacheTreeV0
<ShaderExecutableVarChunk
,
375 6 > ActiveShaderVarTree
;
379 /*! \ingroup GrpSystemShaderBase
380 \ingroup GrpLibOSGSystem
384 template<typename Object1T
, typename RefCountPol1
,
385 typename Object2T
, typename RefCountPol2
>
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;
406 static const UIntPointer UIMaskChoice
= 0x0001;
407 static const UIntPointer UIMaskPtr
= ~0x0001;
413 UIntPointer _uiIntVal
;
422 VariantPtr(const VariantPtr
&source
);
423 void operator =(const VariantPtr
&rhs
);
426 /*! \ingroup GrpSystemShaderBase
427 \ingroup GrpLibOSGSystem
431 template<class ObjectT
, UInt32 LevelBits
>
432 class ShaderCacheTreeV1
434 /*========================== 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
);
448 static const Real32 LevelFactor
;
451 /*---------------------------------------------------------------------*/
452 /*! \name Statistic */
455 ObjectT
*find(const IdStore
&vIds
);
456 bool add (const IdStore
&vIds
,
458 void sub ( UInt32 uiIdx
);
461 /*---------------------------------------------------------------------*/
462 /*! \name Constructors */
465 void dumpDot(const Char8
*szFilename
);
468 /*---------------------------------------------------------------------*/
469 /*! \name Constructors */
472 template <typename ElemDestFunc
>
473 void destroy(ElemDestFunc destFunc
);
476 /*---------------------------------------------------------------------*/
477 /*! \name Constructors */
480 ShaderCacheTreeV1(void);
483 /*---------------------------------------------------------------------*/
484 /*! \name Destructor */
487 ~ShaderCacheTreeV1(void);
490 /*========================= PROTECTED ===============================*/
498 typedef VariantPtr
<ObjectT
, UnrecordedRefCountPolicy
,
499 TreeNode
, NoRefCountPolicy
> ChildPtr
;
509 ObjectUnrecPtr _pObject
;
512 ChildPtr _vChildren
[LevelSize
];
516 TreeNode(const TreeNode
&other
);
517 void operator =(const TreeNode
&rhs
);
524 std::vector
<TreeNode
*> _vLevelEntries
;
525 std::deque
<TreeNode
*> _qFreeElements
;
527 /*---------------------------------------------------------------------*/
528 /*! \name Destructor */
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
,
539 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
543 /*========================== 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
;
558 /*! \ingroup GrpSystemShaderBase
559 \ingroup GrpLibOSGSystem
563 template<class ObjectT
, UInt32 LevelBits
>
564 class ShaderCacheTreeV2
566 /*========================== 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
);
580 static const Real32 LevelFactor
;
583 /*---------------------------------------------------------------------*/
584 /*! \name Statistic */
587 ObjectT
*find(const IdStore
&vIds
);
588 bool add (const IdStore
&vIds
,
590 void sub ( UInt32 uiIdx
);
593 /*---------------------------------------------------------------------*/
594 /*! \name Constructors */
597 void dumpDot(const Char8
*szFilename
);
600 /*---------------------------------------------------------------------*/
601 /*! \name Constructors */
604 template <typename ElemDestFunc
>
605 void destroy(ElemDestFunc destFunc
);
608 /*---------------------------------------------------------------------*/
609 /*! \name Constructors */
612 ShaderCacheTreeV2(void);
615 /*---------------------------------------------------------------------*/
616 /*! \name Destructor */
619 ~ShaderCacheTreeV2(void);
622 /*========================= PROTECTED ===============================*/
631 typedef VariantPtr
<ObjectT
, UnrecordedRefCountPolicy
,
632 TreeNode
, NoRefCountPolicy
> ChildPtr
;
642 ObjectUnrecPtr _pObject
;
645 UInt16 _vJumps
[LevelSize
];
646 ChildPtr _vChildren
[LevelSize
];
650 TreeNode(const TreeNode
&other
);
651 void operator =(const TreeNode
&rhs
);
658 std::vector
<TreeNode
*> _vLevelEntries
;
659 std::deque
<TreeNode
*> _qFreeElements
;
661 /*---------------------------------------------------------------------*/
662 /*! \name Destructor */
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
,
673 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
677 /*========================== 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
;
693 /*! \ingroup GrpSystemShaderBase
694 \ingroup GrpLibOSGSystem
698 template<class ObjectT
, UInt32 LevelBits
>
699 class ShaderCacheTreeV3
701 /*========================== 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
);
715 static const Real32 LevelFactor
;
718 /*---------------------------------------------------------------------*/
719 /*! \name Statistic */
722 ObjectT
*find(const IdStore
&vIds
);
723 bool add (const IdStore
&vIds
,
725 void sub ( UInt32 uiIdx
);
728 /*---------------------------------------------------------------------*/
729 /*! \name Constructors */
732 void dumpDot(const Char8
*szFilename
,
733 bool dumpEmptyLevelEntries
= false);
736 /*---------------------------------------------------------------------*/
737 /*! \name Constructors */
740 template <typename ElemDestFunc
>
741 void destroy(ElemDestFunc destFunc
);
744 /*---------------------------------------------------------------------*/
745 /*! \name Constructors */
748 ShaderCacheTreeV3(void);
751 /*---------------------------------------------------------------------*/
752 /*! \name Destructor */
755 ~ShaderCacheTreeV3(void);
758 /*========================= PROTECTED ===============================*/
766 typedef VariantPtr
<ObjectT
, UnrecordedRefCountPolicy
,
767 TreeNode
, NoRefCountPolicy
> ChildPtr
;
777 ObjectUnrecPtr _pObject
;
780 UInt16 _vJumps
[LevelSize
];
781 ChildPtr _vChildren
[LevelSize
];
785 TreeNode(const TreeNode
&other
);
786 void operator =(const TreeNode
&rhs
);
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 */
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
,
811 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
815 /*========================== 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
;
832 #include "OSGShaderCacheTree.inl"
834 #endif /* _OSGSHADERCACHETREE_H_ */