changed: gcc8 base update
[opensg.git] / Source / Contrib / ComplexSceneManager / OSGCSMClusterWindow.cpp
blobdd80ac8dc08eb1c9ad6586a1bb007f9c191f9e06
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGCSMClusterWindow.h"
50 #include "OSGCSMViewport.h"
52 #include "OSGBalancedMultiWindow.h"
53 #include "OSGSortFirstWindow.h"
54 #include "OSGSortLastWindow.h"
56 #include "OSGCSMMultiWinOptions.h"
57 #include "OSGCSMSortFirstWinOptions.h"
59 #include "OSGNameAttachment.h"
60 #include "OSGImageComposer.h"
62 OSG_BEGIN_NAMESPACE
64 // Documentation for this class is emitted in the
65 // OSGCSMClusterWindowBase.cpp file.
66 // To modify it, please change the .fcd file (OSGCSMClusterWindow.fcd) and
67 // regenerate the base file.
69 /***************************************************************************\
70 * Class variables *
71 \***************************************************************************/
73 bool CSMClusterWindow::_bRun = false;
75 /***************************************************************************\
76 * Class methods *
77 \***************************************************************************/
79 void CSMClusterWindow::initMethod(InitPhase ePhase)
81 Inherited::initMethod(ePhase);
83 if(ePhase == TypeObject::SystemPost)
89 /***************************************************************************\
90 * Instance methods *
91 \***************************************************************************/
93 /*-------------------------------------------------------------------------*\
94 - private -
95 \*-------------------------------------------------------------------------*/
97 /*----------------------- constructors & destructors ----------------------*/
99 CSMClusterWindow::CSMClusterWindow(void) :
100 Inherited ( ),
101 _pClusterWindow(NULL)
105 CSMClusterWindow::CSMClusterWindow(const CSMClusterWindow &source) :
106 Inherited (source),
107 _pClusterWindow(NULL )
111 CSMClusterWindow::~CSMClusterWindow(void)
115 bool CSMClusterWindow::init(void)
117 MultiDisplayWindowUnrecPtr pCMDWindow = NULL;
118 BalancedMultiWindowUnrecPtr pCBMWindow = NULL;
119 SortFirstWindowUnrecPtr pCSFWindow = NULL;
120 SortLastWindowUnrecPtr pCSLWindow = NULL;
122 if(_sfClusterMode.getValue() == "Multi")
124 pCMDWindow = MultiDisplayWindow::create();
126 _pWindow = pCMDWindow;
127 _pClusterWindow = pCMDWindow;
129 else if(_sfClusterMode.getValue() == "Balanced")
131 pCBMWindow = BalancedMultiWindow::create();
133 pCMDWindow = pCBMWindow;
135 _pWindow = pCBMWindow;
136 _pClusterWindow = pCBMWindow;
138 else if(_sfClusterMode.getValue() == "SortFirst")
140 pCSFWindow = SortFirstWindow::create();
142 _pWindow = pCSFWindow;
143 _pClusterWindow = pCSFWindow;
145 else if(_sfClusterMode.getValue() == "SortLast")
147 pCSLWindow = SortLastWindow::create();
149 _pWindow = pCSLWindow;
150 _pClusterWindow = pCSLWindow;
152 else
154 fprintf(stderr, "Unknown cluster mode %s\n",
155 _sfClusterMode.getValue().c_str());
158 MFString::const_iterator serverIt = this->getMFServers()->begin();
159 MFString::const_iterator serverEnd = this->getMFServers()->end ();
161 UInt32 uiNumServer = 0;
163 while(serverIt != serverEnd)
165 fprintf(stderr, "Connecting to %s\n", serverIt->c_str());
167 _pClusterWindow->editMFServers()->push_back(serverIt->c_str());
169 ++uiNumServer;
170 ++serverIt;
173 bool bServerIdsValid = false;
175 if(this->getMFServers()->size() <= this->getMFServerIds()->size())
177 _pClusterWindow->editMFServerIds()->setValues(
178 *(this->getMFServerIds()));
180 bServerIdsValid = true;
182 else
184 if(this->getMFServerIds()->size() != 0)
186 FWARNING(("Not enough server ids (%" PRISize "/%" PRISize "), "
187 "field ignored\n",
188 this->getMFServerIds()->size(),
189 this->getMFServers ()->size() ));
193 _pClusterWindow->setSize(UInt16(this->getXSize()),
194 UInt16(this->getYSize()));
196 _pClusterWindow->setConnectionType(this->getConnectionType());
198 if(this->getSFComposer()->getValue() != NULL)
200 _pClusterWindow->setComposer(this->getSFComposer()->getValue());
203 if(pCMDWindow != NULL)
205 if(uiNumServer != 0)
207 pCMDWindow->setHServers(uiNumServer / this->getServerRows());
209 pCMDWindow->setVServers(this->getServerRows());
211 else
213 pCMDWindow->setHServers(1);
214 pCMDWindow->setVServers(1);
217 CSMMultiWinOptions *pOpts =
218 dynamic_cast<CSMMultiWinOptions *>(this->getOptions());
220 if(pOpts != NULL)
222 pCMDWindow->setXOverlap(pOpts->getXOverlap());
223 pCMDWindow->setYOverlap(pOpts->getYOverlap());
225 pCMDWindow->setManageClientViewports(
226 pOpts->getManageClientViewports());
231 if(pCBMWindow != NULL)
233 CSMMultiWinOptions *pOpts =
234 dynamic_cast<CSMMultiWinOptions *>(this->getOptions());
236 if(pOpts != NULL)
238 pCBMWindow->setBalance (pOpts->getBalance ());
239 pCBMWindow->setBestCut (pOpts->getBestCut ());
240 pCBMWindow->setShowBalancing(pOpts->getShowBalancing());
244 if(pCSFWindow != NULL)
246 CSMSortFirstWinOptions *pOpts =
247 dynamic_cast<CSMSortFirstWinOptions *>(this->getOptions());
249 if(pOpts != NULL)
251 pCSFWindow->setCompression (pOpts->getCompression ());
252 pCSFWindow->setCompose (pOpts->getCompose ());
253 pCSFWindow->setSubtileSize (pOpts->getSubtileSize ());
254 pCSFWindow->setUseFaceDistribution(pOpts->getUseFaceDistribution());
258 if(pCMDWindow != NULL)
260 MFUnrecCSMViewportPtr::const_iterator vIt = getMFViewports()->begin();
261 MFUnrecCSMViewportPtr::const_iterator vEnd = getMFViewports()->end ();
263 while(vIt != vEnd)
265 if((*vIt)->getServerId() != -1)
267 UInt32 uiRealServerId = (*vIt)->getServerId();
269 if(bServerIdsValid == true)
271 Int32 iIdx =
272 this->getMFServerIds()->findIndex(uiRealServerId);
274 if(iIdx != -1)
275 uiRealServerId = iIdx;
278 UInt32 uiHor = uiRealServerId % pCMDWindow->getHServers();
279 UInt32 uiVert = uiRealServerId / pCMDWindow->getHServers();
281 Real32 rHFact = 1.f / Real32(pCMDWindow->getHServers());
282 Real32 rVFact = 1.f / Real32(pCMDWindow->getVServers());
284 Vec2f leftBottom(Real32(uiHor ) * rHFact,
285 Real32(uiVert) * rVFact);
287 Vec2f rightTop (Real32(uiHor + 1) * rHFact,
288 Real32(uiVert + 1) * rVFact);
290 (*vIt)->setLeftBottom(leftBottom);
291 (*vIt)->setRightTop (rightTop );
293 ++vIt;
297 if(_sfClientWindow.getValue() != NULL)
299 _sfClientWindow.getValue()->init();
301 if(this->getRenderClient() == true)
303 _pClusterWindow->setClientWindow(
304 _sfClientWindow.getValue()->getWindow());
308 _pClusterWindow->init();
310 Inherited::init();
312 return true;
315 FieldContainer *CSMClusterWindow::findNamedComponent(const Char8 *szName) const
317 if(_sfClientWindow.getValue() != NULL)
319 const Char8 *szTmpName = NULL;
321 szTmpName = OSG::getName(_sfClientWindow.getValue());
323 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
325 return _sfClientWindow.getValue();
329 return NULL;
332 /*----------------------------- class specific ----------------------------*/
334 void CSMClusterWindow::changed(ConstFieldMaskArg whichField,
335 UInt32 origin,
336 BitVector details)
338 Inherited::changed(whichField, origin, details);
341 void CSMClusterWindow::dump( UInt32 ,
342 const BitVector ) const
344 SLOG << "Dump CSMClusterWindow NI" << std::endl;
347 void CSMClusterWindow::terminateGLContext(void)
351 OSG_END_NAMESPACE