aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llspatialpartition.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llspatialpartition.h')
-rw-r--r--linden/indra/newview/llspatialpartition.h327
1 files changed, 294 insertions, 33 deletions
diff --git a/linden/indra/newview/llspatialpartition.h b/linden/indra/newview/llspatialpartition.h
index 737029a..5804a57 100644
--- a/linden/indra/newview/llspatialpartition.h
+++ b/linden/indra/newview/llspatialpartition.h
@@ -33,26 +33,77 @@
33#include "llmemory.h" 33#include "llmemory.h"
34#include "lldrawable.h" 34#include "lldrawable.h"
35#include "lloctree.h" 35#include "lloctree.h"
36#include "llvertexbuffer.h"
36#include "llgltypes.h" 37#include "llgltypes.h"
38#include "llcubemap.h"
37 39
38#include <queue> 40#include <queue>
39 41
40class LLCullInfo 42#define SG_STATE_INHERIT_MASK (CULLED | OCCLUDED)
43#define SG_INITIAL_STATE_MASK (OCCLUSION_DIRTY | DIRTY | GEOM_DIRTY)
44
45class LLSpatialPartition;
46class LLSpatialBridge;
47
48class LLDrawInfo
41{ 49{
42public: 50public:
43 LLVector3 mPos; 51 LLDrawInfo(U32 start, U32 end, U32 count, U32 offset,
44 F32 mRadius; 52 LLViewerImage* image, LLVertexBuffer* buffer,
45 LLPointer<LLDrawable> mDrawablep; 53 BOOL fullbright = FALSE, U8 bump = 0, BOOL particle = FALSE, F32 part_size = 0);
46}; 54
55 LLPointer<LLVertexBuffer> mVertexBuffer;
56 LLPointer<LLViewerImage> mTexture;
57 LLPointer<LLCubeMap> mReflectionMap;
58 LLColor4U mGlowColor;
59 const LLMatrix4* mTextureMatrix;
60 U32 mStart;
61 U32 mEnd;
62 U32 mCount;
63 U32 mOffset;
64 BOOL mFullbright;
65 U8 mBump;
66 BOOL mParticle;
67 F32 mPartSize;
68 F32 mVSize;
69
70 struct CompareTexture
71 {
72 bool operator()(const LLDrawInfo& lhs, const LLDrawInfo& rhs)
73 {
74 return lhs.mTexture > rhs.mTexture;
75 }
76 };
47 77
48#define SG_STATE_INHERIT_MASK (CULLED | OCCLUDED) 78 struct CompareTexturePtr
49class LLSpatialPartition; 79 {
80 bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
81 {
82
83 return lhs == NULL || rhs == NULL || lhs->mTexture > rhs->mTexture;
84 }
85 };
86
87 struct CompareBump
88 {
89 bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
90 {
91 return lhs == NULL || rhs == NULL || lhs->mBump > rhs->mBump;
92 }
93 };
94};
50 95
51class LLSpatialGroup : public LLOctreeListener<LLDrawable> 96class LLSpatialGroup : public LLOctreeListener<LLDrawable>
52{ 97{
53 friend class LLSpatialPartition; 98 friend class LLSpatialPartition;
54public: 99public:
55 100
101 typedef std::vector<LLPointer<LLSpatialGroup> > sg_vector_t;
102 typedef std::set<LLPointer<LLSpatialGroup> > sg_set_t;
103 typedef std::vector<LLPointer<LLSpatialBridge> > bridge_list_t;
104 typedef std::map<U32, std::vector<LLDrawInfo*> > draw_map_t;
105 typedef std::map<LLPointer<LLViewerImage>, LLPointer<LLVertexBuffer> > buffer_map_t;
106
56 typedef LLOctreeListener<LLDrawable> BaseType; 107 typedef LLOctreeListener<LLDrawable> BaseType;
57 typedef LLOctreeListener<LLDrawable> OctreeListener; 108 typedef LLOctreeListener<LLDrawable> OctreeListener;
58 typedef LLTreeNode<LLDrawable> TreeNode; 109 typedef LLTreeNode<LLDrawable> TreeNode;
@@ -60,6 +111,24 @@ public:
60 typedef LLOctreeRoot<LLDrawable> OctreeRoot; 111 typedef LLOctreeRoot<LLDrawable> OctreeRoot;
61 typedef LLOctreeState<LLDrawable> OctreeState; 112 typedef LLOctreeState<LLDrawable> OctreeState;
62 typedef LLOctreeTraveler<LLDrawable> OctreeTraveler; 113 typedef LLOctreeTraveler<LLDrawable> OctreeTraveler;
114 typedef LLOctreeState<LLDrawable>::element_iter element_iter;
115 typedef LLOctreeState<LLDrawable>::element_list element_list;
116
117 struct CompareDistanceGreater
118 {
119 bool operator()(const LLSpatialGroup* const& lhs, const LLSpatialGroup* const& rhs)
120 {
121 return lhs->mDistance > rhs->mDistance;
122 }
123 };
124
125 struct CompareDepthGreater
126 {
127 bool operator()(const LLSpatialGroup* const& lhs, const LLSpatialGroup* const& rhs)
128 {
129 return lhs->mDepth > rhs->mDepth;
130 }
131 };
63 132
64 typedef enum 133 typedef enum
65 { 134 {
@@ -75,10 +144,17 @@ public:
75 RESHADOW_QUEUE = 0x00000200, 144 RESHADOW_QUEUE = 0x00000200,
76 DIRTY = 0x00000400, 145 DIRTY = 0x00000400,
77 OBJECT_DIRTY = 0x00000800, 146 OBJECT_DIRTY = 0x00000800,
78 DISCARD_QUERY = 0x00001000, 147 GEOM_DIRTY = 0x00001000,
79 QUERY_OUT = 0x00002000, 148 MATRIX_DIRTY = 0x00002000,
80 OCCLUDING = 0x00004000, 149 ALPHA_DIRTY = 0x00004000,
81 SKIP_FRUSTUM_CHECK = 0x00008000, 150 DISCARD_QUERY = 0x00008000,
151 QUERY_OUT = 0x00010000,
152 OCCLUDING = 0x00020000,
153 SKIP_FRUSTUM_CHECK = 0x00040000,
154 OCCLUSION_DIRTY = 0x00080000,
155 BELOW_WATER = 0x00100000,
156 IN_IMAGE_QUEUE = 0x00200000,
157 IMAGE_DIRTY = 0x00400000,
82 } eSpatialState; 158 } eSpatialState;
83 159
84 typedef enum 160 typedef enum
@@ -89,20 +165,21 @@ public:
89 } eSetStateMode; 165 } eSetStateMode;
90 166
91 LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part); 167 LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part);
92 BOOL safeToDelete();
93 virtual ~LLSpatialGroup(); 168 virtual ~LLSpatialGroup();
94 169
95 S32 getCount() const { return mObjects.size(); }
96 BOOL isDead() { return isState(DEAD); } 170 BOOL isDead() { return isState(DEAD); }
97 BOOL isState(U32 state) const { return mState & state ? TRUE : FALSE; } 171 BOOL isState(U32 state) const { return mState & state ? TRUE : FALSE; }
98 U32 getState() { return mState; } 172 U32 getState() { return mState; }
99 void setState(U32 state) { mState |= state; } 173 void setState(U32 state) { mState |= state; }
100 void clearState(U32 state) { mState &= ~state; } 174 void clearState(U32 state) { mState &= ~state; }
101 175
176 void clearDrawMap();
102 void validate(); 177 void validate();
103 178 void validateDrawMap();
179
104 void setState(U32 state, S32 mode); 180 void setState(U32 state, S32 mode);
105 181
182 LLSpatialGroup* getParent();
106 183
107 void clearState(U32 state, S32 mode); 184 void clearState(U32 state, S32 mode);
108 BOOL addObject(LLDrawable *drawablep, BOOL add_all = FALSE, BOOL from_octree = FALSE); 185 BOOL addObject(LLDrawable *drawablep, BOOL add_all = FALSE, BOOL from_octree = FALSE);
@@ -113,8 +190,16 @@ public:
113 BOOL boundObjects(BOOL empty, LLVector3& newMin, LLVector3& newMax); 190 BOOL boundObjects(BOOL empty, LLVector3& newMin, LLVector3& newMax);
114 void unbound(); 191 void unbound();
115 BOOL rebound(); 192 BOOL rebound();
193 void destroyGL();
194
195 void updateDistance(LLCamera& camera);
116 BOOL changeLOD(); 196 BOOL changeLOD();
117 197 void rebuildGeom();
198 void makeStatic();
199
200 void dirtyGeom() { setState(GEOM_DIRTY); }
201 element_list& getData() { return mOctreeNode->getOctState()->getData(); }
202
118 //LISTENER FUNCTIONS 203 //LISTENER FUNCTIONS
119 virtual void handleInsertion(const TreeNode* node, LLDrawable* face); 204 virtual void handleInsertion(const TreeNode* node, LLDrawable* face);
120 virtual void handleRemoval(const TreeNode* node, LLDrawable* face); 205 virtual void handleRemoval(const TreeNode* node, LLDrawable* face);
@@ -124,12 +209,15 @@ public:
124 virtual void handleChildRemoval(const OctreeNode* parent, const OctreeNode* child); 209 virtual void handleChildRemoval(const OctreeNode* parent, const OctreeNode* child);
125 210
126protected: 211protected:
127 std::vector<LLCullInfo> mObjects;
128 U32 mState; 212 U32 mState;
129 S32 mLODHash; 213 S32 mLODHash;
130 static S32 sLODSeed; 214 static S32 sLODSeed;
131 215
132public: 216public:
217 bridge_list_t mBridgeList;
218 buffer_map_t mBufferMap; //used by volume buffers to store unique buffers per texture
219
220 F32 mBuilt;
133 OctreeNode* mOctreeNode; 221 OctreeNode* mOctreeNode;
134 LLSpatialPartition* mSpatialPartition; 222 LLSpatialPartition* mSpatialPartition;
135 LLVector3 mBounds[2]; 223 LLVector3 mBounds[2];
@@ -137,69 +225,130 @@ public:
137 LLVector3 mObjectExtents[2]; 225 LLVector3 mObjectExtents[2];
138 LLVector3 mObjectBounds[2]; 226 LLVector3 mObjectBounds[2];
139 227
228 LLPointer<LLVertexBuffer> mVertexBuffer;
229 LLPointer<LLVertexBuffer> mOcclusionVerts;
230 LLPointer<LLCubeMap> mReflectionMap;
231
232 U32 mBufferUsage;
233 draw_map_t mDrawMap;
234
235 U32 mVertexCount;
236 U32 mIndexCount;
237 F32 mDistance;
238 F32 mDepth;
239 F32 mLastUpdateDistance;
240 F32 mLastUpdateTime;
241 F32 mLastAddTime;
242 F32 mLastRenderTime;
243
244 LLVector3 mViewAngle;
245 LLVector3 mLastUpdateViewAngle;
246
247 F32 mPixelArea;
248 F32 mRadius;
140}; 249};
141 250
142class LLSpatialPartition 251class LLGeometryManager
143{ 252{
144public: 253public:
145 LLSpatialPartition(); 254 std::vector<LLFace*> mFaceList;
255 virtual ~LLGeometryManager() { }
256 virtual void rebuildGeom(LLSpatialGroup* group) = 0;
257 virtual void getGeometry(LLSpatialGroup* group) = 0;
258 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32 &index_count);
259 virtual LLVertexBuffer* createVertexBuffer(U32 type_mask, U32 usage);
260};
261
262class LLSpatialPartition: public LLGeometryManager
263{
264public:
265 LLSpatialPartition(U32 data_mask, BOOL is_volatile = FALSE, U32 mBufferUsage = GL_STATIC_DRAW_ARB);
146 virtual ~LLSpatialPartition(); 266 virtual ~LLSpatialPartition();
147 267
148 LLSpatialGroup *put(LLDrawable *drawablep); 268 LLSpatialGroup *put(LLDrawable *drawablep, BOOL was_visible = FALSE);
149 BOOL remove(LLDrawable *drawablep, LLSpatialGroup *curp); 269 BOOL remove(LLDrawable *drawablep, LLSpatialGroup *curp);
150 270
151 LLDrawable* pickDrawable(const LLVector3& start, const LLVector3& end, LLVector3& collision); 271 LLDrawable* pickDrawable(const LLVector3& start, const LLVector3& end, LLVector3& collision);
152 272
153 // If the drawable moves, move it here. 273 // If the drawable moves, move it here.
154 virtual void move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate = FALSE); 274 virtual void move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate = FALSE);
155 void shift(const LLVector3 &offset); 275 virtual void shift(const LLVector3 &offset);
276
277 virtual F32 calcDistance(LLSpatialGroup* group, LLCamera& camera);
278 virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
279
280 virtual void rebuildGeom(LLSpatialGroup* group);
156 281
157 S32 cull(LLCamera &camera, std::vector<LLDrawable *>* results = NULL, BOOL for_select = FALSE); // Cull on arbitrary frustum 282 S32 cull(LLCamera &camera, std::vector<LLDrawable *>* results = NULL, BOOL for_select = FALSE); // Cull on arbitrary frustum
158 BOOL checkOcclusion(LLSpatialGroup* group, LLCamera* camera); 283 BOOL checkOcclusion(LLSpatialGroup* group, LLCamera* camera);
284 void markReimage(LLSpatialGroup* group);
285 void processImagery(LLCamera* camera);
159 void processOcclusion(LLCamera* camera); 286 void processOcclusion(LLCamera* camera);
287 void buildOcclusion();
160 void doOcclusion(LLCamera* camera); 288 void doOcclusion(LLCamera* camera);
161 BOOL isVisible(const LLVector3& v); 289 BOOL isVisible(const LLVector3& v);
162 290 BOOL isVolatile() const { return mVolatile; }
291
292 virtual LLSpatialBridge* asBridge() { return NULL; }
293 virtual BOOL isBridge() { return asBridge() != NULL; }
294
163 S32 getObjects(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results ); 295 S32 getObjects(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results );
164 S32 getLights(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results ); 296 S32 getLights(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results );
165 297
166 void renderDebug(); 298 void renderDebug();
167 void restoreGL(); 299 void restoreGL();
300 void resetVertexBuffers();
168 301
169protected: 302protected:
170 S32 getDrawables(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results, BOOL get_lights ); 303 S32 getDrawables(const LLVector3& pos, F32 rad, LLDrawable::drawable_set_t &results, BOOL get_lights );
171 304
172 LLSpatialGroup *mLastAddedGroupp; 305 typedef std::set<LLPointer<LLSpatialGroup> > spatial_group_set_t;
173
174 typedef std::set<LLSpatialGroup*> spatial_group_set_t;
175 spatial_group_set_t mSpatialGroups; 306 spatial_group_set_t mSpatialGroups;
176 307
177 //things that might be occluded 308 //things that might be occluded
178 std::queue<LLSpatialGroup*> mOcclusionQueue; 309 typedef std::queue<LLPointer<LLSpatialGroup> > spatial_group_queue_t;
310 spatial_group_queue_t mOcclusionQueue;
311
312 //things that need an image update
313 spatial_group_queue_t mImageQueue;
179 314
180 //things awaiting query 315 //things awaiting query
181 std::queue<LLSpatialGroup*> mQueryQueue; 316 spatial_group_queue_t mQueryQueue;
182 317
183 std::vector<LLGLuint> mOcclusionQueries; 318 std::vector<LLGLuint> mOcclusionQueries;
184 319
185public: 320public:
186 LLSpatialGroup::OctreeNode* mOctree; 321 LLSpatialGroup::OctreeNode* mOctree;
187 322
188 //things that are occluded 323 U32 mBufferUsage;
189 std::vector<LLSpatialGroup*> mOccludedList; 324 BOOL mRenderByGroup;
190 325 BOOL mImageEnabled;
191 std::queue<LLSpatialGroup*> mReshadowQueue; 326 U32 mLODSeed;
327 U32 mLODPeriod;
328 U32 mVertexDataMask;
329 F32 mSlopRatio; //percentage distance must change before drawables receive LOD update (default is 0.25);
330 BOOL mVolatile; //if TRUE, occlusion queries will be discarded when nodes change size
331 BOOL mDepthMask; //if TRUE, objects in this partition will be written to depth during alpha rendering
332 U32 mDrawableType;
333 U32 mPartitionType;
334
335 //index buffer for occlusion verts
336 LLPointer<LLVertexBuffer> mOcclusionIndices;
192 337
338 //things that are occluded
339 std::vector<LLPointer<LLSpatialGroup> > mOccludedList;
193}; 340};
194 341
195// class for creating bridges between spatial partitions 342// class for creating bridges between spatial partitions
196class LLSpatialBridge : public LLDrawable, public LLSpatialPartition 343class LLSpatialBridge : public LLDrawable, public LLSpatialPartition
197{ 344{
198public: 345public:
199 LLSpatialBridge(LLDrawable* root); 346 typedef std::vector<LLPointer<LLSpatialBridge> > bridge_vector_t;
347
348 LLSpatialBridge(LLDrawable* root, U32 data_mask);
200 virtual ~LLSpatialBridge(); 349 virtual ~LLSpatialBridge();
201 350
202 virtual BOOL isSpatialBridge() const { return TRUE; } 351 virtual BOOL isSpatialBridge() const { return TRUE; }
203 352
204 virtual void updateSpatialExtents(); 353 virtual void updateSpatialExtents();
205 virtual void updateBinRadius(); 354 virtual void updateBinRadius();
@@ -212,11 +361,123 @@ public:
212 virtual void shiftPos(const LLVector3& vec); 361 virtual void shiftPos(const LLVector3& vec);
213 virtual void cleanupReferences(); 362 virtual void cleanupReferences();
214 virtual LLSpatialPartition* asPartition() { return this; } 363 virtual LLSpatialPartition* asPartition() { return this; }
215 LLCamera transformCamera(LLCamera& camera); 364 virtual LLSpatialBridge* asBridge() { return this; }
365
366 virtual LLCamera transformCamera(LLCamera& camera);
216 367
217 LLDrawable* mDrawable; 368 LLDrawable* mDrawable;
218}; 369};
219 370
371//spatial partition for water (implemented in LLVOWater.cpp)
372class LLWaterPartition : public LLSpatialPartition
373{
374public:
375 LLWaterPartition();
376 virtual void getGeometry(LLSpatialGroup* group) { }
377 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { }
378};
379
380//spatial partition for terrain (impelmented in LLVOSurfacePatch.cpp)
381class LLTerrainPartition : public LLSpatialPartition
382{
383public:
384 LLTerrainPartition();
385 virtual void getGeometry(LLSpatialGroup* group);
386 virtual LLVertexBuffer* createVertexBuffer(U32 type_mask, U32 usage);
387};
388
389//spatial partition for trees
390class LLTreePartition : public LLSpatialPartition
391{
392public:
393 LLTreePartition();
394 virtual void getGeometry(LLSpatialGroup* group) { }
395 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { }
396
397};
398
399//spatial partition for particles (implemented in LLVOPartGroup.cpp)
400class LLParticlePartition : public LLSpatialPartition
401{
402public:
403 LLParticlePartition();
404 virtual void getGeometry(LLSpatialGroup* group);
405 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count);
406 virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
407protected:
408 U32 mRenderPass;
409};
410
411//spatial partition for grass (implemented in LLVOGrass.cpp)
412class LLGrassPartition : public LLParticlePartition
413{
414public:
415 LLGrassPartition();
416};
417
418//spatial partition for clouds (implemented in LLVOClouds.cpp)
419class LLCloudPartition : public LLParticlePartition
420{
421public:
422 LLCloudPartition();
423};
424
425//class for wrangling geometry out of volumes (implemented in LLVOVolume.cpp)
426class LLVolumeGeometryManager: public LLGeometryManager
427{
428public:
429 virtual ~LLVolumeGeometryManager() { }
430 virtual void rebuildGeom(LLSpatialGroup* group);
431 virtual void getGeometry(LLSpatialGroup* group);
432 void registerFace(LLSpatialGroup* group, LLFace* facep, U32 type);
433};
434
435//spatial partition that uses volume geometry manager (implemented in LLVOVolume.cpp)
436class LLVolumePartition : public LLSpatialPartition, public LLVolumeGeometryManager
437{
438public:
439 LLVolumePartition();
440 virtual void rebuildGeom(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildGeom(group); }
441 virtual void getGeometry(LLSpatialGroup* group) { LLVolumeGeometryManager::getGeometry(group); }
442 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { LLVolumeGeometryManager::addGeometryCount(group, vertex_count, index_count); }
443};
444
445//spatial bridge that uses volume geometry manager (implemented in LLVOVolume.cpp)
446class LLVolumeBridge : public LLSpatialBridge, public LLVolumeGeometryManager
447{
448public:
449 LLVolumeBridge(LLDrawable* drawable);
450 virtual void rebuildGeom(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildGeom(group); }
451 virtual void getGeometry(LLSpatialGroup* group) { LLVolumeGeometryManager::getGeometry(group); }
452 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { LLVolumeGeometryManager::addGeometryCount(group, vertex_count, index_count); }
453};
454
455class LLHUDBridge : public LLVolumeBridge
456{
457public:
458 LLHUDBridge(LLDrawable* drawablep);
459 virtual void shiftPos(const LLVector3& vec);
460 virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
461};
462
463//spatial partition that holds nothing but spatial bridges
464class LLBridgePartition : public LLSpatialPartition
465{
466public:
467 LLBridgePartition();
468 virtual void getGeometry(LLSpatialGroup* group) { }
469 virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { }
470};
471
472class LLHUDPartition : public LLBridgePartition
473{
474public:
475 LLHUDPartition();
476 virtual void shift(const LLVector3 &offset);
477};
478
479void validate_draw_info(LLDrawInfo& params);
480
220extern const F32 SG_BOX_SIDE; 481extern const F32 SG_BOX_SIDE;
221extern const F32 SG_BOX_OFFSET; 482extern const F32 SG_BOX_OFFSET;
222extern const F32 SG_BOX_RAD; 483extern const F32 SG_BOX_RAD;