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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGStateChunk.h"
54 /*! \ingroup GrpSystemStateBase
57 struct StateChunkClassCompare
59 bool operator()(const StateChunkClass
*lhs
,
60 const StateChunkClass
*rhs
)
62 return lhs
->getPriority() < rhs
->getPriority();
70 // Documentation for this class is emited in the
71 // OSGStateChunkBase.cpp file.
72 // To modify it, please change the .fcd file (OSGStateChunk.fcd) and
73 // regenerate the base file.
75 /***************************************************************************\
77 \***************************************************************************/
79 /*! \class OSG::StateChunkClass
81 See \ref StateChunkClass for the
82 conceptual background.
86 /*! \var OSG::StateChunkClass::_classId
87 The numerical ID associated with each StateChunkClass. It is used to
88 uniquely identify and quickly compare the class.
90 \dev The classId is consecutive in the number of slots allocated to the
91 chunk class, i.e. if a class has id 4 and 4 chunks, the next registered
92 class will get id 8. The classId is used as an index into the OSG::State's
93 chunk vector, which necessitates this behaviour. \enddev
96 std::vector
<StateChunkClass
*> *StateChunkClass::_classes
= NULL
;
97 std::vector
<StateChunkClass
*> *StateChunkClass::_initClasses
= NULL
;
99 /*! The global vector of known StateChunkClasses' number of concurrently
100 active slots. Use StateChunkClass::getNumSlots with the Class's ID to access
103 \dev See the OSG::StateChunkClass::_classId for details. \enddev
106 std::vector
<UInt32
> *StateChunkClass::_numslots
= NULL
;
109 bool StateChunkClass::terminate(void)
118 bool StateChunkClass::initialize(void)
120 std::stable_sort(_initClasses
->begin (),
121 _initClasses
->end (),
122 StateChunkClassCompare());
124 _classes
= new std::vector
<StateChunkClass
*>;
125 _numslots
= new std::vector
< UInt32
>;
127 for(UInt32 i
= 0; i
< _initClasses
->size(); ++i
)
129 (*_initClasses
)[i
]->_classId
= UInt32(_classes
->size());
131 for(UInt32 j
= 0; j
< (*_initClasses
)[i
]->_numSlots
; ++j
)
133 _classes
->push_back((*_initClasses
)[i
]);
134 _numslots
->push_back((*_initClasses
)[i
]->_numSlots
);
138 for(UInt32 i
= 0; i
< _classes
->size(); ++i
)
140 FDEBUG_GV(("[%d/%d][%d] %s %d %d\n",
142 StateChunkClass::getUsedSlots(),
143 (*_classes
)[i
]->_classId
,
144 (*_classes
)[i
]->_className
.c_str(),
145 (*_classes
)[i
]->_priority
,
146 (*_classes
)[i
]->_numSlots
));
154 StateChunkClass::StateChunkClassInit
StateChunkClass::InitHelper
;
158 /*! Constructor. The name is mandatory, the number of concurrently active slots
159 is optional, default is 1.
162 StateChunkClass::StateChunkClass(const Char8
*name
,
166 _numSlots (numslots
),
167 _priority (priority
),
172 _initClasses
= new std::vector
<StateChunkClass
*>;
174 addPostFactoryExitFunction(&StateChunkClass::terminate
);
177 _initClasses
->push_back(this);
180 const Char8
*StateChunkClass::getName(void) const
182 return _className
.c_str();
185 Int32
StateChunkClass::getNumSlots(void) const
187 return(*_numslots
)[_classId
];
190 /*! Access the name for the class whose id is index.
193 const Char8
*StateChunkClass::getName(UInt32 index
)
195 if(index
>=(*_classes
).size())
196 return "<Unknown StatChunkClass!>";
198 return(*_classes
)[index
]->_className
.c_str();
202 /*! \var OSG::StateChunkClass::iterator
204 Iterator type to access the chunk class list.
207 /*! Iterator to allow access to all known StateChunkClasses.
210 StateChunkClass::iterator
StateChunkClass::begin(void)
212 return _classes
->begin();
215 /*! Iterator to allow access to all known StateChunkClasses.
218 StateChunkClass::iterator
StateChunkClass::end(void)
220 return _classes
->end();
224 /***************************************************************************\
226 \***************************************************************************/
228 /***************************************************************************\
230 \***************************************************************************/
232 void StateChunk::initMethod(InitPhase ePhase
)
234 Inherited::initMethod(ePhase
);
237 /***************************************************************************\
239 \***************************************************************************/
241 /*-------------------------------------------------------------------------*\
243 \*-------------------------------------------------------------------------*/
246 /*------------- constructors & destructors --------------------------------*/
248 StateChunk::StateChunk(void) :
253 StateChunk::StateChunk(const StateChunk
&source
) :
258 StateChunk::~StateChunk(void)
262 UInt16
StateChunk::getChunkId(void)
267 /*------------------------------- Sync -----------------------------------*/
269 void StateChunk::changed(ConstFieldMaskArg whichField
,
273 Inherited::changed(whichField
, origin
, details
);
276 /*------------------------------ Output ----------------------------------*/
278 void StateChunk::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
279 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
281 SLOG
<< "Dump StateChunk NI" << std::endl
;
285 /*------------------------------ State ------------------------------------*/
287 #ifndef OSG_DISABLE_DEPRECATED
288 void StateChunk::update(DrawEnv
*)
293 /*! Check if the chunk is transparent, i.e. needs to be rendered after the
297 bool StateChunk::isTransparent(void) const
302 void StateChunk::updateObjectDependencies(DrawEnv
*pEnv
,
307 /*---------------------- Chunk Class Access -------------------------------*/
309 const StateChunkClass
*StateChunk::getClass(void) const
314 /*-------------------------- Comparison -----------------------------------*/
316 /*! Calculate how expensive it is to switch from one instance of the chunk
317 class to another. In most cases not implemented yet, will return 0.
320 Real32
StateChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
325 bool StateChunk::operator <(const StateChunk
&other
) const
327 return this < &other
;
330 /*! Compare two chunks. In most cases not implemented yet, will return false.
333 bool StateChunk::operator ==(const StateChunk
&OSG_CHECK_ARG(other
)) const
338 bool StateChunk::operator !=(const StateChunk
&other
) const
340 return !(*this == other
);