PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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