PageRenderTime 112ms CodeModel.GetById 52ms app.highlight 54ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/lltexlayer.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 378 lines | 262 code | 38 blank | 78 comment | 0 complexity | 51639be21860531409f729c2e4e25a0b MD5 | raw file
  1/** 
  2 * @file lltexlayer.h
  3 * @brief Texture layer classes. Used for avatars.
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLTEXLAYER_H
 28#define LL_LLTEXLAYER_H
 29
 30#include <deque>
 31#include "lldynamictexture.h"
 32#include "llvoavatardefines.h"
 33#include "lltexlayerparams.h"
 34
 35class LLVOAvatar;
 36class LLVOAvatarSelf;
 37class LLImageTGA;
 38class LLImageRaw;
 39class LLXmlTreeNode;
 40class LLTexLayerSet;
 41class LLTexLayerSetInfo;
 42class LLTexLayerInfo;
 43class LLTexLayerSetBuffer;
 44class LLWearable;
 45class LLViewerVisualParam;
 46
 47//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 48// LLTexLayerInterface
 49//
 50// Interface class to generalize functionality shared by LLTexLayer 
 51// and LLTexLayerTemplate.
 52//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 53class LLTexLayerInterface 
 54{
 55public:
 56	enum ERenderPass
 57	{
 58		RP_COLOR,
 59		RP_BUMP,
 60		RP_SHINE
 61	};
 62
 63	LLTexLayerInterface(LLTexLayerSet* const layer_set);
 64	LLTexLayerInterface(const LLTexLayerInterface &layer, LLWearable *wearable);
 65	virtual ~LLTexLayerInterface() {}
 66
 67	virtual BOOL			render(S32 x, S32 y, S32 width, S32 height) = 0;
 68	virtual void			deleteCaches() = 0;
 69	virtual BOOL			blendAlphaTexture(S32 x, S32 y, S32 width, S32 height) = 0;
 70	virtual BOOL			isInvisibleAlphaMask() const = 0;
 71
 72	const LLTexLayerInfo* 	getInfo() const 			{ return mInfo; }
 73	virtual BOOL			setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // sets mInfo, calls initialization functions
 74
 75	const std::string&		getName() const;
 76	const LLTexLayerSet* const getTexLayerSet() const 	{ return mTexLayerSet; }
 77	LLTexLayerSet* const 	getTexLayerSet() 			{ return mTexLayerSet; }
 78
 79	void					invalidateMorphMasks();
 80	virtual void			setHasMorph(BOOL newval) 	{ mHasMorph = newval; }
 81	BOOL					hasMorph() const			{ return mHasMorph; }
 82	BOOL					isMorphValid() const		{ return mMorphMasksValid; }
 83
 84	void					requestUpdate();
 85	virtual void			gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height) = 0;
 86	BOOL					hasAlphaParams() const 		{ return !mParamAlphaList.empty(); }
 87
 88	ERenderPass				getRenderPass() const;
 89	BOOL					isVisibilityMask() const;
 90
 91protected:
 92	const std::string&		getGlobalColor() const;
 93	LLViewerVisualParam*	getVisualParamPtr(S32 index) const;
 94
 95protected:
 96	LLTexLayerSet* const	mTexLayerSet;
 97	const LLTexLayerInfo*	mInfo;
 98	BOOL					mMorphMasksValid;
 99	BOOL					mHasMorph;
100
101	// Layers can have either mParamColorList, mGlobalColor, or mFixedColor.  They are looked for in that order.
102	param_color_list_t		mParamColorList;
103	param_alpha_list_t		mParamAlphaList;
104	// 						mGlobalColor name stored in mInfo
105	// 						mFixedColor value stored in mInfo
106};
107
108//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109// LLTexLayerTemplate
110//
111// Only exists for llvoavatarself.
112//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113class LLTexLayerTemplate : public LLTexLayerInterface
114{
115public:
116	LLTexLayerTemplate(LLTexLayerSet* const layer_set);
117	LLTexLayerTemplate(const LLTexLayerTemplate &layer);
118	/*virtual*/ ~LLTexLayerTemplate();
119	/*virtual*/ BOOL		render(S32 x, S32 y, S32 width, S32 height);
120	/*virtual*/ BOOL		setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // This sets mInfo and calls initialization functions
121	/*virtual*/ BOOL		blendAlphaTexture(S32 x, S32 y, S32 width, S32 height); // Multiplies a single alpha texture against the frame buffer
122	/*virtual*/ void		gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
123	/*virtual*/ void		setHasMorph(BOOL newval);
124	/*virtual*/ void		deleteCaches();
125	/*virtual*/ BOOL		isInvisibleAlphaMask() const;
126protected:
127	U32 					updateWearableCache() const;
128	LLTexLayer* 			getLayer(U32 i) const;
129private:
130	typedef std::vector<LLWearable*> wearable_cache_t;
131	mutable wearable_cache_t mWearableCache; // mutable b/c most get- require updating this cache
132};
133
134//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135// LLTexLayer
136//
137// A single texture layer.  Only exists for llvoavatarself.
138//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139class LLTexLayer : public LLTexLayerInterface
140{
141public:
142	LLTexLayer(LLTexLayerSet* const layer_set);
143	LLTexLayer(const LLTexLayer &layer, LLWearable *wearable);
144	LLTexLayer(const LLTexLayerTemplate &layer_template, LLLocalTextureObject *lto, LLWearable *wearable);
145	/*virtual*/ ~LLTexLayer();
146
147	/*virtual*/ BOOL		setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // This sets mInfo and calls initialization functions
148	/*virtual*/ BOOL		render(S32 x, S32 y, S32 width, S32 height);
149
150	/*virtual*/ void		deleteCaches();
151	const U8*				getAlphaData() const;
152
153	BOOL					findNetColor(LLColor4* color) const;
154	/*virtual*/ BOOL		blendAlphaTexture(S32 x, S32 y, S32 width, S32 height); // Multiplies a single alpha texture against the frame buffer
155	/*virtual*/ void		gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
156	BOOL					renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLColor4 &layer_color);
157	void					addAlphaMask(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
158	/*virtual*/ BOOL		isInvisibleAlphaMask() const;
159
160	void					setLTO(LLLocalTextureObject *lto) 	{ mLocalTextureObject = lto; }
161	LLLocalTextureObject* 	getLTO() 							{ return mLocalTextureObject; }
162
163	static void 			calculateTexLayerColor(const param_color_list_t &param_list, LLColor4 &net_color);
164protected:
165	LLUUID					getUUID() const;
166private:
167	typedef std::map<U32, U8*> alpha_cache_t;
168	alpha_cache_t			mAlphaCache;
169	LLLocalTextureObject* 	mLocalTextureObject;
170};
171
172//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173// LLTexLayerSet
174//
175// An ordered set of texture layers that gets composited into a single texture.
176// Only exists for llvoavatarself.
177//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178class LLTexLayerSet
179{
180	friend class LLTexLayerSetBuffer;
181public:
182	LLTexLayerSet(LLVOAvatarSelf* const avatar);
183	~LLTexLayerSet();
184
185	const LLTexLayerSetInfo* 	getInfo() const 			{ return mInfo; }
186	BOOL						setInfo(const LLTexLayerSetInfo *info); // This sets mInfo and calls initialization functions
187
188	BOOL						render(S32 x, S32 y, S32 width, S32 height);
189	void						renderAlphaMaskTextures(S32 x, S32 y, S32 width, S32 height, bool forceClear = false);
190
191	BOOL						isBodyRegion(const std::string& region) const;
192	LLTexLayerSetBuffer*		getComposite();
193	const LLTexLayerSetBuffer* 	getComposite() const; // Do not create one if it doesn't exist.
194	void						requestUpdate();
195	void						requestUpload();
196	void						cancelUpload();
197	void						updateComposite();
198	BOOL						isLocalTextureDataAvailable() const;
199	BOOL						isLocalTextureDataFinal() const;
200	void						createComposite();
201	void						destroyComposite();
202	void						setUpdatesEnabled(BOOL b);
203	BOOL						getUpdatesEnabled()	const 	{ return mUpdatesEnabled; }
204	void						deleteCaches();
205	void						gatherMorphMaskAlpha(U8 *data, S32 width, S32 height);
206	void						applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
207	BOOL						isMorphValid() const;
208	void						invalidateMorphMasks();
209	LLTexLayerInterface*		findLayerByName(const std::string& name);
210	void						cloneTemplates(LLLocalTextureObject *lto, LLVOAvatarDefines::ETextureIndex tex_index, LLWearable* wearable);
211	
212	LLVOAvatarSelf*		    	getAvatar()	const 			{ return mAvatar; }
213	const std::string			getBodyRegionName() const;
214	BOOL						hasComposite() const 		{ return (mComposite.notNull()); }
215	LLVOAvatarDefines::EBakedTextureIndex getBakedTexIndex() { return mBakedTexIndex; }
216	void						setBakedTexIndex(LLVOAvatarDefines::EBakedTextureIndex index) { mBakedTexIndex = index; }
217	BOOL						isVisible() const 			{ return mIsVisible; }
218
219	static BOOL					sHasCaches;
220
221private:
222	typedef std::vector<LLTexLayerInterface *> layer_list_t;
223	layer_list_t				mLayerList;
224	layer_list_t				mMaskLayerList;
225	LLPointer<LLTexLayerSetBuffer>	mComposite;
226	LLVOAvatarSelf*	const		mAvatar; // note: backlink only; don't make this an LLPointer.
227	BOOL						mUpdatesEnabled;
228	BOOL						mIsVisible;
229
230	LLVOAvatarDefines::EBakedTextureIndex mBakedTexIndex;
231	const LLTexLayerSetInfo* 	mInfo;
232};
233
234//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235// LLTexLayerSetInfo
236//
237// Contains shared layer set data.
238//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239class LLTexLayerSetInfo
240{
241	friend class LLTexLayerSet;
242public:
243	LLTexLayerSetInfo();
244	~LLTexLayerSetInfo();
245	BOOL parseXml(LLXmlTreeNode* node);
246	void createVisualParams(LLVOAvatar *avatar);
247private:
248	std::string				mBodyRegion;
249	S32						mWidth;
250	S32						mHeight;
251	std::string				mStaticAlphaFileName;
252	BOOL					mClearAlpha; // Set alpha to 1 for this layerset (if there is no mStaticAlphaFileName)
253	typedef std::vector<LLTexLayerInfo*> layer_info_list_t;
254	layer_info_list_t		mLayerInfoList;
255};
256
257//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258// LLTexLayerSetBuffer
259//
260// The composite image that a LLTexLayerSet writes to.  Each LLTexLayerSet has one.
261//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262class LLTexLayerSetBuffer : public LLViewerDynamicTexture
263{
264public:
265	LLTexLayerSetBuffer(LLTexLayerSet* const owner, S32 width, S32 height);
266	virtual ~LLTexLayerSetBuffer();
267
268public:
269	/*virtual*/ S8          getType() const;
270	BOOL					isInitialized(void) const;
271	static void				dumpTotalByteCount();
272	const std::string		dumpTextureInfo() const;
273	virtual void 			restoreGLTexture();
274	virtual void 			destroyGLTexture();
275protected:
276	void					pushProjection() const;
277	void					popProjection() const;
278private:
279	LLTexLayerSet* const    mTexLayerSet;
280	static S32				sGLByteCount;
281
282	//--------------------------------------------------------------------
283	// Render
284	//--------------------------------------------------------------------
285public:
286	/*virtual*/ BOOL		needsRender();
287protected:
288	BOOL					render(S32 x, S32 y, S32 width, S32 height);
289	virtual void			preRender(BOOL clear_depth);
290	virtual void			postRender(BOOL success);
291	virtual BOOL			render();	
292	
293	//--------------------------------------------------------------------
294	// Uploads
295	//--------------------------------------------------------------------
296public:
297	void					requestUpload();
298	void					cancelUpload();
299	BOOL					uploadNeeded() const; 			// We need to upload a new texture
300	BOOL					uploadInProgress() const; 		// We have started uploading a new texture and are awaiting the result
301	BOOL					uploadPending() const; 			// We are expecting a new texture to be uploaded at some point
302	static void				onTextureUploadComplete(const LLUUID& uuid,
303													void* userdata,
304													S32 result, LLExtStat ext_status);
305protected:
306	BOOL					isReadyToUpload() const;
307	void					doUpload(); 					// Does a read back and upload.
308	void					conditionalRestartUploadTimer();
309private:
310	BOOL					mNeedsUpload; 					// Whether we need to send our baked textures to the server
311	U32						mNumLowresUploads; 				// Number of times we've sent a lowres version of our baked textures to the server
312	BOOL					mUploadPending; 				// Whether we have received back the new baked textures
313	LLUUID					mUploadID; 						// The current upload process (null if none).
314	LLFrameTimer    		mNeedsUploadTimer; 				// Tracks time since upload was requested and performed.
315	S32						mUploadFailCount;				// Number of consecutive upload failures
316	LLFrameTimer    		mUploadRetryTimer; 				// Tracks time since last upload failure.
317
318	//--------------------------------------------------------------------
319	// Updates
320	//--------------------------------------------------------------------
321public:
322	void					requestUpdate();
323	BOOL					requestUpdateImmediate();
324protected:
325	BOOL					isReadyToUpdate() const;
326	void					doUpdate();
327	void					restartUpdateTimer();
328private:
329	BOOL					mNeedsUpdate; 					// Whether we need to locally update our baked textures
330	U32						mNumLowresUpdates; 				// Number of times we've locally updated with lowres version of our baked textures
331	LLFrameTimer    		mNeedsUpdateTimer; 				// Tracks time since update was requested and performed.
332};
333
334//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335// LLTexLayerStaticImageList
336//
337//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338class LLTexLayerStaticImageList : public LLSingleton<LLTexLayerStaticImageList>
339{
340public:
341	LLTexLayerStaticImageList();
342	~LLTexLayerStaticImageList();
343	LLViewerTexture*	getTexture(const std::string& file_name, BOOL is_mask);
344	LLImageTGA*			getImageTGA(const std::string& file_name);
345	void				deleteCachedImages();
346	void				dumpByteCount() const;
347protected:
348	BOOL				loadImageRaw(const std::string& file_name, LLImageRaw* image_raw);
349private:
350	LLStringTable 		mImageNames;
351	typedef std::map<const char*, LLPointer<LLViewerTexture> > texture_map_t;
352	texture_map_t 		mStaticImageList;
353	typedef std::map<const char*, LLPointer<LLImageTGA> > image_tga_map_t;
354	image_tga_map_t 	mStaticImageListTGA;
355	S32 				mGLBytes;
356	S32 				mTGABytes;
357};
358
359//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
360// LLBakedUploadData
361//
362// Used by LLTexLayerSetBuffer for a callback.
363//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364struct LLBakedUploadData
365{
366	LLBakedUploadData(const LLVOAvatarSelf* avatar, 
367					  LLTexLayerSet* layerset, 
368					  const LLUUID& id,
369					  bool highest_res);
370	~LLBakedUploadData() {}
371	const LLUUID				mID;
372	const LLVOAvatarSelf*		mAvatar; // note: backlink only; don't LLPointer 
373	LLTexLayerSet*				mTexLayerSet;
374   	const U64					mStartTime;	// for measuring baked texture upload time
375   	const bool					mIsHighestRes; // whether this is a "final" bake, or intermediate low res
376};
377
378#endif  // LL_LLTEXLAYER_H