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 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
44 #include "OSGHardwareContextTask.h"
45 #include "OSGFieldContainer.h"
47 #include "OSGMField.ins"
51 /*! \class OSG::HardwareContextTask
52 \ingroup GrpSystemRenderingBackend
55 /*-------------------------------------------------------------------------*/
58 HardwareContextTask::HardwareContextTask(UInt32 uiTaskType
) :
60 _uiTypeTask(uiTaskType
)
64 /*-------------------------------------------------------------------------*/
67 HardwareContextTask::~HardwareContextTask(void)
72 //virtual void execute(DrawEnv *pEnv);
74 /*! \class OSG::BlockingTask
75 \ingroup GrpSystemRenderingBackend
78 /*-------------------------------------------------------------------------*/
81 BlockingTask::BlockingTask(UInt32 uiTaskType
) :
82 Inherited (uiTaskType
),
83 _bBarrierActive(false ),
88 /*-------------------------------------------------------------------------*/
91 BlockingTask::~BlockingTask(void)
96 void BlockingTask::activateBarrier(bool bVal
)
98 _bBarrierActive
= bVal
;
100 if(_bBarrierActive
== true && _pBarrier
== NULL
)
102 _pBarrier
= Barrier::get(NULL
, false);
103 _pBarrier
->setNumWaitFor(2);
107 void BlockingTask::setNumWaitFor(UInt32 uiWaitees
)
109 if(_pBarrier
!= NULL
&& uiWaitees
!= 0)
111 _pBarrier
->setNumWaitFor(uiWaitees
);
115 void BlockingTask::waitForBarrier(void)
117 if(_bBarrierActive
== false)
122 OSG_ASSERT(_pBarrier
!= NULL
);
128 /*! \class OSG::CallbackTask
129 \ingroup GrpSystemRenderingBackend
132 CallbackTask::CallbackTask(UInt32 uiType
) :
138 CallbackTask::CallbackTask(const CallbackFunctor
&fCallback
,
141 _fCallback (fCallback
)
145 CallbackTask::~CallbackTask(void)
149 void CallbackTask::execute(HardwareContext
*pContext
, DrawEnv
*pEnv
)
151 OSG_ASSERT(_fCallback
);
157 _fCallback(pContext
, pEnv
);
159 if(_bBarrierActive
== true)
169 void CallbackTask::setCallback(const CallbackFunctor
&fCallback
)
171 _fCallback
= fCallback
;
175 void CallbackTask::dump(UInt32 uiIndent
)
177 for(UInt32 i
= 0; i
< uiIndent
; ++i
) { fprintf(stderr
, " "); }
178 fprintf(stderr
, "CallbackTask : ");
184 fprintf(stderr
, "Callback, barrier active : %d\n",
185 UInt32(_bBarrierActive
));
191 fprintf(stderr
, "Unknown\n");
200 /*! \class OSG::HardwareContextTask
201 \ingroup GrpSystemRenderingBackend
204 /*-------------------------------------------------------------------------*/
207 HardwareContextTaskQueue::HardwareContextTaskQueue(void) :
212 _pStoreLock
= Lock ::get(NULL
, false);
213 _pStoreSema
= Semaphore::get(NULL
, false);
216 /*-------------------------------------------------------------------------*/
219 HardwareContextTaskQueue::~HardwareContextTaskQueue(void)
227 void HardwareContextTaskQueue::queueTask(HardwareContextTask
*pTask
)
231 _pStoreLock
->acquire();
233 _qTaskStore
.push_back(pTask
);
235 _pStoreLock
->release();
243 void HardwareContextTaskQueue::queueTaskFront(HardwareContextTask
*pTask
)
247 _pStoreLock
->acquire();
249 _qTaskStore
.push_front(pTask
);
251 _pStoreLock
->release();
259 HardwareContextTaskTransitPtr
HardwareContextTaskQueue::popTask(void)
263 _pStoreLock
->acquire();
265 OSG_ASSERT(_qTaskStore
.size() != 0);
267 HardwareContextTaskTransitPtr
returnValue(_qTaskStore
.front());
269 _qTaskStore
.pop_front();
271 _pStoreLock
->release();
276 void HardwareContextTaskQueue::dumpQueue(void)
278 TaskStore::const_iterator qIt
= _qTaskStore
.begin();
279 TaskStore::const_iterator qEnd
= _qTaskStore
.end ();
281 fprintf(stderr
, "Dumping task queue\n");
282 fprintf(stderr
, "------------------\n");
284 for(; qIt
!= qEnd
; ++qIt
)
290 void HardwareContextTaskQueue::runAndClearQueue(HardwareContext
*pContext
,
293 TaskStore::const_iterator qIt
= _qTaskStore
.begin();
294 TaskStore::const_iterator qEnd
= _qTaskStore
.end ();
296 for(; qIt
!= qEnd
; ++qIt
)
298 (*qIt
)->execute(pContext
, pEnv
);
304 DataType FieldTraits
<
305 HardwareContextTaskRefPtr
>::_type("HardwareContextTaskRefPtr",
308 OSG_FIELDTRAITS_GETTYPE(HardwareContextTaskRefPtr
)
310 OSG_FIELD_DLLEXPORT_DEF1(MField
, HardwareContextTaskRefPtr
)