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 void operator =(Object1T
* const rhs
);
400 void 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
];
519 std::vector
<TreeNode
*> _vLevelEntries
;
520 std::deque
<TreeNode
*> _qFreeElements
;
522 /*---------------------------------------------------------------------*/
523 /*! \name Destructor */
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
,
534 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
538 /*========================== PRIVATE ================================*/
543 #ifdef OSG_SHC_MODE_3
544 typedef ShaderCacheTreeV1
<ShaderExecutableChunk
,
545 3 > ActiveShaderExeTree
;
546 typedef ShaderCacheTreeV1
<ShaderExecutableVarChunk
,
547 6 > ActiveShaderVarTree
;
550 /*! \ingroup GrpSystemShaderBase
551 \ingroup GrpLibOSGSystem
555 template<class ObjectT
, UInt32 LevelBits
>
556 class ShaderCacheTreeV2
558 /*========================== 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
);
572 static const Real32 LevelFactor
;
575 /*---------------------------------------------------------------------*/
576 /*! \name Statistic */
579 ObjectT
*find(const IdStore
&vIds
);
580 bool add (const IdStore
&vIds
,
582 void sub ( UInt32 uiIdx
);
585 /*---------------------------------------------------------------------*/
586 /*! \name Constructors */
589 void dumpDot(const Char8
*szFilename
);
592 /*---------------------------------------------------------------------*/
593 /*! \name Constructors */
596 template <typename ElemDestFunc
>
597 void destroy(ElemDestFunc destFunc
);
600 /*---------------------------------------------------------------------*/
601 /*! \name Constructors */
604 ShaderCacheTreeV2(void);
607 /*---------------------------------------------------------------------*/
608 /*! \name Destructor */
611 ~ShaderCacheTreeV2(void);
614 /*========================= PROTECTED ===============================*/
623 typedef VariantPtr
<ObjectT
, UnrecordedRefCountPolicy
,
624 TreeNode
, NoRefCountPolicy
> ChildPtr
;
634 ObjectUnrecPtr _pObject
;
637 UInt16 _vJumps
[LevelSize
];
638 ChildPtr _vChildren
[LevelSize
];
645 std::vector
<TreeNode
*> _vLevelEntries
;
646 std::deque
<TreeNode
*> _qFreeElements
;
648 /*---------------------------------------------------------------------*/
649 /*! \name Destructor */
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
,
660 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
664 /*========================== PRIVATE ================================*/
669 #ifdef OSG_SHC_MODE_4
670 typedef ShaderCacheTreeV2
<ShaderExecutableChunk
,
671 3 > ActiveShaderExeTree
;
672 typedef ShaderCacheTreeV2
<ShaderExecutableVarChunk
,
673 6 > ActiveShaderVarTree
;
677 /*! \ingroup GrpSystemShaderBase
678 \ingroup GrpLibOSGSystem
682 template<class ObjectT
, UInt32 LevelBits
>
683 class ShaderCacheTreeV3
685 /*========================== 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
);
699 static const Real32 LevelFactor
;
702 /*---------------------------------------------------------------------*/
703 /*! \name Statistic */
706 ObjectT
*find(const IdStore
&vIds
);
707 bool add (const IdStore
&vIds
,
709 void sub ( UInt32 uiIdx
);
712 /*---------------------------------------------------------------------*/
713 /*! \name Constructors */
716 void dumpDot(const Char8
*szFilename
,
717 bool dumpEmptyLevelEntries
= false);
720 /*---------------------------------------------------------------------*/
721 /*! \name Constructors */
724 template <typename ElemDestFunc
>
725 void destroy(ElemDestFunc destFunc
);
728 /*---------------------------------------------------------------------*/
729 /*! \name Constructors */
732 ShaderCacheTreeV3(void);
735 /*---------------------------------------------------------------------*/
736 /*! \name Destructor */
739 ~ShaderCacheTreeV3(void);
742 /*========================= PROTECTED ===============================*/
750 typedef VariantPtr
<ObjectT
, UnrecordedRefCountPolicy
,
751 TreeNode
, NoRefCountPolicy
> ChildPtr
;
761 ObjectUnrecPtr _pObject
;
764 UInt16 _vJumps
[LevelSize
];
765 ChildPtr _vChildren
[LevelSize
];
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 */
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
,
790 std::vector
< std::vector
<TreeNode
*> > &vLevelStore
,
794 /*========================== PRIVATE ================================*/
799 #ifdef OSG_SHC_MODE_5
800 typedef ShaderCacheTreeV3
<ShaderExecutableChunk
,
801 3 > ActiveShaderExeTree
;
802 typedef ShaderCacheTreeV3
<ShaderExecutableVarChunk
,
803 6 > ActiveShaderVarTree
;
808 #include "OSGShaderCacheTree.inl"
810 #endif /* _OSGSHADERCACHETREE_H_ */