aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltexlayer.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lltexlayer.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lltexlayer.h585
1 files changed, 585 insertions, 0 deletions
diff --git a/linden/indra/newview/lltexlayer.h b/linden/indra/newview/lltexlayer.h
new file mode 100644
index 0000000..3db6f96
--- /dev/null
+++ b/linden/indra/newview/lltexlayer.h
@@ -0,0 +1,585 @@
1/**
2 * @file lltexlayer.h
3 * @brief A texture layer. Used for avatars.
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLTEXLAYER_H
29#define LL_LLTEXLAYER_H
30
31#include <deque>
32#include "llassetstorage.h"
33#include "lldynamictexture.h"
34#include "llrect.h"
35#include "llstring.h"
36#include "lluuid.h"
37#include "llviewerimage.h"
38#include "llviewervisualparam.h"
39#include "llvoavatar.h"
40#include "llwearable.h"
41#include "v4color.h"
42#include "llfloater.h"
43
44class LLTexLayerSetInfo;
45class LLTexLayerSet;
46class LLTexLayerInfo;
47class LLTexLayer;
48class LLImageGL;
49class LLImageTGA;
50class LLTexGlobalColorInfo;
51class LLTexLayerParamAlphaInfo;
52class LLTexLayerParamAlpha;
53class LLTexParamColorInfo;
54class LLTexParamColor;
55class LLPolyMesh;
56class LLXmlTreeNode;
57class LLImageRaw;
58class LLPolyMorphTarget;
59
60class LLTextureCtrl;
61class LLVOAvatar;
62
63
64enum EColorOperation
65{
66 OP_ADD = 0,
67 OP_MULTIPLY = 1,
68 OP_BLEND = 2,
69 OP_COUNT = 3 // Number of operations
70};
71
72
73//-----------------------------------------------------------------------------
74// LLTexLayerParamAlphaInfo
75//-----------------------------------------------------------------------------
76class LLTexLayerParamAlphaInfo : public LLViewerVisualParamInfo
77{
78 friend class LLTexLayerParamAlpha;
79public:
80 LLTexLayerParamAlphaInfo();
81 /*virtual*/ ~LLTexLayerParamAlphaInfo() {};
82
83 /*virtual*/ BOOL parseXml(LLXmlTreeNode* node);
84
85protected:
86 LLString mStaticImageFileName;
87 BOOL mMultiplyBlend;
88 BOOL mSkipIfZeroWeight;
89 F32 mDomain;
90};
91
92//-----------------------------------------------------------------------------
93// LLTexParamColorInfo
94//-----------------------------------------------------------------------------
95class LLTexParamColorInfo : public LLViewerVisualParamInfo
96{
97 friend class LLTexParamColor;
98
99public:
100 LLTexParamColorInfo();
101 virtual ~LLTexParamColorInfo() {};
102 BOOL parseXml( LLXmlTreeNode* node );
103
104protected:
105 enum { MAX_COLOR_VALUES = 20 };
106 EColorOperation mOperation;
107 LLColor4 mColors[MAX_COLOR_VALUES];
108 S32 mNumColors;
109};
110
111//-----------------------------------------------------------------------------
112// LLTexGlobalColorInfo
113//-----------------------------------------------------------------------------
114class LLTexGlobalColorInfo
115{
116 friend class LLTexGlobalColor;
117public:
118 LLTexGlobalColorInfo();
119 ~LLTexGlobalColorInfo();
120
121 BOOL parseXml(LLXmlTreeNode* node);
122
123protected:
124 typedef std::vector<LLTexParamColorInfo *> color_info_list_t;
125 color_info_list_t mColorInfoList;
126 LLString mName;
127};
128
129//-----------------------------------------------------------------------------
130// LLTexLayerSetInfo
131// Containes shared layer set data
132//-----------------------------------------------------------------------------
133class LLTexLayerSetInfo
134{
135 friend class LLTexLayerSet;
136public:
137 LLTexLayerSetInfo();
138 ~LLTexLayerSetInfo();
139
140 BOOL parseXml(LLXmlTreeNode* node);
141
142protected:
143 LLString mBodyRegion;
144 S32 mWidth;
145 S32 mHeight;
146 LLString mStaticAlphaFileName;
147 BOOL mClearAlpha; // Set alpha to 1 for this layerset (if there is no mStaticAlphaFileName)
148
149 typedef std::vector<LLTexLayerInfo*> layer_info_list_t;
150 layer_info_list_t mLayerInfoList;
151};
152
153//-----------------------------------------------------------------------------
154// LLTexLayerInfo
155//-----------------------------------------------------------------------------
156enum ERenderPass
157{
158 RP_COLOR,
159 RP_BUMP,
160 RP_SHINE
161};
162
163class LLTexLayerInfo
164{
165 friend class LLTexLayer;
166public:
167 LLTexLayerInfo();
168 ~LLTexLayerInfo();
169
170 BOOL parseXml(LLXmlTreeNode* node);
171
172protected:
173 LLString mName;
174
175 BOOL mWriteAllChannels; // Don't use masking. Just write RGBA into buffer,
176 ERenderPass mRenderPass;
177
178 LLString mGlobalColor;
179 LLColor4 mFixedColor;
180
181 S32 mLocalTexture;
182 LLString mStaticImageFileName;
183 BOOL mStaticImageIsMask;
184 BOOL mUseLocalTextureAlphaOnly; // Ignore RGB channels from the input texture. Use alpha as a mask
185
186 typedef std::vector<std::pair<LLString,BOOL> > morph_name_list_t;
187 morph_name_list_t mMorphNameList;
188
189 typedef std::vector<LLTexParamColorInfo*> color_info_list_t;
190 color_info_list_t mColorInfoList;
191
192 typedef std::vector<LLTexLayerParamAlphaInfo*> alpha_info_list_t;
193 alpha_info_list_t mAlphaInfoList;
194
195};
196
197//-----------------------------------------------------------------------------
198// LLTexLayerSetBuffer
199// The composite image that a LLTexLayerSet writes to. Each LLTexLayerSet has one.
200//-----------------------------------------------------------------------------
201class LLTexLayerSetBuffer : public LLDynamicTexture
202{
203public:
204 LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 height, BOOL has_bump );
205 virtual ~LLTexLayerSetBuffer();
206
207 virtual void preRender(BOOL clear_depth);
208 virtual void postRender(BOOL success);
209 virtual BOOL render();
210 BOOL updateImmediate();
211 virtual void bindTexture();
212 void bindBumpTexture( U32 stage );
213 BOOL isInitialized() { return mInitialized; } // Initialized here means that we've done at least one render
214 BOOL needsRender();
215 void requestUpdate();
216 void requestUpload();
217 void cancelUpload();
218 BOOL uploadPending() { return mUploadPending; }
219 BOOL render( S32 x, S32 y, S32 width, S32 height );
220 void readBackAndUpload(U8* baked_bump_data);
221 static void onTextureUploadComplete( const LLUUID& uuid,
222 void* userdata,
223 S32 result);
224 static void dumpTotalByteCount();
225
226private:
227 void pushProjection();
228 void popProjection();
229
230private:
231 BOOL mNeedsUpdate;
232 BOOL mNeedsUpload;
233 BOOL mUploadPending;
234 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)
235 LLTexLayerSet* mTexLayerSet;
236 BOOL mInitialized;
237 LLGLuint mBumpTexName; // zero if none
238
239 static S32 sGLByteCount;
240 static S32 sGLBumpByteCount;
241};
242
243//-----------------------------------------------------------------------------
244// LLTexLayerSet
245// An ordered set of texture layers that get composited into a single texture.
246//-----------------------------------------------------------------------------
247class LLTexLayerSet
248{
249public:
250 LLTexLayerSet( LLVOAvatar* avatar );
251 ~LLTexLayerSet();
252
253 //BOOL parseData(LLXmlTreeNode* node);
254 LLTexLayerSetInfo* getInfo() const { return mInfo; }
255 // This sets mInfo and calls initialization functions
256 BOOL setInfo(LLTexLayerSetInfo *info);
257
258 BOOL render( S32 x, S32 y, S32 width, S32 height );
259 BOOL renderBump( S32 x, S32 y, S32 width,S32 height );
260 BOOL isBodyRegion( const char* region ) { return mInfo->mBodyRegion == region; }
261 LLTexLayerSetBuffer* getComposite();
262 void requestUpdate();
263 void requestUpload();
264 void cancelUpload();
265 LLVOAvatar* getAvatar() { return mAvatar; }
266 void updateComposite();
267 BOOL isLocalTextureDataAvailable();
268 BOOL isLocalTextureDataFinal();
269 void createComposite();
270 void destroyComposite();
271 void setUpdatesEnabled( BOOL b );
272 BOOL getUpdatesEnabled() { return mUpdatesEnabled; }
273 void deleteCaches();
274 void gatherAlphaMasks(U8 *data, S32 width, S32 height);
275 void applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
276 const LLString& getBodyRegion() { return mInfo->mBodyRegion; }
277 BOOL hasComposite() { return (mComposite != NULL); }
278 void setBump( BOOL b ) { mHasBump = b; }
279 BOOL hasBump() { return mHasBump; }
280
281public:
282 static BOOL sHasCaches;
283
284protected:
285 typedef std::vector<LLTexLayer *> layer_list_t;
286 layer_list_t mLayerList;
287 LLTexLayerSetBuffer* mComposite;
288 LLVOAvatar* mAvatar;
289 BOOL mUpdatesEnabled;
290 BOOL mHasBump;
291
292 LLTexLayerSetInfo *mInfo;
293};
294
295//-----------------------------------------------------------------------------
296// LLMaskedMorph
297//-----------------------------------------------------------------------------
298
299class LLMaskedMorph
300{
301public:
302 LLMaskedMorph( LLPolyMorphTarget *morph_target, BOOL invert );
303
304public:
305 LLPolyMorphTarget *mMorphTarget;
306 BOOL mInvert;
307};
308
309//-----------------------------------------------------------------------------
310// LLTexLayer
311// A single texture layer
312//-----------------------------------------------------------------------------
313class LLTexLayer
314{
315public:
316 LLTexLayer( LLTexLayerSet* layer_set );
317 ~LLTexLayer();
318
319 //BOOL parseData(LLXmlTreeNode* node);
320 LLTexLayerInfo* getInfo() const { return mInfo; }
321 // This sets mInfo and calls initialization functions
322 BOOL setInfo(LLTexLayerInfo *info);
323
324 BOOL render( S32 x, S32 y, S32 width, S32 height );
325 void requestUpdate();
326 LLTexLayerSet* getTexLayerSet() { return mTexLayerSet; }
327
328 const std::string& getName() { return mInfo->mName; }
329
330 void addMaskedMorph(LLPolyMorphTarget* morph_target, BOOL invert);
331 void deleteCaches();
332 U8* getAlphaData();
333 void applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
334
335 void invalidateMorphMasks();
336 ERenderPass getRenderPass() { return mInfo->mRenderPass; }
337 const LLString& getGlobalColor() { return mInfo->mGlobalColor; }
338 BOOL findNetColor( LLColor4* color );
339 BOOL renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 in_components, S32 width, S32 height, BOOL is_mask );
340 BOOL renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4* colorp );
341 BOOL hasAlphaParams() { return (!mParamAlphaList.empty());}
342
343protected:
344 BOOL loadStaticImageRaw();
345
346protected:
347 LLTexLayerSet* mTexLayerSet;
348 LLPointer<LLImageRaw> mStaticImageRaw;
349
350 // Layers can have either mParamColorList, mGlobalColor, or mFixedColor. They are looked for in that order.
351 typedef std::vector<LLTexParamColor *> color_list_t;
352 color_list_t mParamColorList;
353 // mGlobalColor name stored in mInfo
354 // mFixedColor value stored in mInfo
355
356 typedef std::vector<LLTexLayerParamAlpha *> alpha_list_t;
357 alpha_list_t mParamAlphaList;
358
359
360 typedef std::deque<LLMaskedMorph> morph_list_t;
361 morph_list_t mMaskedMorphs;
362 typedef std::map<U32, U8*> alpha_cache_t;
363 alpha_cache_t mAlphaCache;
364 BOOL mMorphMasksValid;
365 BOOL mStaticImageInvalid;
366
367 LLTexLayerInfo *mInfo;
368};
369
370//-----------------------------------------------------------------------------
371// LLTexLayerParamAlpha
372//-----------------------------------------------------------------------------
373class LLTexLayerParamAlpha : public LLViewerVisualParam
374{
375public:
376 LLTexLayerParamAlpha( LLTexLayer* layer );
377 /*virtual*/ ~LLTexLayerParamAlpha();
378
379 // Special: These functions are overridden by child classes
380 LLTexLayerParamAlphaInfo* getInfo() const { return (LLTexLayerParamAlphaInfo*)mInfo; }
381 // This sets mInfo and calls initialization functions
382 BOOL setInfo(LLTexLayerParamAlphaInfo *info);
383
384 // LLVisualParam Virtual functions
385 ///*virtual*/ BOOL parseData(LLXmlTreeNode* node);
386 /*virtual*/ void apply( ESex avatar_sex ) {}
387 /*virtual*/ void setWeight(F32 weight, BOOL set_by_user);
388 /*virtual*/ void setAnimationTarget(F32 target_value, BOOL set_by_user);
389 /*virtual*/ void animate(F32 delta, BOOL set_by_user);
390
391 // LLViewerVisualParam Virtual functions
392 /*virtual*/ F32 getTotalDistortion() { return 1.f; }
393 /*virtual*/ const LLVector3& getAvgDistortion() { return mAvgDistortionVec; }
394 /*virtual*/ F32 getMaxDistortion() { return 3.f; }
395 /*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector3(1.f, 1.f, 1.f);}
396 /*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
397 /*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
398
399 // New functions
400 BOOL render( S32 x, S32 y, S32 width, S32 height );
401 BOOL getSkip();
402 void deleteCaches();
403 LLTexLayer* getTexLayer() { return mTexLayer; }
404 BOOL getMultiplyBlend() { return getInfo()->mMultiplyBlend; }
405
406protected:
407 LLPointer<LLImageGL> mCachedProcessedImageGL;
408 LLTexLayer* mTexLayer;
409 LLPointer<LLImageTGA> mStaticImageTGA;
410 LLPointer<LLImageRaw> mStaticImageRaw;
411 BOOL mNeedsCreateTexture;
412 BOOL mStaticImageInvalid;
413 LLVector3 mAvgDistortionVec;
414 F32 mCachedEffectiveWeight;
415
416public:
417 // Global list of instances for gathering statistics
418 static void dumpCacheByteCount();
419 static void getCacheByteCount( S32* gl_bytes );
420
421 typedef std::list< LLTexLayerParamAlpha* > param_alpha_ptr_list_t;
422 static param_alpha_ptr_list_t sInstances;
423};
424
425
426//-----------------------------------------------------------------------------
427// LLTexGlobalColor
428//-----------------------------------------------------------------------------
429class LLTexGlobalColor
430{
431public:
432 LLTexGlobalColor( LLVOAvatar* avatar );
433 ~LLTexGlobalColor();
434
435 //BOOL parseData(LLXmlTreeNode* node);
436 LLTexGlobalColorInfo* getInfo() const { return mInfo; }
437 // This sets mInfo and calls initialization functions
438 BOOL setInfo(LLTexGlobalColorInfo *info);
439
440 void requstUpdate();
441 LLVOAvatar* getAvatar() { return mAvatar; }
442 LLColor4 getColor();
443 const std::string& getName() { return mInfo->mName; }
444
445protected:
446 typedef std::vector<LLTexParamColor *> param_list_t;
447 param_list_t mParamList;
448 LLVOAvatar* mAvatar;
449
450 LLTexGlobalColorInfo *mInfo;
451};
452
453
454//-----------------------------------------------------------------------------
455// LLTexParamColor
456//-----------------------------------------------------------------------------
457class LLTexParamColor : public LLViewerVisualParam
458{
459public:
460 LLTexParamColor( LLTexGlobalColor* tex_color );
461 LLTexParamColor( LLTexLayer* layer );
462 /* virtual */ ~LLTexParamColor();
463
464 // Special: These functions are overridden by child classes
465 LLTexParamColorInfo* getInfo() const { return (LLTexParamColorInfo*)mInfo; }
466 // This sets mInfo and calls initialization functions
467 BOOL setInfo(LLTexParamColorInfo *info);
468
469 // LLVisualParam Virtual functions
470 ///*virtual*/ BOOL parseData(LLXmlTreeNode* node);
471 /*virtual*/ void apply( ESex avatar_sex ) {}
472 /*virtual*/ void setWeight(F32 weight, BOOL set_by_user);
473 /*virtual*/ void setAnimationTarget(F32 target_value, BOOL set_by_user);
474 /*virtual*/ void animate(F32 delta, BOOL set_by_user);
475
476
477 // LLViewerVisualParam Virtual functions
478 /*virtual*/ F32 getTotalDistortion() { return 1.f; }
479 /*virtual*/ const LLVector3& getAvgDistortion() { return mAvgDistortionVec; }
480 /*virtual*/ F32 getMaxDistortion() { return 3.f; }
481 /*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector3(1.f, 1.f, 1.f); }
482 /*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
483 /*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
484
485 // New functions
486 LLColor4 getNetColor();
487 EColorOperation getOperation() const { return getInfo()->mOperation; }
488
489
490protected:
491 LLVector3 mAvgDistortionVec;
492 LLTexGlobalColor* mTexGlobalColor; // either has mTexGlobalColor or mTexLayer as its parent
493 LLTexLayer* mTexLayer;
494 LLVOAvatar* mAvatar; // redundant, but simplifies the code
495};
496
497//-----------------------------------------------------------------------------
498// LLTexStaticImageList
499//-----------------------------------------------------------------------------
500
501class LLTexStaticImageList
502{
503public:
504 LLTexStaticImageList();
505 ~LLTexStaticImageList();
506
507 LLImageRaw* getImageRaw( const LLString& file_name );
508 LLImageGL* getImageGL( const LLString& file_name, BOOL is_mask );
509 LLImageTGA* getImageTGA( const LLString& file_name );
510
511 void deleteCachedImages();
512 void dumpByteCount();
513
514private:
515 BOOL loadImageRaw( const LLString& file_name, LLImageRaw* image_raw );
516
517private:
518 static LLStringTable sImageNames;
519
520 typedef std::map< const char *, LLPointer<LLImageRaw> > image_raw_map_t;
521 typedef std::map< const char *, LLPointer<LLImageGL> > image_gl_map_t;
522 typedef std::map< const char *, LLPointer<LLImageTGA> > image_tga_map_t;
523 image_raw_map_t mStaticImageListRaw;
524 image_gl_map_t mStaticImageListGL;
525 image_tga_map_t mStaticImageListTGA;
526
527public:
528 S32 mRawBytes;
529 S32 mGLBytes;
530 S32 mTGABytes;
531};
532
533
534//-----------------------------------------------------------------------------
535// LLGradientPaletteList
536// A static set of ramp grayscale palettes. The "effective_weight" is used
537// to determine the x position of the ramp (offset)
538//
539// "Domain" isn't really the right word. It refers to the width of the
540// ramp portion of the function that relates input and output pixel values.
541// A domain of 0 gives a step function.
542//
543// | /----------------
544// O| / |
545// u| / |
546// t| / |
547// p|------------------/ |
548// u| | |
549// t|<---------------->|<-->|
550// | "offset" "domain"
551// |
552// --+---Input--------------------------------
553// |
554//-----------------------------------------------------------------------------
555class LLGradientPaletteList
556{
557public:
558 LLGradientPaletteList() {}
559 ~LLGradientPaletteList();
560
561 void initPalette(F32 domain);
562 void setHardwarePalette(F32 domain, F32 effective_weight);
563
564private:
565 typedef std::map<F32, U8*> palette_map_t;
566 palette_map_t mPaletteMap;
567};
568
569// Used by LLTexLayerSetBuffer for a callback.
570class LLBakedUploadData
571{
572public:
573 LLBakedUploadData( LLVOAvatar* avatar, LLTexLayerSetBuffer* layerset_buffer );
574 ~LLBakedUploadData() {}
575
576 LLUUID mID;
577 LLVOAvatar* mAvatar;
578 LLTexLayerSetBuffer* mLayerSetBuffer;
579 LLUUID mWearableAssets[WT_COUNT];
580};
581
582extern LLTexStaticImageList gTexStaticImageList;
583
584
585#endif // LL_LLTEXLAYER_H