lldrawable.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /**
  2. * @file lldrawable.h
  3. * @brief LLDrawable class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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_DRAWABLE_H
  33. #define LL_DRAWABLE_H
  34. #include <map>
  35. #include <vector>
  36. #include "hbfastset.h"
  37. #include "llviewerobject.h"
  38. #include "llvieweroctree.h"
  39. class LLCamera;
  40. class LLDrawPool;
  41. class LLDrawable;
  42. class LLFace;
  43. class LLFacePool;
  44. class LLSpatialGroup;
  45. class LLSpatialBridge;
  46. class LLSpatialPartition;
  47. class LLViewerTexture;
  48. class LLVOVolume;
  49. // Can have multiple silhouettes for each object
  50. constexpr U32 SILHOUETTE_HIGHLIGHT = 0;
  51. // All data for new renderer goes into this class.
  52. class alignas(16) LLDrawable : public LLViewerOctreeEntryData
  53. {
  54. friend class LLDrawPool;
  55. friend class LLPipeline;
  56. friend class LLSpatialBridge;
  57. protected:
  58. LOG_CLASS(LLDrawable);
  59. public:
  60. LL_VOLUME_AREANA_NEW_DELETE
  61. LLDrawable(const LLDrawable& rhs)
  62. : LLViewerOctreeEntryData(rhs)
  63. {
  64. *this = rhs;
  65. }
  66. const LLDrawable& operator=(const LLDrawable& rhs)
  67. {
  68. llerrs << "Illegal operation !" << llendl;
  69. return *this;
  70. }
  71. LLDrawable(LLViewerObject* vobj, bool new_entry = false);
  72. void markDead(); // Mark this drawable as dead
  73. LL_INLINE bool isDead() const { return isState(DEAD); }
  74. LL_INLINE bool isNew() const { return !isState(BUILT); }
  75. bool isLight() const;
  76. bool isVisible() const override;
  77. bool isRecentlyVisible() const override;
  78. virtual void setVisible(LLCamera& camera_in,
  79. std::vector<LLDrawable*>* results = NULL,
  80. bool for_select = false);
  81. LL_INLINE LLSpatialGroup* getSpatialGroup() const { return (LLSpatialGroup*)getGroup(); }
  82. LL_INLINE LLViewerRegion* getRegion() const { return mVObjp.notNull() ? mVObjp->getRegion() : NULL; }
  83. LL_INLINE const LLTextureEntry* getTextureEntry(U8 which) const
  84. {
  85. return mVObjp.notNull() ? mVObjp->getTE(which) : NULL;
  86. }
  87. LL_INLINE LLPointer<LLViewerObject>& getVObj() { return mVObjp; }
  88. LL_INLINE const LLViewerObject* getVObj() const { return mVObjp; }
  89. LLVOVolume* getVOVolume() const; // cast mVObjp to LLVOVolume if OK
  90. LL_INLINE const LLMatrix4& getWorldMatrix() const { return mXform.getWorldMatrix(); }
  91. const LLMatrix4& getRenderMatrix() const;
  92. LL_INLINE void setPosition(LLVector3 v) const {}
  93. LL_INLINE const LLVector3& getPosition() const { return mXform.getPosition(); }
  94. LL_INLINE const LLVector3& getWorldPosition() const { return mXform.getPositionW(); }
  95. const LLVector3 getPositionAgent() const;
  96. LL_INLINE const LLVector3& getScale() const { return mCurrentScale; }
  97. LL_INLINE void setScale(const LLVector3& scale) { mCurrentScale = scale; }
  98. LL_INLINE const LLQuaternion& getWorldRotation() const
  99. {
  100. return mXform.getWorldRotation();
  101. }
  102. LL_INLINE const LLQuaternion& getRotation() const { return mXform.getRotation(); }
  103. LL_INLINE F32 getIntensity() const { return llmin(mXform.getScale().mV[0], 4.f); }
  104. LL_INLINE S32 getLOD() const { return mVObjp.notNull() ? mVObjp->getLOD() : 1; }
  105. LL_INLINE void getMinMax(LLVector3& min,LLVector3& max) const
  106. {
  107. mXform.getMinMax(min, max);
  108. }
  109. LL_INLINE LLXformMatrix* getXform() { return &mXform; }
  110. LL_INLINE U32 getState() const { return mState; }
  111. LL_INLINE bool isState(U32 bits) const { return (mState & bits) != 0; }
  112. LL_INLINE void setState(U32 bits) { mState |= bits; }
  113. LL_INLINE void clearState(U32 bits) { mState &= ~bits; }
  114. LLDrawable* getRoot();
  115. LL_INLINE bool isRoot() const { return !mParent || mParent->isAvatar(); }
  116. LL_INLINE bool isAvatar() const { return mVObjp.notNull() && mVObjp->isAvatar(); }
  117. LL_INLINE bool isSpatialRoot() const { return !mParent || mParent->isAvatar(); }
  118. LL_INLINE virtual bool isSpatialBridge() const { return false; }
  119. LL_INLINE virtual LLSpatialPartition* asPartition() { return NULL; }
  120. // Note: parent must be set only via LLViewerObject::setParent()
  121. LL_INLINE LLDrawable* getParent() const { return mParent; }
  122. LLFace* getFace(S32 i) const;
  123. LL_INLINE S32 getNumFaces() const { return (S32)mFaces.size(); }
  124. typedef std::vector<LLFace*> face_list_t;
  125. LL_INLINE face_list_t& getFaces() { return mFaces; }
  126. LL_INLINE const face_list_t& getFaces() const { return mFaces; }
  127. LLFace* addFace(LLFacePool* poolp, LLViewerTexture* texturep);
  128. LLFace* addFace(const LLTextureEntry* te, LLViewerTexture* texturep);
  129. LLFace* addFace(const LLTextureEntry* te, LLViewerTexture* texturep,
  130. LLViewerTexture* normalp);
  131. LLFace* addFace(const LLTextureEntry* te, LLViewerTexture* texturep,
  132. LLViewerTexture* normalp, LLViewerTexture* specularp);
  133. void deleteFaces(S32 offset, S32 count);
  134. void setNumFaces(S32 num_faces, LLFacePool* poolp, LLViewerTexture* texp);
  135. void setNumFacesFast(S32 num, LLFacePool* poolp, LLViewerTexture* texp);
  136. void mergeFaces(LLDrawable* src);
  137. void init(bool new_entry);
  138. void update();
  139. F32 updateXform(bool undamped);
  140. virtual void makeActive();
  141. void makeStatic(bool warning_enabled = true);
  142. LL_INLINE bool isActive() const { return isState(ACTIVE); }
  143. LL_INLINE bool isStatic() const { return !isActive(); }
  144. bool isAnimating() const;
  145. virtual bool updateMove();
  146. virtual void movePartition();
  147. void updateTexture();
  148. LL_INLINE void updateMaterial() {}
  149. virtual void updateDistance(LLCamera& camera, bool force_update);
  150. bool updateGeometry();
  151. void updateFaceSize(S32 idx);
  152. virtual void shiftPos(const LLVector4a& shift_vector);
  153. LL_INLINE S32 getGeneration() const { return mGeneration; }
  154. LL_INLINE bool getLit() const { return !isState(UNLIT); }
  155. LL_INLINE void setLit(bool lit) { lit ? clearState(UNLIT) : setState(UNLIT); }
  156. virtual void cleanupReferences();
  157. void setGroup(LLViewerOctreeGroup* group) override;
  158. LL_INLINE void setRadius(F32 radius) { mRadius = radius; }
  159. LL_INLINE F32 getRadius() const { return mRadius; }
  160. F32 getVisibilityRadius() const;
  161. // Updates the cache of sun space bounding box.
  162. LL_INLINE void updateUVMinMax() {}
  163. const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
  164. virtual void updateSpatialExtents();
  165. virtual void updateBinRadius();
  166. LL_INLINE void setRenderType(S32 type) { mRenderType = type; }
  167. LL_INLINE bool isRenderType(S32 type) { return mRenderType == type; }
  168. LL_INLINE S32 getRenderType() { return mRenderType; }
  169. LLSpatialPartition* getSpatialPartition();
  170. void removeFromOctree();
  171. LL_INLINE void setSpatialBridge(LLSpatialBridge* brg)
  172. {
  173. mSpatialBridge = (LLDrawable*)brg;
  174. }
  175. LL_INLINE LLSpatialBridge* getSpatialBridge()
  176. {
  177. return (LLSpatialBridge*)((LLDrawable*)mSpatialBridge);
  178. }
  179. #if LL_DEBUG && 0
  180. // Debugging methods
  181. S32 findReferences(LLDrawable* drawablep);
  182. static void cleanupDeadDrawables();
  183. #endif
  184. // Statics
  185. static void incrementVisible();
  186. protected:
  187. ~LLDrawable() override;
  188. void moveUpdatePipeline(bool moved);
  189. void updatePartition();
  190. bool updateMoveDamped();
  191. bool updateMoveUndamped();
  192. public:
  193. typedef fast_hset<LLPointer<LLDrawable> > draw_set_t;
  194. typedef std::vector<LLPointer<LLDrawable> > draw_vec_t;
  195. typedef std::list<LLPointer<LLDrawable> > draw_list_t;
  196. struct CompareDistanceGreater
  197. {
  198. LL_INLINE bool operator()(const LLDrawable* const& lhs,
  199. const LLDrawable* const& rhs)
  200. {
  201. // Farthest = last
  202. return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera;
  203. }
  204. };
  205. struct CompareDistanceGreaterVisibleFirst
  206. {
  207. LL_INLINE bool operator()(const LLDrawable* const& lhs,
  208. const LLDrawable* const& rhs)
  209. {
  210. if (lhs->isVisible() && !rhs->isVisible())
  211. {
  212. return true; // visible things come first
  213. }
  214. if (!lhs->isVisible() && rhs->isVisible())
  215. {
  216. return false; // rhs is visible, comes first
  217. }
  218. // Farthest = last
  219. return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera;
  220. }
  221. };
  222. typedef enum e_drawable_flags
  223. {
  224. IN_REBUILD_QUEUE= 0x00000001,
  225. EARLY_MOVE = 0x00000004,
  226. MOVE_UNDAMPED = 0x00000008,
  227. ON_MOVE_LIST = 0x00000010,
  228. UV = 0x00000020,
  229. UNLIT = 0x00000040,
  230. LIGHT = 0x00000080,
  231. REBUILD_VOLUME = 0x00000100, // volume changed LOD or parameters, or vertex buffer changed
  232. REBUILD_TCOORD = 0x00000200, // texture coordinates changed
  233. REBUILD_COLOR = 0x00000400, // color changed
  234. REBUILD_POSITION= 0x00000800, // vertex positions/normals changed
  235. REBUILD_GEOMETRY= REBUILD_POSITION | REBUILD_TCOORD | REBUILD_COLOR,
  236. REBUILD_MATERIAL= REBUILD_TCOORD | REBUILD_COLOR,
  237. REBUILD_ALL = REBUILD_GEOMETRY | REBUILD_VOLUME,
  238. REBUILD_RIGGED = 0x00001000,
  239. ON_SHIFT_LIST = 0x00002000,
  240. ACTIVE = 0x00004000,
  241. DEAD = 0x00008000,
  242. INVISIBLE = 0x00010000, // stay invisible until flag is cleared
  243. NEARBY_LIGHT = 0x00020000, // In gPipeline.mNearbyLightSet
  244. BUILT = 0x00040000,
  245. FORCE_INVISIBLE = 0x00080000,
  246. HAS_ALPHA = 0x00100000,
  247. RIGGED = 0x00200000, // has a rigged face
  248. RIGGED_CHILD = 0x00400000, // has a child with a rigged face
  249. PARTITION_MOVE = 0x00800000,
  250. ANIMATED_CHILD = 0x01000000,
  251. ACTIVE_CHILD = 0x02000000,
  252. } EDrawableFlags;
  253. public:
  254. LLXformMatrix mXform;
  255. LLPointer<LLDrawable> mParent;
  256. F32 mDistanceWRTCamera;
  257. static F32 sCurPixelAngle; // current pixels per radian
  258. private:
  259. U32 mState;
  260. S32 mRenderType;
  261. S32 mGeneration;
  262. F32 mRadius;
  263. LLVector3 mCurrentScale;
  264. LLPointer<LLViewerObject> mVObjp;
  265. LLPointer<LLDrawable> mSpatialBridge;
  266. face_list_t mFaces;
  267. static U32 sNumZombieDrawables;
  268. #if LL_DEBUG
  269. static std::vector<LLPointer<LLDrawable> > sDeadList;
  270. #endif
  271. };
  272. #endif