changed: gcc8 base update
[opensg.git] / Source / Contrib / ComputeBase / Base / OSGComputeAlgorithm.cpp
blob4c4cf20ba3b2eb2b3e5143e250733bea94a4e92f
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 #include <cstdlib>
40 #include <cstdio>
42 #include <sstream>
43 #include <fstream>
45 #include "OSGConfig.h"
47 #include "OSGAction.h"
48 #include "OSGCamera.h"
49 #include "OSGSceneFileHandler.h"
50 #include "OSGVolumeDraw.h"
52 #include "OSGComputeAlgorithm.h"
53 #include "OSGDrawEnv.h"
55 OSG_USING_NAMESPACE
57 // Documentation for this class is emited in the
58 // OSGComputeAlgorithmBase.cpp file.
59 // To modify it, please change the .fcd file (OSGComputeAlgorithm.fcd) and
60 // regenerate the base file.
62 /*-------------------------------------------------------------------------*/
63 /* Sync */
65 void ComputeAlgorithm::changed(ConstFieldMaskArg whichField,
66 UInt32 origin,
67 BitVector details)
69 Inherited::changed(whichField, origin, details);
72 /*-------------------------------------------------------------------------*/
73 /* Dump */
75 void ComputeAlgorithm::dump( UInt32 OSG_CHECK_ARG(uiIndent),
76 const BitVector OSG_CHECK_ARG(bvFlags )) const
78 SLOG << "Dump ComputeAlgorithm NI" << std::endl;
81 /*-------------------------------------------------------------------------*/
82 /* Constructors */
84 ComputeAlgorithm::ComputeAlgorithm(void) :
85 Inherited()
89 ComputeAlgorithm::ComputeAlgorithm(const ComputeAlgorithm &source) :
90 Inherited(source)
94 /*-------------------------------------------------------------------------*/
95 /* Destructor */
97 ComputeAlgorithm::~ComputeAlgorithm(void)
101 /*-------------------------------------------------------------------------*/
102 /* Draw */
105 /*-------------------------------------------------------------------------*/
106 /* loading */
108 /*-------------------------------------------------------------------------*/
109 /* Init */
111 void ComputeAlgorithm::initMethod(InitPhase ePhase)
113 Inherited::initMethod(ePhase);
115 if(ePhase == TypeObject::SystemPost)
122 /*-------------------------------------------------------------------------*/
123 /* Task */
126 ComputeAlgorithmDrawTask::ComputeAlgorithmDrawTask(UInt32 uiType) :
127 Inherited (uiType),
128 _pAlgorithm(NULL ),
129 _pBarrier (NULL )
131 if(_uiTypeTask == AlgorithmWithBarrier)
133 _pBarrier = Barrier::get(NULL, false);
134 _pBarrier->setNumWaitFor(2);
138 ComputeAlgorithmDrawTask::ComputeAlgorithmDrawTask(
139 ComputeAlgorithmP pAlgorithm,
140 UInt32 uiType ) :
142 Inherited (uiType ),
143 _pAlgorithm(pAlgorithm),
144 _pBarrier (NULL )
146 if(_uiTypeTask == AlgorithmWithBarrier)
148 _pBarrier = Barrier::get(NULL, false);
149 _pBarrier->setNumWaitFor(2);
153 ComputeAlgorithmDrawTask::~ComputeAlgorithmDrawTask(void)
155 _pAlgorithm = NULL;
156 _pBarrier = NULL;
159 void ComputeAlgorithmDrawTask::execute(HardwareContext *pContext,
160 DrawEnv *pEnv )
162 Window *pWindow = pEnv->getWindow();
164 OSG_ASSERT( pWindow != NULL);
165 OSG_ASSERT(_pAlgorithm );
167 switch(_uiTypeTask)
169 case Algorithm:
171 _pAlgorithm->execute(pContext, pEnv);
173 break;
175 case AlgorithmWithBarrier:
177 _pAlgorithm->execute(pContext, pEnv);
179 OSG_ASSERT(_pBarrier != NULL);
181 _pBarrier->enter();
183 break;
185 default:
186 break;
190 void ComputeAlgorithmDrawTask::activateBarrier(bool bVal)
192 if(bVal == true)
194 _uiTypeTask = AlgorithmWithBarrier;
196 if(_pBarrier == NULL)
198 _pBarrier = Barrier::get(NULL, false);
199 _pBarrier->setNumWaitFor(2);
202 else
204 _uiTypeTask = Algorithm;
208 void ComputeAlgorithmDrawTask::setAlgorithm(ComputeAlgorithmP pAlgorithm)
210 _pAlgorithm = pAlgorithm;
214 void ComputeAlgorithmDrawTask::waitForBarrier(void)
216 OSG_ASSERT(_uiTypeTask == AlgorithmWithBarrier);
217 OSG_ASSERT(_pBarrier != NULL );
219 _pBarrier->enter();
222 void ComputeAlgorithmDrawTask::dump(UInt32 uiIndent)
224 for(UInt32 i = 0; i < uiIndent; ++i) { fprintf(stderr, " "); }
225 fprintf(stderr, "ComputeAlgorithmDrawTask : ");
227 switch(_uiTypeTask)
229 case Algorithm:
231 fprintf(stderr, "Algorithm\n");
233 break;
235 case AlgorithmWithBarrier:
237 fprintf(stderr, "AlgorithmWithBarrier\n");
239 break;
241 default:
243 fprintf(stderr, "Unknown\n");
245 break;