1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/**
* @file llviewertexlayer.cpp
* @brief Viewer texture layer. Used for avatars.
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llviewertexlayer.h"
#include "llagent.h"
#include "llimagej2c.h"
#include "llnotificationsutil.h"
#include "llvfile.h"
#include "llvfs.h"
#include "llviewerregion.h"
#include "llglslshader.h"
#include "llvoavatarself.h"
#include "pipeline.h"
#include "llviewercontrol.h"
// runway consolidate
extern std::string self_av_string();
//-----------------------------------------------------------------------------
// LLViewerTexLayerSetBuffer
// The composite image that a LLViewerTexLayerSet writes to. Each LLViewerTexLayerSet has one.
//-----------------------------------------------------------------------------
// static
S32 LLViewerTexLayerSetBuffer::sGLByteCount = 0;
LLViewerTexLayerSetBuffer::LLViewerTexLayerSetBuffer(LLTexLayerSet* const owner,
S32 width, S32 height) :
// ORDER_LAST => must render these after the hints are created.
LLTexLayerSetBuffer(owner),
LLViewerDynamicTexture( width, height, 4, LLViewerDynamicTexture::ORDER_LAST, TRUE ),
mNeedsUpdate(TRUE),
mNumLowresUpdates(0)
{
LLViewerTexLayerSetBuffer::sGLByteCount += getSize();
mNeedsUpdateTimer.start();
}
LLViewerTexLayerSetBuffer::~LLViewerTexLayerSetBuffer()
{
LLViewerTexLayerSetBuffer::sGLByteCount -= getSize();
destroyGLTexture();
for( S32 order = 0; order < ORDER_COUNT; order++ )
{
LLViewerDynamicTexture::sInstances[order].erase(this); // will fail in all but one case.
}
}
//virtual
S8 LLViewerTexLayerSetBuffer::getType() const
{
return LLViewerDynamicTexture::LL_TEX_LAYER_SET_BUFFER ;
}
//virtual
void LLViewerTexLayerSetBuffer::restoreGLTexture()
{
LLViewerDynamicTexture::restoreGLTexture() ;
}
//virtual
void LLViewerTexLayerSetBuffer::destroyGLTexture()
{
LLViewerDynamicTexture::destroyGLTexture() ;
}
// static
void LLViewerTexLayerSetBuffer::dumpTotalByteCount()
{
LL_INFOS() << "Composite System GL Buffers: " << (LLViewerTexLayerSetBuffer::sGLByteCount/1024) << "KB" << LL_ENDL;
}
void LLViewerTexLayerSetBuffer::requestUpdate()
{
restartUpdateTimer();
mNeedsUpdate = TRUE;
mNumLowresUpdates = 0;
}
void LLViewerTexLayerSetBuffer::restartUpdateTimer()
{
mNeedsUpdateTimer.reset();
mNeedsUpdateTimer.start();
}
// virtual
BOOL LLViewerTexLayerSetBuffer::needsRender()
{
llassert(mTexLayerSet->getAvatarAppearance() == gAgentAvatarp);
if (!isAgentAvatarValid()) return FALSE;
const BOOL update_now = mNeedsUpdate && isReadyToUpdate();
// Don't render if we don't want to (or aren't ready to) update.
if (!update_now)
{
return FALSE;
}
// Don't render if we're animating our appearance.
if (gAgentAvatarp->getIsAppearanceAnimating())
{
return FALSE;
}
// Don't render if we are trying to create a skirt texture but aren't wearing a skirt.
if (gAgentAvatarp->getBakedTE(getViewerTexLayerSet()) == LLAvatarAppearanceDefines::TEX_SKIRT_BAKED &&
!gAgentAvatarp->isWearingWearableType(LLWearableType::WT_SKIRT))
{
return FALSE;
}
// Render if we have at least minimal level of detail for each local texture.
return getViewerTexLayerSet()->isLocalTextureDataAvailable();
}
// virtual
void LLViewerTexLayerSetBuffer::preRenderTexLayerSet()
{
LLTexLayerSetBuffer::preRenderTexLayerSet();
// keep depth buffer, we don't need to clear it
LLViewerDynamicTexture::preRender(FALSE);
}
// virtual
void LLViewerTexLayerSetBuffer::postRenderTexLayerSet(BOOL success)
{
LLTexLayerSetBuffer::postRenderTexLayerSet(success);
LLViewerDynamicTexture::postRender(success);
}
// virtual
void LLViewerTexLayerSetBuffer::midRenderTexLayerSet(BOOL success)
{
const BOOL update_now = mNeedsUpdate && isReadyToUpdate();
if (update_now)
{
doUpdate();
}
// *TODO: Old logic does not check success before setGLTextureCreated
// we have valid texture data now
mGLTexturep->setGLTextureCreated(true);
}
BOOL LLViewerTexLayerSetBuffer::isInitialized(void) const
{
return mGLTexturep.notNull() && mGLTexturep->isGLTextureCreated();
}
BOOL LLViewerTexLayerSetBuffer::isReadyToUpdate() const
{
// If we requested an update and have the final LOD ready, then update.
if (getViewerTexLayerSet()->isLocalTextureDataFinal()) return TRUE;
// If we haven't done an update yet, then just do one now regardless of state of textures.
if (mNumLowresUpdates == 0) return TRUE;
// Update if we've hit a timeout. Unlike for uploads, we can make this timeout fairly small
// since render unnecessarily doesn't cost much.
const U32 texture_timeout = gSavedSettings.getU32("AvatarBakedLocalTextureUpdateTimeout");
if (texture_timeout != 0)
{
// If we hit our timeout and have textures available at even lower resolution, then update.
const BOOL is_update_textures_timeout = mNeedsUpdateTimer.getElapsedTimeF32() >= texture_timeout;
const BOOL has_lower_lod = getViewerTexLayerSet()->isLocalTextureDataAvailable();
if (has_lower_lod && is_update_textures_timeout) return TRUE;
}
return FALSE;
}
BOOL LLViewerTexLayerSetBuffer::requestUpdateImmediate()
{
mNeedsUpdate = TRUE;
BOOL result = FALSE;
if (needsRender())
{
preRender(FALSE);
result = render();
postRender(result);
}
return result;
}
// Mostly bookkeeping; don't need to actually "do" anything since
// render() will actually do the update.
void LLViewerTexLayerSetBuffer::doUpdate()
{
LLViewerTexLayerSet* layer_set = getViewerTexLayerSet();
const BOOL highest_lod = layer_set->isLocalTextureDataFinal();
if (highest_lod)
{
mNeedsUpdate = FALSE;
}
else
{
mNumLowresUpdates++;
}
restartUpdateTimer();
// need to switch to using this layerset if this is the first update
// after getting the lowest LOD
layer_set->getAvatar()->updateMeshTextures();
// Print out notification that we updated this texture.
if (gSavedSettings.getBOOL("DebugAvatarRezTime"))
{
const BOOL highest_lod = layer_set->isLocalTextureDataFinal();
const std::string lod_str = highest_lod ? "HighRes" : "LowRes";
LLSD args;
args["EXISTENCE"] = llformat("%d",(U32)layer_set->getAvatar()->debugGetExistenceTimeElapsedF32());
args["TIME"] = llformat("%d",(U32)mNeedsUpdateTimer.getElapsedTimeF32());
args["BODYREGION"] = layer_set->getBodyRegionName();
args["RESOLUTION"] = lod_str;
LLNotificationsUtil::add("AvatarRezSelfBakedTextureUpdateNotification",args);
LL_DEBUGS("Avatar") << self_av_string() << "Locally updating [ name: " << layer_set->getBodyRegionName() << " res:" << lod_str << " time:" << (U32)mNeedsUpdateTimer.getElapsedTimeF32() << " ]" << LL_ENDL;
}
}
//-----------------------------------------------------------------------------
// LLViewerTexLayerSet
// An ordered set of texture layers that get composited into a single texture.
//-----------------------------------------------------------------------------
LLViewerTexLayerSet::LLViewerTexLayerSet(LLAvatarAppearance* const appearance) :
LLTexLayerSet(appearance),
mUpdatesEnabled( FALSE )
{
}
// virtual
LLViewerTexLayerSet::~LLViewerTexLayerSet()
{
}
// Returns TRUE if at least one packet of data has been received for each of the textures that this layerset depends on.
BOOL LLViewerTexLayerSet::isLocalTextureDataAvailable() const
{
if (!mAvatarAppearance->isSelf()) return FALSE;
return getAvatar()->isLocalTextureDataAvailable(this);
}
// Returns TRUE if all of the data for the textures that this layerset depends on have arrived.
BOOL LLViewerTexLayerSet::isLocalTextureDataFinal() const
{
if (!mAvatarAppearance->isSelf()) return FALSE;
return getAvatar()->isLocalTextureDataFinal(this);
}
// virtual
void LLViewerTexLayerSet::requestUpdate()
{
if( mUpdatesEnabled )
{
createComposite();
getViewerComposite()->requestUpdate();
}
}
void LLViewerTexLayerSet::updateComposite()
{
createComposite();
getViewerComposite()->requestUpdateImmediate();
}
// virtual
void LLViewerTexLayerSet::createComposite()
{
if(!mComposite)
{
S32 width = mInfo->getWidth();
S32 height = mInfo->getHeight();
// Composite other avatars at reduced resolution
if( !mAvatarAppearance->isSelf() )
{
LL_ERRS() << "composites should not be created for non-self avatars!" << LL_ENDL;
}
mComposite = new LLViewerTexLayerSetBuffer( this, width, height );
}
}
void LLViewerTexLayerSet::setUpdatesEnabled( BOOL b )
{
mUpdatesEnabled = b;
}
LLVOAvatarSelf* LLViewerTexLayerSet::getAvatar()
{
return dynamic_cast<LLVOAvatarSelf*> (mAvatarAppearance);
}
const LLVOAvatarSelf* LLViewerTexLayerSet::getAvatar() const
{
return dynamic_cast<const LLVOAvatarSelf*> (mAvatarAppearance);
}
LLViewerTexLayerSetBuffer* LLViewerTexLayerSet::getViewerComposite()
{
return dynamic_cast<LLViewerTexLayerSetBuffer*> (getComposite());
}
const LLViewerTexLayerSetBuffer* LLViewerTexLayerSet::getViewerComposite() const
{
return dynamic_cast<const LLViewerTexLayerSetBuffer*> (getComposite());
}
const std::string LLViewerTexLayerSetBuffer::dumpTextureInfo() const
{
if (!isAgentAvatarValid()) return "";
const BOOL is_high_res = TRUE;
const U32 num_low_res = 0;
const std::string local_texture_info = gAgentAvatarp->debugDumpLocalTextureDataInfo(getViewerTexLayerSet());
std::string text = llformat("[HiRes:%d LoRes:%d] %s",
is_high_res, num_low_res,
local_texture_info.c_str());
return text;
}
|