PageRenderTime 532ms CodeModel.GetById 151ms app.highlight 221ms RepoModel.GetById 151ms app.codeStats 1ms

/indra/newview/llspatialpartition.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 744 lines | 566 code | 126 blank | 52 comment | 29 complexity | e76f99436b47ac1465dc9ec56afa4744 MD5 | raw file
  1/** 
  2 * @file llspatialpartition.h
  3 * @brief LLSpatialGroup header file including definitions for supporting functions
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLSPATIALPARTITION_H
 28#define LL_LLSPATIALPARTITION_H
 29
 30#define SG_MIN_DIST_RATIO 0.00001f
 31
 32#include "lldrawable.h"
 33#include "lloctree.h"
 34#include "llpointer.h"
 35#include "llrefcount.h"
 36#include "llvertexbuffer.h"
 37#include "llgltypes.h"
 38#include "llcubemap.h"
 39#include "lldrawpool.h"
 40#include "llface.h"
 41#include "llviewercamera.h"
 42#include "llvector4a.h"
 43#include <queue>
 44
 45#define SG_STATE_INHERIT_MASK (OCCLUDED)
 46#define SG_INITIAL_STATE_MASK (DIRTY | GEOM_DIRTY)
 47
 48class LLSpatialPartition;
 49class LLSpatialBridge;
 50class LLSpatialGroup;
 51class LLTextureAtlas;
 52class LLTextureAtlasSlot;
 53
 54S32 AABBSphereIntersect(const LLVector4a& min, const LLVector4a& max, const LLVector3 &origin, const F32 &rad);
 55S32 AABBSphereIntersectR2(const LLVector4a& min, const LLVector4a& max, const LLVector3 &origin, const F32 &radius_squared);
 56
 57S32 AABBSphereIntersect(const LLVector3& min, const LLVector3& max, const LLVector3 &origin, const F32 &rad);
 58S32 AABBSphereIntersectR2(const LLVector3& min, const LLVector3& max, const LLVector3 &origin, const F32 &radius_squared);
 59void pushVerts(LLFace* face, U32 mask);
 60
 61// get index buffer for binary encoded axis vertex buffer given a box at center being viewed by given camera
 62U32 get_box_fan_indices(LLCamera* camera, const LLVector4a& center);
 63U8* get_box_fan_indices_ptr(LLCamera* camera, const LLVector4a& center);
 64
 65class LLDrawInfo : public LLRefCount 
 66{
 67protected:
 68	~LLDrawInfo();	
 69	
 70public:
 71
 72	LLDrawInfo(const LLDrawInfo& rhs)
 73	{
 74		*this = rhs;
 75	}
 76
 77	const LLDrawInfo& operator=(const LLDrawInfo& rhs)
 78	{
 79		llerrs << "Illegal operation!" << llendl;
 80		return *this;
 81	}
 82
 83	LLDrawInfo(U16 start, U16 end, U32 count, U32 offset, 
 84				LLViewerTexture* image, LLVertexBuffer* buffer, 
 85				BOOL fullbright = FALSE, U8 bump = 0, BOOL particle = FALSE, F32 part_size = 0);
 86	
 87
 88	void validate();
 89
 90	LLVector4a mExtents[2];
 91	
 92	LLPointer<LLVertexBuffer> mVertexBuffer;
 93	LLPointer<LLViewerTexture>     mTexture;
 94	std::vector<LLPointer<LLViewerTexture> > mTextureList;
 95
 96	S32 mDebugColor;
 97	const LLMatrix4* mTextureMatrix;
 98	const LLMatrix4* mModelMatrix;
 99	U16 mStart;
100	U16 mEnd;
101	U32 mCount;
102	U32 mOffset;
103	BOOL mFullbright;
104	U8 mBump;
105	BOOL mParticle;
106	F32 mPartSize;
107	F32 mVSize;
108	LLSpatialGroup* mGroup;
109	LLFace* mFace; //associated face
110	F32 mDistance;
111	U32 mDrawMode;
112
113	struct CompareTexture
114	{
115		bool operator()(const LLDrawInfo& lhs, const LLDrawInfo& rhs)
116		{
117			return lhs.mTexture > rhs.mTexture;
118		}
119	};
120
121	struct CompareTexturePtr
122	{ //sort by texture
123		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs)	
124		{
125			// sort by pointer, sort NULL down to the end
126			return lhs.get() != rhs.get() 
127						&& (lhs.isNull() || (rhs.notNull() && lhs->mTexture.get() > rhs->mTexture.get()));
128		}
129	};
130
131	struct CompareVertexBuffer
132	{ //sort by texture
133		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs)	
134		{
135			// sort by pointer, sort NULL down to the end
136			return lhs.get() != rhs.get() 
137					&& (lhs.isNull() || (rhs.notNull() && lhs->mVertexBuffer.get() > rhs->mVertexBuffer.get()));
138		}
139	};
140
141	struct CompareTexturePtrMatrix
142	{
143		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs)	
144		{
145			return lhs.get() != rhs.get() 
146						&& (lhs.isNull() || (rhs.notNull() && (lhs->mTexture.get() > rhs->mTexture.get() ||
147															   (lhs->mTexture.get() == rhs->mTexture.get() && lhs->mModelMatrix > rhs->mModelMatrix))));
148		}
149
150	};
151
152	struct CompareMatrixTexturePtr
153	{
154		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs)	
155		{
156			return lhs.get() != rhs.get() 
157				&& (lhs.isNull() || (rhs.notNull() && (lhs->mModelMatrix > rhs->mModelMatrix ||
158													   (lhs->mModelMatrix == rhs->mModelMatrix && lhs->mTexture.get() > rhs->mTexture.get()))));
159		}
160
161	};
162
163	struct CompareBump
164	{
165		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs) 
166		{
167			// sort by mBump value, sort NULL down to the end
168			return lhs.get() != rhs.get() 
169						&& (lhs.isNull() || (rhs.notNull() && lhs->mBump > rhs->mBump));
170		}
171	};
172
173	struct CompareDistanceGreater
174	{
175		bool operator()(const LLPointer<LLDrawInfo>& lhs, const LLPointer<LLDrawInfo>& rhs) 
176		{
177			// sort by mBump value, sort NULL down to the end
178			return lhs.get() != rhs.get() 
179						&& (lhs.isNull() || (rhs.notNull() && lhs->mDistance > rhs->mDistance));
180		}
181	};
182};
183
184LL_ALIGN_PREFIX(64)
185class LLSpatialGroup : public LLOctreeListener<LLDrawable>
186{
187	friend class LLSpatialPartition;
188	friend class LLOctreeStateCheck;
189public:
190
191	LLSpatialGroup(const LLSpatialGroup& rhs)
192	{
193		*this = rhs;
194	}
195
196	const LLSpatialGroup& operator=(const LLSpatialGroup& rhs)
197	{
198		llerrs << "Illegal operation!" << llendl;
199		return *this;
200	}
201
202	static std::set<GLuint> sPendingQueries; //pending occlusion queries
203	static U32 sNodeCount;
204	static BOOL sNoDelete; //deletion of spatial groups and draw info not allowed if TRUE
205
206	typedef std::vector<LLPointer<LLSpatialGroup> > sg_vector_t;
207	typedef std::vector<LLPointer<LLSpatialBridge> > bridge_list_t;
208	typedef std::vector<LLPointer<LLDrawInfo> > drawmap_elem_t; 
209	typedef std::map<U32, drawmap_elem_t > draw_map_t;	
210	typedef std::vector<LLPointer<LLVertexBuffer> > buffer_list_t;
211	typedef std::map<LLFace*, buffer_list_t> buffer_texture_map_t;
212	typedef std::map<U32, buffer_texture_map_t> buffer_map_t;
213
214	typedef LLOctreeListener<LLDrawable>	BaseType;
215	typedef LLOctreeListener<LLDrawable>	OctreeListener;
216	typedef LLTreeNode<LLDrawable>			TreeNode;
217	typedef LLOctreeNode<LLDrawable>		OctreeNode;
218	typedef LLOctreeRoot<LLDrawable>		OctreeRoot;
219	typedef LLOctreeTraveler<LLDrawable>	OctreeTraveler;
220	typedef LLOctreeNode<LLDrawable>::element_iter element_iter;
221	typedef LLOctreeNode<LLDrawable>::element_list element_list;
222
223	struct CompareDistanceGreater
224	{
225		bool operator()(const LLSpatialGroup* const& lhs, const LLSpatialGroup* const& rhs)
226		{
227			return lhs->mDistance > rhs->mDistance;
228		}
229	};
230
231	struct CompareUpdateUrgency
232	{
233		bool operator()(const LLPointer<LLSpatialGroup> lhs, const LLPointer<LLSpatialGroup> rhs)
234		{
235			return lhs->getUpdateUrgency() > rhs->getUpdateUrgency();
236		}
237	};
238
239	struct CompareDepthGreater
240	{
241		bool operator()(const LLSpatialGroup* const& lhs, const LLSpatialGroup* const& rhs)
242		{
243			return lhs->mDepth > rhs->mDepth;
244		}
245	};
246
247	typedef enum
248	{
249		OCCLUDED				= 0x00010000,
250		QUERY_PENDING			= 0x00020000,
251		ACTIVE_OCCLUSION		= 0x00040000,
252		DISCARD_QUERY			= 0x00080000,
253		EARLY_FAIL				= 0x00100000,
254	} eOcclusionState;
255
256	typedef enum
257	{
258		DEAD					= 0x00000001,
259		DIRTY					= 0x00000002,
260		OBJECT_DIRTY			= 0x00000004,
261		GEOM_DIRTY				= 0x00000008,
262		ALPHA_DIRTY				= 0x00000010,
263		SKIP_FRUSTUM_CHECK		= 0x00000020,
264		IN_IMAGE_QUEUE			= 0x00000040,
265		IMAGE_DIRTY				= 0x00000080,
266		OCCLUSION_DIRTY			= 0x00000100,
267		MESH_DIRTY				= 0x00000200,
268		NEW_DRAWINFO			= 0x00000400,
269		IN_BUILD_Q1				= 0x00000800,
270		IN_BUILD_Q2				= 0x00001000,
271		STATE_MASK				= 0x0000FFFF,
272	} eSpatialState;
273
274	typedef enum
275	{
276		STATE_MODE_SINGLE = 0,		//set one node
277		STATE_MODE_BRANCH,			//set entire branch
278		STATE_MODE_DIFF,			//set entire branch as long as current state is different
279		STATE_MODE_ALL_CAMERAS,		//used for occlusion state, set state for all cameras
280	} eSetStateMode;
281
282	LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part);
283
284	BOOL isHUDGroup() ;
285	BOOL isDead()							{ return isState(DEAD); }
286	BOOL isState(U32 state) const;	
287	BOOL isOcclusionState(U32 state) const	{ return mOcclusionState[LLViewerCamera::sCurCameraID] & state ? TRUE : FALSE; }
288	U32 getState()							{ return mState; }
289	void setState(U32 state);	
290	void clearState(U32 state);	
291	
292	void clearDrawMap();
293	void validate();
294	void checkStates();
295	void validateDrawMap();
296	
297	void setState(U32 state, S32 mode);
298	void clearState(U32 state, S32 mode);
299
300	void setOcclusionState(U32 state, S32 mode = STATE_MODE_SINGLE);
301	void clearOcclusionState(U32 state, S32 mode = STATE_MODE_SINGLE);
302
303	LLSpatialGroup* getParent();
304
305	
306	BOOL addObject(LLDrawable *drawablep, BOOL add_all = FALSE, BOOL from_octree = FALSE);
307	BOOL removeObject(LLDrawable *drawablep, BOOL from_octree = FALSE);
308	BOOL updateInGroup(LLDrawable *drawablep, BOOL immediate = FALSE); // Update position if it's in the group
309	BOOL isVisible() const;
310	BOOL isRecentlyVisible() const;
311	void setVisible();
312	void shift(const LLVector4a &offset);
313	BOOL boundObjects(BOOL empty, LLVector4a& newMin, LLVector4a& newMax);
314	void unbound();
315	BOOL rebound();
316	void buildOcclusion(); //rebuild mOcclusionVerts
317	void checkOcclusion(); //read back last occlusion query (if any)
318	void doOcclusion(LLCamera* camera); //issue occlusion query
319	void destroyGL();
320	
321	void updateDistance(LLCamera& camera);
322	BOOL needsUpdate();
323	F32 getUpdateUrgency() const;
324	BOOL changeLOD();
325	void rebuildGeom();
326	void rebuildMesh();
327
328	void dirtyGeom() { setState(GEOM_DIRTY); }
329	void dirtyMesh() { setState(MESH_DIRTY); }
330	element_list& getData() { return mOctreeNode->getData(); }
331	U32 getElementCount() const { return mOctreeNode->getElementCount(); }
332
333	void drawObjectBox(LLColor4 col);
334
335	 //LISTENER FUNCTIONS
336	virtual void handleInsertion(const TreeNode* node, LLDrawable* face);
337	virtual void handleRemoval(const TreeNode* node, LLDrawable* face);
338	virtual void handleDestruction(const TreeNode* node);
339	virtual void handleStateChange(const TreeNode* node);
340	virtual void handleChildAddition(const OctreeNode* parent, OctreeNode* child);
341	virtual void handleChildRemoval(const OctreeNode* parent, const OctreeNode* child);
342
343//-------------------
344//for atlas use
345//-------------------
346	//atlas	
347	void setCurUpdatingTime(U32 t) {mCurUpdatingTime = t ;}
348	U32  getCurUpdatingTime() const { return mCurUpdatingTime ;}
349	
350	void setCurUpdatingSlot(LLTextureAtlasSlot* slotp) ;
351	LLTextureAtlasSlot* getCurUpdatingSlot(LLViewerTexture* imagep, S8 recursive_level = 3) ;
352
353	void setCurUpdatingTexture(LLViewerTexture* tex){ mCurUpdatingTexture = tex ;}
354	LLViewerTexture* getCurUpdatingTexture() const { return mCurUpdatingTexture ;}
355	
356	BOOL hasAtlas(LLTextureAtlas* atlasp) ;
357	LLTextureAtlas* getAtlas(S8 ncomponents, S8 to_be_reserved, S8 recursive_level = 3) ;
358	void addAtlas(LLTextureAtlas* atlasp, S8 recursive_level = 3) ;
359	void removeAtlas(LLTextureAtlas* atlasp, BOOL remove_group = TRUE, S8 recursive_level = 3) ;
360	void clearAtlasList() ;
361
362public:
363
364	typedef enum
365	{
366		BOUNDS = 0,
367		EXTENTS = 2,
368		OBJECT_BOUNDS = 4,
369		OBJECT_EXTENTS = 6,
370		VIEW_ANGLE = 8,
371		LAST_VIEW_ANGLE = 9,
372		V4_COUNT = 10
373	} eV4Index;
374
375	LLVector4a mBounds[2]; // bounding box (center, size) of this node and all its children (tight fit to objects)
376	LLVector4a mExtents[2]; // extents (min, max) of this node and all its children
377	LLVector4a mObjectExtents[2]; // extents (min, max) of objects in this node
378	LLVector4a mObjectBounds[2]; // bounding box (center, size) of objects in this node
379	LLVector4a mViewAngle;
380	LLVector4a mLastUpdateViewAngle;
381		
382private:
383	U32                     mCurUpdatingTime ;
384	//do not make the below two to use LLPointer
385	//because mCurUpdatingTime invalidates them automatically.
386	LLTextureAtlasSlot* mCurUpdatingSlotp ;
387	LLViewerTexture*          mCurUpdatingTexture ;
388
389	std::vector< std::list<LLTextureAtlas*> > mAtlasList ; 
390//-------------------
391//end for atlas use
392//-------------------
393
394protected:
395	virtual ~LLSpatialGroup();
396
397	U32 mState;
398	U32 mOcclusionState[LLViewerCamera::NUM_CAMERAS];
399	U32 mOcclusionIssued[LLViewerCamera::NUM_CAMERAS];
400
401	S32 mLODHash;
402	static S32 sLODSeed;
403
404public:
405	bridge_list_t mBridgeList;
406	buffer_map_t mBufferMap; //used by volume buffers to attempt to reuse vertex buffers
407
408	F32 mBuilt;
409	OctreeNode* mOctreeNode;
410	LLSpatialPartition* mSpatialPartition;
411	
412	LLPointer<LLVertexBuffer> mVertexBuffer;
413	LLPointer<LLVertexBuffer> mOcclusionVerts;
414	GLuint					mOcclusionQuery[LLViewerCamera::NUM_CAMERAS];
415
416	U32 mBufferUsage;
417	draw_map_t mDrawMap;
418	
419	S32 mVisible[LLViewerCamera::NUM_CAMERAS];
420	F32 mDistance;
421	F32 mDepth;
422	F32 mLastUpdateDistance;
423	F32 mLastUpdateTime;
424	
425	F32 mPixelArea;
426	F32 mRadius;
427} LL_ALIGN_POSTFIX(64);
428
429class LLGeometryManager
430{
431public:
432	std::vector<LLFace*> mFaceList;
433	virtual ~LLGeometryManager() { }
434	virtual void rebuildGeom(LLSpatialGroup* group) = 0;
435	virtual void rebuildMesh(LLSpatialGroup* group) = 0;
436	virtual void getGeometry(LLSpatialGroup* group) = 0;
437	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32 &index_count);
438	
439	virtual LLVertexBuffer* createVertexBuffer(U32 type_mask, U32 usage);
440};
441
442class LLSpatialPartition: public LLGeometryManager
443{
444public:
445	LLSpatialPartition(U32 data_mask,  BOOL render_by_group, U32 mBufferUsage);
446	virtual ~LLSpatialPartition();
447
448	LLSpatialGroup *put(LLDrawable *drawablep, BOOL was_visible = FALSE);
449	BOOL remove(LLDrawable *drawablep, LLSpatialGroup *curp);
450	
451	LLDrawable* lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
452									 BOOL pick_transparent, 
453									 S32* face_hit,                          // return the face hit
454									 LLVector3* intersection = NULL,         // return the intersection point
455									 LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
456									 LLVector3* normal = NULL,               // return the surface normal at the intersection point
457									 LLVector3* bi_normal = NULL             // return the surface bi-normal at the intersection point
458		);
459	
460	
461	// If the drawable moves, move it here.
462	virtual void move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate = FALSE);
463	virtual void shift(const LLVector4a &offset);
464
465	virtual F32 calcDistance(LLSpatialGroup* group, LLCamera& camera);
466	virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
467
468	virtual void rebuildGeom(LLSpatialGroup* group);
469	virtual void rebuildMesh(LLSpatialGroup* group);
470
471	BOOL visibleObjectsInFrustum(LLCamera& camera);
472	S32 cull(LLCamera &camera, std::vector<LLDrawable *>* results = NULL, BOOL for_select = FALSE); // Cull on arbitrary frustum
473	
474	BOOL isVisible(const LLVector3& v);
475	bool isHUDPartition() ;
476	
477	virtual LLSpatialBridge* asBridge() { return NULL; }
478	virtual BOOL isBridge() { return asBridge() != NULL; }
479
480	void renderPhysicsShapes();
481	void renderDebug();
482	void renderIntersectingBBoxes(LLCamera* camera);
483	void restoreGL();
484	void resetVertexBuffers();
485	BOOL isOcclusionEnabled();
486	BOOL getVisibleExtents(LLCamera& camera, LLVector3& visMin, LLVector3& visMax);
487
488public:
489	LLSpatialGroup::OctreeNode* mOctree;
490	BOOL mOcclusionEnabled; // if TRUE, occlusion culling is performed
491	BOOL mInfiniteFarClip; // if TRUE, frustum culling ignores far clip plane
492	U32 mBufferUsage;
493	const BOOL mRenderByGroup;
494	U32 mLODSeed;
495	U32 mLODPeriod;	//number of frames between LOD updates for a given spatial group (staggered by mLODSeed)
496	U32 mVertexDataMask;
497	F32 mSlopRatio; //percentage distance must change before drawables receive LOD update (default is 0.25);
498	BOOL mDepthMask; //if TRUE, objects in this partition will be written to depth during alpha rendering
499	U32 mDrawableType;
500	U32 mPartitionType;
501};
502
503// class for creating bridges between spatial partitions
504class LLSpatialBridge : public LLDrawable, public LLSpatialPartition
505{
506protected:
507	~LLSpatialBridge();
508
509public:
510	typedef std::vector<LLPointer<LLSpatialBridge> > bridge_vector_t;
511	
512	LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 data_mask);
513	
514	virtual BOOL isSpatialBridge() const		{ return TRUE; }
515
516	virtual void updateSpatialExtents();
517	virtual void updateBinRadius();
518	virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
519	virtual void updateDistance(LLCamera& camera_in, bool force_update);
520	virtual void makeActive();
521	virtual void move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate = FALSE);
522	virtual BOOL updateMove();
523	virtual void shiftPos(const LLVector4a& vec);
524	virtual void cleanupReferences();
525	virtual LLSpatialPartition* asPartition()		{ return this; }
526	virtual LLSpatialBridge* asBridge()				{ return this; }
527	
528	virtual LLCamera transformCamera(LLCamera& camera);
529	
530	LLDrawable* mDrawable;
531};
532
533class LLCullResult 
534{
535public:
536	LLCullResult();
537
538	typedef std::vector<LLSpatialGroup*> sg_list_t;
539	typedef std::vector<LLDrawable*> drawable_list_t;
540	typedef std::vector<LLSpatialBridge*> bridge_list_t;
541	typedef std::vector<LLDrawInfo*> drawinfo_list_t;
542
543	void clear();
544	
545	sg_list_t::iterator beginVisibleGroups();
546	sg_list_t::iterator endVisibleGroups();
547
548	sg_list_t::iterator beginAlphaGroups();
549	sg_list_t::iterator endAlphaGroups();
550
551	bool hasOcclusionGroups() { return mOcclusionGroupsSize > 0; }
552	sg_list_t::iterator beginOcclusionGroups();
553	sg_list_t::iterator endOcclusionGroups();
554
555	sg_list_t::iterator beginDrawableGroups();
556	sg_list_t::iterator endDrawableGroups();
557
558	drawable_list_t::iterator beginVisibleList();
559	drawable_list_t::iterator endVisibleList();
560
561	bridge_list_t::iterator beginVisibleBridge();
562	bridge_list_t::iterator endVisibleBridge();
563
564	drawinfo_list_t::iterator beginRenderMap(U32 type);
565	drawinfo_list_t::iterator endRenderMap(U32 type);
566
567	void pushVisibleGroup(LLSpatialGroup* group);
568	void pushAlphaGroup(LLSpatialGroup* group);
569	void pushOcclusionGroup(LLSpatialGroup* group);
570	void pushDrawableGroup(LLSpatialGroup* group);
571	void pushDrawable(LLDrawable* drawable);
572	void pushBridge(LLSpatialBridge* bridge);
573	void pushDrawInfo(U32 type, LLDrawInfo* draw_info);
574	
575	U32 getVisibleGroupsSize()		{ return mVisibleGroupsSize; }
576	U32	getAlphaGroupsSize()		{ return mAlphaGroupsSize; }
577	U32	getDrawableGroupsSize()		{ return mDrawableGroupsSize; }
578	U32	getVisibleListSize()		{ return mVisibleListSize; }
579	U32	getVisibleBridgeSize()		{ return mVisibleBridgeSize; }
580	U32	getRenderMapSize(U32 type)	{ return mRenderMapSize[type]; }
581
582	void assertDrawMapsEmpty();
583
584private:
585	U32					mVisibleGroupsSize;
586	U32					mAlphaGroupsSize;
587	U32					mOcclusionGroupsSize;
588	U32					mDrawableGroupsSize;
589	U32					mVisibleListSize;
590	U32					mVisibleBridgeSize;
591	U32					mRenderMapSize[LLRenderPass::NUM_RENDER_TYPES];
592
593	sg_list_t			mVisibleGroups;
594	sg_list_t::iterator mVisibleGroupsEnd;
595	sg_list_t			mAlphaGroups;
596	sg_list_t::iterator mAlphaGroupsEnd;
597	sg_list_t			mOcclusionGroups;
598	sg_list_t::iterator	mOcclusionGroupsEnd;
599	sg_list_t			mDrawableGroups;
600	sg_list_t::iterator mDrawableGroupsEnd;
601	drawable_list_t		mVisibleList;
602	drawable_list_t::iterator mVisibleListEnd;
603	bridge_list_t		mVisibleBridge;
604	bridge_list_t::iterator mVisibleBridgeEnd;
605	drawinfo_list_t		mRenderMap[LLRenderPass::NUM_RENDER_TYPES];
606	drawinfo_list_t::iterator mRenderMapEnd[LLRenderPass::NUM_RENDER_TYPES];
607};
608
609
610//spatial partition for water (implemented in LLVOWater.cpp)
611class LLWaterPartition : public LLSpatialPartition
612{
613public:
614	LLWaterPartition();
615	virtual void getGeometry(LLSpatialGroup* group) {  }
616	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { }
617};
618
619//spatial partition for hole and edge water (implemented in LLVOWater.cpp)
620class LLVoidWaterPartition : public LLWaterPartition
621{
622public:
623	LLVoidWaterPartition();
624};
625
626//spatial partition for terrain (impelmented in LLVOSurfacePatch.cpp)
627class LLTerrainPartition : public LLSpatialPartition
628{
629public:
630	LLTerrainPartition();
631	virtual void getGeometry(LLSpatialGroup* group);
632	virtual LLVertexBuffer* createVertexBuffer(U32 type_mask, U32 usage);
633};
634
635//spatial partition for trees
636class LLTreePartition : public LLSpatialPartition
637{
638public:
639	LLTreePartition();
640	virtual void getGeometry(LLSpatialGroup* group) { }
641	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { }
642
643};
644
645//spatial partition for particles (implemented in LLVOPartGroup.cpp)
646class LLParticlePartition : public LLSpatialPartition
647{
648public:
649	LLParticlePartition();
650	virtual void getGeometry(LLSpatialGroup* group);
651	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count);
652	virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
653protected:
654	U32 mRenderPass;
655};
656
657class LLHUDParticlePartition : public LLParticlePartition
658{
659public:
660	LLHUDParticlePartition();
661};
662
663//spatial partition for grass (implemented in LLVOGrass.cpp)
664class LLGrassPartition : public LLParticlePartition
665{
666public:
667	LLGrassPartition();
668};
669
670//class for wrangling geometry out of volumes (implemented in LLVOVolume.cpp)
671class LLVolumeGeometryManager: public LLGeometryManager
672{
673 public:
674	typedef enum
675	{
676		NONE = 0,
677		BATCH_SORT,
678		DISTANCE_SORT
679	} eSortType;
680
681	virtual ~LLVolumeGeometryManager() { }
682	virtual void rebuildGeom(LLSpatialGroup* group);
683	virtual void rebuildMesh(LLSpatialGroup* group);
684	virtual void getGeometry(LLSpatialGroup* group);
685	void genDrawInfo(LLSpatialGroup* group, U32 mask, std::vector<LLFace*>& faces, BOOL distance_sort = FALSE, BOOL batch_textures = FALSE);
686	void registerFace(LLSpatialGroup* group, LLFace* facep, U32 type);
687};
688
689//spatial partition that uses volume geometry manager (implemented in LLVOVolume.cpp)
690class LLVolumePartition : public LLSpatialPartition, public LLVolumeGeometryManager
691{
692public:
693	LLVolumePartition();
694	virtual void rebuildGeom(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildGeom(group); }
695	virtual void getGeometry(LLSpatialGroup* group) { LLVolumeGeometryManager::getGeometry(group); }
696	virtual void rebuildMesh(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildMesh(group); }
697	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { LLVolumeGeometryManager::addGeometryCount(group, vertex_count, index_count); }
698};
699
700//spatial bridge that uses volume geometry manager (implemented in LLVOVolume.cpp)
701class LLVolumeBridge : public LLSpatialBridge, public LLVolumeGeometryManager
702{
703public:
704	LLVolumeBridge(LLDrawable* drawable);
705	virtual void rebuildGeom(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildGeom(group); }
706	virtual void getGeometry(LLSpatialGroup* group) { LLVolumeGeometryManager::getGeometry(group); }
707	virtual void rebuildMesh(LLSpatialGroup* group) { LLVolumeGeometryManager::rebuildMesh(group); }
708	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) { LLVolumeGeometryManager::addGeometryCount(group, vertex_count, index_count); }
709};
710
711class LLHUDBridge : public LLVolumeBridge
712{
713public:
714	LLHUDBridge(LLDrawable* drawablep);
715	virtual void shiftPos(const LLVector4a& vec);
716	virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
717};
718
719//spatial partition that holds nothing but spatial bridges
720class LLBridgePartition : public LLSpatialPartition
721{
722public:
723	LLBridgePartition();
724	virtual void getGeometry(LLSpatialGroup* group) { }
725	virtual void addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32& index_count) {  }
726};
727
728class LLHUDPartition : public LLBridgePartition
729{
730public:
731	LLHUDPartition();
732	virtual void shift(const LLVector4a &offset);
733};
734
735extern const F32 SG_BOX_SIDE;
736extern const F32 SG_BOX_OFFSET;
737extern const F32 SG_BOX_RAD;
738
739extern const F32 SG_OBJ_SIDE;
740extern const F32 SG_MAX_OBJ_RAD;
741
742
743#endif //LL_LLSPATIALPARTITION_H
744