diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llviewerimage.h | |
parent | README.txt (diff) | |
download | meta-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 'linden/indra/newview/llviewerimage.h')
-rw-r--r-- | linden/indra/newview/llviewerimage.h | 409 |
1 files changed, 409 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerimage.h b/linden/indra/newview/llviewerimage.h new file mode 100644 index 0000000..e2f44e5 --- /dev/null +++ b/linden/indra/newview/llviewerimage.h | |||
@@ -0,0 +1,409 @@ | |||
1 | /** | ||
2 | * @file llviewerimage.h | ||
3 | * @brief Object for managing images and their textures | ||
4 | * | ||
5 | * Copyright (c) 2000-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_LLVIEWERIMAGE_H | ||
29 | #define LL_LLVIEWERIMAGE_H | ||
30 | |||
31 | #include "llimagegl.h" | ||
32 | #include "lltimer.h" | ||
33 | #include "llframetimer.h" | ||
34 | #include "llhost.h" | ||
35 | |||
36 | #include <map> | ||
37 | #include <list> | ||
38 | |||
39 | class LLViewerImage; | ||
40 | |||
41 | typedef void (*loaded_callback_func)( BOOL success, LLViewerImage *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata ); | ||
42 | |||
43 | class LLVFile; | ||
44 | class LLViewerImagePacket; | ||
45 | class LLMessageSystem; | ||
46 | |||
47 | class LLLoadedCallbackEntry | ||
48 | { | ||
49 | public: | ||
50 | LLLoadedCallbackEntry(loaded_callback_func cb, | ||
51 | S32 discard_level, | ||
52 | BOOL need_imageraw, // Needs image raw for the callback | ||
53 | void* userdata ) | ||
54 | : mCallback(cb), | ||
55 | mLastUsedDiscard(MAX_DISCARD_LEVEL+1), | ||
56 | mDesiredDiscard(discard_level), | ||
57 | mNeedsImageRaw(need_imageraw), | ||
58 | mUserData(userdata) | ||
59 | { | ||
60 | } | ||
61 | |||
62 | loaded_callback_func mCallback; | ||
63 | S32 mLastUsedDiscard; | ||
64 | S32 mDesiredDiscard; | ||
65 | BOOL mNeedsImageRaw; | ||
66 | void* mUserData; | ||
67 | }; | ||
68 | |||
69 | class LLTextureBar; | ||
70 | |||
71 | class LLViewerImage : public LLImageGL | ||
72 | { | ||
73 | // friend class LLViewerImageList; | ||
74 | friend class LLTextureBar; // debug info only | ||
75 | friend class LLTextureView; // debug info only | ||
76 | |||
77 | public: | ||
78 | static void initClass(); | ||
79 | static void cleanupClass(); | ||
80 | static void updateClass(const F32 velocity, const F32 angular_velocity); | ||
81 | static void receiveImage(LLMessageSystem *msg, void **user_data); | ||
82 | static void receiveImagePacket(LLMessageSystem *msg, void **user_data); | ||
83 | static BOOL bindTexture(LLImageGL* image, const U32 stage = 0) | ||
84 | { | ||
85 | if (image) | ||
86 | { | ||
87 | return image->bind(stage); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | return sDefaultImagep->bind(stage); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | struct Compare | ||
96 | { | ||
97 | // lhs < rhs | ||
98 | bool operator()(const LLPointer<LLViewerImage> &lhs, const LLPointer<LLViewerImage> &rhs) const | ||
99 | { | ||
100 | const LLViewerImage* lhsp = (const LLViewerImage*)lhs; | ||
101 | const LLViewerImage* rhsp = (const LLViewerImage*)rhs; | ||
102 | // greater priority is "less" | ||
103 | const F32 lpriority = lhsp->getDecodePriority(); | ||
104 | const F32 rpriority = rhsp->getDecodePriority(); | ||
105 | if (lpriority > rpriority) // higher priority | ||
106 | return true; | ||
107 | if (lpriority < rpriority) | ||
108 | return false; | ||
109 | return lhsp < rhsp; | ||
110 | } | ||
111 | }; | ||
112 | |||
113 | struct CompareByHostAndPriority | ||
114 | { | ||
115 | // lhs < rhs | ||
116 | bool operator()(const LLPointer<LLViewerImage> &lhs, const LLPointer<LLViewerImage> &rhs) const | ||
117 | { | ||
118 | const LLViewerImage* lhsp = (const LLViewerImage*)lhs; | ||
119 | const LLViewerImage* rhsp = (const LLViewerImage*)rhs; | ||
120 | if (lhsp->mTargetHost != rhsp->mTargetHost) | ||
121 | return lhsp->mTargetHost < rhsp->mTargetHost; | ||
122 | |||
123 | const F32 lpriority = lhsp->getDecodePriority(); | ||
124 | const F32 rpriority = rhsp->getDecodePriority(); | ||
125 | if (lpriority != rpriority) | ||
126 | return lpriority > rpriority; // greater priority is "less" | ||
127 | |||
128 | return lhsp < rhsp; | ||
129 | } | ||
130 | }; | ||
131 | |||
132 | struct CompareForRemoval | ||
133 | { | ||
134 | // lhs < rhs | ||
135 | bool operator()(const LLPointer<LLViewerImage> &lhs, const LLPointer<LLViewerImage> &rhs) const | ||
136 | { | ||
137 | const LLViewerImage* lhsp = (const LLViewerImage*)lhs; | ||
138 | const LLViewerImage* rhsp = (const LLViewerImage*)rhs; | ||
139 | // compare bind time | ||
140 | if (lhsp->mLastBindTime < rhsp->mLastBindTime) // older | ||
141 | return true; | ||
142 | if (lhsp->mLastBindTime > rhsp->mLastBindTime) | ||
143 | return false; | ||
144 | if (lhsp->getDiscardLevel() < rhsp->getDiscardLevel()) // larger | ||
145 | return true; | ||
146 | if (lhsp->getDiscardLevel() > rhsp->getDiscardLevel()) | ||
147 | return false; | ||
148 | return lhsp < rhsp; | ||
149 | } | ||
150 | }; | ||
151 | |||
152 | struct CompareForWorstVisibility | ||
153 | { | ||
154 | // lhs < rhs | ||
155 | bool operator()(const LLPointer<LLViewerImage> &lhs, const LLPointer<LLViewerImage> &rhs) const | ||
156 | { | ||
157 | const LLViewerImage* lhsp = (const LLViewerImage*)lhs; | ||
158 | const LLViewerImage* rhsp = (const LLViewerImage*)rhs; | ||
159 | F32 lhsvis = ((lhsp->getWidth() * lhsp->getHeight()) / lhsp->mMaxVirtualSize); | ||
160 | F32 rhsvis = ((rhsp->getWidth() * rhsp->getHeight()) / rhsp->mMaxVirtualSize); | ||
161 | if (lhsvis > rhsvis) // fewer relative visible pixels | ||
162 | return true; | ||
163 | if (rhsvis < lhsvis) | ||
164 | return false; | ||
165 | return lhsp < rhsp; | ||
166 | } | ||
167 | }; | ||
168 | |||
169 | enum | ||
170 | { | ||
171 | MAX_IMAGE_SIZE_DEFAULT = 1024, | ||
172 | INVALID_DISCARD_LEVEL = 0x7fff | ||
173 | }; | ||
174 | |||
175 | protected: | ||
176 | /*virtual*/ ~LLViewerImage(); | ||
177 | |||
178 | public: | ||
179 | LLViewerImage(const LLUUID& id, BOOL usemipmaps = TRUE); | ||
180 | LLViewerImage(const U32 width, const U32 height, const U8 components, BOOL usemipmaps); | ||
181 | LLViewerImage(const LLImageRaw* raw, BOOL usemipmaps); | ||
182 | |||
183 | /*virtual*/ void dump(); // debug info to llinfos | ||
184 | |||
185 | /*virtual*/ BOOL bind(const S32 stage = 0) const; | ||
186 | |||
187 | void reinit(BOOL usemipmaps = TRUE); | ||
188 | |||
189 | const LLUUID& getID() { return mID; } | ||
190 | |||
191 | void setFormattedImage(LLImageFormatted* imagep); | ||
192 | |||
193 | // Load an image from the static VFS | ||
194 | BOOL loadLocalImage(const LLUUID& uuid); | ||
195 | |||
196 | // Start loading of data from VFS, if any | ||
197 | BOOL startVFSLoad(); | ||
198 | void startImageDecode(); | ||
199 | |||
200 | // Methods for loading and decoding data | ||
201 | void setDecodeData(U8 *data, U32 size); | ||
202 | void decodeImage(const F32 decode_time = 0.0); | ||
203 | bool isDecoding(); | ||
204 | |||
205 | // Poll the VFS to see if the read is complete. Returns TRUE if | ||
206 | // the read is complete (and sets mStreamFile to NULL). | ||
207 | BOOL loadStreamFile(); | ||
208 | |||
209 | // New methods for determining image quality/priority | ||
210 | // texel_area_ratio is ("scaled" texel area)/(original texel area), approximately. | ||
211 | void addTextureStats(F32 pixel_area, | ||
212 | F32 texel_area_ratio = 1.0f, | ||
213 | F32 cos_center_angle = 1.0f) const; | ||
214 | void resetTextureStats(BOOL zero = FALSE); | ||
215 | |||
216 | // Process image stats to determine priority/quality requirements. | ||
217 | void processTextureStats(); | ||
218 | |||
219 | // Checks image data and decodes if ready. Returns true if packets were decoded or are pending | ||
220 | BOOL checkPacketData(); | ||
221 | |||
222 | // Set callbacks to get called when the image gets updated with higher | ||
223 | // resolution versions. | ||
224 | void setLoadedCallback(loaded_callback_func cb, | ||
225 | S32 discard_level, | ||
226 | BOOL keep_imageraw, | ||
227 | void* userdata); | ||
228 | |||
229 | BOOL createTexture(S32 usename = 0); | ||
230 | BOOL destroyTexture(); | ||
231 | |||
232 | BOOL needsAux() const { return mNeedsAux; } | ||
233 | void setNeedsAux(const BOOL needs_aux) { mNeedsAux = needs_aux; } | ||
234 | BOOL needsDecode() const { return mNeedsDecode; } | ||
235 | void setNeedsDecode(const BOOL needs_decode) { mNeedsDecode = needs_decode; } | ||
236 | |||
237 | // setDesiredDiscardLevel is only used by LLViewerImageList | ||
238 | void setDesiredDiscardLevel(S32 discard) { mDesiredDiscardLevel = discard; } | ||
239 | S32 getDesiredDiscardLevel() { return mDesiredDiscardLevel; } | ||
240 | |||
241 | void setMinDiscardLevel(S32 discard) { mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); } | ||
242 | |||
243 | // Host we think might have this image, used for baked av textures. | ||
244 | void setTargetHost(LLHost host) { mTargetHost = host; } | ||
245 | LLHost getTargetHost() const { return mTargetHost; } | ||
246 | |||
247 | enum | ||
248 | { | ||
249 | BOOST_NONE = 0, | ||
250 | BOOST_TERRAIN = 1, | ||
251 | BOOST_AVATAR_BAKED = 2, | ||
252 | BOOST_AVATAR = 3, | ||
253 | BOOST_CLOUDS = 4, | ||
254 | |||
255 | BOOST_HIGH = 10, | ||
256 | BOOST_SELECTED = 11, | ||
257 | BOOST_HUD = 12, | ||
258 | BOOST_AVATAR_BAKED_SELF = 13, | ||
259 | BOOST_UI = 14, | ||
260 | BOOST_PREVIEW = 15, | ||
261 | BOOST_MAP = 16, | ||
262 | BOOST_MAP_LAYER = 17, | ||
263 | BOOST_AVATAR_SELF = 18, // needed for baking avatar | ||
264 | BOOST_MAX_LEVEL | ||
265 | }; | ||
266 | void setBoostLevel(S32 level); | ||
267 | S32 getBoostLevel() { return mBoostLevel; } | ||
268 | |||
269 | F32 getDecodePriority() const { return mDecodePriority; }; | ||
270 | F32 calcDecodePriority(); | ||
271 | static F32 maxDecodePriority(); | ||
272 | |||
273 | // Set the decode priority for this image... | ||
274 | // DON'T CALL THIS UNLESS YOU KNOW WHAT YOU'RE DOING, it can mess up | ||
275 | // the priority list, and cause horrible things to happen. | ||
276 | void setDecodePriority(F32 priority = -1.0f); | ||
277 | |||
278 | // Override the computation of discard levels if we know the exact output | ||
279 | // size of the image. Used for UI textures to not decode, even if we have | ||
280 | // more data. | ||
281 | void setKnownDrawSize(S32 width, S32 height); | ||
282 | |||
283 | void setIsMissingAsset(BOOL b) { mIsMissingAsset = b; } | ||
284 | BOOL isMissingAsset() { return mIsMissingAsset; } | ||
285 | |||
286 | BOOL getNeedsCreateTexture() const { return mNeedsCreateTexture; } | ||
287 | |||
288 | bool hasCallbacks() { return mLoadedCallbackList.empty() ? false : true; } | ||
289 | |||
290 | void doLoadedCallbacks(); | ||
291 | S32 getLastPacket() { return mLastPacket; } | ||
292 | F32 getDecodeProgress(F32 *data_progress_p = 0); | ||
293 | |||
294 | void abortDecode(); | ||
295 | void destroyRawImage(); // Delete the raw image for this discard level | ||
296 | |||
297 | private: | ||
298 | /*virtual*/ void cleanup(); // Cleanup the LLViewerImage (so we can reinitialize it) | ||
299 | |||
300 | void init(bool firstinit); | ||
301 | void hoseStreamFile(); | ||
302 | void resetPacketData(); | ||
303 | |||
304 | // Used to be in LLImageGL | ||
305 | LLImageRaw* createRawImage(S8 discard_level = 0, BOOL allocate = FALSE); | ||
306 | |||
307 | public: | ||
308 | S32 mFullWidth; | ||
309 | S32 mFullHeight; | ||
310 | LLVFile *mStreamFile; | ||
311 | |||
312 | // Data used for calculating required image priority/quality level/decimation | ||
313 | mutable F32 mMaxVirtualSize; // The largest virtual size of the image, in pixels - how much data to we need? | ||
314 | mutable F32 mMaxCosAngle; // The largest cos of the angle between camera X vector and the object | ||
315 | |||
316 | F32 mTexelsPerImage; // Texels per image. | ||
317 | |||
318 | S8 mInImageList; // TRUE if image is in list (in which case don't reset priority!) | ||
319 | S8 mIsMediaTexture; // TRUE if image is being replaced by media (in which case don't update) | ||
320 | S8 mInStaticVFS; // Source data in local VFS | ||
321 | S8 mFormattedFlushed; | ||
322 | |||
323 | S8 mRequested; // An image request is currently in process. | ||
324 | S8 mFullyLoaded; | ||
325 | |||
326 | // Various info regarding image requests | ||
327 | LLFrameTimer mRequestTime; | ||
328 | S32 mRequestedDiscardLevel; | ||
329 | F32 mRequestedDownloadPriority; | ||
330 | |||
331 | // Timers | ||
332 | LLFrameTimer mLastDecodeTime; // Time since last decode. | ||
333 | LLFrameTimer mLastPacketTimer; // Time since last packet. | ||
334 | LLFrameTimer mLastReferencedTimer; | ||
335 | |||
336 | private: | ||
337 | LLUUID mID; | ||
338 | LLPointer<LLImageFormatted> mFormattedImagep; | ||
339 | |||
340 | S8 mDesiredDiscardLevel; // The discard level we'd LIKE to have - if we have it and there's space | ||
341 | S8 mMinDesiredDiscardLevel; // The minimum discard level we'd like to have | ||
342 | S8 mGotFirstPacket; | ||
343 | S8 mNeedsCreateTexture; | ||
344 | |||
345 | S8 mNeedsDecode; // We have a compressed image that we want to decode, now. | ||
346 | S8 mNeedsAux; // We need to decode the auxiliary channels | ||
347 | |||
348 | S8 mDecodingAux; // Are we decoding high components | ||
349 | mutable S8 mIsMissingAsset; // True if we know that there is no image asset with this image id in the database. | ||
350 | |||
351 | // Codec of incoming packet data | ||
352 | U8 mDataCodec; | ||
353 | S8 mIsRawImageValid; | ||
354 | |||
355 | typedef std::map<U16, LLViewerImagePacket *> vip_map_t; | ||
356 | vip_map_t mReceivedPacketMap; | ||
357 | S32 mLastPacketProcessed; | ||
358 | U32 mLastBytesProcessed; // Total bytes including the last packet rec'd | ||
359 | |||
360 | // Data download/decode info | ||
361 | U32 mPacketsReceived; | ||
362 | U32 mTotalBytes; | ||
363 | S32 mLastPacket; // Last packet received without a gap. | ||
364 | U16 mPackets; | ||
365 | |||
366 | // VFS info | ||
367 | U8 *mCachedData; | ||
368 | S32 mCachedSize; | ||
369 | |||
370 | // Override the computation of discard levels if we know the exact output size of the image. | ||
371 | // Used for UI textures to not decode, even if we have more data. | ||
372 | S32 mKnownDrawWidth; | ||
373 | S32 mKnownDrawHeight; | ||
374 | |||
375 | F32 mDecodePriority; // The priority for decoding this image. | ||
376 | S32 mBoostLevel; // enum describing priority level | ||
377 | |||
378 | typedef std::list<LLLoadedCallbackEntry*> callback_list_t; | ||
379 | callback_list_t mLoadedCallbackList; | ||
380 | |||
381 | LLPointer<LLImageRaw> mRawImage; | ||
382 | S32 mRawDiscardLevel; | ||
383 | // Used ONLY for cloth meshes right now. Make SURE you know what you're | ||
384 | // doing if you use it for anything else! - djs | ||
385 | LLPointer<LLImageRaw> mAuxRawImage; | ||
386 | |||
387 | LLHost mTargetHost; // if LLHost::invalid, just request from agent's simulator | ||
388 | |||
389 | public: | ||
390 | static const U32 sCurrentFileVersion; | ||
391 | // Default textures | ||
392 | static LLPointer<LLViewerImage> sMissingAssetImagep; // Texture to show for an image asset that is not in the database | ||
393 | static LLPointer<LLViewerImage> sWhiteImagep; // Texture to show NOTHING (whiteness) | ||
394 | static LLPointer<LLImageGL> sDefaultImagep; // "Default" texture for error cases | ||
395 | static LLPointer<LLViewerImage> sSmokeImagep; // Old "Default" translucent texture | ||
396 | static LLPointer<LLImageGL> sNullImagep; // Null texture for non-textured objects. | ||
397 | |||
398 | static S32 sImageCount; | ||
399 | static LLTimer sEvaluationTimer; | ||
400 | static F32 sDesiredDiscardBias; | ||
401 | static F32 sDesiredDiscardScale; | ||
402 | static S32 sBoundTextureMemory; | ||
403 | static S32 sTotalTextureMemory; | ||
404 | static S32 sMaxBoundTextureMem; | ||
405 | static S32 sMaxTotalTextureMem; | ||
406 | static BOOL sDontLoadVolumeTextures; | ||
407 | }; | ||
408 | |||
409 | #endif | ||