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 _OSGHARDWARECONTEXTTASK_H_
40 #define _OSGHARDWARECONTEXTTASK_H_
46 #include "OSGMemoryObject.h"
47 #include "OSGTransitPtr.h"
48 #include "OSGBaseDef.h"
50 #include "OSGSemaphore.h"
51 #include "OSGBarrier.h"
52 #include "OSGMField.h"
59 class HardwareContext
;
61 /*! \ingroup GrpBaseMemoryObjectsBase
62 \ingroup GrpBaseHardwareContext
63 \ingroup GrpLibOSGBase
66 class OSG_BASE_DLLMAPPING HardwareContextTask
: public MemoryObject
68 /*========================== PUBLIC =================================*/
72 typedef MemoryObject Inherited
;
74 static const UInt32 EndThread
= 0x0001;
75 static const UInt32 LastType
= 0x0001;
77 /*---------------------------------------------------------------------*/
78 /*! \name Statistic */
81 virtual void execute(HardwareContext
*pContext
, DrawEnv
*pEnv
) = 0;
84 /*---------------------------------------------------------------------*/
89 /*---------------------------------------------------------------------*/
94 /*---------------------------------------------------------------------*/
99 /*---------------------------------------------------------------------*/
104 /*---------------------------------------------------------------------*/
105 /*! \name Constructors */
109 /*---------------------------------------------------------------------*/
110 /*! \name Constructors */
114 /*---------------------------------------------------------------------*/
115 /*! \name Constructors */
119 /*---------------------------------------------------------------------*/
120 /*! \name Constructors */
124 /*---------------------------------------------------------------------*/
125 /*! \name Debugging */
128 virtual void dump(UInt32 uiIndent
) = 0;
131 /*========================= PROTECTED ===============================*/
137 /*---------------------------------------------------------------------*/
142 /*---------------------------------------------------------------------*/
143 /*! \name Constructors */
146 HardwareContextTask(UInt32 uiTaskType
);
149 /*---------------------------------------------------------------------*/
150 /*! \name Destructor */
153 virtual ~HardwareContextTask(void);
156 /*---------------------------------------------------------------------*/
157 /*! \name Destructor */
161 /*========================== PRIVATE ================================*/
165 /*! \brief prohibit default function (move to 'public' if needed) */
166 HardwareContextTask(const HardwareContextTask
&source
);
167 /*! \brief prohibit default function (move to 'public' if needed) */
168 void operator =(const HardwareContextTask
&source
);
171 /*! \ingroup GrpBaseMemoryObjectsBase
172 \ingroup GrpBaseHardwareContext
173 \ingroup GrpLibOSGBase
176 class OSG_BASE_DLLMAPPING BlockingTask
: public HardwareContextTask
178 /*========================== PUBLIC =================================*/
182 typedef HardwareContextTask Inherited
;
184 /*---------------------------------------------------------------------*/
185 /*! \name Statistic */
188 void activateBarrier(bool bVal
);
191 /*---------------------------------------------------------------------*/
195 void setNumWaitFor (UInt32 uiWaitees
);
196 void waitForBarrier(void );
199 /*---------------------------------------------------------------------*/
204 /*---------------------------------------------------------------------*/
209 /*---------------------------------------------------------------------*/
214 /*---------------------------------------------------------------------*/
215 /*! \name Constructors */
219 /*---------------------------------------------------------------------*/
220 /*! \name Constructors */
224 /*---------------------------------------------------------------------*/
225 /*! \name Constructors */
229 /*---------------------------------------------------------------------*/
230 /*! \name Constructors */
234 /*---------------------------------------------------------------------*/
235 /*! \name Debugging */
238 virtual void dump(UInt32 uiIndent
) = 0;
241 /*========================= PROTECTED ===============================*/
245 bool _bBarrierActive
;
246 BarrierRefPtr _pBarrier
;
248 /*---------------------------------------------------------------------*/
253 /*---------------------------------------------------------------------*/
254 /*! \name Constructors */
257 BlockingTask(UInt32 uiTaskType
);
260 /*---------------------------------------------------------------------*/
261 /*! \name Destructor */
264 virtual ~BlockingTask(void);
267 /*---------------------------------------------------------------------*/
268 /*! \name Destructor */
272 /*========================== PRIVATE ================================*/
276 /*! \brief prohibit default function (move to 'public' if needed) */
277 BlockingTask(const BlockingTask
&source
);
278 /*! \brief prohibit default function (move to 'public' if needed) */
279 void operator =(const BlockingTask
&source
);
282 /*! \ingroup GrpBaseMemoryObjectsBase
283 \ingroup GrpBaseHardwareContext
284 \ingroup GrpLibOSGBase
287 class OSG_BASE_DLLMAPPING CallbackTask
: public BlockingTask
289 /*========================== PUBLIC =================================*/
293 static const UInt32 Callback
= Inherited::LastType
+ 1;
294 static const UInt32 LastType
= Callback
;
296 typedef BlockingTask Inherited
;
298 typedef boost::function
<void (HardwareContext
*,
299 DrawEnv
*)> CallbackFunctor
;
301 /*---------------------------------------------------------------------*/
302 /*! \name Statistic */
305 CallbackTask(UInt32 uiType
);
306 CallbackTask(const CallbackFunctor
&fCallback
, UInt32 uiType
);
309 /*---------------------------------------------------------------------*/
313 virtual void execute(HardwareContext
*pContext
, DrawEnv
*pEnv
);
316 /*---------------------------------------------------------------------*/
320 void setCallback(const CallbackFunctor
&fCallback
);
323 /*---------------------------------------------------------------------*/
328 /*---------------------------------------------------------------------*/
333 /*---------------------------------------------------------------------*/
337 virtual void dump(UInt32 uiIndent
);
340 /*========================= PROTECTED ===============================*/
344 /*---------------------------------------------------------------------*/
348 CallbackFunctor _fCallback
;
351 /*---------------------------------------------------------------------*/
352 /*! \name Destructor */
355 virtual ~CallbackTask(void);
358 /*========================== PRIVATE ================================*/
362 /*! \brief prohibit default function (move to 'public' if needed) */
363 CallbackTask(const CallbackTask
&source
);
364 /*! \brief prohibit default function (move to 'public' if needed) */
365 void operator =(const CallbackTask
&source
);
368 /*! \ingroup GrpBaseHardwareContext
371 typedef RefCountPtr
<HardwareContextTask
,
372 MemObjRefCountPolicy
> HardwareContextTaskRefPtr
;
374 /*! \ingroup GrpBaseHardwareContext
377 typedef RefCountPtr
<BlockingTask
,
378 MemObjRefCountPolicy
> BlockingTaskRefPtr
;
380 /*! \ingroup GrpBaseHardwareContext
383 typedef RefCountPtr
<CallbackTask
,
384 MemObjRefCountPolicy
> CallbackTaskRefPtr
;
387 /*! \ingroup GrpBaseHardwareContext
390 typedef TransitPtr
<HardwareContextTask
> HardwareContextTaskTransitPtr
;
392 /*! \ingroup GrpBaseHardwareContext
395 typedef TransitPtr
<BlockingTask
> BlockingTaskTransitPtr
;
397 /*! \ingroup GrpBaseHardwareContext
400 typedef TransitPtr
<CallbackTask
> CallbackTaskTransitPtr
;
402 /*! \ingroup GrpBaseHardwareContextFieldTraits
403 \ingroup GrpLibOSGBase
407 struct FieldTraits
<HardwareContextTaskRefPtr
> :
408 public FieldTraitsTemplateBase
<HardwareContextTaskRefPtr
>
412 static DataType _type
;
416 typedef FieldTraits
<HardwareContextTaskRefPtr
> Self
;
418 enum { Convertible
= Self::NotConvertible
};
421 static DataType
&getType (void);
423 static const char *getMName(void) { return "MFHardwareContextTask"; }
425 static SizeT
getBinSize(const HardwareContextTaskRefPtr
*,
431 static void copyToBin( BinaryDataHandler
&,
432 const HardwareContextTaskRefPtr
*,
435 SWARNING
<< "FieldTraits<HardwareContextTaskRefPtr>::copyToBin: "
440 static void copyFromBin(BinaryDataHandler
&,
441 HardwareContextTaskRefPtr
*,
444 SWARNING
<< "FieldTraits<HardwareContextTaskRefPtr>::copyFromBin: "
450 #ifndef DOXYGEN_SHOULD_SKIP_THIS
451 /*! \ingroup GrpBaseHardwareContextFieldMFields */
452 typedef MField
<HardwareContextTaskRefPtr
, 0> MFHardwareContextTask
;
453 #else // these are the doxygen hacks
454 /*! \ingroup GrpBaseHardwareContextFieldMFields */
455 typedef MFHardwareContextTask
: public MField
<HardwareContextTaskRefPtr
, 0> {};
456 #endif // these are the doxygen hacks
458 /*! \ingroup GrpBaseMemoryObjectsBase
459 \ingroup GrpBaseHardwareContext
460 \ingroup GrpLibOSGBase
464 class OSG_BASE_DLLMAPPING HardwareContextTaskQueue
466 /*========================== PUBLIC =================================*/
470 /*---------------------------------------------------------------------*/
471 /*! \name Statistic */
474 void queueTask (HardwareContextTask
*pTask
);
475 void queueTaskFront(HardwareContextTask
*pTask
);
476 HardwareContextTaskTransitPtr
popTask (void );
479 /*---------------------------------------------------------------------*/
480 /*! \name Constructors */
484 /*---------------------------------------------------------------------*/
485 /*! \name Constructors */
489 /*---------------------------------------------------------------------*/
490 /*! \name Constructors */
493 HardwareContextTaskQueue(void);
496 /*---------------------------------------------------------------------*/
497 /*! \name Destructor */
500 virtual ~HardwareContextTaskQueue(void);
503 /*---------------------------------------------------------------------*/
504 /*! \name Debugging */
507 // Implementation in OSGWindow.inl
508 void dumpQueue (void );
509 void runAndClearQueue(HardwareContext
*pContext
,
513 /*========================= PROTECTED ===============================*/
517 typedef std::deque
<HardwareContextTaskRefPtr
> TaskStore
;
519 TaskStore _qTaskStore
;
520 LockRefPtr _pStoreLock
;
521 SemaphoreRefPtr _pStoreSema
;
523 /*---------------------------------------------------------------------*/
528 /*---------------------------------------------------------------------*/
529 /*! \name Destructor */
533 /*========================== PRIVATE ================================*/
537 /*! \brief prohibit default function (move to 'public' if needed) */
538 HardwareContextTaskQueue(const HardwareContextTaskQueue
&source
);
539 /*! \brief prohibit default function (move to 'public' if needed) */
540 void operator =(const HardwareContextTaskQueue
&source
);
546 #include "OSGHardwareContextTask.inl"
548 #endif /* _OSGHARDWARECONTEXTTASK_H_ */