llface.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLFACE_H
00033 #define LL_LLFACE_H
00034 
00035 #include "llstrider.h"
00036 
00037 #include "v2math.h"
00038 #include "v3math.h"
00039 #include "v4math.h"
00040 #include "m4math.h"
00041 #include "v4coloru.h"
00042 #include "llquaternion.h"
00043 #include "xform.h"
00044 #include "lldarrayptr.h"
00045 #include "llvertexbuffer.h"
00046 #include "llviewerimage.h"
00047 #include "llstat.h"
00048 #include "lldrawable.h"
00049 
00050 class LLFacePool;
00051 class LLVolume;
00052 class LLViewerImage;
00053 class LLTextureEntry;
00054 class LLVertexProgram;
00055 class LLViewerImage;
00056 class LLGeometryManager;
00057 
00058 const F32 MIN_ALPHA_SIZE = 1024.f;
00059 const F32 MIN_TEX_ANIM_SIZE = 512.f;
00060 
00061 class LLFace
00062 {
00063 public:
00064 
00065         enum EMasks
00066         {
00067                 LIGHT                   = 0x0001,
00068                 GLOBAL                  = 0x0002,
00069                 FULLBRIGHT              = 0x0004,
00070                 HUD_RENDER              = 0x0008,
00071                 USE_FACE_COLOR  = 0x0010,
00072                 TEXTURE_ANIM    = 0x0020, 
00073         };
00074 
00075         static void initClass();
00076 
00077 public:
00078         LLFace(LLDrawable* drawablep, LLViewerObject* objp)   { init(drawablep, objp); }
00079         ~LLFace()  { destroy(); }
00080 
00081         const LLMatrix4& getWorldMatrix()       const   { return mVObjp->getWorldMatrix(mXform); }
00082         const LLMatrix4& getRenderMatrix() const;
00083         U32                             getIndicesCount()       const   { return mIndicesCount; };
00084         S32                             getIndicesStart()       const   { return mIndicesIndex; };
00085         U16                             getGeomCount()          const   { return mGeomCount; }          // vertex count for this face
00086         U16                             getGeomIndex()          const   { return mGeomIndex; }          // index into draw pool
00087         U16                             getGeomStart()          const   { return mGeomIndex; }          // index into draw pool
00088         LLViewerImage*  getTexture()            const   { return mTexture; }
00089         void                    setTexture(LLViewerImage* tex) { mTexture = tex; }
00090         LLXformMatrix*  getXform()                      const   { return mXform; }
00091         BOOL                    hasGeometry()           const   { return mGeomCount > 0; }
00092         LLVector3               getPositionAgent()      const;
00093         
00094         U32                             getState()                      const   { return mState; }
00095         void                    setState(U32 state)                     { mState |= state; }
00096         void                    clearState(U32 state)           { mState &= ~state; }
00097         BOOL                    isState(U32 state)      const   { return ((mState & state) != 0) ? TRUE : FALSE; }
00098         void                    setVirtualSize(F32 size) { mVSize = size; }
00099         void                    setPixelArea(F32 area)  { mPixelArea = area; }
00100         F32                             getVirtualSize() const { return mVSize; }
00101         F32                             getPixelArea() const { return mPixelArea; }
00102         void                    bindTexture(S32 stage = 0)              const   { LLViewerImage::bindTexture(mTexture, stage); }
00103 
00104         void                    renderSetColor() const;
00105         S32                             renderElements(const U16 *index_array) const;
00106         S32                             renderIndexed ();
00107         S32                             renderIndexed (U32 mask);
00108         S32                             pushVertices(const U16* index_array) const;
00109         
00110         void                    setWorldMatrix(const LLMatrix4& mat);
00111         const LLTextureEntry* getTextureEntry() const { return mVObjp->getTE(mTEOffset); }
00112 
00113         LLFacePool*             getPool()                       const   { return mDrawPoolp; }
00114         U32                             getPoolType()           const   { return mPoolType; }
00115         LLDrawable*             getDrawable()           const   { return mDrawablep; }
00116         LLViewerObject* getViewerObject()       const   { return mVObjp; }
00117         S32                             getLOD()                        const   { return mVObjp.notNull() ? mVObjp->getLOD() : 0; }
00118         LLVertexBuffer* getVertexBuffer()       const   { return mVertexBuffer; }
00119         void                    setPoolType(U32 type)           { mPoolType = type; }
00120         S32                             getTEOffset()                           { return mTEOffset; }
00121 
00122         void                    setViewerObject(LLViewerObject* object);
00123         void                    setPool(LLFacePool *pool, LLViewerImage *texturep);
00124         
00125         void                    setDrawable(LLDrawable *drawable);
00126         void                    setTEOffset(const S32 te_offset);
00127         
00128 
00129         void                    setFaceColor(const LLColor4& color); // override material color
00130         void                    unsetFaceColor(); // switch back to material color
00131         const LLColor4& getFaceColor() const { return mFaceColor; } 
00132         const LLColor4& getRenderColor() const;
00133         
00134         //for volumes
00135         BOOL getGeometryVolume(const LLVolume& volume,
00136                                                 const S32 &f,
00137                                                 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal,
00138                                                 const U16 &index_offset);
00139 
00140         // For avatar
00141         U16                      getGeometryAvatar(
00142                                                                         LLStrider<LLVector3> &vertices,
00143                                                                         LLStrider<LLVector3> &normals,
00144                                                                     LLStrider<LLVector2> &texCoords,
00145                                                                         LLStrider<F32>           &vertex_weights,
00146                                                                         LLStrider<LLVector4> &clothing_weights);
00147 
00148         // For volumes, etc.
00149         U16                             getGeometry(LLStrider<LLVector3> &vertices,  
00150                                                                 LLStrider<LLVector3> &normals,
00151                                                                 LLStrider<LLVector2> &texCoords, 
00152                                                                 LLStrider<U16>  &indices);
00153 
00154         S32 getColors(LLStrider<LLColor4U> &colors);
00155         S32 getIndices(LLStrider<U16> &indices);
00156 
00157         void            setSize(const S32 numVertices, const S32 num_indices = 0);
00158         
00159         BOOL            genVolumeBBoxes(const LLVolume &volume, S32 f,
00160                                                                    const LLMatrix4& mat, const LLMatrix3& inv_trans_mat, BOOL global_volume = FALSE);
00161         
00162         void            init(LLDrawable* drawablep, LLViewerObject* objp);
00163         void            destroy();
00164         void            update();
00165 
00166         void            updateCenterAgent(); // Update center when xform has changed.
00167         void            renderSelectedUV(const S32 offset = 0, const S32 count = 0);
00168 
00169         void            renderForSelect(U32 data_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD);
00170         void            renderSelected(LLImageGL *image, const LLColor4 &color);
00171 
00172         F32                     getKey()                                        const   { return mDistance; }
00173 
00174         S32                     getReferenceIndex()             const   { return mReferenceIndex; }
00175         void            setReferenceIndex(const S32 index)      { mReferenceIndex = index; }
00176 
00177         BOOL            verify(const U32* indices_array = NULL) const;
00178         void            printDebugInfo() const;
00179 
00180         void            setGeomIndex(U16 idx) { mGeomIndex = idx; }
00181         void            setIndicesIndex(S32 idx) { mIndicesIndex = idx; }
00182         
00183 protected:
00184 
00185 public:
00186         LLVector3               mCenterLocal;
00187         LLVector3               mCenterAgent;
00188         LLVector3               mExtents[2];
00189         LLVector2               mTexExtents[2];
00190         F32                             mDistance;
00191         LLPointer<LLVertexBuffer> mVertexBuffer;
00192         LLPointer<LLVertexBuffer> mLastVertexBuffer;
00193         F32                     mLastUpdateTime;
00194         F32                     mLastMoveTime;
00195         LLMatrix4*      mTextureMatrix;
00196 
00197 protected:
00198         friend class LLGeometryManager;
00199         friend class LLVolumeGeometryManager;
00200 
00201         U32                     mState;
00202         LLFacePool*     mDrawPoolp;
00203         U32                     mPoolType;
00204         LLColor4        mFaceColor;                     // overrides material color if state |= USE_FACE_COLOR
00205         
00206         U16                     mGeomCount;                     // vertex count for this face
00207         U16                     mGeomIndex;                     // index into draw pool
00208         U32                     mIndicesCount;
00209         U32                     mIndicesIndex;          // index into draw pool for indices (yeah, I know!)
00210 
00211         //previous rebuild's geometry info
00212         U16                     mLastGeomCount;
00213         U16                     mLastGeomIndex;
00214         U32                     mLastIndicesCount;
00215         U32                     mLastIndicesIndex;
00216 
00217         LLXformMatrix* mXform;
00218         LLPointer<LLViewerImage> mTexture;
00219         LLPointer<LLDrawable> mDrawablep;
00220         LLPointer<LLViewerObject> mVObjp;
00221         S32                     mTEOffset;
00222 
00223         S32                     mReferenceIndex;
00224         F32                     mVSize;
00225         F32                     mPixelArea;
00226         
00227 protected:
00228         static BOOL     sSafeRenderSelect;
00229         
00230 public:
00231         struct CompareDistanceGreater
00232         {
00233                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00234                 {
00235                         return lhs->mDistance > rhs->mDistance; // farthest = first
00236                 }
00237         };
00238         
00239         struct CompareTexture
00240         {
00241                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00242                 {
00243                         return lhs->getTexture() < rhs->getTexture();
00244                 }
00245         };
00246 
00247         struct CompareBatchBreaker
00248         {
00249                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00250                 {
00251                         const LLTextureEntry* lte = lhs->getTextureEntry();
00252                         const LLTextureEntry* rte = rhs->getTextureEntry();
00253 
00254                         if (lhs->getTexture() != rhs->getTexture())
00255                         {
00256                                 return lhs->getTexture() < rhs->getTexture();
00257                         }
00258                         else if (lte->getBumpShinyFullbright() != rte->getBumpShinyFullbright())
00259                         {
00260                                 return lte->getBumpShinyFullbright() < rte->getBumpShinyFullbright();
00261                         }
00262                         else 
00263                         {
00264                                 return lte->getGlow() < rte->getGlow();
00265                         }
00266                 }
00267         };
00268 
00269         struct CompareTextureAndGeomCount
00270         {
00271                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00272                 {
00273                         return lhs->getTexture() == rhs->getTexture() ? 
00274                                 lhs->getGeomCount() < rhs->getGeomCount() :  //smallest = first
00275                                 lhs->getTexture() > rhs->getTexture();
00276                 }
00277         };
00278 
00279         struct CompareTextureAndLOD
00280         {
00281                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00282                 {
00283                         return lhs->getTexture() == rhs->getTexture() ? 
00284                                 lhs->getLOD() < rhs->getLOD() :
00285                                 lhs->getTexture() < rhs->getTexture();
00286                 }
00287         };
00288 
00289         struct CompareTextureAndTime
00290         {
00291                 bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
00292                 {
00293                         return lhs->getTexture() == rhs->getTexture() ? 
00294                                 lhs->mLastUpdateTime < rhs->mLastUpdateTime :
00295                                 lhs->getTexture() < rhs->getTexture();
00296                 }
00297         };
00298 };
00299 
00300 #endif // LL_LLFACE_H

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