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