00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _GEO_TILE_LOAD_BALANCER_H_
00040 #define _GEO_TILE_LOAD_BALANCER_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <map>
00046 #include <vector>
00047 #include <OSGSystemDef.h>
00048 #include <OSGBaseTypes.h>
00049 #include <OSGTileGeometryLoad.h>
00050 #include <OSGRenderNode.h>
00051
00052 OSG_BEGIN_NAMESPACE
00053
00054 class Action;
00055
00056 class OSG_SYSTEMLIB_DLLMAPPING TileLoadBalancer
00057 {
00058
00059 public:
00060 struct Region {
00061 Int32 x1,y1,x2,y2;
00062 Real32 culledFaces;
00063 Real32 culledNodes;
00064 Real32 faces;
00065 Real32 pixel;
00066 };
00067 typedef std::vector<TileGeometryLoad> TileGeometryLoadLstT;
00068 typedef std::map<UInt32,TileGeometryLoadLstT::iterator> TileGeometryLoadMapT;
00069 typedef std::vector<Region> ResultT;
00070 typedef std::vector<RenderNode> RenderNodeLstT;
00071
00072
00077
00082
00086 TileLoadBalancer(bool useFaceDistribution=false,
00087 bool cutBestDirection=true);
00088 TileLoadBalancer(const TileLoadBalancer &source);
00089
00091
00095 TileLoadBalancer& operator =(const TileLoadBalancer &source);
00096
00098
00102 virtual ~TileLoadBalancer(void);
00103
00105
00109 void update (NodePtr node );
00110 void balance (ViewportPtr vp,
00111 bool shrink,
00112 ResultT &result );
00113 void addRenderNode (const RenderNode &rn,UInt32 id);
00114 void drawVolumes (WindowPtr win);
00115 void setRegionStatistics(ViewportPtr vp,
00116 ResultT &result);
00117
00119
00124
00129
00134
00135 protected:
00136
00137
00141 class RegionLoad
00142 {
00143 public:
00144 RegionLoad ( TileGeometryLoad *load=NULL );
00145 Real32 getCost ( const RenderNode &renderNode );
00146 Real32 getCost ( const RenderNode &renderNode,
00147 const Int32 wmin[2],
00148 const Int32 wmax[2] ) const;
00149 TileGeometryLoad *getLoad ( void );
00150 void updateCost( const Int32 wmin[2],
00151 const Int32 wmax[2] );
00152 private:
00153 Real32 _visibleFaces;
00154 Real32 _invisibleFaces;
00155 Real32 _pixel;
00156 TileGeometryLoad *_load;
00157 };
00158 typedef std::vector<RegionLoad> RegionLoadVecT;
00159
00161
00165 TileGeometryLoadLstT _tileGeometryLoad;
00166 RenderNodeLstT _renderNode;
00167 bool _useFaceDistribution;
00168 bool _cutBestDirection;
00169
00171
00175 double runFaceBench(GLuint dlist,UInt32 size,Real32 visible);
00176 void updateSubtree (NodePtr &node,TileGeometryLoadMapT &loadMap);
00177 void splitRegion (UInt32 rnFrom,
00178 UInt32 rnTo,
00179 RegionLoadVecT &visible,
00180 Int32 amin[2],
00181 Int32 amax[2],
00182 UInt32 depth,
00183 ResultT &result);
00184 Real32 findBestCut (const RenderNode &renderNodeA,
00185 const RenderNode &renderNodeB,
00186 RegionLoadVecT &visible,
00187 Int32 amin[2],
00188 Int32 amax[2],
00189 Int32 &bestAxis,
00190 Int32 &bestCut);
00191 double calcFaceRenderingCost(TileGeometryLoad *load,
00192 Int32 amin[2],Int32 amax[2]);
00193
00196
00197 private:
00198 friend class RegionLoad;
00199 };
00200
00201 OSG_END_NAMESPACE
00202
00203 #include "OSGTileLoadBalancer.inl"
00204
00205 #define OSG_TILE_LOAD_BALANCER_HEADER_CVSID "@(#)$Id:$"
00206
00207 #endif
00208
00209
00210
00211