changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / FieldContainer / Threading / OSGHardwareContextTask.h
blob3cff94447bcb940781266269c5055d4c3bdea30c
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 _OSGHARDWARECONTEXTTASK_H_
40 #define _OSGHARDWARECONTEXTTASK_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGMemoryObject.h"
47 #include "OSGTransitPtr.h"
48 #include "OSGBaseDef.h"
49 #include "OSGLock.h"
50 #include "OSGSemaphore.h"
51 #include "OSGBarrier.h"
52 #include "OSGMField.h"
54 #include <deque>
56 OSG_BEGIN_NAMESPACE
58 class DrawEnv;
59 class HardwareContext;
61 /*! \ingroup GrpBaseMemoryObjectsBase
62 \ingroup GrpBaseHardwareContext
63 \ingroup GrpLibOSGBase
66 class OSG_BASE_DLLMAPPING HardwareContextTask : public MemoryObject
68 /*========================== PUBLIC =================================*/
70 public:
72 typedef MemoryObject Inherited;
74 static const UInt32 EndThread = 0x0001;
75 static const UInt32 LastType = 0x0001;
77 /*---------------------------------------------------------------------*/
78 /*! \name Statistic */
79 /*! \{ */
81 virtual void execute(HardwareContext *pContext, DrawEnv *pEnv) = 0;
83 /*! \} */
84 /*---------------------------------------------------------------------*/
85 /*! \name Access */
86 /*! \{ */
88 /*! \} */
89 /*---------------------------------------------------------------------*/
90 /*! \name Access */
91 /*! \{ */
93 /*! \} */
94 /*---------------------------------------------------------------------*/
95 /*! \name Access */
96 /*! \{ */
98 /*! \} */
99 /*---------------------------------------------------------------------*/
100 /*! \name Access */
101 /*! \{ */
103 /*! \} */
104 /*---------------------------------------------------------------------*/
105 /*! \name Constructors */
106 /*! \{ */
108 /*! \} */
109 /*---------------------------------------------------------------------*/
110 /*! \name Constructors */
111 /*! \{ */
113 /*! \} */
114 /*---------------------------------------------------------------------*/
115 /*! \name Constructors */
116 /*! \{ */
118 /*! \} */
119 /*---------------------------------------------------------------------*/
120 /*! \name Constructors */
121 /*! \{ */
123 /*! \} */
124 /*---------------------------------------------------------------------*/
125 /*! \name Debugging */
126 /*! \{ */
128 virtual void dump(UInt32 uiIndent) = 0;
130 /*! \} */
131 /*========================= PROTECTED ===============================*/
133 protected:
135 UInt32 _uiTypeTask;
137 /*---------------------------------------------------------------------*/
138 /*! \name Member */
139 /*! \{ */
141 /*! \} */
142 /*---------------------------------------------------------------------*/
143 /*! \name Constructors */
144 /*! \{ */
146 HardwareContextTask(UInt32 uiTaskType);
148 /*! \} */
149 /*---------------------------------------------------------------------*/
150 /*! \name Destructor */
151 /*! \{ */
153 virtual ~HardwareContextTask(void);
155 /*! \} */
156 /*---------------------------------------------------------------------*/
157 /*! \name Destructor */
158 /*! \{ */
160 /*! \} */
161 /*========================== PRIVATE ================================*/
163 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 =================================*/
180 public:
182 typedef HardwareContextTask Inherited;
184 /*---------------------------------------------------------------------*/
185 /*! \name Statistic */
186 /*! \{ */
188 void activateBarrier(bool bVal);
190 /*! \} */
191 /*---------------------------------------------------------------------*/
192 /*! \name Access */
193 /*! \{ */
195 void setNumWaitFor (UInt32 uiWaitees);
196 void waitForBarrier(void );
198 /*! \} */
199 /*---------------------------------------------------------------------*/
200 /*! \name Access */
201 /*! \{ */
203 /*! \} */
204 /*---------------------------------------------------------------------*/
205 /*! \name Access */
206 /*! \{ */
208 /*! \} */
209 /*---------------------------------------------------------------------*/
210 /*! \name Access */
211 /*! \{ */
213 /*! \} */
214 /*---------------------------------------------------------------------*/
215 /*! \name Constructors */
216 /*! \{ */
218 /*! \} */
219 /*---------------------------------------------------------------------*/
220 /*! \name Constructors */
221 /*! \{ */
223 /*! \} */
224 /*---------------------------------------------------------------------*/
225 /*! \name Constructors */
226 /*! \{ */
228 /*! \} */
229 /*---------------------------------------------------------------------*/
230 /*! \name Constructors */
231 /*! \{ */
233 /*! \} */
234 /*---------------------------------------------------------------------*/
235 /*! \name Debugging */
236 /*! \{ */
238 virtual void dump(UInt32 uiIndent) = 0;
240 /*! \} */
241 /*========================= PROTECTED ===============================*/
243 protected:
245 bool _bBarrierActive;
246 BarrierRefPtr _pBarrier;
248 /*---------------------------------------------------------------------*/
249 /*! \name Member */
250 /*! \{ */
252 /*! \} */
253 /*---------------------------------------------------------------------*/
254 /*! \name Constructors */
255 /*! \{ */
257 BlockingTask(UInt32 uiTaskType);
259 /*! \} */
260 /*---------------------------------------------------------------------*/
261 /*! \name Destructor */
262 /*! \{ */
264 virtual ~BlockingTask(void);
266 /*! \} */
267 /*---------------------------------------------------------------------*/
268 /*! \name Destructor */
269 /*! \{ */
271 /*! \} */
272 /*========================== PRIVATE ================================*/
274 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 =================================*/
291 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 */
303 /*! \{ */
305 CallbackTask(UInt32 uiType);
306 CallbackTask(const CallbackFunctor &fCallback, UInt32 uiType);
308 /*! \} */
309 /*---------------------------------------------------------------------*/
310 /*! \name Access */
311 /*! \{ */
313 virtual void execute(HardwareContext *pContext, DrawEnv *pEnv);
315 /*! \} */
316 /*---------------------------------------------------------------------*/
317 /*! \name Access */
318 /*! \{ */
320 void setCallback(const CallbackFunctor &fCallback);
322 /*! \} */
323 /*---------------------------------------------------------------------*/
324 /*! \name Access */
325 /*! \{ */
327 /*! \} */
328 /*---------------------------------------------------------------------*/
329 /*! \name Access */
330 /*! \{ */
332 /*! \} */
333 /*---------------------------------------------------------------------*/
334 /*! \name Access */
335 /*! \{ */
337 virtual void dump(UInt32 uiIndent);
339 /*! \} */
340 /*========================= PROTECTED ===============================*/
342 protected:
344 /*---------------------------------------------------------------------*/
345 /*! \name Member */
346 /*! \{ */
348 CallbackFunctor _fCallback;
350 /*! \} */
351 /*---------------------------------------------------------------------*/
352 /*! \name Destructor */
353 /*! \{ */
355 virtual ~CallbackTask(void);
357 /*! \} */
358 /*========================== PRIVATE ================================*/
360 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
406 template <>
407 struct FieldTraits<HardwareContextTaskRefPtr> :
408 public FieldTraitsTemplateBase<HardwareContextTaskRefPtr>
410 private:
412 static DataType _type;
414 public:
416 typedef FieldTraits<HardwareContextTaskRefPtr> Self;
418 enum { Convertible = Self::NotConvertible };
420 OSG_BASE_DLLMAPPING
421 static DataType &getType (void);
423 static const char *getMName(void) { return "MFHardwareContextTask"; }
425 static SizeT getBinSize(const HardwareContextTaskRefPtr *,
426 SizeT )
428 return 0;
431 static void copyToBin( BinaryDataHandler &,
432 const HardwareContextTaskRefPtr *,
433 SizeT )
435 SWARNING << "FieldTraits<HardwareContextTaskRefPtr>::copyToBin: "
436 << "Not supported."
437 << std::endl;
440 static void copyFromBin(BinaryDataHandler &,
441 HardwareContextTaskRefPtr *,
442 SizeT )
444 SWARNING << "FieldTraits<HardwareContextTaskRefPtr>::copyFromBin: "
445 << "Not supported."
446 << std::endl;
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
461 \nohierarchy
464 class OSG_BASE_DLLMAPPING HardwareContextTaskQueue
466 /*========================== PUBLIC =================================*/
468 public:
470 /*---------------------------------------------------------------------*/
471 /*! \name Statistic */
472 /*! \{ */
474 void queueTask (HardwareContextTask *pTask);
475 void queueTaskFront(HardwareContextTask *pTask);
476 HardwareContextTaskTransitPtr popTask (void );
478 /*! \} */
479 /*---------------------------------------------------------------------*/
480 /*! \name Constructors */
481 /*! \{ */
483 /*! \} */
484 /*---------------------------------------------------------------------*/
485 /*! \name Constructors */
486 /*! \{ */
488 /*! \} */
489 /*---------------------------------------------------------------------*/
490 /*! \name Constructors */
491 /*! \{ */
493 HardwareContextTaskQueue(void);
495 /*! \} */
496 /*---------------------------------------------------------------------*/
497 /*! \name Destructor */
498 /*! \{ */
500 virtual ~HardwareContextTaskQueue(void);
502 /*! \} */
503 /*---------------------------------------------------------------------*/
504 /*! \name Debugging */
505 /*! \{ */
507 // Implementation in OSGWindow.inl
508 void dumpQueue (void );
509 void runAndClearQueue(HardwareContext *pContext,
510 DrawEnv *pEnv );
512 /*! \} */
513 /*========================= PROTECTED ===============================*/
515 protected:
517 typedef std::deque<HardwareContextTaskRefPtr> TaskStore;
519 TaskStore _qTaskStore;
520 LockRefPtr _pStoreLock;
521 SemaphoreRefPtr _pStoreSema;
523 /*---------------------------------------------------------------------*/
524 /*! \name Member */
525 /*! \{ */
527 /*! \} */
528 /*---------------------------------------------------------------------*/
529 /*! \name Destructor */
530 /*! \{ */
532 /*! \} */
533 /*========================== PRIVATE ================================*/
535 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);
544 OSG_END_NAMESPACE
546 #include "OSGHardwareContextTask.inl"
548 #endif /* _OSGHARDWARECONTEXTTASK_H_ */