lldrawable.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_DRAWABLE_H
00033 #define LL_DRAWABLE_H
00034 
00035 #include <vector>
00036 #include <map>
00037 
00038 #include "v2math.h"
00039 #include "v3math.h"
00040 #include "v4math.h"
00041 #include "m4math.h"
00042 #include "v4coloru.h"
00043 #include "llquaternion.h"
00044 #include "xform.h"
00045 #include "llmemtype.h"
00046 #include "llprimitive.h"
00047 #include "lldarray.h"
00048 #include "llstat.h"
00049 #include "llviewerobject.h"
00050 #include "llrect.h"
00051 #include "llappviewer.h" // for gFrameTimeSeconds
00052 
00053 class LLCamera;
00054 class LLDrawPool;
00055 class LLDrawable;
00056 class LLFace;
00057 class LLSpatialGroup;
00058 class LLSpatialBridge;
00059 class LLSpatialPartition;
00060 class LLVOVolume;
00061 class LLViewerImage;
00062 
00063 // Can have multiple silhouettes for each object
00064 const U32 SILHOUETTE_HIGHLIGHT = 0;
00065 
00066 
00067 // All data for new renderer goes into this class.
00068 class LLDrawable : public LLRefCount
00069 {
00070 public:
00071         static void initClass();
00072 
00073         LLDrawable()                            { init(); }
00074         MEM_TYPE_NEW(LLMemType::MTYPE_DRAWABLE);
00075         
00076         void markDead();                        // Mark this drawable as dead
00077         BOOL isDead() const                     { return isState(DEAD); }
00078         BOOL isNew() const                      { return !isState(BUILT); }
00079 
00080         BOOL isLight() const;
00081 
00082         BOOL isVisible() const;         
00083         virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
00084 
00085 
00086         LLViewerRegion* getRegion()               const { return mVObjp->getRegion(); }
00087         const LLTextureEntry* getTextureEntry(U8 which) const { return mVObjp->getTE(which); }
00088         LLPointer<LLViewerObject>& getVObj()                                                      { return mVObjp; }
00089         const LLViewerObject *getVObj() const                                             { return mVObjp; }
00090         LLVOVolume*     getVOVolume() const; // cast mVObjp tp LLVOVolume if OK
00091 
00092         const LLMatrix4&      getWorldMatrix() const            { return mXform.getWorldMatrix(); }
00093         const LLMatrix4&          getRenderMatrix() const               { return isRoot() ? getWorldMatrix() : getParent()->getWorldMatrix(); }
00094         void                              setPosition(LLVector3 v) const { }
00095         const LLVector3&          getPosition() const                   { return mXform.getPosition(); }
00096         const LLVector3&      getWorldPosition() const          { return mXform.getPositionW(); }
00097         const LLVector3           getPositionAgent() const;
00098         const LLVector3d&         getPositionGroup() const              { return mPositionGroup; }
00099         const LLVector3&          getScale() const                              { return mCurrentScale; }
00100         const LLQuaternion&   getWorldRotation() const          { return mXform.getWorldRotation(); }
00101         const LLQuaternion&   getRotation() const                       { return mXform.getRotation(); }
00102         F32                               getIntensity() const                  { return llmin(mXform.getScale().mV[0], 4.f); }
00103         S32                                       getLOD() const                                { return mVObjp ? mVObjp->getLOD() : 1; }
00104         F64                                       getBinRadius() const                  { return mBinRadius; }
00105         void  getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
00106         LLXformMatrix*          getXform() { return &mXform; }
00107 
00108         U32                                     getState()           const { return mState; }
00109         BOOL                            isState   (U32 bits) const { return ((mState & bits) != 0); }
00110         void                setState  (U32 bits)       { mState |= bits; }
00111         void                clearState(U32 bits)       { mState &= ~bits; }
00112 
00113         BOOL                            isAvatar()      const                   { return mVObjp.notNull() && mVObjp->isAvatar(); }
00114         BOOL                            isRoot() const                          { return !mParent || mParent->isAvatar(); }
00115         BOOL                            isSpatialRoot() const           { return !mParent || mParent->isAvatar(); }
00116         virtual BOOL            isSpatialBridge() const         { return FALSE; }
00117         virtual LLSpatialPartition* asPartition()               { return NULL; }
00118         LLDrawable*                     getParent() const                       { return mParent; }
00119         LLDrawable*                     getChild(U32 index)                     { return mVObjp->mChildList[index]->mDrawable; }
00120         U32                                     getChildCount()                         { return mVObjp ? mVObjp->mChildList.size() : 0; }
00121         
00122         // must set parent through LLViewerObject::             ()
00123         //BOOL                setParent(LLDrawable *parent);
00124         
00125         inline LLFace*      getFace(const S32 i) const;
00126         inline S32                      getNumFaces()            const;
00127 
00128         //void                removeFace(const S32 i); // SJB: Avoid using this, it's slow
00129         LLFace*                         addFace(LLFacePool *poolp, LLViewerImage *texturep);
00130         LLFace*                         addFace(const LLTextureEntry *te, LLViewerImage *texturep);
00131         void                            deleteFaces(S32 offset, S32 count);
00132         void                setNumFaces(const S32 numFaces, LLFacePool *poolp, LLViewerImage *texturep);
00133         void                setNumFacesFast(const S32 numFaces, LLFacePool *poolp, LLViewerImage *texturep);
00134         void                            mergeFaces(LLDrawable* src);
00135 
00136         void init();
00137         void destroy();
00138 
00139         void update();
00140         F32 updateXform(BOOL undamped);
00141 
00142         virtual void makeActive();
00143         /*virtual*/ void makeStatic(BOOL warning_enabled = TRUE);
00144 
00145         BOOL isActive() const                                                   { return isState(ACTIVE); }
00146         BOOL isStatic() const                                                   { return !isActive(); }
00147         BOOL isAnimating() const;
00148 
00149         virtual BOOL updateMove();
00150         virtual void movePartition();
00151         
00152         void updateTexture();
00153         void updateMaterial();
00154         virtual void updateDistance(LLCamera& camera);
00155         BOOL updateGeometry(BOOL priority);
00156         void updateFaceSize(S32 idx);
00157                 
00158         void updateSpecialHoverCursor(BOOL enabled);
00159 
00160         virtual void shiftPos(const LLVector3 &shift_vector);
00161 
00162         S32 getGeneration() const                                       { return mGeneration; }
00163 
00164         BOOL getLit() const                                                     { return isState(UNLIT) ? FALSE : TRUE; }
00165         void setLit(BOOL lit)                                           { lit ? clearState(UNLIT) : setState(UNLIT); }
00166 
00167         virtual void cleanupReferences();
00168 
00169         void setRadius(const F32 radius);
00170         F32 getRadius() const                                           { return mRadius; }
00171         F32 getVisibilityRadius() const;
00172 
00173         void updateUVMinMax();  // Updates the cache of sun space bounding box.
00174 
00175         const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
00176         virtual void updateSpatialExtents();
00177         virtual void updateBinRadius();
00178         const LLVector3* getSpatialExtents() const;
00179         void setSpatialExtents(LLVector3 min, LLVector3 max);
00180         void setPositionGroup(const LLVector3d& pos);
00181         void setPositionGroup(const LLVector3& pos) { setPositionGroup(LLVector3d(pos)); }
00182 
00183         void setRenderType(S32 type)                            { mRenderType = type; }
00184         BOOL isRenderType(S32 type)                             { return mRenderType == type; }
00185         S32  getRenderType()                                            { return mRenderType; }
00186         
00187         // Debugging methods
00188         S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
00189 
00190         void setSpatialGroup(LLSpatialGroup *groupp);
00191         LLSpatialGroup *getSpatialGroup() const                 { return mSpatialGroupp; }
00192         LLSpatialPartition* getSpatialPartition();
00193         
00194         // Statics
00195         static void incrementVisible();
00196         static void cleanupDeadDrawables();
00197 
00198 protected:
00199         ~LLDrawable() { destroy(); }
00200         void moveUpdatePipeline(BOOL moved);
00201         void updatePartition();
00202         BOOL updateMoveDamped();
00203         BOOL updateMoveUndamped();
00204         
00205 public:
00206         friend class LLPipeline;
00207         friend class LLDrawPool;
00208         friend class LLSpatialBridge;
00209         
00210         typedef std::set<LLPointer<LLDrawable> > drawable_set_t;
00211         typedef std::vector<LLPointer<LLDrawable> > drawable_vector_t;
00212         typedef std::list<LLPointer<LLDrawable> > drawable_list_t;
00213         typedef std::queue<LLPointer<LLDrawable> > drawable_queue_t;
00214         
00215         struct CompareDistanceGreater
00216         {
00217                 bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
00218                 {
00219                         return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
00220                 }
00221         };
00222 
00223         struct CompareDistanceGreaterVisibleFirst
00224         {
00225                 bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
00226                 {
00227                         if (lhs->isVisible() && !rhs->isVisible())
00228                         {
00229                                 return TRUE; //visible things come first
00230                         }
00231                         else if (!lhs->isVisible() && rhs->isVisible())
00232                         {
00233                                 return FALSE; //rhs is visible, comes first
00234                         }
00235                         
00236                         return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
00237                 }
00238         };
00239         
00240         typedef enum e_drawable_flags
00241         {
00242                 IN_REBUILD_Q1   = 0x00000002,
00243                 IN_REBUILD_Q2   = 0x00000004,
00244                 IN_LIGHT_Q              = 0x00000008,
00245                 EARLY_MOVE              = 0x00000010,
00246                 MOVE_UNDAMPED   = 0x00000020,
00247                 ON_MOVE_LIST    = 0x00000040,
00248                 USE_BACKLIGHT   = 0x00000080,
00249                 UV                              = 0x00000100,
00250                 UNLIT                   = 0x00000200,
00251                 LIGHT                   = 0x00000400,
00252                 LIGHTING_BUILT  = 0x00000800,
00253                 REBUILD_VOLUME  = 0x00001000,   //volume changed LOD or parameters, or vertex buffer changed
00254                 REBUILD_TCOORD  = 0x00002000,   //texture coordinates changed
00255                 REBUILD_COLOR   = 0x00004000,   //color changed
00256                 REBUILD_POSITION= 0x00010000,   //vertex positions/normals changed
00257                 REBUILD_GEOMETRY= REBUILD_POSITION|REBUILD_TCOORD|REBUILD_COLOR,
00258                 REBUILD_MATERIAL= REBUILD_TCOORD|REBUILD_COLOR,
00259                 REBUILD_ALL             = REBUILD_GEOMETRY|REBUILD_VOLUME,
00260                 ON_SHIFT_LIST   = 0x00100000,
00261                 BLOCKER                 = 0x00400000,
00262                 ACTIVE                  = 0x00800000,
00263                 DEAD                    = 0x01000000,
00264                 INVISIBLE               = 0x02000000, // stay invisible until flag is cleared
00265                 NEARBY_LIGHT    = 0x04000000, // In gPipeline.mNearbyLightSet
00266                 BUILT                   = 0x08000000,
00267                 FORCE_INVISIBLE = 0x10000000, // stay invis until CLEAR_INVISIBLE is set (set of orphaned)
00268                 CLEAR_INVISIBLE = 0x20000000, // clear FORCE_INVISIBLE next draw frame
00269                 REBUILD_SHADOW =  0x40000000
00270         } EDrawableFlags;
00271 
00272         LLXformMatrix       mXform;
00273 
00274         // vis data
00275         LLPointer<LLDrawable> mParent;
00276 
00277         F32                             mDistanceWRTCamera;
00278         
00279         S32                             mQuietCount;
00280 
00281         static S32 getCurrentFrame() { return sCurVisible; }
00282         
00283         void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
00284         LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
00285         
00286         static F32 sCurPixelAngle; //current pixels per radian
00287 
00288 private:
00289         typedef std::vector<LLFace*> face_list_t;
00290         
00291         U32                             mState;
00292         S32                             mRenderType;
00293         LLPointer<LLViewerObject> mVObjp;
00294         face_list_t     mFaces;
00295         LLSpatialGroup* mSpatialGroupp;
00296         LLPointer<LLDrawable> mSpatialBridge;
00297         
00298         mutable U32             mVisible;
00299         F32                             mRadius;
00300         LLVector3               mExtents[2];
00301         LLVector3d              mPositionGroup;
00302         F64                             mBinRadius;
00303         S32                             mGeneration;
00304 
00305         LLVector3               mCurrentScale;
00306         
00307         static U32 sCurVisible; // Counter for what value of mVisible means currently visible
00308 
00309         static U32 sNumZombieDrawables;
00310         static LLDynamicArrayPtr<LLPointer<LLDrawable> > sDeadList;
00311 };
00312 
00313 
00314 inline LLFace* LLDrawable::getFace(const S32 i) const
00315 {
00316         llassert((U32)i < mFaces.size());
00317         llassert(mFaces[i]);
00318         return mFaces[i];
00319 }
00320 
00321 
00322 inline S32 LLDrawable::getNumFaces()const
00323 {
00324         return (S32)mFaces.size();
00325 }
00326 
00327 #endif

Generated on Fri May 16 08:33:17 2008 for SecondLife by  doxygen 1.5.5