PageRenderTime 84ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lldrawable.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 353 lines | 249 code | 68 blank | 36 comment | 12 complexity | 5bf0f7256456b49fbfbb65045da1db29 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldrawable.h
  3. * @brief LLDrawable class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&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_DRAWABLE_H
  27. #define LL_DRAWABLE_H
  28. #include <vector>
  29. #include <map>
  30. #include "v2math.h"
  31. #include "v3math.h"
  32. #include "v4math.h"
  33. #include "m4math.h"
  34. #include "v4coloru.h"
  35. #include "llvector4a.h"
  36. #include "llquaternion.h"
  37. #include "xform.h"
  38. #include "llmemtype.h"
  39. #include "lldarray.h"
  40. #include "llviewerobject.h"
  41. #include "llrect.h"
  42. #include "llappviewer.h" // for gFrameTimeSeconds
  43. class LLCamera;
  44. class LLDrawPool;
  45. class LLDrawable;
  46. class LLFace;
  47. class LLFacePool;
  48. class LLSpatialGroup;
  49. class LLSpatialBridge;
  50. class LLSpatialPartition;
  51. class LLVOVolume;
  52. class LLViewerTexture;
  53. // Can have multiple silhouettes for each object
  54. const U32 SILHOUETTE_HIGHLIGHT = 0;
  55. // All data for new renderer goes into this class.
  56. class LLDrawable : public LLRefCount
  57. {
  58. public:
  59. LLDrawable(const LLDrawable& rhs)
  60. {
  61. *this = rhs;
  62. }
  63. const LLDrawable& operator=(const LLDrawable& rhs)
  64. {
  65. llerrs << "Illegal operation!" << llendl;
  66. return *this;
  67. }
  68. static void initClass();
  69. LLDrawable() { init(); }
  70. MEM_TYPE_NEW(LLMemType::MTYPE_DRAWABLE);
  71. void markDead(); // Mark this drawable as dead
  72. BOOL isDead() const { return isState(DEAD); }
  73. BOOL isNew() const { return !isState(BUILT); }
  74. BOOL isLight() const;
  75. BOOL isVisible() const;
  76. BOOL isRecentlyVisible() const;
  77. virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
  78. LLViewerRegion* getRegion() const { return mVObjp->getRegion(); }
  79. const LLTextureEntry* getTextureEntry(U8 which) const { return mVObjp->getTE(which); }
  80. LLPointer<LLViewerObject>& getVObj() { return mVObjp; }
  81. const LLViewerObject *getVObj() const { return mVObjp; }
  82. LLVOVolume* getVOVolume() const; // cast mVObjp tp LLVOVolume if OK
  83. const LLMatrix4& getWorldMatrix() const { return mXform.getWorldMatrix(); }
  84. const LLMatrix4& getRenderMatrix() const;
  85. void setPosition(LLVector3 v) const { }
  86. const LLVector3& getPosition() const { return mXform.getPosition(); }
  87. const LLVector3& getWorldPosition() const { return mXform.getPositionW(); }
  88. const LLVector3 getPositionAgent() const;
  89. const LLVector4a& getPositionGroup() const { return mPositionGroup; }
  90. const LLVector3& getScale() const { return mCurrentScale; }
  91. void setScale(const LLVector3& scale) { mCurrentScale = scale; }
  92. const LLQuaternion& getWorldRotation() const { return mXform.getWorldRotation(); }
  93. const LLQuaternion& getRotation() const { return mXform.getRotation(); }
  94. F32 getIntensity() const { return llmin(mXform.getScale().mV[0], 4.f); }
  95. S32 getLOD() const { return mVObjp ? mVObjp->getLOD() : 1; }
  96. F32 getBinRadius() const { return mBinRadius; }
  97. void getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
  98. LLXformMatrix* getXform() { return &mXform; }
  99. U32 getState() const { return mState; }
  100. BOOL isState (U32 bits) const { return ((mState & bits) != 0); }
  101. void setState (U32 bits) { mState |= bits; }
  102. void clearState(U32 bits) { mState &= ~bits; }
  103. BOOL isAvatar() const { return mVObjp.notNull() && mVObjp->isAvatar(); }
  104. BOOL isRoot() const { return !mParent || mParent->isAvatar(); }
  105. BOOL isSpatialRoot() const { return !mParent || mParent->isAvatar(); }
  106. virtual BOOL isSpatialBridge() const { return FALSE; }
  107. virtual LLSpatialPartition* asPartition() { return NULL; }
  108. LLDrawable* getParent() const { return mParent; }
  109. // must set parent through LLViewerObject:: ()
  110. //BOOL setParent(LLDrawable *parent);
  111. inline LLFace* getFace(const S32 i) const;
  112. inline S32 getNumFaces() const;
  113. //void removeFace(const S32 i); // SJB: Avoid using this, it's slow
  114. LLFace* addFace(LLFacePool *poolp, LLViewerTexture *texturep);
  115. LLFace* addFace(const LLTextureEntry *te, LLViewerTexture *texturep);
  116. void deleteFaces(S32 offset, S32 count);
  117. void setNumFaces(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
  118. void setNumFacesFast(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
  119. void mergeFaces(LLDrawable* src);
  120. void init();
  121. void destroy();
  122. void update();
  123. F32 updateXform(BOOL undamped);
  124. virtual void makeActive();
  125. /*virtual*/ void makeStatic(BOOL warning_enabled = TRUE);
  126. BOOL isActive() const { return isState(ACTIVE); }
  127. BOOL isStatic() const { return !isActive(); }
  128. BOOL isAnimating() const;
  129. virtual BOOL updateMove();
  130. virtual void movePartition();
  131. void updateTexture();
  132. void updateMaterial();
  133. virtual void updateDistance(LLCamera& camera, bool force_update);
  134. BOOL updateGeometry(BOOL priority);
  135. void updateFaceSize(S32 idx);
  136. void updateSpecialHoverCursor(BOOL enabled);
  137. virtual void shiftPos(const LLVector4a &shift_vector);
  138. S32 getGeneration() const { return mGeneration; }
  139. BOOL getLit() const { return isState(UNLIT) ? FALSE : TRUE; }
  140. void setLit(BOOL lit) { lit ? clearState(UNLIT) : setState(UNLIT); }
  141. virtual void cleanupReferences();
  142. void setRadius(const F32 radius);
  143. F32 getRadius() const { return mRadius; }
  144. F32 getVisibilityRadius() const;
  145. void updateUVMinMax(); // Updates the cache of sun space bounding box.
  146. const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
  147. virtual void updateSpatialExtents();
  148. virtual void updateBinRadius();
  149. const LLVector4a* getSpatialExtents() const;
  150. void setSpatialExtents(const LLVector3& min, const LLVector3& max);
  151. void setSpatialExtents(const LLVector4a& min, const LLVector4a& max);
  152. void setPositionGroup(const LLVector4a& pos);
  153. void setRenderType(S32 type) { mRenderType = type; }
  154. BOOL isRenderType(S32 type) { return mRenderType == type; }
  155. S32 getRenderType() { return mRenderType; }
  156. // Debugging methods
  157. S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
  158. void setSpatialGroup(LLSpatialGroup *groupp);
  159. LLSpatialGroup *getSpatialGroup() const { return mSpatialGroupp; }
  160. LLSpatialPartition* getSpatialPartition();
  161. // Statics
  162. static void incrementVisible();
  163. static void cleanupDeadDrawables();
  164. protected:
  165. ~LLDrawable() { destroy(); }
  166. void moveUpdatePipeline(BOOL moved);
  167. void updatePartition();
  168. BOOL updateMoveDamped();
  169. BOOL updateMoveUndamped();
  170. public:
  171. friend class LLPipeline;
  172. friend class LLDrawPool;
  173. friend class LLSpatialBridge;
  174. typedef std::set<LLPointer<LLDrawable> > drawable_set_t;
  175. typedef std::vector<LLPointer<LLDrawable> > drawable_vector_t;
  176. typedef std::list<LLPointer<LLDrawable> > drawable_list_t;
  177. typedef std::queue<LLPointer<LLDrawable> > drawable_queue_t;
  178. struct CompareDistanceGreater
  179. {
  180. bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
  181. {
  182. return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
  183. }
  184. };
  185. struct CompareDistanceGreaterVisibleFirst
  186. {
  187. bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
  188. {
  189. if (lhs->isVisible() && !rhs->isVisible())
  190. {
  191. return TRUE; //visible things come first
  192. }
  193. else if (!lhs->isVisible() && rhs->isVisible())
  194. {
  195. return FALSE; //rhs is visible, comes first
  196. }
  197. return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
  198. }
  199. };
  200. typedef enum e_drawable_flags
  201. {
  202. IN_REBUILD_Q1 = 0x00000001,
  203. IN_REBUILD_Q2 = 0x00000002,
  204. IN_LIGHT_Q = 0x00000004,
  205. EARLY_MOVE = 0x00000008,
  206. MOVE_UNDAMPED = 0x00000010,
  207. ON_MOVE_LIST = 0x00000020,
  208. USE_BACKLIGHT = 0x00000040,
  209. UV = 0x00000080,
  210. UNLIT = 0x00000100,
  211. LIGHT = 0x00000200,
  212. LIGHTING_BUILT = 0x00000400,
  213. REBUILD_VOLUME = 0x00000800, //volume changed LOD or parameters, or vertex buffer changed
  214. REBUILD_TCOORD = 0x00001000, //texture coordinates changed
  215. REBUILD_COLOR = 0x00002000, //color changed
  216. REBUILD_POSITION= 0x00004000, //vertex positions/normals changed
  217. REBUILD_GEOMETRY= REBUILD_POSITION|REBUILD_TCOORD|REBUILD_COLOR,
  218. REBUILD_MATERIAL= REBUILD_TCOORD|REBUILD_COLOR,
  219. REBUILD_ALL = REBUILD_GEOMETRY|REBUILD_VOLUME,
  220. REBUILD_RIGGED = 0x00008000,
  221. ON_SHIFT_LIST = 0x00010000,
  222. BLOCKER = 0x00020000,
  223. ACTIVE = 0x00040000,
  224. DEAD = 0x00080000,
  225. INVISIBLE = 0x00100000, // stay invisible until flag is cleared
  226. NEARBY_LIGHT = 0x00200000, // In gPipeline.mNearbyLightSet
  227. BUILT = 0x00400000,
  228. FORCE_INVISIBLE = 0x00800000, // stay invis until CLEAR_INVISIBLE is set (set of orphaned)
  229. CLEAR_INVISIBLE = 0x01000000, // clear FORCE_INVISIBLE next draw frame
  230. REBUILD_SHADOW = 0x02000000,
  231. HAS_ALPHA = 0x04000000,
  232. RIGGED = 0x08000000,
  233. PARTITION_MOVE = 0x10000000,
  234. } EDrawableFlags;
  235. private: //aligned members
  236. LLVector4a mExtents[2];
  237. LLVector4a mPositionGroup;
  238. public:
  239. LLXformMatrix mXform;
  240. // vis data
  241. LLPointer<LLDrawable> mParent;
  242. F32 mDistanceWRTCamera;
  243. S32 mQuietCount;
  244. static S32 getCurrentFrame() { return sCurVisible; }
  245. static S32 getMinVisFrameRange();
  246. void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
  247. LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
  248. static F32 sCurPixelAngle; //current pixels per radian
  249. private:
  250. typedef std::vector<LLFace*> face_list_t;
  251. U32 mState;
  252. S32 mRenderType;
  253. LLPointer<LLViewerObject> mVObjp;
  254. face_list_t mFaces;
  255. LLSpatialGroup* mSpatialGroupp;
  256. LLPointer<LLDrawable> mSpatialBridge;
  257. mutable U32 mVisible;
  258. F32 mRadius;
  259. F32 mBinRadius;
  260. S32 mGeneration;
  261. LLVector3 mCurrentScale;
  262. static U32 sCurVisible; // Counter for what value of mVisible means currently visible
  263. static U32 sNumZombieDrawables;
  264. static LLDynamicArrayPtr<LLPointer<LLDrawable> > sDeadList;
  265. };
  266. inline LLFace* LLDrawable::getFace(const S32 i) const
  267. {
  268. //switch these asserts to llerrs -- davep
  269. //llassert((U32)i < mFaces.size());
  270. //llassert(mFaces[i]);
  271. if ((U32) i >= mFaces.size())
  272. {
  273. llerrs << "Invalid face index." << llendl;
  274. }
  275. if (!mFaces[i])
  276. {
  277. llerrs << "Null face found." << llendl;
  278. }
  279. return mFaces[i];
  280. }
  281. inline S32 LLDrawable::getNumFaces()const
  282. {
  283. return (S32)mFaces.size();
  284. }
  285. #endif