llspatialpartition.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /**
  2. * @file llspatialpartition.h
  3. * @brief LLSpatialGroup header file including definitions for supporting functions
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLSPATIALPARTITION_H
  33. #define LL_LLSPATIALPARTITION_H
  34. #include <queue>
  35. #include "llcubemap.h"
  36. #include "hbfastmap.h"
  37. #include "llmaterial.h"
  38. #include "lloctree.h"
  39. #include "llrefcount.h"
  40. #include "llvertexbuffer.h"
  41. #include "lldrawable.h"
  42. #include "lldrawpool.h"
  43. #include "llface.h"
  44. #include "llfetchedgltfmaterial.h"
  45. #include "llviewercamera.h"
  46. #include "llvoavatar.h"
  47. #define SG_MIN_DIST_RATIO 0.00001f
  48. #define SG_STATE_INHERIT_MASK (OCCLUDED)
  49. #define SG_INITIAL_STATE_MASK (DIRTY | GEOM_DIRTY)
  50. class LLColor4U;
  51. class LLSpatialBridge;
  52. class LLSpatialPartition;
  53. class LLViewerOctreePartition;
  54. class LLViewerRegion;
  55. // NOTE: mask is ignored for PBR rendering. HB
  56. void pushVerts(LLFace* face, U32 mask);
  57. class alignas(16) LLDrawInfo final : public LLRefCount
  58. {
  59. protected:
  60. LOG_CLASS(LLDrawInfo);
  61. ~LLDrawInfo();
  62. public:
  63. LL_ALIGNED16_NEW_DELETE
  64. LL_INLINE LLDrawInfo(const LLDrawInfo& rhs)
  65. {
  66. *this = rhs;
  67. }
  68. LL_INLINE const LLDrawInfo& operator=(const LLDrawInfo& rhs)
  69. {
  70. llerrs << "Illegal operation !" << llendl;
  71. return *this;
  72. }
  73. LLDrawInfo(U16 start, U16 end, U32 count, U32 offset,
  74. LLViewerTexture* texp, LLVertexBuffer* bufferp,
  75. bool fullbright = false, U8 bump = 0);
  76. void validate();
  77. // Returns mSkinHash->mHash, or 0 if mSkinHash is NULL
  78. U64 getSkinHash();
  79. // Returns a hash of this LLDrawInfo as a debug color
  80. LLColor4U getDebugColor();
  81. struct CompareTexture
  82. {
  83. LL_INLINE bool operator()(const LLDrawInfo& lhs, const LLDrawInfo& rhs)
  84. {
  85. return lhs.mTexture > rhs.mTexture;
  86. }
  87. };
  88. struct CompareTexturePtr
  89. {
  90. // Sort by texture
  91. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  92. const LLPointer<LLDrawInfo>& rhs)
  93. {
  94. // sort by pointer, sort NULL down to the end
  95. return lhs.get() != rhs.get() &&
  96. (lhs.isNull() ||
  97. (rhs.notNull() &&
  98. lhs->mTexture.get() > rhs->mTexture.get()));
  99. }
  100. };
  101. struct CompareVertexBuffer
  102. {
  103. // Sort by texture
  104. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  105. const LLPointer<LLDrawInfo>& rhs)
  106. {
  107. // sort by pointer, sort NULL down to the end
  108. return lhs.get() != rhs.get() &&
  109. (lhs.isNull() ||
  110. (rhs.notNull() &&
  111. lhs->mVertexBuffer.get() > rhs->mVertexBuffer.get()));
  112. }
  113. };
  114. struct CompareTexturePtrMatrix
  115. {
  116. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  117. const LLPointer<LLDrawInfo>& rhs)
  118. {
  119. return lhs.get() != rhs.get() &&
  120. (lhs.isNull() ||
  121. (rhs.notNull() &&
  122. (lhs->mTexture.get() > rhs->mTexture.get() ||
  123. (lhs->mTexture.get() == rhs->mTexture.get() &&
  124. lhs->mModelMatrix > rhs->mModelMatrix))));
  125. }
  126. };
  127. struct CompareMatrixTexturePtr
  128. {
  129. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  130. const LLPointer<LLDrawInfo>& rhs)
  131. {
  132. return lhs.get() != rhs.get() &&
  133. (lhs.isNull() ||
  134. (rhs.notNull() &&
  135. (lhs->mModelMatrix > rhs->mModelMatrix ||
  136. (lhs->mModelMatrix == rhs->mModelMatrix &&
  137. lhs->mTexture.get() > rhs->mTexture.get()))));
  138. }
  139. };
  140. struct CompareBump
  141. {
  142. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  143. const LLPointer<LLDrawInfo>& rhs)
  144. {
  145. // Sort by mBump value, sort NULL down to the end
  146. return lhs.get() != rhs.get() &&
  147. (lhs.isNull() ||
  148. (rhs.notNull() && lhs->mBump > rhs->mBump));
  149. }
  150. };
  151. struct CompareDistanceGreater
  152. {
  153. LL_INLINE bool operator()(const LLPointer<LLDrawInfo>& lhs,
  154. const LLPointer<LLDrawInfo>& rhs)
  155. {
  156. // Sort by mBump value, sort NULL down to the end
  157. return lhs.get() != rhs.get() &&
  158. (lhs.isNull() ||
  159. (rhs.notNull() && lhs->mDistance > rhs->mDistance));
  160. }
  161. };
  162. public:
  163. // Note: before these variables, we find the 32 bits counter from
  164. // LLRefCount... Since mExtents will be 16-bytes aligned, fill-up the gap
  165. // in the cache line with other member variables. HB
  166. U32 mShaderMask;
  167. U32 mBlendFuncSrc;
  168. U32 mBlendFuncDst;
  169. alignas(16) LLVector4a mExtents[2];
  170. LLPointer<LLVertexBuffer> mVertexBuffer;
  171. LLPointer<LLViewerTexture> mTexture;
  172. LLPointer<LLVOAvatar> mAvatar;
  173. LLPointer<LLMeshSkinInfo> mSkinInfo;
  174. // PBR material parameters, for the PBR renderer only.
  175. LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
  176. const LLMatrix4* mTextureMatrix;
  177. const LLMatrix4* mModelMatrix;
  178. U16 mStart;
  179. U16 mEnd;
  180. U32 mCount;
  181. U32 mOffset;
  182. F32 mVSize;
  183. F32 mDistance;
  184. typedef std::vector<LLPointer<LLViewerTexture> > tex_vec_t;
  185. tex_vec_t mTextureList;
  186. // Virtual size of mTexture and mTextureList textures used to update the
  187. // decode priority of textures in this DrawInfo.
  188. std::vector<F32> mTextureListVSize;
  189. // If mMaterial is null, the following parameters are unused:
  190. LLMaterialPtr mMaterial;
  191. LLUUID mMaterialID;
  192. LLPointer<LLViewerTexture> mSpecularMap;
  193. LLPointer<LLViewerTexture> mNormalMap;
  194. // XYZ = Specular RGB, W = Specular Exponent:
  195. LLVector4 mSpecColor;
  196. F32 mEnvIntensity;
  197. F32 mAlphaMaskCutoff;
  198. // Cache for getDebugColor(). HB
  199. LLColor4U mDebugColor;
  200. // Set to 'true' when a this face pertains to one of the agent's avatar
  201. // attachments. HB
  202. bool mIsAgentAttachment;
  203. // Set to 'true' when a legacy material is used. HB
  204. bool mHasALM;
  205. // Set to 'true' when a PBR material is used. HB
  206. bool mHasPBR;
  207. // Set to 'true' when a fallback is provided for non-PBR viewers. HB
  208. bool mHasLegacyFallback;
  209. // Set to 'true' when we use our hack to render the base color texture
  210. // to replace a missing fallback diffuse texture or legacy material. HB
  211. bool mHasBasecolorFallback;
  212. bool mFullbright;
  213. bool mHasGlow;
  214. U8 mBump;
  215. U8 mShiny;
  216. U8 mDiffuseAlphaMode;
  217. };
  218. class alignas(16) LLSpatialGroup final : public LLOcclusionCullingGroup
  219. {
  220. friend class LLSpatialPartition;
  221. friend class LLOctreeStateCheck;
  222. protected:
  223. LOG_CLASS(LLSpatialGroup);
  224. ~LLSpatialGroup() override;
  225. public:
  226. LL_VOLUME_AREANA_NEW_DELETE
  227. LLSpatialGroup(const LLSpatialGroup& rhs)
  228. : LLOcclusionCullingGroup(rhs)
  229. {
  230. *this = rhs;
  231. }
  232. const LLSpatialGroup& operator=(const LLSpatialGroup& rhs)
  233. {
  234. llerrs << "Illegal operation!" << llendl;
  235. return *this;
  236. }
  237. typedef std::vector<LLPointer<LLSpatialGroup> > sg_vector_t;
  238. typedef std::vector<LLPointer<LLSpatialBridge> > bridge_list_t;
  239. typedef std::vector<LLPointer<LLDrawInfo> > drawmap_elem_t;
  240. typedef fast_hmap<U32, drawmap_elem_t> draw_map_t;
  241. typedef std::vector<LLPointer<LLVertexBuffer> > buffer_list_t;
  242. typedef fast_hmap<LLFace*, buffer_list_t> buffer_texture_map_t;
  243. typedef fast_hmap<U32, buffer_texture_map_t> buffer_map_t;
  244. struct CompareDistanceGreater
  245. {
  246. LL_INLINE bool operator()(const LLSpatialGroup* const& lhs,
  247. const LLSpatialGroup* const& rhs)
  248. {
  249. return lhs->mDistance > rhs->mDistance;
  250. }
  251. };
  252. struct CompareDepthGreater
  253. {
  254. LL_INLINE bool operator()(const LLSpatialGroup* const& lhs,
  255. const LLSpatialGroup* const& rhs)
  256. {
  257. return lhs->mDepth > rhs->mDepth;
  258. }
  259. };
  260. struct CompareRenderOrder
  261. {
  262. LL_INLINE bool operator()(const LLSpatialGroup* const& lhs,
  263. const LLSpatialGroup* const& rhs)
  264. {
  265. if (lhs->mAvatarp != rhs->mAvatarp)
  266. {
  267. return lhs->mAvatarp < rhs->mAvatarp;
  268. }
  269. return lhs->mRenderOrder < rhs->mRenderOrder;
  270. }
  271. };
  272. typedef enum
  273. {
  274. GEOM_DIRTY = LLViewerOctreeGroup::INVALID_STATE,
  275. ALPHA_DIRTY = GEOM_DIRTY << 1,
  276. IN_IMAGE_QUEUE = ALPHA_DIRTY << 1,
  277. IMAGE_DIRTY = IN_IMAGE_QUEUE << 1,
  278. MESH_DIRTY = IMAGE_DIRTY << 1,
  279. NEW_DRAWINFO = MESH_DIRTY << 1,
  280. IN_BUILD_QUEUE = NEW_DRAWINFO << 1,
  281. STATE_MASK = 0x0000FFFF,
  282. } eSpatialState;
  283. LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part);
  284. bool isHUDGroup();
  285. void clearDrawMap();
  286. void setState(U32 state, S32 mode);
  287. void clearState(U32 state, S32 mode);
  288. LL_INLINE void clearState(U32 state) { mState &= ~state; }
  289. LLSpatialGroup* getParent();
  290. bool addObject(LLDrawable* drawablep);
  291. bool removeObject(LLDrawable* drawablep, bool from_octree = false);
  292. // Update position if it's in the group:
  293. bool updateInGroup(LLDrawable* drawablep, bool immediate = false);
  294. void shift(const LLVector4a& offset);
  295. void destroyGL(bool keep_occlusion = false);
  296. void updateDistance(LLCamera& camera);
  297. bool changeLOD();
  298. void rebuildGeom();
  299. void rebuildMesh();
  300. LL_INLINE void setState(U32 state) { mState |= state; }
  301. LL_INLINE void dirtyGeom() { setState(GEOM_DIRTY); }
  302. LL_INLINE void dirtyMesh() { setState(MESH_DIRTY); }
  303. void drawObjectBox(LLColor4 col);
  304. LLDrawable* lineSegmentIntersect(const LLVector4a& start,
  305. const LLVector4a& end,
  306. bool pick_transparent, bool pick_rigged,
  307. S32* face_hit,
  308. LLVector4a* intersection = NULL,
  309. LLVector2* tex_coord = NULL,
  310. LLVector4a* normal = NULL,
  311. LLVector4a* tangent = NULL);
  312. LL_INLINE LLSpatialPartition* getSpatialPartition()
  313. {
  314. return (LLSpatialPartition*)mSpatialPartition;
  315. }
  316. // LLOcclusionCullingGroup overrides
  317. void handleInsertion(const TreeNode* node,
  318. LLViewerOctreeEntry* entry) override;
  319. void handleRemoval(const TreeNode* node,
  320. LLViewerOctreeEntry* entry) override;
  321. void handleDestruction(const TreeNode* node) override;
  322. void handleChildAddition(const OctreeNode* parent,
  323. OctreeNode* child) override;
  324. public:
  325. LLVector4a mViewAngle;
  326. LLVector4a mLastUpdateViewAngle;
  327. // Cached llmax(mObjectBounds[1].getLength3(), 10.f)
  328. F32 mObjectBoxSize;
  329. protected:
  330. static S32 sLODSeed;
  331. public:
  332. LLPointer<LLVertexBuffer> mVertexBuffer;
  333. // Reflection Probe associated with this node (if any)
  334. LLPointer<LLReflectionMap> mReflectionProbe;
  335. bridge_list_t mBridgeList;
  336. // Used by volume buffers to attempt to reuse vertex buffers:
  337. buffer_map_t mBufferMap;
  338. draw_map_t mDrawMap;
  339. // Used by LLVOAvatar to set render order in alpha draw pool to preserve
  340. // legacy render order behaviour.
  341. LLVOAvatar* mAvatarp;
  342. U32 mRenderOrder;
  343. F32 mBuilt;
  344. F32 mDistance;
  345. F32 mDepth;
  346. F32 mLastUpdateDistance;
  347. F32 mLastUpdateTime;
  348. F32 mPixelArea;
  349. F32 mRadius;
  350. // Used by volumes to track how many bytes of geometry data are in this
  351. // node:
  352. U32 mGeometryBytes;
  353. // Used by volumes to track estimated surface area of geometry in this
  354. // node:
  355. F32 mSurfaceArea;
  356. static U32 sNodeCount;
  357. // Deletion of spatial groups and draw info not allowed if true:
  358. static bool sNoDelete;
  359. };
  360. class LLGeometryManager
  361. {
  362. public:
  363. std::vector<LLFace*> mFaceList;
  364. virtual ~LLGeometryManager() = default;
  365. virtual void rebuildGeom(LLSpatialGroup* group) = 0;
  366. virtual void rebuildMesh(LLSpatialGroup* group) = 0;
  367. virtual void getGeometry(LLSpatialGroup* group) = 0;
  368. virtual void addGeometryCount(LLSpatialGroup* group, U32& vertex_count,
  369. U32& index_count);
  370. // Note: not for PBR rendering
  371. virtual LLVertexBuffer* createVertexBuffer(U32 type_mask);
  372. };
  373. class LLSpatialPartition : public LLViewerOctreePartition,
  374. public LLGeometryManager
  375. {
  376. protected:
  377. LOG_CLASS(LLSpatialPartition);
  378. public:
  379. LLSpatialPartition(U32 data_mask, bool render_by_group,
  380. LLViewerRegion* regionp);
  381. ~LLSpatialPartition() override;
  382. LLSpatialGroup* put(LLDrawable* drawablep, bool was_visible = false);
  383. bool remove(LLDrawable* drawablep, LLSpatialGroup* curp);
  384. LLDrawable* lineSegmentIntersect(const LLVector4a& start,
  385. const LLVector4a& end,
  386. bool pick_transparent, bool pick_rigged,
  387. S32* face_hit,
  388. LLVector4a* intersection = NULL,
  389. LLVector2* tex_coord = NULL,
  390. LLVector4a* normal = NULL,
  391. LLVector4a* tangent = NULL);
  392. // If the drawable moves, move it here.
  393. virtual void move(LLDrawable* drawablep, LLSpatialGroup* curp,
  394. bool immediate = false);
  395. virtual void shift(const LLVector4a& offset);
  396. virtual F32 calcDistance(LLSpatialGroup* group, LLCamera& camera);
  397. virtual F32 calcPixelArea(LLSpatialGroup* group, LLCamera& camera);
  398. void rebuildGeom(LLSpatialGroup* group) override;
  399. LL_INLINE void rebuildMesh(LLSpatialGroup*) override
  400. {
  401. }
  402. // Cull on arbitrary frustum
  403. S32 cull(LLCamera& camera, bool do_occlusion = false) override;
  404. S32 cull(LLCamera& camera, std::vector<LLDrawable*>* res, bool for_sel);
  405. bool isVisible(const LLVector3& v);
  406. bool isHUDPartition();
  407. LL_INLINE LLSpatialBridge* asBridge() { return mBridge; }
  408. LL_INLINE bool isBridge() { return asBridge() != NULL; }
  409. void renderPhysicsShapes(bool wireframe = false);
  410. void renderDebug();
  411. void resetVertexBuffers();
  412. bool getVisibleExtents(LLCamera& camera, LLVector3& visMin,
  413. LLVector3& visMax);
  414. public:
  415. // NULL for non-LLSpatialBridge instances, otherwise, mBridge == this. Uses
  416. // a pointer instead of making "isBridge" and "asBridge" virtual so it is
  417. // safe to call asBridge() from the destructor:
  418. LLSpatialBridge* mBridge;
  419. U32 mVertexDataMask;
  420. // Percentage distance must change before drawables receive LOD update
  421. // (default is 0.25):
  422. F32 mSlopRatio;
  423. // If true, frustum culling ignores far clip plane:
  424. bool mInfiniteFarClip;
  425. // If true, objects in this partition will be written to depth during alpha
  426. // rendering:
  427. bool mDepthMask;
  428. const bool mRenderByGroup;
  429. // Started to issue a teleport request
  430. static bool sTeleportRequested;
  431. };
  432. // Class for creating bridges between spatial partitions
  433. class LLSpatialBridge : public LLDrawable, public LLSpatialPartition
  434. {
  435. protected:
  436. LOG_CLASS(LLSpatialBridge);
  437. ~LLSpatialBridge() override;
  438. public:
  439. typedef std::vector<LLPointer<LLSpatialBridge> > bridge_vector_t;
  440. LLSpatialBridge(LLDrawable* root, bool render_by_group, U32 data_mask,
  441. LLViewerRegion* regionp);
  442. void destroyTree();
  443. // Transforms agent space camera into this Spatial Bridge coordinate frame
  444. LLCamera transformCamera(LLCamera& camera);
  445. // LLDrawable overrides
  446. LL_INLINE bool isSpatialBridge() const override { return true; }
  447. LL_INLINE LLSpatialPartition* asPartition() override
  448. {
  449. return this;
  450. }
  451. void updateBinRadius() override;
  452. void updateSpatialExtents() override;
  453. // Transform agent space camera into this Spatial Bridge's coordinate frame
  454. void transformExtents(const LLVector4a* src, LLVector4a* dst);
  455. void setVisible(LLCamera& camera_in,
  456. std::vector<LLDrawable*>* results = NULL,
  457. bool for_select = false) override;
  458. void updateDistance(LLCamera& camera_in, bool force_update) override;
  459. void makeActive() override;
  460. void shiftPos(const LLVector4a& vec) override;
  461. void cleanupReferences() override;
  462. bool updateMove() override;
  463. // LLSpatialPartition override
  464. void move(LLDrawable* drawablep, LLSpatialGroup* curp,
  465. bool immediate = false) override;
  466. public:
  467. LLPointer<LLDrawable> mDrawable;
  468. LLPointer<LLVOAvatar> mAvatar;
  469. };
  470. class LLCullResult
  471. {
  472. protected:
  473. LOG_CLASS(LLCullResult);
  474. public:
  475. LLCullResult() = default;
  476. typedef std::vector<LLSpatialGroup*> sg_list_t;
  477. typedef std::vector<LLDrawable*> drawable_list_t;
  478. typedef std::vector<LLSpatialBridge*> bridge_list_t;
  479. typedef std::vector<LLDrawInfo*> drawinfo_list_t;
  480. // Note: whenever possible, avoid using such an iterator since all the
  481. // "lists" are now of the std::vector type, which elements are way faster
  482. // to access via their index. I provided get*() methods to instead work on
  483. // the vectors themselves. This iterator type (and the associated begin*()
  484. // and end*() methods are only kept because we need to use std::sort in a
  485. // couple of places, on the alpha group "lists". HB
  486. typedef sg_list_t::iterator sg_iterator;
  487. void clear();
  488. LL_INLINE sg_list_t& getAlphaGroups() { return mAlphaGroups; }
  489. LL_INLINE sg_iterator beginAlphaGroups() { return mAlphaGroups.begin(); }
  490. LL_INLINE sg_iterator endAlphaGroups() { return mAlphaGroups.end(); }
  491. LL_INLINE sg_list_t& getRiggedAlphaGroups() { return mRiggedAlphaGroups; }
  492. LL_INLINE sg_iterator beginRiggedAlphaGroups() { return mRiggedAlphaGroups.begin(); }
  493. LL_INLINE sg_iterator endRiggedAlphaGroups() { return mRiggedAlphaGroups.end(); }
  494. LL_INLINE sg_list_t& getDrawableGroups() { return mDrawableGroups; }
  495. LL_INLINE sg_list_t& getOcclusionGroups() { return mOcclusionGroups; }
  496. LL_INLINE bool hasOcclusionGroups() const { return !mOcclusionGroups.empty(); }
  497. LL_INLINE sg_list_t& getVisibleGroups() { return mVisibleGroups; }
  498. LL_INLINE drawable_list_t& getVisibleList() { return mVisibleList; }
  499. LL_INLINE bridge_list_t& getVisibleBridge() { return mVisibleBridge; }
  500. LL_INLINE drawinfo_list_t& getRenderMap(U32 type) { return mRenderMap[type]; }
  501. LL_INLINE bool hasRenderMap(U32 type) const
  502. {
  503. return type < LLRenderPass::NUM_RENDER_TYPES &&
  504. !mRenderMap[type].empty();
  505. }
  506. LL_INLINE void pushVisibleGroup(LLSpatialGroup* g) { mVisibleGroups.push_back(g); }
  507. LL_INLINE void pushAlphaGroup(LLSpatialGroup* g) { mAlphaGroups.push_back(g); }
  508. LL_INLINE void pushRiggedAlphaGroup(LLSpatialGroup* g)
  509. {
  510. mRiggedAlphaGroups.push_back(g);
  511. }
  512. LL_INLINE void pushOcclusionGroup(LLSpatialGroup* g)
  513. {
  514. mOcclusionGroups.push_back(g);
  515. }
  516. LL_INLINE void pushDrawableGroup(LLSpatialGroup* g) { mDrawableGroups.push_back(g); }
  517. LL_INLINE void pushDrawable(LLDrawable* drawable) { mVisibleList.push_back(drawable); }
  518. LL_INLINE void pushBridge(LLSpatialBridge* bridge) { mVisibleBridge.push_back(bridge); }
  519. void pushDrawInfo(U32 type, LLDrawInfo* draw_info);
  520. void assertDrawMapsEmpty();
  521. private:
  522. sg_list_t mVisibleGroups;
  523. sg_list_t mAlphaGroups;
  524. sg_list_t mRiggedAlphaGroups;
  525. sg_list_t mOcclusionGroups;
  526. sg_list_t mDrawableGroups;
  527. drawable_list_t mVisibleList;
  528. bridge_list_t mVisibleBridge;
  529. drawinfo_list_t mRenderMap[LLRenderPass::NUM_RENDER_TYPES];
  530. };
  531. // Spatial partition for water (implemented in llvowater.cpp)
  532. class LLWaterPartition : public LLSpatialPartition
  533. {
  534. public:
  535. LLWaterPartition(LLViewerRegion* regionp);
  536. LL_INLINE void getGeometry(LLSpatialGroup*) override
  537. {
  538. }
  539. LL_INLINE void addGeometryCount(LLSpatialGroup*, U32&, U32&) override
  540. {
  541. }
  542. };
  543. // Spatial partition for hole and edge water (implemented in llvowater.cpp)
  544. class LLVoidWaterPartition : public LLWaterPartition
  545. {
  546. public:
  547. LLVoidWaterPartition(LLViewerRegion* regionp);
  548. };
  549. // Spatial partition for terrain (impelmented in llvosurfacepatch.cpp)
  550. class LLTerrainPartition final : public LLSpatialPartition
  551. {
  552. public:
  553. LLTerrainPartition(LLViewerRegion* regionp);
  554. void getGeometry(LLSpatialGroup* group) override;
  555. // Note: not for PBR rendering
  556. LLVertexBuffer* createVertexBuffer(U32 type_mask) override;
  557. };
  558. // Spatial partition for trees (implemented in llvotree.cpp)
  559. class LLTreePartition final : public LLSpatialPartition
  560. {
  561. public:
  562. LLTreePartition(LLViewerRegion* regionp);
  563. LL_INLINE void getGeometry(LLSpatialGroup*) override
  564. {
  565. }
  566. LL_INLINE void addGeometryCount(LLSpatialGroup*, U32&, U32&) override
  567. {
  568. }
  569. };
  570. // Spatial partition for particles (implemented in llvopartgroup.cpp)
  571. class LLParticlePartition : public LLSpatialPartition
  572. {
  573. public:
  574. LLParticlePartition(LLViewerRegion* regionp);
  575. void rebuildGeom(LLSpatialGroup* group) override;
  576. void getGeometry(LLSpatialGroup* group) override;
  577. void addGeometryCount(LLSpatialGroup* group, U32& vertex_count,
  578. U32& index_count) override;
  579. LL_INLINE F32 calcPixelArea(LLSpatialGroup*, LLCamera&) override
  580. {
  581. return 1024.f;
  582. }
  583. protected:
  584. static bool createVB(LLPointer<LLVertexBuffer>& vb, U32 vert_count,
  585. U32 idx_count);
  586. protected:
  587. U32 mRenderPass;
  588. };
  589. class LLHUDParticlePartition final : public LLParticlePartition
  590. {
  591. public:
  592. LLHUDParticlePartition(LLViewerRegion* regionp);
  593. };
  594. // Spatial partition for grass (implemented in llvograss.cpp)
  595. class LLGrassPartition final : public LLSpatialPartition
  596. {
  597. public:
  598. LLGrassPartition(LLViewerRegion* regionp);
  599. void getGeometry(LLSpatialGroup* group) override;
  600. void addGeometryCount(LLSpatialGroup* group, U32& vertex_count,
  601. U32& index_count) override;
  602. protected:
  603. U32 mRenderPass;
  604. };
  605. // Spatial partition for clouds (implemented in llvoclouds.cpp)
  606. class LLCloudPartition final : public LLParticlePartition
  607. {
  608. public:
  609. LLCloudPartition(LLViewerRegion* regionp);
  610. };
  611. // Class for wrangling geometry out of volumes (implemented in llvovolume.cpp)
  612. class LLVolumeGeometryManager : public LLGeometryManager
  613. {
  614. protected:
  615. LOG_CLASS(LLVolumeGeometryManager);
  616. public:
  617. typedef enum
  618. {
  619. NONE = 0,
  620. BATCH_SORT,
  621. DISTANCE_SORT
  622. } eSortType;
  623. LLVolumeGeometryManager();
  624. ~LLVolumeGeometryManager() override;
  625. void rebuildGeom(LLSpatialGroup* group) override;
  626. void rebuildMesh(LLSpatialGroup* group) override;
  627. LL_INLINE void getGeometry(LLSpatialGroup*) override {}
  628. LL_INLINE void addGeometryCount(LLSpatialGroup*, U32&, U32&) override
  629. {
  630. }
  631. void genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace** faces,
  632. U32 face_count, bool distance_sort = false,
  633. bool batch_textures = false, bool rigged = false);
  634. void registerFace(LLSpatialGroup* group, LLFace* facep, U32 type);
  635. private:
  636. void allocateFaces(U32 max_face_count);
  637. void freeFaces();
  638. private:
  639. static S32 sInstanceCount;
  640. static LLFace** sFullbrightFaces[2];
  641. static LLFace** sBumpFaces[2];
  642. static LLFace** sSimpleFaces[2];
  643. static LLFace** sNormFaces[2];
  644. static LLFace** sSpecFaces[2];
  645. static LLFace** sNormSpecFaces[2];
  646. static LLFace** sPbrFaces[2];
  647. static LLFace** sAlphaFaces[2];
  648. };
  649. // Spatial partition that uses volume geometry manager (implemented in
  650. // llvovolume.cpp)
  651. class LLVolumePartition final : public LLSpatialPartition,
  652. public LLVolumeGeometryManager
  653. {
  654. public:
  655. LLVolumePartition(LLViewerRegion* regionp);
  656. LL_INLINE void rebuildGeom(LLSpatialGroup* group) override
  657. {
  658. LLVolumeGeometryManager::rebuildGeom(group);
  659. }
  660. LL_INLINE void getGeometry(LLSpatialGroup* group) override
  661. {
  662. LLVolumeGeometryManager::getGeometry(group);
  663. }
  664. LL_INLINE void rebuildMesh(LLSpatialGroup* group) override
  665. {
  666. LLVolumeGeometryManager::rebuildMesh(group);
  667. }
  668. LL_INLINE void addGeometryCount(LLSpatialGroup* group, U32& vertex_count,
  669. U32& index_count) override
  670. {
  671. LLVolumeGeometryManager::addGeometryCount(group, vertex_count,
  672. index_count);
  673. }
  674. };
  675. // Spatial bridge that uses volume geometry manager (implemented in
  676. // llvovolume.cpp)
  677. class LLVolumeBridge : public LLSpatialBridge, public LLVolumeGeometryManager
  678. {
  679. public:
  680. LLVolumeBridge(LLDrawable* drawable, LLViewerRegion* regionp);
  681. LL_INLINE void rebuildGeom(LLSpatialGroup* group) override
  682. {
  683. LLVolumeGeometryManager::rebuildGeom(group);
  684. }
  685. LL_INLINE void getGeometry(LLSpatialGroup* group) override
  686. {
  687. LLVolumeGeometryManager::getGeometry(group);
  688. }
  689. LL_INLINE void rebuildMesh(LLSpatialGroup* group) override
  690. {
  691. LLVolumeGeometryManager::rebuildMesh(group);
  692. }
  693. LL_INLINE void addGeometryCount(LLSpatialGroup* group, U32& vertex_count,
  694. U32& index_count) override
  695. {
  696. LLVolumeGeometryManager::addGeometryCount(group, vertex_count,
  697. index_count);
  698. }
  699. };
  700. // Spatial attachment bridge that uses volume geometry manager (implemented in
  701. // llvovolume.cpp)
  702. class LLAvatarBridge final : public LLVolumeBridge
  703. {
  704. public:
  705. LLAvatarBridge(LLDrawable* drawable, LLViewerRegion* regionp);
  706. };
  707. class LLPuppetBridge final : public LLVolumeBridge
  708. {
  709. public:
  710. LLPuppetBridge(LLDrawable* drawable, LLViewerRegion* regionp);
  711. };
  712. class LLHUDBridge final : public LLVolumeBridge
  713. {
  714. public:
  715. LLHUDBridge(LLDrawable* drawablep, LLViewerRegion* regionp);
  716. // HUD objects do not shift with region crossing. That would be silly.
  717. LL_INLINE void shiftPos(const LLVector4a&) override {}
  718. LL_INLINE F32 calcPixelArea(LLSpatialGroup*, LLCamera&) override
  719. {
  720. return 1024.f;
  721. }
  722. };
  723. // Spatial partition that holds nothing but spatial bridges
  724. class LLBridgePartition : public LLSpatialPartition
  725. {
  726. public:
  727. LLBridgePartition(LLViewerRegion* regionp);
  728. LL_INLINE void getGeometry(LLSpatialGroup*) override
  729. {
  730. }
  731. LL_INLINE void addGeometryCount(LLSpatialGroup*, U32&, U32&) override
  732. {
  733. }
  734. };
  735. // Spatial partition that holds nothing but spatial bridges
  736. class LLAvatarPartition final : public LLBridgePartition
  737. {
  738. public:
  739. LLAvatarPartition(LLViewerRegion* regionp);
  740. };
  741. // Spatial partition that holds nothing but spatial bridges
  742. class LLPuppetPartition final : public LLBridgePartition
  743. {
  744. public:
  745. LLPuppetPartition(LLViewerRegion* regionp);
  746. };
  747. class LLHUDPartition final : public LLBridgePartition
  748. {
  749. public:
  750. LLHUDPartition(LLViewerRegion* regionp);
  751. // HUD objects do not shift with region crossing. That would be silly.
  752. LL_INLINE void shift(const LLVector4a&) override {}
  753. };
  754. typedef fast_hset<LLSpatialGroup*> spatial_groups_set_t;
  755. extern spatial_groups_set_t gVisibleSelectedGroups;
  756. // This is set to true in LLReflectionMap::autoAdjustOrigin() when we are
  757. // searching for reflection probes intersections for rendering. HB
  758. extern bool gPickingProbe;
  759. #endif //LL_LLSPATIALPARTITION_H