lltexlayer.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLTEXLAYER_H
00033 #define LL_LLTEXLAYER_H
00034 
00035 #include <deque>
00036 #include "llassetstorage.h"
00037 #include "lldynamictexture.h"
00038 #include "llrect.h"
00039 #include "llstring.h"
00040 #include "lluuid.h"
00041 #include "llviewerimage.h"
00042 #include "llviewervisualparam.h"
00043 #include "llvoavatar.h"
00044 #include "llwearable.h"
00045 #include "v4color.h"
00046 #include "llfloater.h"
00047 
00048 class LLTexLayerSetInfo;
00049 class LLTexLayerSet;
00050 class LLTexLayerInfo;
00051 class LLTexLayer;
00052 class LLImageGL;
00053 class LLImageTGA;
00054 class LLTexGlobalColorInfo;
00055 class LLTexLayerParamAlphaInfo;
00056 class LLTexLayerParamAlpha;
00057 class LLTexParamColorInfo;
00058 class LLTexParamColor;
00059 class LLPolyMesh;
00060 class LLXmlTreeNode;
00061 class LLImageRaw;
00062 class LLPolyMorphTarget;
00063 
00064 class LLTextureCtrl;
00065 class LLVOAvatar;
00066 
00067 
00068 enum EColorOperation
00069 {
00070         OP_ADD = 0,
00071         OP_MULTIPLY = 1,
00072         OP_BLEND = 2,
00073         OP_COUNT = 3 // Number of operations
00074 };
00075 
00076 
00077 //-----------------------------------------------------------------------------
00078 // LLTexLayerParamAlphaInfo
00079 //-----------------------------------------------------------------------------
00080 class LLTexLayerParamAlphaInfo : public LLViewerVisualParamInfo
00081 {
00082         friend class LLTexLayerParamAlpha;
00083 public:
00084         LLTexLayerParamAlphaInfo();
00085         /*virtual*/ ~LLTexLayerParamAlphaInfo() {};
00086 
00087         /*virtual*/ BOOL parseXml(LLXmlTreeNode* node);
00088 
00089 protected:
00090         LLString                                mStaticImageFileName;
00091         BOOL                                    mMultiplyBlend;
00092         BOOL                                    mSkipIfZeroWeight;
00093         F32                                             mDomain;
00094 };
00095 
00096 //-----------------------------------------------------------------------------
00097 // LLTexParamColorInfo
00098 //-----------------------------------------------------------------------------
00099 class LLTexParamColorInfo : public LLViewerVisualParamInfo
00100 {
00101         friend class LLTexParamColor;
00102 
00103 public:
00104         LLTexParamColorInfo();
00105         virtual ~LLTexParamColorInfo() {};
00106         BOOL parseXml( LLXmlTreeNode* node );
00107                 
00108 protected:
00109         enum { MAX_COLOR_VALUES = 20 };
00110         EColorOperation         mOperation;
00111         LLColor4                        mColors[MAX_COLOR_VALUES];
00112         S32                                     mNumColors;
00113 };
00114 
00115 //-----------------------------------------------------------------------------
00116 // LLTexGlobalColorInfo
00117 //-----------------------------------------------------------------------------
00118 class LLTexGlobalColorInfo
00119 {
00120         friend class LLTexGlobalColor;
00121 public:
00122         LLTexGlobalColorInfo();
00123         ~LLTexGlobalColorInfo();
00124 
00125         BOOL parseXml(LLXmlTreeNode* node);
00126         
00127 protected:
00128         typedef std::vector<LLTexParamColorInfo *> color_info_list_t;
00129         color_info_list_t               mColorInfoList;
00130         LLString                                mName;
00131 };
00132 
00133 //-----------------------------------------------------------------------------
00134 // LLTexLayerSetInfo
00135 // Containes shared layer set data
00136 //-----------------------------------------------------------------------------
00137 class LLTexLayerSetInfo
00138 {
00139         friend class LLTexLayerSet;
00140 public:
00141         LLTexLayerSetInfo();
00142         ~LLTexLayerSetInfo();
00143         
00144         BOOL parseXml(LLXmlTreeNode* node);
00145 
00146 protected:
00147         LLString                                mBodyRegion;
00148         S32                                             mWidth;
00149         S32                                             mHeight;
00150         LLString                                mStaticAlphaFileName;
00151         BOOL                                    mClearAlpha;            // Set alpha to 1 for this layerset (if there is no mStaticAlphaFileName)
00152         
00153         typedef std::vector<LLTexLayerInfo*> layer_info_list_t;
00154         layer_info_list_t               mLayerInfoList;
00155 };
00156 
00157 //-----------------------------------------------------------------------------
00158 // LLTexLayerInfo
00159 //-----------------------------------------------------------------------------
00160 enum ERenderPass 
00161 {
00162         RP_COLOR,
00163         RP_BUMP,
00164         RP_SHINE
00165 };
00166 
00167 class LLTexLayerInfo
00168 {
00169         friend class LLTexLayer;
00170 public:
00171         LLTexLayerInfo();
00172         ~LLTexLayerInfo();
00173 
00174         BOOL parseXml(LLXmlTreeNode* node);
00175 
00176 protected:
00177         LLString                                mName;
00178         
00179         BOOL                                    mWriteAllChannels;  // Don't use masking.  Just write RGBA into buffer,
00180         ERenderPass                             mRenderPass;
00181 
00182         LLString                                mGlobalColor;
00183         LLColor4                                mFixedColor;
00184 
00185         S32                                             mLocalTexture;
00186         LLString                                mStaticImageFileName;
00187         BOOL                                    mStaticImageIsMask;
00188         BOOL                                    mUseLocalTextureAlphaOnly;      // Ignore RGB channels from the input texture.  Use alpha as a mask
00189 
00190         typedef std::vector<std::pair<LLString,BOOL> > morph_name_list_t;
00191         morph_name_list_t               mMorphNameList;
00192 
00193         typedef std::vector<LLTexParamColorInfo*> color_info_list_t;
00194         color_info_list_t               mColorInfoList;
00195 
00196         typedef std::vector<LLTexLayerParamAlphaInfo*> alpha_info_list_t;
00197         alpha_info_list_t               mAlphaInfoList;
00198         
00199 };
00200 
00201 //-----------------------------------------------------------------------------
00202 // LLTexLayerSetBuffer
00203 // The composite image that a LLTexLayerSet writes to.  Each LLTexLayerSet has one.
00204 //-----------------------------------------------------------------------------
00205 class LLTexLayerSetBuffer : public LLDynamicTexture
00206 {
00207 public:
00208         LLTexLayerSetBuffer( LLTexLayerSet*     owner, S32 width, S32 height, BOOL has_bump );
00209         virtual ~LLTexLayerSetBuffer();
00210 
00211         virtual void                    preRender(BOOL clear_depth);
00212         virtual void                    postRender(BOOL success);
00213         virtual BOOL                    render();
00214         BOOL                                    updateImmediate();
00215         virtual void                    bindTexture();
00216         void                                    bindBumpTexture( U32 stage );
00217         BOOL                                    isInitialized()                                                 { return mInitialized; }  // Initialized here means that we've done at least one render
00218         BOOL                                    needsRender();
00219         void                                    requestUpdate();
00220         void                                    requestUpload();
00221         void                                    cancelUpload();
00222         BOOL                                    uploadPending() { return mUploadPending; }
00223         BOOL                                    render( S32 x, S32 y, S32 width, S32 height );
00224         void                                    readBackAndUpload(U8* baked_bump_data);
00225         static void                             onTextureUploadComplete( const LLUUID& uuid,
00226                                                                                                          void* userdata,
00227                                                                                                          S32 result, LLExtStat ext_status);
00228         static void                             dumpTotalByteCount();
00229 
00230 private:
00231         void                                    pushProjection();
00232         void                                    popProjection();
00233 
00234 private:
00235         BOOL                                    mNeedsUpdate;
00236         BOOL                                    mNeedsUpload;
00237         BOOL                                    mUploadPending;
00238         LLUUID                                  mUploadID;              // Identifys the current upload process (null if none).  Used to avoid overlaps (eg, when the user rapidly makes two changes outside of Face Edit)
00239         LLTexLayerSet*                  mTexLayerSet;
00240         BOOL                                    mInitialized;
00241         LLGLuint                                mBumpTexName;   // zero if none
00242 
00243         static S32                              sGLByteCount;
00244         static S32                              sGLBumpByteCount;
00245 };
00246 
00247 //-----------------------------------------------------------------------------
00248 // LLTexLayerSet
00249 // An ordered set of texture layers that get composited into a single texture.
00250 //-----------------------------------------------------------------------------
00251 class LLTexLayerSet
00252 {
00253 public:
00254         LLTexLayerSet( LLVOAvatar* avatar );
00255         ~LLTexLayerSet();
00256 
00257         //BOOL                                  parseData(LLXmlTreeNode* node);
00258         LLTexLayerSetInfo*              getInfo() const { return mInfo; }
00259         //   This sets mInfo and calls initialization functions
00260         BOOL                                    setInfo(LLTexLayerSetInfo *info);
00261         
00262         BOOL                                    render( S32 x, S32 y, S32 width, S32 height );
00263         BOOL                                    renderBump( S32 x, S32 y, S32 width,S32 height );
00264         BOOL                                    isBodyRegion( const char* region )              { return mInfo->mBodyRegion == region; }
00265         LLTexLayerSetBuffer*    getComposite();
00266         void                                    requestUpdate();
00267         void                                    requestUpload();
00268         void                                    cancelUpload();
00269         LLVOAvatar*                             getAvatar()                                                             { return mAvatar; }
00270         void                                    updateComposite();
00271         BOOL                                    isLocalTextureDataAvailable();
00272         BOOL                                    isLocalTextureDataFinal();
00273         void                                    createComposite();
00274         void                                    destroyComposite();
00275         void                                    setUpdatesEnabled( BOOL b );
00276         BOOL                                    getUpdatesEnabled()                                             { return mUpdatesEnabled; }
00277         void                                    deleteCaches();
00278         void                                    gatherAlphaMasks(U8 *data, S32 width, S32 height);
00279         void                                    applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
00280         const LLString&                 getBodyRegion()                                 { return mInfo->mBodyRegion; }
00281         BOOL                                    hasComposite()                                  { return (mComposite != NULL); }
00282         void                                    setBump( BOOL b )                               { mHasBump = b; }
00283         BOOL                                    hasBump()                                               { return mHasBump; }
00284 
00285 public:
00286         static BOOL             sHasCaches;
00287 
00288 protected:
00289         typedef std::vector<LLTexLayer *> layer_list_t;
00290         layer_list_t                    mLayerList;
00291         LLTexLayerSetBuffer*    mComposite;
00292         // Backlink only; don't make this an LLPointer.
00293         LLVOAvatar*                             mAvatar;
00294         BOOL                                    mUpdatesEnabled;
00295         BOOL                                    mHasBump;
00296 
00297         LLTexLayerSetInfo               *mInfo;
00298 };
00299 
00300 //-----------------------------------------------------------------------------
00301 // LLMaskedMorph
00302 //-----------------------------------------------------------------------------
00303 
00304 class LLMaskedMorph
00305 {
00306 public:
00307         LLMaskedMorph( LLPolyMorphTarget *morph_target, BOOL invert );
00308         
00309 public:
00310         LLPolyMorphTarget       *mMorphTarget;
00311         BOOL                            mInvert;
00312 };
00313 
00314 //-----------------------------------------------------------------------------
00315 // LLTexLayer
00316 // A single texture layer
00317 //-----------------------------------------------------------------------------
00318 class LLTexLayer
00319 {
00320 public:
00321         LLTexLayer( LLTexLayerSet* layer_set );
00322         ~LLTexLayer();
00323 
00324         //BOOL                                  parseData(LLXmlTreeNode* node);
00325         LLTexLayerInfo*                 getInfo() const { return mInfo; }
00326         //   This sets mInfo and calls initialization functions
00327         BOOL                                    setInfo(LLTexLayerInfo *info);
00328         
00329         BOOL                                    render( S32 x, S32 y, S32 width, S32 height );
00330         void                                    requestUpdate();
00331         LLTexLayerSet*                  getTexLayerSet()                                                { return mTexLayerSet; }
00332 
00333         const std::string&              getName()                                                               { return mInfo->mName; }
00334 
00335         void                                    addMaskedMorph(LLPolyMorphTarget* morph_target, BOOL invert);
00336         void                                    deleteCaches();
00337         U8*                                             getAlphaData();
00338         void                                    applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
00339 
00340         void                                    invalidateMorphMasks();
00341         ERenderPass                             getRenderPass()                                                 { return mInfo->mRenderPass; }
00342         const LLString&                 getGlobalColor()                                                { return mInfo->mGlobalColor; }
00343         BOOL                                    findNetColor( LLColor4* color );
00344         BOOL                                    renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 in_components, S32 width, S32 height, BOOL is_mask );
00345         BOOL                                    renderAlphaMasks(  S32 x, S32 y, S32 width, S32 height, LLColor4* colorp );
00346         BOOL                                    hasAlphaParams() { return (!mParamAlphaList.empty());}
00347 
00348 protected:
00349         LLTexLayerSet*                  mTexLayerSet;
00350         LLPointer<LLImageRaw>   mStaticImageRaw;
00351 
00352         // Layers can have either mParamColorList, mGlobalColor, or mFixedColor.  They are looked for in that order.
00353         typedef std::vector<LLTexParamColor *> color_list_t;
00354         color_list_t                    mParamColorList;
00355         //                                              mGlobalColor name stored in mInfo
00356         //                                              mFixedColor value stored in mInfo
00357 
00358         typedef std::vector<LLTexLayerParamAlpha *> alpha_list_t;
00359         alpha_list_t                    mParamAlphaList;
00360         
00361         
00362         typedef std::deque<LLMaskedMorph> morph_list_t;
00363         morph_list_t                    mMaskedMorphs;
00364         typedef std::map<U32, U8*> alpha_cache_t;
00365         alpha_cache_t                   mAlphaCache;
00366         BOOL                                    mMorphMasksValid;
00367         BOOL                                    mStaticImageInvalid;
00368 
00369         LLTexLayerInfo                  *mInfo;
00370 };
00371 
00372 //-----------------------------------------------------------------------------
00373 // LLTexLayerParamAlpha
00374 //-----------------------------------------------------------------------------
00375 class LLTexLayerParamAlpha : public LLViewerVisualParam
00376 {
00377 public:
00378         LLTexLayerParamAlpha( LLTexLayer* layer );
00379         /*virtual*/ ~LLTexLayerParamAlpha();
00380 
00381         // Special: These functions are overridden by child classes
00382         LLTexLayerParamAlphaInfo*       getInfo() const { return (LLTexLayerParamAlphaInfo*)mInfo; }
00383         //   This sets mInfo and calls initialization functions
00384         BOOL                                            setInfo(LLTexLayerParamAlphaInfo *info);
00385         
00386         // LLVisualParam Virtual functions
00388         /*virtual*/ void                apply( ESex avatar_sex ) {}
00389         /*virtual*/ void                setWeight(F32 weight, BOOL set_by_user);
00390         /*virtual*/ void                setAnimationTarget(F32 target_value, BOOL set_by_user); 
00391         /*virtual*/ void                animate(F32 delta, BOOL set_by_user);
00392 
00393         // LLViewerVisualParam Virtual functions
00394         /*virtual*/ F32                                 getTotalDistortion()                                                                    { return 1.f; }
00395         /*virtual*/ const LLVector3&    getAvgDistortion()                                                                              { return mAvgDistortionVec; }
00396         /*virtual*/ F32                                 getMaxDistortion()                                                                              { return 3.f; }
00397         /*virtual*/ LLVector3                   getVertexDistortion(S32 index, LLPolyMesh *poly_mesh)   { return LLVector3(1.f, 1.f, 1.f);}
00398         /*virtual*/ const LLVector3*    getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)  { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
00399         /*virtual*/ const LLVector3*    getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)   { index = 0; poly_mesh = NULL; return NULL;};
00400 
00401         // New functions
00402         BOOL                                    render( S32 x, S32 y, S32 width, S32 height );
00403         BOOL                                    getSkip();
00404         void                                    deleteCaches();
00405         LLTexLayer*                             getTexLayer()           { return mTexLayer; }
00406         BOOL                                    getMultiplyBlend()      { return getInfo()->mMultiplyBlend; }
00407 
00408 protected:
00409         LLPointer<LLImageGL>    mCachedProcessedImageGL;
00410         LLTexLayer*                             mTexLayer;
00411         LLPointer<LLImageTGA>   mStaticImageTGA;
00412         LLPointer<LLImageRaw>   mStaticImageRaw;
00413         BOOL                                    mNeedsCreateTexture;
00414         BOOL                                    mStaticImageInvalid;
00415         LLVector3                               mAvgDistortionVec;
00416         F32                                             mCachedEffectiveWeight;
00417 
00418 public:
00419         // Global list of instances for gathering statistics
00420         static void                             dumpCacheByteCount();
00421         static void                             getCacheByteCount( S32* gl_bytes );
00422 
00423         typedef std::list< LLTexLayerParamAlpha* > param_alpha_ptr_list_t;
00424         static param_alpha_ptr_list_t sInstances;
00425 };
00426 
00427 
00428 //-----------------------------------------------------------------------------
00429 // LLTexGlobalColor
00430 //-----------------------------------------------------------------------------
00431 class LLTexGlobalColor
00432 {
00433 public:
00434         LLTexGlobalColor( LLVOAvatar* avatar );
00435         ~LLTexGlobalColor();
00436 
00437         //BOOL                                  parseData(LLXmlTreeNode* node);
00438         LLTexGlobalColorInfo*   getInfo() const { return mInfo; }
00439         //   This sets mInfo and calls initialization functions
00440         BOOL                                    setInfo(LLTexGlobalColorInfo *info);
00441         
00442         void                                    requstUpdate();
00443         LLVOAvatar*                             getAvatar()                                             { return mAvatar; }
00444         LLColor4                                getColor();
00445         const std::string&              getName()                                               { return mInfo->mName; }
00446 
00447 protected:
00448         typedef std::vector<LLTexParamColor *> param_list_t;
00449         param_list_t                    mParamList;
00450         LLVOAvatar*                             mAvatar;  // just backlink, don't LLPointer 
00451 
00452         LLTexGlobalColorInfo    *mInfo;
00453 };
00454 
00455 
00456 //-----------------------------------------------------------------------------
00457 // LLTexParamColor
00458 //-----------------------------------------------------------------------------
00459 class LLTexParamColor : public LLViewerVisualParam
00460 {
00461 public:
00462         LLTexParamColor( LLTexGlobalColor* tex_color );
00463         LLTexParamColor( LLTexLayer* layer );
00464         /* virtual */ ~LLTexParamColor();
00465 
00466         // Special: These functions are overridden by child classes
00467         LLTexParamColorInfo*            getInfo() const { return (LLTexParamColorInfo*)mInfo; }
00468         //   This sets mInfo and calls initialization functions
00469         BOOL                                            setInfo(LLTexParamColorInfo *info);
00470         
00471         // LLVisualParam Virtual functions
00473         /*virtual*/ void                        apply( ESex avatar_sex ) {}
00474         /*virtual*/ void                        setWeight(F32 weight, BOOL set_by_user);
00475         /*virtual*/ void                        setAnimationTarget(F32 target_value, BOOL set_by_user);
00476         /*virtual*/ void                        animate(F32 delta, BOOL set_by_user);
00477 
00478 
00479         // LLViewerVisualParam Virtual functions
00480         /*virtual*/ F32                                 getTotalDistortion()                                                                    { return 1.f; }
00481         /*virtual*/ const LLVector3&    getAvgDistortion()                                                                              { return mAvgDistortionVec; }
00482         /*virtual*/ F32                                 getMaxDistortion()                                                                              { return 3.f; }
00483         /*virtual*/ LLVector3                   getVertexDistortion(S32 index, LLPolyMesh *poly_mesh)   { return LLVector3(1.f, 1.f, 1.f); }
00484         /*virtual*/ const LLVector3*    getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)  { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
00485         /*virtual*/ const LLVector3*    getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)   { index = 0; poly_mesh = NULL; return NULL;};
00486 
00487         // New functions
00488         LLColor4                                getNetColor();
00489         EColorOperation                 getOperation() const    { return getInfo()->mOperation; }
00490 
00491         
00492 protected:
00493         LLVector3                               mAvgDistortionVec;
00494         LLTexGlobalColor*               mTexGlobalColor;        // either has mTexGlobalColor or mTexLayer as its parent
00495         LLTexLayer*                             mTexLayer;
00496         LLVOAvatar*                             mAvatar;                        // redundant, but simplifies the code (don't LLPointer)
00497 };
00498 
00499 //-----------------------------------------------------------------------------
00500 // LLTexStaticImageList
00501 //-----------------------------------------------------------------------------
00502 
00503 class LLTexStaticImageList
00504 {
00505 public:
00506         LLTexStaticImageList();
00507         ~LLTexStaticImageList();
00508 
00509         LLImageRaw*     getImageRaw( const LLString& file_name );
00510         LLImageGL*      getImageGL( const LLString& file_name, BOOL is_mask  );
00511         LLImageTGA*     getImageTGA( const LLString& file_name );
00512 
00513         void            deleteCachedImages();
00514         void            dumpByteCount();
00515 
00516 private:
00517         BOOL            loadImageRaw( const LLString& file_name, LLImageRaw* image_raw );
00518 
00519 private:
00520         static LLStringTable sImageNames;
00521 
00522         typedef std::map< const char *, LLPointer<LLImageGL> > image_gl_map_t;
00523         typedef std::map< const char *, LLPointer<LLImageTGA> > image_tga_map_t;
00524         image_gl_map_t mStaticImageListGL;
00525         image_tga_map_t mStaticImageListTGA;
00526 
00527 public:
00528         S32 mGLBytes;
00529         S32 mTGABytes;
00530 };
00531 
00532 
00533 //-----------------------------------------------------------------------------
00534 // LLGradientPaletteList
00535 // A static set of ramp grayscale palettes.  The "effective_weight" is used 
00536 // to determine the x position of the ramp (offset)
00537 //
00538 // "Domain" isn't really the right word.  It refers to the width of the 
00539 // ramp portion of the function that relates input and output pixel values.
00540 // A domain of 0 gives a step function.
00541 // 
00542 //   |                      /----------------
00543 //  O|                     / |
00544 //  u|                    /  |
00545 //  t|                   /   |
00546 //  p|------------------/    |
00547 //  u|                  |    | 
00548 //  t|<---------------->|<-->|
00549 //   |  "offset"         "domain"
00550 //   |
00551 // --+---Input--------------------------------
00552 //   |
00553 //-----------------------------------------------------------------------------
00554 class LLGradientPaletteList
00555 {
00556 public:
00557         LLGradientPaletteList() {}
00558         ~LLGradientPaletteList();
00559 
00560         void             initPalette(F32 domain);
00561         void             setHardwarePalette(F32 domain, F32 effective_weight);
00562         
00563 private:
00564         typedef std::map<F32, U8*> palette_map_t;
00565         palette_map_t           mPaletteMap;
00566 };
00567 
00568 // Used by LLTexLayerSetBuffer for a callback.
00569 class LLBakedUploadData
00570 {
00571 public:
00572         LLBakedUploadData( LLVOAvatar* avatar, LLTexLayerSetBuffer* layerset_buffer );
00573         ~LLBakedUploadData() {}
00574 
00575         LLUUID                                  mID;
00576         LLVOAvatar*                             mAvatar;         // just backlink, don't LLPointer 
00577         LLTexLayerSetBuffer*    mLayerSetBuffer;
00578         LLUUID                                  mWearableAssets[WT_COUNT];
00579 };
00580 
00581 extern LLTexStaticImageList gTexStaticImageList;
00582 
00583 
00584 #endif  // LL_LLTEXLAYER_H

Generated on Thu Jul 1 06:09:16 2010 for Second Life Viewer by  doxygen 1.4.7