PageRenderTime 554ms CodeModel.GetById 142ms app.highlight 254ms RepoModel.GetById 148ms app.codeStats 0ms

/indra/newview/llviewertexture.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 831 lines | 578 code | 145 blank | 108 comment | 4 complexity | b37c58f51cc6b1555ac74ed4f2e7633a MD5 | raw file
  1/** 
  2 * @file llviewertexture.h
  3 * @brief Object for managing images and their textures
  4 *
  5 * $LicenseInfo:firstyear=2000&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_LLVIEWERTEXTURE_H					
 28#define LL_LLVIEWERTEXTURE_H
 29
 30#include "lltexture.h"
 31#include "lltimer.h"
 32#include "llframetimer.h"
 33#include "llhost.h"
 34#include "llgltypes.h"
 35#include "llrender.h"
 36#include "llmetricperformancetester.h"
 37
 38#include <map>
 39#include <list>
 40
 41#define MIN_VIDEO_RAM_IN_MEGA_BYTES    32
 42#define MAX_VIDEO_RAM_IN_MEGA_BYTES    512 // 512MB max for performance reasons.
 43
 44class LLFace;
 45class LLImageGL ;
 46class LLImageRaw;
 47class LLViewerObject;
 48class LLViewerTexture;
 49class LLViewerFetchedTexture ;
 50class LLViewerMediaTexture ;
 51class LLTexturePipelineTester ;
 52
 53
 54typedef	void	(*loaded_callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
 55
 56class LLVFile;
 57class LLMessageSystem;
 58class LLViewerMediaImpl ;
 59class LLVOVolume ;
 60
 61class LLLoadedCallbackEntry
 62{
 63public:
 64	typedef std::set< LLUUID > source_callback_list_t;
 65
 66public:
 67	LLLoadedCallbackEntry(loaded_callback_func cb,
 68						  S32 discard_level,
 69						  BOOL need_imageraw, // Needs image raw for the callback
 70						  void* userdata,
 71						  source_callback_list_t* src_callback_list,
 72						  LLViewerFetchedTexture* target,
 73						  BOOL pause);
 74	~LLLoadedCallbackEntry();
 75	void removeTexture(LLViewerFetchedTexture* tex) ;
 76
 77	loaded_callback_func	mCallback;
 78	S32						mLastUsedDiscard;
 79	S32						mDesiredDiscard;
 80	BOOL					mNeedsImageRaw;
 81	BOOL                    mPaused;
 82	void*					mUserData;
 83	source_callback_list_t* mSourceCallbackList;
 84	
 85public:
 86	static void cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list) ;
 87};
 88
 89class LLTextureBar;
 90
 91class LLViewerTexture : public LLTexture
 92{
 93public:
 94	enum
 95	{
 96		MAX_IMAGE_SIZE_DEFAULT = 1024,
 97		INVALID_DISCARD_LEVEL = 0x7fff
 98	};
 99	enum
100	{
101		LOCAL_TEXTURE,		
102		MEDIA_TEXTURE,
103		DYNAMIC_TEXTURE,
104		FETCHED_TEXTURE,
105		LOD_TEXTURE,
106		ATLAS_TEXTURE,
107		INVALID_TEXTURE_TYPE
108	};
109
110	enum EBoostLevel
111	{
112		BOOST_NONE 			= 0,
113		BOOST_AVATAR_BAKED	,
114		BOOST_AVATAR		,
115		BOOST_CLOUDS		,
116		BOOST_SCULPTED      ,
117		
118		BOOST_HIGH 			= 10,
119		BOOST_BUMP          ,
120		BOOST_TERRAIN		, // has to be high priority for minimap / low detail
121		BOOST_SELECTED		,		
122		BOOST_AVATAR_BAKED_SELF	,
123		BOOST_AVATAR_SELF	, // needed for baking avatar
124		BOOST_SUPER_HIGH    , //textures higher than this need to be downloaded at the required resolution without delay.
125		BOOST_HUD			,
126		BOOST_ICON			,
127		BOOST_UI			,
128		BOOST_PREVIEW		,
129		BOOST_MAP			,
130		BOOST_MAP_VISIBLE	,		
131		BOOST_MAX_LEVEL,
132
133		//other texture Categories
134		LOCAL = BOOST_MAX_LEVEL,
135		AVATAR_SCRATCH_TEX,
136		DYNAMIC_TEX,
137		MEDIA,
138		ATLAS,
139		OTHER,
140		MAX_GL_IMAGE_CATEGORY
141	};
142	static S32 getTotalNumOfCategories() ;
143	static S32 getIndexFromCategory(S32 category) ;
144	static S32 getCategoryFromIndex(S32 index) ;
145
146	typedef std::vector<LLFace*> ll_face_list_t;
147	typedef std::vector<LLVOVolume*> ll_volume_list_t;
148
149
150protected:
151	virtual ~LLViewerTexture();
152	LOG_CLASS(LLViewerTexture);
153
154public:	
155	static void initClass();
156	static void updateClass(const F32 velocity, const F32 angular_velocity) ;
157	
158	LLViewerTexture(BOOL usemipmaps = TRUE);
159	LLViewerTexture(const LLUUID& id, BOOL usemipmaps) ;
160	LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
161	LLViewerTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
162
163	virtual S8 getType() const;
164	virtual BOOL isMissingAsset()const ;
165	virtual void dump();	// debug info to llinfos
166	
167	/*virtual*/ bool bindDefaultImage(const S32 stage = 0) ;
168	/*virtual*/ void forceImmediateUpdate() ;
169	
170	const LLUUID& getID() const { return mID; }
171	
172	void setBoostLevel(S32 level);
173	S32  getBoostLevel() { return mBoostLevel; }
174
175	void addTextureStats(F32 virtual_size, BOOL needs_gltexture = TRUE) const;
176	void resetTextureStats();	
177	void setMaxVirtualSizeResetInterval(S32 interval)const {mMaxVirtualSizeResetInterval = interval;}
178	void resetMaxVirtualSizeResetCounter()const {mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;}
179
180	virtual F32  getMaxVirtualSize() ;
181
182	LLFrameTimer* getLastReferencedTimer() {return &mLastReferencedTimer ;}
183	
184	S32 getFullWidth() const { return mFullWidth; }
185	S32 getFullHeight() const { return mFullHeight; }	
186	/*virtual*/ void setKnownDrawSize(S32 width, S32 height);
187
188	virtual void addFace(LLFace* facep) ;
189	virtual void removeFace(LLFace* facep) ; 
190	S32 getNumFaces() const;
191	const ll_face_list_t* getFaceList() const {return &mFaceList;}
192
193	virtual void addVolume(LLVOVolume* volumep);
194	virtual void removeVolume(LLVOVolume* volumep);
195	S32 getNumVolumes() const;
196	const ll_volume_list_t* getVolumeList() const { return &mVolumeList; }
197
198	void generateGLTexture() ;
199	void destroyGLTexture() ;
200	
201	//---------------------------------------------------------------------------------------------
202	//functions to access LLImageGL
203	//---------------------------------------------------------------------------------------------
204	/*virtual*/S32	       getWidth(S32 discard_level = -1) const;
205	/*virtual*/S32	       getHeight(S32 discard_level = -1) const;
206	
207	BOOL       hasGLTexture() const ;
208	LLGLuint   getTexName() const ;		
209	BOOL       createGLTexture() ;
210	BOOL       createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLViewerTexture::OTHER);
211	virtual void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
212
213	void       setFilteringOption(LLTexUnit::eTextureFilterOptions option);
214	void       setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
215	void       setAddressMode(LLTexUnit::eTextureAddressMode mode);
216	BOOL       setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height);
217	BOOL       setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height);
218	void       setGLTextureCreated (bool initialized);
219	void       setCategory(S32 category) ;
220
221	LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
222	S32        getMaxDiscardLevel() const;
223	S32        getDiscardLevel() const;
224	S8		   getComponents() const ;		
225	BOOL       getBoundRecently() const;
226	S32        getTextureMemory() const ;
227	LLGLenum   getPrimaryFormat() const;
228	BOOL       getIsAlphaMask() const ;
229	LLTexUnit::eTextureType getTarget(void) const ;
230	BOOL       getMask(const LLVector2 &tc);
231	F32        getTimePassedSinceLastBound();
232	BOOL       getMissed() const ;
233	BOOL       isJustBound()const ;
234	void       forceUpdateBindStats(void) const;
235
236	U32        getTexelsInAtlas() const ;
237	U32        getTexelsInGLTexture() const ;
238	BOOL       isGLTextureCreated() const ;
239	S32        getDiscardLevelInAtlas() const ;
240	//---------------------------------------------------------------------------------------------
241	//end of functions to access LLImageGL
242	//---------------------------------------------------------------------------------------------
243
244	//-----------------
245	/*virtual*/ void setActive() ;
246	void forceActive() ;
247	void setNoDelete() ;
248	void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
249	BOOL getDontDiscard() const { return mDontDiscard; }
250	//-----------------	
251	
252	BOOL isLargeImage() ;	
253	
254	void setParcelMedia(LLViewerMediaTexture* media) {mParcelMedia = media;}
255	BOOL hasParcelMedia() const { return mParcelMedia != NULL;}
256	LLViewerMediaTexture* getParcelMedia() const { return mParcelMedia;}
257
258	/*virtual*/ void updateBindStatsForTester() ;
259protected:
260	void cleanup() ;
261	void init(bool firstinit) ;	
262	void reorganizeFaceList() ;
263	void reorganizeVolumeList() ;
264	void setTexelsPerImage();
265private:
266	//note: do not make this function public.
267	/*virtual*/ LLImageGL* getGLTexture() const ;
268	virtual void switchToCachedImage();
269	
270	static bool isMemoryForTextureLow() ;
271protected:
272	LLUUID mID;
273	S32 mBoostLevel;				// enum describing priority level
274	S32 mFullWidth;
275	S32 mFullHeight;
276	BOOL  mUseMipMaps ;
277	S8  mComponents;
278	F32 mTexelsPerImage;			// Texels per image.
279	mutable S8  mNeedsGLTexture;
280	mutable F32 mMaxVirtualSize;	// The largest virtual size of the image, in pixels - how much data to we need?	
281	mutable S32  mMaxVirtualSizeResetCounter ;
282	mutable S32  mMaxVirtualSizeResetInterval;
283	mutable F32 mAdditionalDecodePriority;  // priority add to mDecodePriority.
284	LLFrameTimer mLastReferencedTimer;	
285
286	//GL texture
287	LLPointer<LLImageGL> mGLTexturep ;
288	S8 mDontDiscard;			// Keep full res version of this image (for UI, etc)
289
290	ll_face_list_t    mFaceList ; //reverse pointer pointing to the faces using this image as texture
291	U32               mNumFaces ;
292	LLFrameTimer      mLastFaceListUpdateTimer ;
293
294	ll_volume_list_t  mVolumeList;
295	U32					mNumVolumes;
296	LLFrameTimer	  mLastVolumeListUpdateTimer;
297
298	//do not use LLPointer here.
299	LLViewerMediaTexture* mParcelMedia ;
300
301protected:
302	typedef enum 
303	{
304		DELETED = 0,         //removed from memory
305		DELETION_CANDIDATE,  //ready to be removed from memory
306		INACTIVE,            //not be used for the last certain period (i.e., 30 seconds).
307		ACTIVE,              //just being used, can become inactive if not being used for a certain time (10 seconds).
308		NO_DELETE = 99       //stay in memory, can not be removed.
309	} LLGLTextureState;
310	LLGLTextureState  mTextureState ;
311
312public:
313	static const U32 sCurrentFileVersion;	
314	static S32 sImageCount;
315	static S32 sRawCount;
316	static S32 sAuxCount;
317	static LLFrameTimer sEvaluationTimer;
318	static F32 sDesiredDiscardBias;
319	static F32 sDesiredDiscardScale;
320	static S32 sBoundTextureMemoryInBytes;
321	static S32 sTotalTextureMemoryInBytes;
322	static S32 sMaxBoundTextureMemInMegaBytes;
323	static S32 sMaxTotalTextureMemInMegaBytes;
324	static S32 sMaxDesiredTextureMemInBytes ;
325	static S8  sCameraMovingDiscardBias;
326	static S32 sMaxSculptRez ;
327	static S32 sMinLargeImageSize ;
328	static S32 sMaxSmallImageSize ;
329	static BOOL sFreezeImageScalingDown ;//do not scale down image res if set.
330	static F32  sCurrentTime ;
331	static BOOL sUseTextureAtlas ;
332
333	static LLPointer<LLViewerTexture> sNullImagep; // Null texture for non-textured objects.
334	static LLPointer<LLViewerTexture> sBlackImagep;	// Texture to show NOTHING (pure black)
335};
336
337
338//
339//textures are managed in gTextureList.
340//raw image data is fetched from remote or local cache
341//but the raw image this texture pointing to is fixed.
342//
343class LLViewerFetchedTexture : public LLViewerTexture
344{
345	friend class LLTextureBar; // debug info only
346	friend class LLTextureView; // debug info only
347
348protected:
349	/*virtual*/ ~LLViewerFetchedTexture();
350public:
351	LLViewerFetchedTexture(const LLUUID& id, const LLHost& host = LLHost::invalid, BOOL usemipmaps = TRUE);
352	LLViewerFetchedTexture(const LLImageRaw* raw, BOOL usemipmaps);
353	LLViewerFetchedTexture(const std::string& url, const LLUUID& id, BOOL usemipmaps = TRUE);
354
355public:
356	static F32 maxDecodePriority();
357	
358	struct Compare
359	{
360		// lhs < rhs
361		bool operator()(const LLPointer<LLViewerFetchedTexture> &lhs, const LLPointer<LLViewerFetchedTexture> &rhs) const
362		{
363			const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs;
364			const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs;
365			// greater priority is "less"
366			const F32 lpriority = lhsp->getDecodePriority();
367			const F32 rpriority = rhsp->getDecodePriority();
368			if (lpriority > rpriority) // higher priority
369				return true;
370			if (lpriority < rpriority)
371				return false;
372			return lhsp < rhsp;
373		}
374	};
375
376public:
377	/*virtual*/ S8 getType() const ;
378	/*virtual*/ void forceImmediateUpdate() ;
379	/*virtual*/ void dump() ;
380
381	// Set callbacks to get called when the image gets updated with higher 
382	// resolution versions.
383	void setLoadedCallback(loaded_callback_func cb,
384						   S32 discard_level, BOOL keep_imageraw, BOOL needs_aux,
385						   void* userdata, LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause = FALSE);
386	bool hasCallbacks() { return mLoadedCallbackList.empty() ? false : true; }	
387	void pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
388	void unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
389	bool doLoadedCallbacks();
390	void deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
391	void clearCallbackEntryList() ;
392
393	void addToCreateTexture();
394
395	 // ONLY call from LLViewerTextureList
396	BOOL createTexture(S32 usename = 0);
397	void destroyTexture() ;	
398	
399	virtual void processTextureStats() ;
400	F32  calcDecodePriority() ;
401
402	BOOL needsAux() const { return mNeedsAux; }
403
404	// Host we think might have this image, used for baked av textures.
405	void setTargetHost(LLHost host)			{ mTargetHost = host; }
406	LLHost getTargetHost() const			{ return mTargetHost; }
407	
408	// Set the decode priority for this image...
409	// DON'T CALL THIS UNLESS YOU KNOW WHAT YOU'RE DOING, it can mess up
410	// the priority list, and cause horrible things to happen.
411	void setDecodePriority(F32 priority = -1.0f);
412	F32 getDecodePriority() const { return mDecodePriority; };
413
414	void setAdditionalDecodePriority(F32 priority) ;
415	
416	void updateVirtualSize() ;
417
418	S32  getDesiredDiscardLevel()			 { return mDesiredDiscardLevel; }
419	void setMinDiscardLevel(S32 discard) 	{ mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); }
420
421	bool updateFetch();
422	
423	// Override the computation of discard levels if we know the exact output
424	// size of the image.  Used for UI textures to not decode, even if we have
425	// more data.
426	/*virtual*/ void setKnownDrawSize(S32 width, S32 height);
427
428	void setIsMissingAsset();
429	/*virtual*/ BOOL isMissingAsset()	const		{ return mIsMissingAsset; }
430
431	// returns dimensions of original image for local files (before power of two scaling)
432	// and returns 0 for all asset system images
433	S32 getOriginalWidth() { return mOrigWidth; }
434	S32 getOriginalHeight() { return mOrigHeight; }
435
436	BOOL isInImageList() const {return mInImageList ;}
437	void setInImageList(BOOL flag) {mInImageList = flag ;}
438
439	LLFrameTimer* getLastPacketTimer() {return &mLastPacketTimer;}
440
441	U32 getFetchPriority() const { return mFetchPriority ;}
442	F32 getDownloadProgress() const {return mDownloadProgress ;}
443
444	LLImageRaw* reloadRawImage(S8 discard_level) ;
445	void destroyRawImage();
446	bool needsToSaveRawImage();
447
448	const std::string& getUrl() const {return mUrl;}
449	//---------------
450	BOOL isDeleted() ;
451	BOOL isInactive() ;
452	BOOL isDeletionCandidate();
453	void setDeletionCandidate() ;
454	void setInactive() ;
455	BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }	
456	//---------------
457
458	void setForSculpt();
459	BOOL forSculpt() const {return mForSculpt;}
460	BOOL isForSculptOnly() const;
461
462	//raw image management	
463	void        checkCachedRawSculptImage() ;
464	LLImageRaw* getRawImage()const { return mRawImage ;}
465	S32         getRawImageLevel() const {return mRawDiscardLevel;}
466	LLImageRaw* getCachedRawImage() const { return mCachedRawImage ;}
467	S32         getCachedRawImageLevel() const {return mCachedRawDiscardLevel;}
468	BOOL        isCachedRawImageReady() const {return mCachedRawImageReady ;}
469	BOOL        isRawImageValid()const { return mIsRawImageValid ; }	
470	void        forceToSaveRawImage(S32 desired_discard = 0, F32 kept_time = 0.f) ;
471	/*virtual*/ void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
472	void        destroySavedRawImage() ;
473	LLImageRaw* getSavedRawImage() ;
474	BOOL        hasSavedRawImage() const ;
475	F32         getElapsedLastReferencedSavedRawImageTime() const ;
476	BOOL		isFullyLoaded() const;
477
478	BOOL        hasFetcher() const { return mHasFetcher;}
479	void        setCanUseHTTP(bool can_use_http) {mCanUseHTTP = can_use_http;}
480
481protected:
482	/*virtual*/ void switchToCachedImage();
483	S32 getCurrentDiscardLevelForFetching() ;
484
485private:
486	void init(bool firstinit) ;
487	void cleanup() ;
488
489	void saveRawImage() ;
490	void setCachedRawImage() ;
491
492	//for atlas
493	void resetFaceAtlas() ;
494	void invalidateAtlas(BOOL rebuild_geom) ;
495	BOOL insertToAtlas() ;
496
497private:
498	BOOL  mFullyLoaded;
499
500protected:		
501	std::string mLocalFileName;
502
503	S32 mOrigWidth;
504	S32 mOrigHeight;
505
506	// Override the computation of discard levels if we know the exact output size of the image.
507	// Used for UI textures to not decode, even if we have more data.
508	S32 mKnownDrawWidth;
509	S32	mKnownDrawHeight;
510	BOOL mKnownDrawSizeChanged ;
511	std::string mUrl;
512	
513	S32 mRequestedDiscardLevel;
514	F32 mRequestedDownloadPriority;
515	S32 mFetchState;
516	U32 mFetchPriority;
517	F32 mDownloadProgress;
518	F32 mFetchDeltaTime;
519	F32 mRequestDeltaTime;
520	F32 mDecodePriority;			// The priority for decoding this image.
521	S32	mMinDiscardLevel;
522	S8  mDesiredDiscardLevel;			// The discard level we'd LIKE to have - if we have it and there's space	
523	S8  mMinDesiredDiscardLevel;	// The minimum discard level we'd like to have
524
525	S8  mNeedsAux;					// We need to decode the auxiliary channels
526	S8  mDecodingAux;				// Are we decoding high components
527	S8  mIsRawImageValid;
528	S8  mHasFetcher;				// We've made a fecth request
529	S8  mIsFetching;				// Fetch request is active
530	bool mCanUseHTTP ;              //This texture can be fetched through http if true.
531	
532	mutable S8 mIsMissingAsset;		// True if we know that there is no image asset with this image id in the database.		
533
534	typedef std::list<LLLoadedCallbackEntry*> callback_list_t;
535	S8              mLoadedCallbackDesiredDiscardLevel;
536	BOOL            mPauseLoadedCallBacks;
537	callback_list_t mLoadedCallbackList;
538	F32             mLastCallBackActiveTime;
539
540	LLPointer<LLImageRaw> mRawImage;
541	S32 mRawDiscardLevel;
542
543	// Used ONLY for cloth meshes right now.  Make SURE you know what you're 
544	// doing if you use it for anything else! - djs
545	LLPointer<LLImageRaw> mAuxRawImage;
546
547	//keep a copy of mRawImage for some special purposes
548	//when mForceToSaveRawImage is set.
549	BOOL mForceToSaveRawImage ;
550	BOOL mSaveRawImage;
551	LLPointer<LLImageRaw> mSavedRawImage;
552	S32 mSavedRawDiscardLevel;
553	S32 mDesiredSavedRawDiscardLevel;
554	F32 mLastReferencedSavedRawImageTime ;
555	F32 mKeptSavedRawImageTime ;
556
557	//a small version of the copy of the raw image (<= 64 * 64)
558	LLPointer<LLImageRaw> mCachedRawImage;
559	S32 mCachedRawDiscardLevel;
560	BOOL mCachedRawImageReady; //the rez of the mCachedRawImage reaches the upper limit.	
561
562	LLHost mTargetHost;	// if LLHost::invalid, just request from agent's simulator
563
564	// Timers
565	LLFrameTimer mLastPacketTimer;		// Time since last packet.
566	LLFrameTimer mStopFetchingTimer;	// Time since mDecodePriority == 0.f.
567
568	BOOL  mInImageList;				// TRUE if image is in list (in which case don't reset priority!)
569	BOOL  mNeedsCreateTexture;	
570
571	BOOL   mForSculpt ; //a flag if the texture is used as sculpt data.
572	BOOL   mIsFetched ; //is loaded from remote or from cache, not generated locally.
573
574public:
575	static LLPointer<LLViewerFetchedTexture> sMissingAssetImagep;	// Texture to show for an image asset that is not in the database
576	static LLPointer<LLViewerFetchedTexture> sWhiteImagep;	// Texture to show NOTHING (whiteness)
577	static LLPointer<LLViewerFetchedTexture> sDefaultImagep; // "Default" texture for error cases, the only case of fetched texture which is generated in local.
578	static LLPointer<LLViewerFetchedTexture> sSmokeImagep; // Old "Default" translucent texture
579};
580
581//
582//the image data is fetched from remote or from local cache
583//the resolution of the texture is adjustable: depends on the view-dependent parameters.
584//
585class LLViewerLODTexture : public LLViewerFetchedTexture
586{
587protected:
588	/*virtual*/ ~LLViewerLODTexture(){}
589
590public:
591	LLViewerLODTexture(const LLUUID& id, const LLHost& host = LLHost::invalid, BOOL usemipmaps = TRUE);
592	LLViewerLODTexture(const std::string& url, const LLUUID& id, BOOL usemipmaps = TRUE);
593
594	/*virtual*/ S8 getType() const;
595	// Process image stats to determine priority/quality requirements.
596	/*virtual*/ void processTextureStats();
597	BOOL isUpdateFrozen() ;
598
599private:
600	void init(bool firstinit) ;
601	bool scaleDown() ;		
602
603private:
604	F32 mDiscardVirtualSize;		// Virtual size used to calculate desired discard	
605	F32 mCalculatedDiscardLevel;    // Last calculated discard level
606};
607
608//
609//the image data is fetched from the media pipeline periodically
610//the resolution of the texture is also adjusted by the media pipeline
611//
612class LLViewerMediaTexture : public LLViewerTexture
613{
614protected:
615	/*virtual*/ ~LLViewerMediaTexture() ;
616
617public:
618	LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
619
620	/*virtual*/ S8 getType() const;
621	void reinit(BOOL usemipmaps = TRUE);	
622
623	BOOL  getUseMipMaps() {return mUseMipMaps ; }
624	void  setUseMipMaps(BOOL mipmap) ;	
625	
626	void setPlaying(BOOL playing) ;
627	BOOL isPlaying() const {return mIsPlaying;}
628	void setMediaImpl() ;
629
630	void initVirtualSize() ;	
631	void invalidateMediaImpl() ;
632
633	void addMediaToFace(LLFace* facep) ;
634	void removeMediaFromFace(LLFace* facep) ;
635
636	/*virtual*/ void addFace(LLFace* facep) ;
637	/*virtual*/ void removeFace(LLFace* facep) ; 
638
639	/*virtual*/ F32  getMaxVirtualSize() ;
640private:
641	void switchTexture(LLFace* facep) ;
642	BOOL findFaces() ;
643	void stopPlaying() ;
644
645private:
646	//
647	//an instant list, recording all faces referencing or can reference to this media texture.
648	//NOTE: it is NOT thread safe. 
649	//
650	std::list< LLFace* > mMediaFaceList ; 
651
652	//an instant list keeping all textures which are replaced by the current media texture,
653	//is only used to avoid the removal of those textures from memory.
654	std::list< LLPointer<LLViewerTexture> > mTextureList ;
655
656	LLViewerMediaImpl* mMediaImplp ;	
657	BOOL mIsPlaying ;
658	U32  mUpdateVirtualSizeTime ;
659
660public:
661	static void updateClass() ;
662	static void cleanUpClass() ;	
663
664	static LLViewerMediaTexture* findMediaTexture(const LLUUID& media_id) ;
665	static void removeMediaImplFromTexture(const LLUUID& media_id) ;
666
667private:
668	typedef std::map< LLUUID, LLPointer<LLViewerMediaTexture> > media_map_t ;
669	static media_map_t sMediaMap ;	
670};
671
672//just an interface class, do not create instance from this class.
673class LLViewerTextureManager
674{
675private:
676	//make the constructor private to preclude creating instances from this class.
677	LLViewerTextureManager(){}
678
679public:
680    //texture pipeline tester
681	static LLTexturePipelineTester* sTesterp ;
682
683	//returns NULL if tex is not a LLViewerFetchedTexture nor derived from LLViewerFetchedTexture.
684	static LLViewerFetchedTexture*    staticCastToFetchedTexture(LLTexture* tex, BOOL report_error = FALSE) ;
685
686	//
687	//"find-texture" just check if the texture exists, if yes, return it, otherwise return null.
688	//
689	static LLViewerTexture*           findTexture(const LLUUID& id) ;
690	static LLViewerMediaTexture*      findMediaTexture(const LLUUID& id) ;
691	
692	static LLViewerMediaTexture*      createMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
693
694	//
695	//"get-texture" will create a new texture if the texture does not exist.
696	//
697	static LLViewerMediaTexture*      getMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
698	
699	static LLPointer<LLViewerTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE);
700	static LLPointer<LLViewerTexture> getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
701	static LLPointer<LLViewerTexture> getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
702	static LLPointer<LLViewerTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
703
704	static LLViewerFetchedTexture* getFetchedTexture(const LLUUID &image_id,									 
705									 BOOL usemipmap = TRUE,
706									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
707									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
708									 LLGLint internal_format = 0,
709									 LLGLenum primary_format = 0,
710									 LLHost request_from_host = LLHost()
711									 );
712	
713	static LLViewerFetchedTexture* getFetchedTextureFromFile(const std::string& filename,									 
714									 BOOL usemipmap = TRUE,
715									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,
716									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
717									 LLGLint internal_format = 0,
718									 LLGLenum primary_format = 0,
719									 const LLUUID& force_id = LLUUID::null
720									 );
721
722	static LLViewerFetchedTexture* getFetchedTextureFromUrl(const std::string& url,									 
723									 BOOL usemipmap = TRUE,
724									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,
725									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
726									 LLGLint internal_format = 0,
727									 LLGLenum primary_format = 0,
728									 const LLUUID& force_id = LLUUID::null
729									 );
730
731	static LLViewerFetchedTexture* getFetchedTextureFromHost(const LLUUID& image_id, LLHost host) ;
732
733	static void init() ;
734	static void cleanup() ;
735};
736//
737//this class is used for test/debug only
738//it tracks the activities of the texture pipeline
739//records them, and outputs them to log files
740//
741class LLTexturePipelineTester : public LLMetricPerformanceTesterWithSession
742{
743	enum
744	{
745		MIN_LARGE_IMAGE_AREA = 262144  //512 * 512
746	};
747public:
748	LLTexturePipelineTester() ;
749	~LLTexturePipelineTester() ;
750
751	void update();		
752	void updateTextureBindingStats(const LLViewerTexture* imagep) ;
753	void updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache) ;
754	void updateGrayTextureBinding() ;
755	void setStablizingTime() ;
756
757private:
758	void reset() ;
759	void updateStablizingTime() ;
760
761	/*virtual*/ void outputTestRecord(LLSD* sd) ;
762
763private:
764	BOOL mPause ;
765private:
766	BOOL mUsingDefaultTexture;            //if set, some textures are still gray.
767
768	U32 mTotalBytesUsed ;                     //total bytes of textures bound/used for the current frame.
769	U32 mTotalBytesUsedForLargeImage ;        //total bytes of textures bound/used for the current frame for images larger than 256 * 256.
770	U32 mLastTotalBytesUsed ;                 //total bytes of textures bound/used for the previous frame.
771	U32 mLastTotalBytesUsedForLargeImage ;    //total bytes of textures bound/used for the previous frame for images larger than 256 * 256.
772		
773	//
774	//data size
775	//
776	U32 mTotalBytesLoaded ;               //total bytes fetched by texture pipeline
777	U32 mTotalBytesLoadedFromCache ;      //total bytes fetched by texture pipeline from local cache	
778	U32 mTotalBytesLoadedForLargeImage ;  //total bytes fetched by texture pipeline for images larger than 256 * 256. 
779	U32 mTotalBytesLoadedForSculpties ;   //total bytes fetched by texture pipeline for sculpties
780
781	//
782	//time
783	//NOTE: the error tolerances of the following timers is one frame time.
784	//
785	F32 mStartFetchingTime ;
786	F32 mTotalGrayTime ;                  //total loading time when no gray textures.
787	F32 mTotalStablizingTime ;            //total stablizing time when texture memory overflows
788	F32 mStartTimeLoadingSculpties ;      //the start moment of loading sculpty images.
789	F32 mEndTimeLoadingSculpties ;        //the end moment of loading sculpty images.
790	F32 mStartStablizingTime ;
791	F32 mEndStablizingTime ;
792
793private:
794	//
795	//The following members are used for performance analyzing
796	//
797	class LLTextureTestSession : public LLTestSession
798	{
799	public:
800		LLTextureTestSession() ;
801		/*virtual*/ ~LLTextureTestSession() ;
802
803		void reset() ;
804
805		F32 mTotalFetchingTime ;
806		F32 mTotalGrayTime ;
807		F32 mTotalStablizingTime ;
808		F32 mStartTimeLoadingSculpties ; 
809		F32 mTotalTimeLoadingSculpties ;
810
811		S32 mTotalBytesLoaded ; 
812		S32 mTotalBytesLoadedFromCache ;
813		S32 mTotalBytesLoadedForLargeImage ;
814		S32 mTotalBytesLoadedForSculpties ; 
815
816		typedef struct _texture_instant_preformance_t
817		{
818			S32 mAverageBytesUsedPerSecond ;         
819			S32 mAverageBytesUsedForLargeImagePerSecond ;
820			F32 mAveragePercentageBytesUsedPerSecond ;
821			F32 mTime ;
822		}texture_instant_preformance_t ;
823		std::vector<texture_instant_preformance_t> mInstantPerformanceList ;
824		S32 mInstantPerformanceListCounter ;
825	};
826
827	/*virtual*/ LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) ;
828	/*virtual*/ void compareTestSessions(std::ofstream* os) ;
829};
830
831#endif