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 _OSGBALANCEDMULTIWINDOW_H_
40 #define _OSGBALANCEDMULTIWINDOW_H_
47 #include "OSGBalancedMultiWindowBase.h"
49 #include "OSGViewport.h"
53 //#define MW_TILE_SIZE 21
54 //#define MW_TILE_SIZE 44
55 #define MW_TILE_SIZE 256
57 // TODO use dynamic performance values
58 #define MW_INDICES_PER_SEC 100000000.0
59 #define MW_VISIBLE_INDICES_PER_SEC 30000000.0
60 #define MW_PIXEL_PER_SEC 1000000000.0
61 #define MW_SHADED_PIXEL_PER_SEC 5000000.0
63 /*! \brief BalancedMultiWindow class. See \ref
64 PageSystemBalancedMultiWindow for a description.
65 \ingroup GrpClusterWindowObj
66 \ingroup GrpLibOSGCluster
70 class OSG_CLUSTER_DLLMAPPING BalancedMultiWindow
:
71 public BalancedMultiWindowBase
75 typedef BalancedMultiWindowBase Inherited
;
85 /*========================== PUBLIC =================================*/
89 /*---------------------------------------------------------------------*/
93 virtual void changed(ConstFieldMaskArg whichField
,
98 /*---------------------------------------------------------------------*/
102 virtual void dump( UInt32 uiIndent
= 0,
103 const BitVector bvFlags
= 0) const;
106 /*========================= PROTECTED ===============================*/
123 friend struct LoadGroup
;
126 friend struct Server
;
127 friend struct WorkPackage
;
130 friend struct Cluster
;
131 friend struct Worker
;
132 friend struct OpenBBox
;
133 friend struct ServerComp
;
134 friend struct BBoxList
;
170 ViewportUnrecPtr serverPort
;
175 Real32 loadCenter
[2];
176 std::vector
<BBox
> bboxes
;
194 std::vector
<VPort
> viewports
;
203 Server(const Server
&other
) :
206 viewports(other
.viewports
),
207 window (other
.window
) {}
209 Server
&operator =(const Server
&rhs
)
213 viewports
= rhs
.viewports
;
243 unsigned int width
:16;
244 unsigned int height
:15;
245 unsigned int last
:1 ;
248 UInt8 pixel
[MW_TILE_SIZE
*MW_TILE_SIZE
*3];
256 UInt16 workpackageId
;
257 std::vector
<Tile
> tiles
;
270 std::vector
<NodeUnrecPtr
> rootNodes
;
271 std::vector
<LoadGroup
> loadGroups
;
272 std::vector
<Server
> servers
;
273 std::vector
<WorkPackage
> workpackages
;
274 std::vector
<Area
> areas
;
309 bool operator () (Server
*s1
,Server
*s2
)
311 return (s1
->load
< s2
->load
);
326 std::vector
<BBoxList
*> _groupOpen
;
327 std::vector
<BBoxList
*> _groupClose
;
328 std::vector
<BBoxList
> _bboxlist
;
339 bool _rebuildLoadGroups
;
342 /*---------------------------------------------------------------------*/
344 // calculate rendering load
345 inline Real32
getVisibleLoad(Int32
const (&rect
)[4],
347 // get number of tiles for the given area
348 UInt32
calcTileCount(Int32
const (&rect
)[4]);
349 // project group and calculate bounding box
350 bool calculateProjectedBBox(VPort
&port
,
354 // create load groups for all root nodes
355 void createLoadGroups(void);
356 // collect load for a subtree
357 void collectLoadGroups(Node
*node
,Node
*root
);
358 // collect visible viewports
359 void collectVisibleViewports(Server
&server
);
360 // calculate server viewport
361 bool calculateServerPort(VPort
&port
, Int32
const (&rect
)[4]);
362 // create view dependent bboxes
363 void createBBoxes(Server
&server
);
364 // do load balancing for all servers
365 void balanceServer(void);
367 void splitViewport(std::vector
<Worker
> &worker
,
369 Int32
const (&rect
)[4],
372 void sortBBoxes(VPort
&port
,UInt32 axis
, Int32
const (&rect
)[4]);
373 // split load at a given axis
374 void splitAxis(Real32
const (&load
)[2],
376 Int32
const (&rect
)[4],
378 Real32 (&resultLoad
)[2],
379 Int32 (&resultRect
)[2][4]);
381 // render part of a viewport viewport
382 void renderViewport(Window
*serverWindow
,
384 RenderActionBase
*action
,
386 Int32
const (&rect
)[4]);
388 void clearViewports(Window
*serverWindow
,
390 RenderActionBase
*action
);
393 void storeViewport(Area
&area
,Viewport
*vp
, Int32
const (&rect
)[4]);
395 // do rendering and network transfer
396 void drawSendAndRecv(Window
*serverWindow
,
397 RenderActionBase
*action
,
400 // preload display lists and textures
401 void preloadCache(Window
*window
,
402 RenderActionBase
*action
);
405 /*---------------------------------------------------------------------*/
406 /*! \name Constructors */
409 BalancedMultiWindow(void);
410 BalancedMultiWindow(const BalancedMultiWindow
&source
);
413 /*---------------------------------------------------------------------*/
414 /*! \name Destructors */
417 virtual ~BalancedMultiWindow(void);
420 /*---------------------------------------------------------------------*/
424 static void initMethod(InitPhase ePhase
);
427 /*---------------------------------------------------------------------*/
431 virtual void resolveLinks(void);
434 /*--------------------------------------------------------------------*/
435 /*! \name server window funcitons */
438 virtual void serverInit (Window
*serverWindow
,
441 virtual void serverRender(Window
*serverWindow
,
443 RenderActionBase
*action
);
446 /*--------------------------------------------------------------------*/
447 /*! \name client window functions */
450 virtual void clientInit (void );
451 virtual void clientPreSync(void );
452 virtual void clientRender (RenderActionBase
*action
);
455 /*========================== PRIVATE ================================*/
459 friend class FieldContainer
;
460 friend class BalancedMultiWindowBase
;
462 // prohibit default functions (move to 'public' if you need one)
463 void operator =(const BalancedMultiWindow
&source
);
466 typedef BalancedMultiWindow
*BalancedMultiWindowP
;
470 #include "OSGBalancedMultiWindowBase.inl"
471 #include "OSGBalancedMultiWindow.inl"
473 #endif /* _OSGBALANCEDMULTIWINDOW_H_ */