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

Generated on Thu Jul 1 06:08:25 2010 for Second Life Viewer by  doxygen 1.4.7