PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llvoavatarself.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2172 lines | 1699 code | 240 blank | 233 comment | 341 complexity | b27d8f34f13dc9cf3682a2cd0c9b2009 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvoavatar.cpp
  3. * @brief Implementation of LLVOAvatar class which is a derivation fo LLViewerObject
  4. *
  5. * $LicenseInfo:firstyear=2001&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. #if LL_MSVC
  27. // disable warning about boost::lexical_cast returning uninitialized data
  28. // when it fails to parse the string
  29. #pragma warning (disable:4701)
  30. #endif
  31. #include "llviewerprecompiledheaders.h"
  32. #include "llvoavatarself.h"
  33. #include "llvoavatar.h"
  34. #include "pipeline.h"
  35. #include "llagent.h" // Get state values from here
  36. #include "llagentcamera.h"
  37. #include "llagentwearables.h"
  38. #include "llhudeffecttrail.h"
  39. #include "llhudmanager.h"
  40. #include "llinventoryfunctions.h"
  41. #include "llnotificationsutil.h"
  42. #include "llselectmgr.h"
  43. #include "lltoolgrab.h" // for needsRenderBeam
  44. #include "lltoolmgr.h" // for needsRenderBeam
  45. #include "lltoolmorph.h"
  46. #include "lltrans.h"
  47. #include "llviewercamera.h"
  48. #include "llviewercontrol.h"
  49. #include "llviewermenu.h"
  50. #include "llviewerobjectlist.h"
  51. #include "llviewerstats.h"
  52. #include "llviewerregion.h"
  53. #include "llappearancemgr.h"
  54. #include "llmeshrepository.h"
  55. #include "llvovolume.h"
  56. #if LL_MSVC
  57. // disable boost::lexical_cast warning
  58. #pragma warning (disable:4702)
  59. #endif
  60. #include <boost/lexical_cast.hpp>
  61. LLVOAvatarSelf *gAgentAvatarp = NULL;
  62. BOOL isAgentAvatarValid()
  63. {
  64. return (gAgentAvatarp &&
  65. (gAgentAvatarp->getRegion() != NULL) &&
  66. (!gAgentAvatarp->isDead()));
  67. }
  68. using namespace LLVOAvatarDefines;
  69. /*********************************************************************************
  70. ** **
  71. ** Begin private LLVOAvatarSelf Support classes
  72. **
  73. **/
  74. struct LocalTextureData
  75. {
  76. LocalTextureData() :
  77. mIsBakedReady(false),
  78. mDiscard(MAX_DISCARD_LEVEL+1),
  79. mImage(NULL),
  80. mWearableID(IMG_DEFAULT_AVATAR),
  81. mTexEntry(NULL)
  82. {}
  83. LLPointer<LLViewerFetchedTexture> mImage;
  84. bool mIsBakedReady;
  85. S32 mDiscard;
  86. LLUUID mWearableID; // UUID of the wearable that this texture belongs to, not of the image itself
  87. LLTextureEntry *mTexEntry;
  88. };
  89. //-----------------------------------------------------------------------------
  90. // Callback data
  91. //-----------------------------------------------------------------------------
  92. /**
  93. **
  94. ** End LLVOAvatarSelf Support classes
  95. ** **
  96. *********************************************************************************/
  97. //-----------------------------------------------------------------------------
  98. // Static Data
  99. //-----------------------------------------------------------------------------
  100. S32 LLVOAvatarSelf::sScratchTexBytes = 0;
  101. LLMap< LLGLenum, LLGLuint*> LLVOAvatarSelf::sScratchTexNames;
  102. LLMap< LLGLenum, F32*> LLVOAvatarSelf::sScratchTexLastBindTime;
  103. /*********************************************************************************
  104. ** **
  105. ** Begin LLVOAvatarSelf Constructor routines
  106. **
  107. **/
  108. LLVOAvatarSelf::LLVOAvatarSelf(const LLUUID& id,
  109. const LLPCode pcode,
  110. LLViewerRegion* regionp) :
  111. LLVOAvatar(id, pcode, regionp),
  112. mScreenp(NULL),
  113. mLastRegionHandle(0),
  114. mRegionCrossingCount(0)
  115. {
  116. gAgentWearables.setAvatarObject(this);
  117. mMotionController.mIsSelf = TRUE;
  118. lldebugs << "Marking avatar as self " << id << llendl;
  119. }
  120. void LLVOAvatarSelf::initInstance()
  121. {
  122. BOOL status = TRUE;
  123. // creates hud joint(mScreen) among other things
  124. status &= loadAvatarSelf();
  125. // adds attachment points to mScreen among other things
  126. LLVOAvatar::initInstance();
  127. llinfos << "Self avatar object created. Starting timer." << llendl;
  128. mDebugSelfLoadTimer.reset();
  129. // clear all times to -1 for debugging
  130. for (U32 i =0; i < LLVOAvatarDefines::TEX_NUM_INDICES; ++i)
  131. {
  132. for (U32 j = 0; j <= MAX_DISCARD_LEVEL; ++j)
  133. {
  134. mDebugTextureLoadTimes[i][j] = -1.0f;
  135. }
  136. }
  137. for (U32 i =0; i < LLVOAvatarDefines::BAKED_NUM_INDICES; ++i)
  138. {
  139. mDebugBakedTextureTimes[i][0] = -1.0f;
  140. mDebugBakedTextureTimes[i][1] = -1.0f;
  141. }
  142. status &= buildMenus();
  143. if (!status)
  144. {
  145. llerrs << "Unable to load user's avatar" << llendl;
  146. return;
  147. }
  148. }
  149. // virtual
  150. void LLVOAvatarSelf::markDead()
  151. {
  152. mBeam = NULL;
  153. LLVOAvatar::markDead();
  154. }
  155. /*virtual*/ BOOL LLVOAvatarSelf::loadAvatar()
  156. {
  157. BOOL success = LLVOAvatar::loadAvatar();
  158. // set all parameters sotred directly in the avatar to have
  159. // the isSelfParam to be TRUE - this is used to prevent
  160. // them from being animated or trigger accidental rebakes
  161. // when we copy params from the wearable to the base avatar.
  162. for (LLViewerVisualParam* param = (LLViewerVisualParam*) getFirstVisualParam();
  163. param;
  164. param = (LLViewerVisualParam*) getNextVisualParam())
  165. {
  166. if (param->getWearableType() != LLWearableType::WT_INVALID)
  167. {
  168. param->setIsDummy(TRUE);
  169. }
  170. }
  171. return success;
  172. }
  173. BOOL LLVOAvatarSelf::loadAvatarSelf()
  174. {
  175. BOOL success = TRUE;
  176. // avatar_skeleton.xml
  177. if (!buildSkeletonSelf(sAvatarSkeletonInfo))
  178. {
  179. llwarns << "avatar file: buildSkeleton() failed" << llendl;
  180. return FALSE;
  181. }
  182. // TODO: make loadLayersets() called only by self.
  183. //success &= loadLayersets();
  184. return success;
  185. }
  186. BOOL LLVOAvatarSelf::buildSkeletonSelf(const LLVOAvatarSkeletonInfo *info)
  187. {
  188. LLMemType mt(LLMemType::MTYPE_AVATAR);
  189. // add special-purpose "screen" joint
  190. mScreenp = new LLViewerJoint("mScreen", NULL);
  191. // for now, put screen at origin, as it is only used during special
  192. // HUD rendering mode
  193. F32 aspect = LLViewerCamera::getInstance()->getAspect();
  194. LLVector3 scale(1.f, aspect, 1.f);
  195. mScreenp->setScale(scale);
  196. mScreenp->setWorldPosition(LLVector3::zero);
  197. // need to update screen agressively when sidebar opens/closes, for example
  198. mScreenp->mUpdateXform = TRUE;
  199. return TRUE;
  200. }
  201. BOOL LLVOAvatarSelf::buildMenus()
  202. {
  203. //-------------------------------------------------------------------------
  204. // build the attach and detach menus
  205. //-------------------------------------------------------------------------
  206. gAttachBodyPartPieMenus[0] = NULL;
  207. LLContextMenu::Params params;
  208. params.label(LLTrans::getString("BodyPartsRightArm"));
  209. params.name(params.label);
  210. params.visible(false);
  211. gAttachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
  212. params.label(LLTrans::getString("BodyPartsHead"));
  213. params.name(params.label);
  214. gAttachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
  215. params.label(LLTrans::getString("BodyPartsLeftArm"));
  216. params.name(params.label);
  217. gAttachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
  218. gAttachBodyPartPieMenus[4] = NULL;
  219. params.label(LLTrans::getString("BodyPartsLeftLeg"));
  220. params.name(params.label);
  221. gAttachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
  222. params.label(LLTrans::getString("BodyPartsTorso"));
  223. params.name(params.label);
  224. gAttachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
  225. params.label(LLTrans::getString("BodyPartsRightLeg"));
  226. params.name(params.label);
  227. gAttachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
  228. gDetachBodyPartPieMenus[0] = NULL;
  229. params.label(LLTrans::getString("BodyPartsRightArm"));
  230. params.name(params.label);
  231. gDetachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
  232. params.label(LLTrans::getString("BodyPartsHead"));
  233. params.name(params.label);
  234. gDetachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
  235. params.label(LLTrans::getString("BodyPartsLeftArm"));
  236. params.name(params.label);
  237. gDetachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
  238. gDetachBodyPartPieMenus[4] = NULL;
  239. params.label(LLTrans::getString("BodyPartsLeftLeg"));
  240. params.name(params.label);
  241. gDetachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
  242. params.label(LLTrans::getString("BodyPartsTorso"));
  243. params.name(params.label);
  244. gDetachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
  245. params.label(LLTrans::getString("BodyPartsRightLeg"));
  246. params.name(params.label);
  247. gDetachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
  248. for (S32 i = 0; i < 8; i++)
  249. {
  250. if (gAttachBodyPartPieMenus[i])
  251. {
  252. gAttachPieMenu->appendContextSubMenu( gAttachBodyPartPieMenus[i] );
  253. }
  254. else
  255. {
  256. BOOL attachment_found = FALSE;
  257. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  258. iter != mAttachmentPoints.end();
  259. ++iter)
  260. {
  261. LLViewerJointAttachment* attachment = iter->second;
  262. if (attachment->getGroup() == i)
  263. {
  264. LLMenuItemCallGL::Params item_params;
  265. std::string sub_piemenu_name = attachment->getName();
  266. if (LLTrans::getString(sub_piemenu_name) != "")
  267. {
  268. item_params.label = LLTrans::getString(sub_piemenu_name);
  269. }
  270. else
  271. {
  272. item_params.label = sub_piemenu_name;
  273. }
  274. item_params.name =(item_params.label );
  275. item_params.on_click.function_name = "Object.AttachToAvatar";
  276. item_params.on_click.parameter = iter->first;
  277. item_params.on_enable.function_name = "Object.EnableWear";
  278. item_params.on_enable.parameter = iter->first;
  279. LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  280. gAttachPieMenu->addChild(item);
  281. attachment_found = TRUE;
  282. break;
  283. }
  284. }
  285. }
  286. if (gDetachBodyPartPieMenus[i])
  287. {
  288. gDetachPieMenu->appendContextSubMenu( gDetachBodyPartPieMenus[i] );
  289. }
  290. else
  291. {
  292. BOOL attachment_found = FALSE;
  293. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  294. iter != mAttachmentPoints.end();
  295. ++iter)
  296. {
  297. LLViewerJointAttachment* attachment = iter->second;
  298. if (attachment->getGroup() == i)
  299. {
  300. LLMenuItemCallGL::Params item_params;
  301. std::string sub_piemenu_name = attachment->getName();
  302. if (LLTrans::getString(sub_piemenu_name) != "")
  303. {
  304. item_params.label = LLTrans::getString(sub_piemenu_name);
  305. }
  306. else
  307. {
  308. item_params.label = sub_piemenu_name;
  309. }
  310. item_params.name =(item_params.label );
  311. item_params.on_click.function_name = "Attachment.Detach";
  312. item_params.on_click.parameter = iter->first;
  313. item_params.on_enable.function_name = "Attachment.EnableDetach";
  314. item_params.on_enable.parameter = iter->first;
  315. LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  316. gDetachPieMenu->addChild(item);
  317. attachment_found = TRUE;
  318. break;
  319. }
  320. }
  321. }
  322. }
  323. // add screen attachments
  324. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  325. iter != mAttachmentPoints.end();
  326. ++iter)
  327. {
  328. LLViewerJointAttachment* attachment = iter->second;
  329. if (attachment->getGroup() == 8)
  330. {
  331. LLMenuItemCallGL::Params item_params;
  332. std::string sub_piemenu_name = attachment->getName();
  333. if (LLTrans::getString(sub_piemenu_name) != "")
  334. {
  335. item_params.label = LLTrans::getString(sub_piemenu_name);
  336. }
  337. else
  338. {
  339. item_params.label = sub_piemenu_name;
  340. }
  341. item_params.name =(item_params.label );
  342. item_params.on_click.function_name = "Object.AttachToAvatar";
  343. item_params.on_click.parameter = iter->first;
  344. item_params.on_enable.function_name = "Object.EnableWear";
  345. item_params.on_enable.parameter = iter->first;
  346. LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  347. gAttachScreenPieMenu->addChild(item);
  348. item_params.on_click.function_name = "Attachment.DetachFromPoint";
  349. item_params.on_click.parameter = iter->first;
  350. item_params.on_enable.function_name = "Attachment.PointFilled";
  351. item_params.on_enable.parameter = iter->first;
  352. item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  353. gDetachScreenPieMenu->addChild(item);
  354. }
  355. }
  356. for (S32 pass = 0; pass < 2; pass++)
  357. {
  358. // *TODO: Skinning - gAttachSubMenu is an awful, awful hack
  359. if (!gAttachSubMenu)
  360. {
  361. break;
  362. }
  363. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  364. iter != mAttachmentPoints.end();
  365. ++iter)
  366. {
  367. LLViewerJointAttachment* attachment = iter->second;
  368. if (attachment->getIsHUDAttachment() != (pass == 1))
  369. {
  370. continue;
  371. }
  372. LLMenuItemCallGL::Params item_params;
  373. std::string sub_piemenu_name = attachment->getName();
  374. if (LLTrans::getString(sub_piemenu_name) != "")
  375. {
  376. item_params.label = LLTrans::getString(sub_piemenu_name);
  377. }
  378. else
  379. {
  380. item_params.label = sub_piemenu_name;
  381. }
  382. item_params.name =(item_params.label );
  383. item_params.on_click.function_name = "Object.AttachToAvatar";
  384. item_params.on_click.parameter = iter->first;
  385. item_params.on_enable.function_name = "Object.EnableWear";
  386. item_params.on_enable.parameter = iter->first;
  387. //* TODO: Skinning:
  388. //LLSD params;
  389. //params["index"] = iter->first;
  390. //params["label"] = attachment->getName();
  391. //item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
  392. LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  393. gAttachSubMenu->addChild(item);
  394. item_params.on_click.function_name = "Attachment.DetachFromPoint";
  395. item_params.on_click.parameter = iter->first;
  396. item_params.on_enable.function_name = "Attachment.PointFilled";
  397. item_params.on_enable.parameter = iter->first;
  398. //* TODO: Skinning: item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
  399. item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  400. gDetachSubMenu->addChild(item);
  401. }
  402. if (pass == 0)
  403. {
  404. // put separator between non-hud and hud attachments
  405. gAttachSubMenu->addSeparator();
  406. gDetachSubMenu->addSeparator();
  407. }
  408. }
  409. for (S32 group = 0; group < 8; group++)
  410. {
  411. // skip over groups that don't have sub menus
  412. if (!gAttachBodyPartPieMenus[group] || !gDetachBodyPartPieMenus[group])
  413. {
  414. continue;
  415. }
  416. std::multimap<S32, S32> attachment_pie_menu_map;
  417. // gather up all attachment points assigned to this group, and throw into map sorted by pie slice number
  418. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  419. iter != mAttachmentPoints.end();
  420. ++iter)
  421. {
  422. LLViewerJointAttachment* attachment = iter->second;
  423. if(attachment->getGroup() == group)
  424. {
  425. // use multimap to provide a partial order off of the pie slice key
  426. S32 pie_index = attachment->getPieSlice();
  427. attachment_pie_menu_map.insert(std::make_pair(pie_index, iter->first));
  428. }
  429. }
  430. // add in requested order to pie menu, inserting separators as necessary
  431. for (std::multimap<S32, S32>::iterator attach_it = attachment_pie_menu_map.begin();
  432. attach_it != attachment_pie_menu_map.end(); ++attach_it)
  433. {
  434. S32 attach_index = attach_it->second;
  435. LLViewerJointAttachment* attachment = get_if_there(mAttachmentPoints, attach_index, (LLViewerJointAttachment*)NULL);
  436. if (attachment)
  437. {
  438. LLMenuItemCallGL::Params item_params;
  439. item_params.name = attachment->getName();
  440. item_params.label = LLTrans::getString(attachment->getName());
  441. item_params.on_click.function_name = "Object.AttachToAvatar";
  442. item_params.on_click.parameter = attach_index;
  443. item_params.on_enable.function_name = "Object.EnableWear";
  444. item_params.on_enable.parameter = attach_index;
  445. LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  446. gAttachBodyPartPieMenus[group]->addChild(item);
  447. item_params.on_click.function_name = "Attachment.DetachFromPoint";
  448. item_params.on_click.parameter = attach_index;
  449. item_params.on_enable.function_name = "Attachment.PointFilled";
  450. item_params.on_enable.parameter = attach_index;
  451. item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
  452. gDetachBodyPartPieMenus[group]->addChild(item);
  453. }
  454. }
  455. }
  456. return TRUE;
  457. }
  458. void LLVOAvatarSelf::cleanup()
  459. {
  460. markDead();
  461. delete mScreenp;
  462. mScreenp = NULL;
  463. mRegionp = NULL;
  464. }
  465. LLVOAvatarSelf::~LLVOAvatarSelf()
  466. {
  467. cleanup();
  468. }
  469. /**
  470. **
  471. ** End LLVOAvatarSelf Constructor routines
  472. ** **
  473. *********************************************************************************/
  474. //virtual
  475. BOOL LLVOAvatarSelf::loadLayersets()
  476. {
  477. BOOL success = TRUE;
  478. for (LLVOAvatarXmlInfo::layer_info_list_t::const_iterator iter = sAvatarXmlInfo->mLayerInfoList.begin();
  479. iter != sAvatarXmlInfo->mLayerInfoList.end();
  480. ++iter)
  481. {
  482. // Construct a layerset for each one specified in avatar_lad.xml and initialize it as such.
  483. const LLTexLayerSetInfo *info = *iter;
  484. LLTexLayerSet* layer_set = new LLTexLayerSet( this );
  485. if (!layer_set->setInfo(info))
  486. {
  487. stop_glerror();
  488. delete layer_set;
  489. llwarns << "avatar file: layer_set->parseData() failed" << llendl;
  490. return FALSE;
  491. }
  492. // scan baked textures and associate the layerset with the appropriate one
  493. EBakedTextureIndex baked_index = BAKED_NUM_INDICES;
  494. for (LLVOAvatarDictionary::BakedTextures::const_iterator baked_iter = LLVOAvatarDictionary::getInstance()->getBakedTextures().begin();
  495. baked_iter != LLVOAvatarDictionary::getInstance()->getBakedTextures().end();
  496. ++baked_iter)
  497. {
  498. const LLVOAvatarDictionary::BakedEntry *baked_dict = baked_iter->second;
  499. if (layer_set->isBodyRegion(baked_dict->mName))
  500. {
  501. baked_index = baked_iter->first;
  502. // ensure both structures are aware of each other
  503. mBakedTextureDatas[baked_index].mTexLayerSet = layer_set;
  504. layer_set->setBakedTexIndex(baked_index);
  505. break;
  506. }
  507. }
  508. // if no baked texture was found, warn and cleanup
  509. if (baked_index == BAKED_NUM_INDICES)
  510. {
  511. llwarns << "<layer_set> has invalid body_region attribute" << llendl;
  512. delete layer_set;
  513. return FALSE;
  514. }
  515. // scan morph masks and let any affected layers know they have an associated morph
  516. for (LLVOAvatar::morph_list_t::const_iterator morph_iter = mBakedTextureDatas[baked_index].mMaskedMorphs.begin();
  517. morph_iter != mBakedTextureDatas[baked_index].mMaskedMorphs.end();
  518. ++morph_iter)
  519. {
  520. LLMaskedMorph *morph = *morph_iter;
  521. LLTexLayerInterface* layer = layer_set->findLayerByName(morph->mLayer);
  522. if (layer)
  523. {
  524. layer->setHasMorph(TRUE);
  525. }
  526. else
  527. {
  528. llwarns << "Could not find layer named " << morph->mLayer << " to set morph flag" << llendl;
  529. success = FALSE;
  530. }
  531. }
  532. }
  533. return success;
  534. }
  535. // virtual
  536. BOOL LLVOAvatarSelf::updateCharacter(LLAgent &agent)
  537. {
  538. LLMemType mt(LLMemType::MTYPE_AVATAR);
  539. // update screen joint size
  540. if (mScreenp)
  541. {
  542. F32 aspect = LLViewerCamera::getInstance()->getAspect();
  543. LLVector3 scale(1.f, aspect, 1.f);
  544. mScreenp->setScale(scale);
  545. mScreenp->updateWorldMatrixChildren();
  546. resetHUDAttachments();
  547. }
  548. return LLVOAvatar::updateCharacter(agent);
  549. }
  550. // virtual
  551. BOOL LLVOAvatarSelf::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
  552. {
  553. if (!isAgentAvatarValid())
  554. {
  555. return TRUE;
  556. }
  557. LLVOAvatar::idleUpdate(agent, world, time);
  558. idleUpdateTractorBeam();
  559. return TRUE;
  560. }
  561. // virtual
  562. LLJoint *LLVOAvatarSelf::getJoint(const std::string &name)
  563. {
  564. if (mScreenp)
  565. {
  566. LLJoint* jointp = mScreenp->findJoint(name);
  567. if (jointp) return jointp;
  568. }
  569. return LLVOAvatar::getJoint(name);
  570. }
  571. //virtual
  572. void LLVOAvatarSelf::resetJointPositions( void )
  573. {
  574. return LLVOAvatar::resetJointPositions();
  575. }
  576. // virtual
  577. BOOL LLVOAvatarSelf::setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL upload_bake )
  578. {
  579. if (!which_param)
  580. {
  581. return FALSE;
  582. }
  583. LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(which_param->getID());
  584. return setParamWeight(param,weight,upload_bake);
  585. }
  586. // virtual
  587. BOOL LLVOAvatarSelf::setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake )
  588. {
  589. if (!param_name)
  590. {
  591. return FALSE;
  592. }
  593. LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(param_name);
  594. return setParamWeight(param,weight,upload_bake);
  595. }
  596. // virtual
  597. BOOL LLVOAvatarSelf::setVisualParamWeight(S32 index, F32 weight, BOOL upload_bake )
  598. {
  599. LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(index);
  600. return setParamWeight(param,weight,upload_bake);
  601. }
  602. BOOL LLVOAvatarSelf::setParamWeight(LLViewerVisualParam *param, F32 weight, BOOL upload_bake )
  603. {
  604. if (!param)
  605. {
  606. return FALSE;
  607. }
  608. if (param->getCrossWearable())
  609. {
  610. LLWearableType::EType type = (LLWearableType::EType)param->getWearableType();
  611. U32 size = gAgentWearables.getWearableCount(type);
  612. for (U32 count = 0; count < size; ++count)
  613. {
  614. LLWearable *wearable = gAgentWearables.getWearable(type,count);
  615. if (wearable)
  616. {
  617. wearable->setVisualParamWeight(param->getID(), weight, upload_bake);
  618. }
  619. }
  620. }
  621. return LLCharacter::setVisualParamWeight(param,weight,upload_bake);
  622. }
  623. /*virtual*/
  624. void LLVOAvatarSelf::updateVisualParams()
  625. {
  626. LLVOAvatar::updateVisualParams();
  627. }
  628. /*virtual*/
  629. void LLVOAvatarSelf::idleUpdateAppearanceAnimation()
  630. {
  631. // Animate all top-level wearable visual parameters
  632. gAgentWearables.animateAllWearableParams(calcMorphAmount(), FALSE);
  633. // apply wearable visual params to avatar
  634. for (U32 type = 0; type < LLWearableType::WT_COUNT; type++)
  635. {
  636. LLWearable *wearable = gAgentWearables.getTopWearable((LLWearableType::EType)type);
  637. if (wearable)
  638. {
  639. wearable->writeToAvatar();
  640. }
  641. }
  642. //allow avatar to process updates
  643. LLVOAvatar::idleUpdateAppearanceAnimation();
  644. }
  645. // virtual
  646. void LLVOAvatarSelf::requestStopMotion(LLMotion* motion)
  647. {
  648. // Only agent avatars should handle the stop motion notifications.
  649. // Notify agent that motion has stopped
  650. gAgent.requestStopMotion(motion);
  651. }
  652. // virtual
  653. void LLVOAvatarSelf::stopMotionFromSource(const LLUUID& source_id)
  654. {
  655. for (AnimSourceIterator motion_it = mAnimationSources.find(source_id); motion_it != mAnimationSources.end(); )
  656. {
  657. gAgent.sendAnimationRequest(motion_it->second, ANIM_REQUEST_STOP);
  658. mAnimationSources.erase(motion_it++);
  659. }
  660. LLViewerObject* object = gObjectList.findObject(source_id);
  661. if (object)
  662. {
  663. object->mFlags &= ~FLAGS_ANIM_SOURCE;
  664. }
  665. }
  666. void LLVOAvatarSelf::setLocalTextureTE(U8 te, LLViewerTexture* image, U32 index)
  667. {
  668. if (te >= TEX_NUM_INDICES)
  669. {
  670. llassert(0);
  671. return;
  672. }
  673. if (getTEImage(te)->getID() == image->getID())
  674. {
  675. return;
  676. }
  677. if (isIndexBakedTexture((ETextureIndex)te))
  678. {
  679. llassert(0);
  680. return;
  681. }
  682. setTEImage(te, image);
  683. }
  684. //virtual
  685. void LLVOAvatarSelf::removeMissingBakedTextures()
  686. {
  687. BOOL removed = FALSE;
  688. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  689. {
  690. const S32 te = mBakedTextureDatas[i].mTextureIndex;
  691. const LLViewerTexture* tex = getTEImage(te);
  692. // Replace with default if we can't find the asset, assuming the
  693. // default is actually valid (which it should be unless something
  694. // is seriously wrong).
  695. if (!tex || tex->isMissingAsset())
  696. {
  697. LLViewerTexture *imagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
  698. if (imagep)
  699. {
  700. setTEImage(te, imagep);
  701. removed = TRUE;
  702. }
  703. }
  704. }
  705. if (removed)
  706. {
  707. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  708. {
  709. mBakedTextureDatas[i].mTexLayerSet->setUpdatesEnabled(TRUE);
  710. invalidateComposite(mBakedTextureDatas[i].mTexLayerSet, FALSE);
  711. }
  712. updateMeshTextures();
  713. requestLayerSetUploads();
  714. }
  715. }
  716. //virtual
  717. void LLVOAvatarSelf::updateRegion(LLViewerRegion *regionp)
  718. {
  719. // Save the global position
  720. LLVector3d global_pos_from_old_region = getPositionGlobal();
  721. // Change the region
  722. setRegion(regionp);
  723. if (regionp)
  724. { // Set correct region-relative position from global coordinates
  725. setPositionGlobal(global_pos_from_old_region);
  726. // Diagnostic info
  727. //LLVector3d pos_from_new_region = getPositionGlobal();
  728. //llinfos << "pos_from_old_region is " << global_pos_from_old_region
  729. // << " while pos_from_new_region is " << pos_from_new_region
  730. // << llendl;
  731. }
  732. if (!regionp || (regionp->getHandle() != mLastRegionHandle))
  733. {
  734. if (mLastRegionHandle != 0)
  735. {
  736. ++mRegionCrossingCount;
  737. F64 delta = (F64)mRegionCrossingTimer.getElapsedTimeF32();
  738. F64 avg = (mRegionCrossingCount == 1) ? 0 : LLViewerStats::getInstance()->getStat(LLViewerStats::ST_CROSSING_AVG);
  739. F64 delta_avg = (delta + avg*(mRegionCrossingCount-1)) / mRegionCrossingCount;
  740. LLViewerStats::getInstance()->setStat(LLViewerStats::ST_CROSSING_AVG, delta_avg);
  741. F64 max = (mRegionCrossingCount == 1) ? 0 : LLViewerStats::getInstance()->getStat(LLViewerStats::ST_CROSSING_MAX);
  742. max = llmax(delta, max);
  743. LLViewerStats::getInstance()->setStat(LLViewerStats::ST_CROSSING_MAX, max);
  744. // Diagnostics
  745. llinfos << "Region crossing took " << (F32)(delta * 1000.0) << " ms " << llendl;
  746. }
  747. if (regionp)
  748. {
  749. mLastRegionHandle = regionp->getHandle();
  750. }
  751. }
  752. mRegionCrossingTimer.reset();
  753. LLViewerObject::updateRegion(regionp);
  754. }
  755. //--------------------------------------------------------------------
  756. // draw tractor beam when editing objects
  757. //--------------------------------------------------------------------
  758. //virtual
  759. void LLVOAvatarSelf::idleUpdateTractorBeam()
  760. {
  761. // This is only done for yourself (maybe it should be in the agent?)
  762. if (!needsRenderBeam() || !mIsBuilt)
  763. {
  764. mBeam = NULL;
  765. }
  766. else if (!mBeam || mBeam->isDead())
  767. {
  768. // VEFFECT: Tractor Beam
  769. mBeam = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM);
  770. mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
  771. mBeam->setSourceObject(this);
  772. mBeamTimer.reset();
  773. }
  774. if (!mBeam.isNull())
  775. {
  776. LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
  777. if (gAgentCamera.mPointAt.notNull())
  778. {
  779. // get point from pointat effect
  780. mBeam->setPositionGlobal(gAgentCamera.mPointAt->getPointAtPosGlobal());
  781. mBeam->triggerLocal();
  782. }
  783. else if (selection->getFirstRootObject() &&
  784. selection->getSelectType() != SELECT_TYPE_HUD)
  785. {
  786. LLViewerObject* objectp = selection->getFirstRootObject();
  787. mBeam->setTargetObject(objectp);
  788. }
  789. else
  790. {
  791. mBeam->setTargetObject(NULL);
  792. LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
  793. if (tool->isEditing())
  794. {
  795. if (tool->getEditingObject())
  796. {
  797. mBeam->setTargetObject(tool->getEditingObject());
  798. }
  799. else
  800. {
  801. mBeam->setPositionGlobal(tool->getEditingPointGlobal());
  802. }
  803. }
  804. else
  805. {
  806. const LLPickInfo& pick = gViewerWindow->getLastPick();
  807. mBeam->setPositionGlobal(pick.mPosGlobal);
  808. }
  809. }
  810. if (mBeamTimer.getElapsedTimeF32() > 0.25f)
  811. {
  812. mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
  813. mBeam->setNeedsSendToSim(TRUE);
  814. mBeamTimer.reset();
  815. }
  816. }
  817. }
  818. //-----------------------------------------------------------------------------
  819. // restoreMeshData()
  820. //-----------------------------------------------------------------------------
  821. // virtual
  822. void LLVOAvatarSelf::restoreMeshData()
  823. {
  824. LLMemType mt(LLMemType::MTYPE_AVATAR);
  825. //llinfos << "Restoring" << llendl;
  826. mMeshValid = TRUE;
  827. updateJointLODs();
  828. updateAttachmentVisibility(gAgentCamera.getCameraMode());
  829. // force mesh update as LOD might not have changed to trigger this
  830. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY, TRUE);
  831. }
  832. //-----------------------------------------------------------------------------
  833. // updateAttachmentVisibility()
  834. //-----------------------------------------------------------------------------
  835. void LLVOAvatarSelf::updateAttachmentVisibility(U32 camera_mode)
  836. {
  837. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  838. iter != mAttachmentPoints.end();
  839. ++iter)
  840. {
  841. LLViewerJointAttachment* attachment = iter->second;
  842. if (attachment->getIsHUDAttachment())
  843. {
  844. attachment->setAttachmentVisibility(TRUE);
  845. }
  846. else
  847. {
  848. switch (camera_mode)
  849. {
  850. case CAMERA_MODE_MOUSELOOK:
  851. if (LLVOAvatar::sVisibleInFirstPerson && attachment->getVisibleInFirstPerson())
  852. {
  853. attachment->setAttachmentVisibility(TRUE);
  854. }
  855. else
  856. {
  857. attachment->setAttachmentVisibility(FALSE);
  858. }
  859. break;
  860. default:
  861. attachment->setAttachmentVisibility(TRUE);
  862. break;
  863. }
  864. }
  865. }
  866. }
  867. /*virtual*/ BOOL LLVOAvatarSelf::isWearingWearableType(LLWearableType::EType type ) const
  868. {
  869. return gAgentWearables.getWearableCount(type) > 0;
  870. }
  871. //-----------------------------------------------------------------------------
  872. // updatedWearable( LLWearableType::EType type )
  873. // forces an update to any baked textures relevant to type.
  874. // will force an upload of the resulting bake if the second parameter is TRUE
  875. //-----------------------------------------------------------------------------
  876. void LLVOAvatarSelf::wearableUpdated( LLWearableType::EType type, BOOL upload_result )
  877. {
  878. for (LLVOAvatarDictionary::BakedTextures::const_iterator baked_iter = LLVOAvatarDictionary::getInstance()->getBakedTextures().begin();
  879. baked_iter != LLVOAvatarDictionary::getInstance()->getBakedTextures().end();
  880. ++baked_iter)
  881. {
  882. const LLVOAvatarDictionary::BakedEntry *baked_dict = baked_iter->second;
  883. const LLVOAvatarDefines::EBakedTextureIndex index = baked_iter->first;
  884. if (baked_dict)
  885. {
  886. for (LLVOAvatarDefines::wearables_vec_t::const_iterator type_iter = baked_dict->mWearables.begin();
  887. type_iter != baked_dict->mWearables.end();
  888. ++type_iter)
  889. {
  890. const LLWearableType::EType comp_type = *type_iter;
  891. if (comp_type == type)
  892. {
  893. if (mBakedTextureDatas[index].mTexLayerSet)
  894. {
  895. mBakedTextureDatas[index].mTexLayerSet->setUpdatesEnabled(true);
  896. invalidateComposite(mBakedTextureDatas[index].mTexLayerSet, upload_result);
  897. }
  898. break;
  899. }
  900. }
  901. }
  902. }
  903. // Physics type has no associated baked textures, but change of params needs to be sent to
  904. // other avatars.
  905. if (type == LLWearableType::WT_PHYSICS)
  906. {
  907. gAgent.sendAgentSetAppearance();
  908. }
  909. }
  910. //-----------------------------------------------------------------------------
  911. // isWearingAttachment()
  912. //-----------------------------------------------------------------------------
  913. BOOL LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
  914. {
  915. const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
  916. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin();
  917. iter != mAttachmentPoints.end();
  918. ++iter)
  919. {
  920. const LLViewerJointAttachment* attachment = iter->second;
  921. if (attachment->getAttachedObject(base_inv_item_id))
  922. {
  923. return TRUE;
  924. }
  925. }
  926. return FALSE;
  927. }
  928. //-----------------------------------------------------------------------------
  929. BOOL LLVOAvatarSelf::attachmentWasRequested(const LLUUID& inv_item_id) const
  930. {
  931. const F32 REQUEST_EXPIRATION_SECONDS = 5.0; // any request older than this is ignored/removed.
  932. std::map<LLUUID,LLTimer>::iterator it = mAttachmentRequests.find(inv_item_id);
  933. if (it != mAttachmentRequests.end())
  934. {
  935. const LLTimer& request_time = it->second;
  936. F32 request_time_elapsed = request_time.getElapsedTimeF32();
  937. if (request_time_elapsed > REQUEST_EXPIRATION_SECONDS)
  938. {
  939. mAttachmentRequests.erase(it);
  940. return FALSE;
  941. }
  942. else
  943. {
  944. return TRUE;
  945. }
  946. }
  947. else
  948. {
  949. return FALSE;
  950. }
  951. }
  952. //-----------------------------------------------------------------------------
  953. void LLVOAvatarSelf::addAttachmentRequest(const LLUUID& inv_item_id)
  954. {
  955. LLTimer current_time;
  956. mAttachmentRequests[inv_item_id] = current_time;
  957. }
  958. //-----------------------------------------------------------------------------
  959. void LLVOAvatarSelf::removeAttachmentRequest(const LLUUID& inv_item_id)
  960. {
  961. mAttachmentRequests.erase(inv_item_id);
  962. }
  963. //-----------------------------------------------------------------------------
  964. // getWornAttachment()
  965. //-----------------------------------------------------------------------------
  966. LLViewerObject* LLVOAvatarSelf::getWornAttachment(const LLUUID& inv_item_id)
  967. {
  968. const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
  969. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin();
  970. iter != mAttachmentPoints.end();
  971. ++iter)
  972. {
  973. LLViewerJointAttachment* attachment = iter->second;
  974. if (LLViewerObject *attached_object = attachment->getAttachedObject(base_inv_item_id))
  975. {
  976. return attached_object;
  977. }
  978. }
  979. return NULL;
  980. }
  981. const std::string LLVOAvatarSelf::getAttachedPointName(const LLUUID& inv_item_id) const
  982. {
  983. const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
  984. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin();
  985. iter != mAttachmentPoints.end();
  986. ++iter)
  987. {
  988. const LLViewerJointAttachment* attachment = iter->second;
  989. if (attachment->getAttachedObject(base_inv_item_id))
  990. {
  991. return attachment->getName();
  992. }
  993. }
  994. return LLStringUtil::null;
  995. }
  996. //virtual
  997. const LLViewerJointAttachment *LLVOAvatarSelf::attachObject(LLViewerObject *viewer_object)
  998. {
  999. const LLViewerJointAttachment *attachment = LLVOAvatar::attachObject(viewer_object);
  1000. if (!attachment)
  1001. {
  1002. return 0;
  1003. }
  1004. updateAttachmentVisibility(gAgentCamera.getCameraMode());
  1005. // Then make sure the inventory is in sync with the avatar.
  1006. // Should just be the last object added
  1007. if (attachment->isObjectAttached(viewer_object))
  1008. {
  1009. const LLUUID& attachment_id = viewer_object->getAttachmentItemID();
  1010. LLAppearanceMgr::instance().registerAttachment(attachment_id);
  1011. // Clear any pending requests once the attachment arrives.
  1012. removeAttachmentRequest(attachment_id);
  1013. updateLODRiggedAttachments();
  1014. }
  1015. return attachment;
  1016. }
  1017. //virtual
  1018. BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object)
  1019. {
  1020. const LLUUID attachment_id = viewer_object->getAttachmentItemID();
  1021. if ( LLVOAvatar::detachObject(viewer_object) )
  1022. {
  1023. LLVOAvatar::cleanupAttachedMesh( viewer_object );
  1024. // the simulator should automatically handle permission revocation
  1025. stopMotionFromSource(attachment_id);
  1026. LLFollowCamMgr::setCameraActive(viewer_object->getID(), FALSE);
  1027. LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
  1028. for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
  1029. iter != child_list.end();
  1030. ++iter)
  1031. {
  1032. LLViewerObject* child_objectp = *iter;
  1033. // the simulator should automatically handle
  1034. // permissions revocation
  1035. stopMotionFromSource(child_objectp->getID());
  1036. LLFollowCamMgr::setCameraActive(child_objectp->getID(), FALSE);
  1037. }
  1038. // Make sure the inventory is in sync with the avatar.
  1039. // Update COF contents, don't trigger appearance update.
  1040. if (!isAgentAvatarValid())
  1041. {
  1042. llinfos << "removeItemLinks skipped, avatar is under destruction" << llendl;
  1043. }
  1044. else
  1045. {
  1046. LLAppearanceMgr::instance().unregisterAttachment(attachment_id);
  1047. }
  1048. return TRUE;
  1049. }
  1050. return FALSE;
  1051. }
  1052. // static
  1053. BOOL LLVOAvatarSelf::detachAttachmentIntoInventory(const LLUUID &item_id)
  1054. {
  1055. LLInventoryItem* item = gInventory.getItem(item_id);
  1056. if (item)
  1057. {
  1058. gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
  1059. gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
  1060. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1061. gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id);
  1062. gMessageSystem->sendReliable(gAgent.getRegion()->getHost());
  1063. // This object might have been selected, so let the selection manager know it's gone now
  1064. LLViewerObject *found_obj = gObjectList.findObject(item_id);
  1065. if (found_obj)
  1066. {
  1067. LLSelectMgr::getInstance()->remove(found_obj);
  1068. }
  1069. // Error checking in case this object was attached to an invalid point
  1070. // In that case, just remove the item from COF preemptively since detach
  1071. // will fail.
  1072. if (isAgentAvatarValid())
  1073. {
  1074. const LLViewerObject *attached_obj = gAgentAvatarp->getWornAttachment(item_id);
  1075. if (!attached_obj)
  1076. {
  1077. LLAppearanceMgr::instance().removeCOFItemLinks(item_id, false);
  1078. }
  1079. }
  1080. return TRUE;
  1081. }
  1082. return FALSE;
  1083. }
  1084. U32 LLVOAvatarSelf::getNumWearables(LLVOAvatarDefines::ETextureIndex i) const
  1085. {
  1086. LLWearableType::EType type = LLVOAvatarDictionary::getInstance()->getTEWearableType(i);
  1087. return gAgentWearables.getWearableCount(type);
  1088. }
  1089. // virtual
  1090. void LLVOAvatarSelf::localTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src_raw, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
  1091. {
  1092. const LLUUID& src_id = src_vi->getID();
  1093. LLAvatarTexData *data = (LLAvatarTexData *)userdata;
  1094. ETextureIndex index = data->mIndex;
  1095. if (!isIndexLocalTexture(index)) return;
  1096. LLLocalTextureObject *local_tex_obj = getLocalTextureObject(index, 0);
  1097. // fix for EXT-268. Preventing using of NULL pointer
  1098. if(NULL == local_tex_obj)
  1099. {
  1100. LL_WARNS("TAG") << "There is no Local Texture Object with index: " << index
  1101. << ", final: " << final
  1102. << LL_ENDL;
  1103. return;
  1104. }
  1105. if (success)
  1106. {
  1107. if (!local_tex_obj->getBakedReady() &&
  1108. local_tex_obj->getImage() != NULL &&
  1109. (local_tex_obj->getID() == src_id) &&
  1110. discard_level < local_tex_obj->getDiscard())
  1111. {
  1112. local_tex_obj->setDiscard(discard_level);
  1113. if (isUsingBakedTextures())
  1114. {
  1115. requestLayerSetUpdate(index);
  1116. }
  1117. else
  1118. {
  1119. LLVisualParamHint::requestHintUpdates();
  1120. }
  1121. updateMeshTextures();
  1122. }
  1123. }
  1124. else if (final)
  1125. {
  1126. // Failed: asset is missing
  1127. if (!local_tex_obj->getBakedReady() &&
  1128. local_tex_obj->getImage() != NULL &&
  1129. local_tex_obj->getImage()->getID() == src_id)
  1130. {
  1131. local_tex_obj->setDiscard(0);
  1132. requestLayerSetUpdate(index);
  1133. updateMeshTextures();
  1134. }
  1135. }
  1136. }
  1137. // virtual
  1138. BOOL LLVOAvatarSelf::getLocalTextureGL(ETextureIndex type, LLViewerTexture** tex_pp, U32 index) const
  1139. {
  1140. *tex_pp = NULL;
  1141. if (!isIndexLocalTexture(type)) return FALSE;
  1142. if (getLocalTextureID(type, index) == IMG_DEFAULT_AVATAR) return TRUE;
  1143. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
  1144. if (!local_tex_obj)
  1145. {
  1146. return FALSE;
  1147. }
  1148. *tex_pp = local_tex_obj->getImage();
  1149. return TRUE;
  1150. }
  1151. LLViewerFetchedTexture* LLVOAvatarSelf::getLocalTextureGL(LLVOAvatarDefines::ETextureIndex type, U32 index) const
  1152. {
  1153. if (!isIndexLocalTexture(type))
  1154. {
  1155. return NULL;
  1156. }
  1157. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
  1158. if (!local_tex_obj)
  1159. {
  1160. return NULL;
  1161. }
  1162. if (local_tex_obj->getID() == IMG_DEFAULT_AVATAR)
  1163. {
  1164. return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
  1165. }
  1166. return local_tex_obj->getImage();
  1167. }
  1168. const LLUUID& LLVOAvatarSelf::getLocalTextureID(ETextureIndex type, U32 index) const
  1169. {
  1170. if (!isIndexLocalTexture(type)) return IMG_DEFAULT_AVATAR;
  1171. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
  1172. if (local_tex_obj && local_tex_obj->getImage() != NULL)
  1173. {
  1174. return local_tex_obj->getImage()->getID();
  1175. }
  1176. return IMG_DEFAULT_AVATAR;
  1177. }
  1178. //-----------------------------------------------------------------------------
  1179. // isLocalTextureDataAvailable()
  1180. // Returns true if at least the lowest quality discard level exists for every texture
  1181. // in the layerset.
  1182. //-----------------------------------------------------------------------------
  1183. BOOL LLVOAvatarSelf::isLocalTextureDataAvailable(const LLTexLayerSet* layerset) const
  1184. {
  1185. /* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
  1186. return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
  1187. for (LLVOAvatarDictionary::BakedTextures::const_iterator baked_iter = LLVOAvatarDictionary::getInstance()->getBakedTextures().begin();
  1188. baked_iter != LLVOAvatarDictionary::getInstance()->getBakedTextures().end();
  1189. ++baked_iter)
  1190. {
  1191. const EBakedTextureIndex baked_index = baked_iter->first;
  1192. if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
  1193. {
  1194. BOOL ret = true;
  1195. const LLVOAvatarDictionary::BakedEntry *baked_dict = baked_iter->second;
  1196. for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
  1197. local_tex_iter != baked_dict->mLocalTextures.end();
  1198. ++local_tex_iter)
  1199. {
  1200. const ETextureIndex tex_index = *local_tex_iter;
  1201. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(tex_index);
  1202. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1203. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1204. {
  1205. ret &= (getLocalDiscardLevel(tex_index, wearable_index) >= 0);
  1206. }
  1207. }
  1208. return ret;
  1209. }
  1210. }
  1211. llassert(0);
  1212. return FALSE;
  1213. }
  1214. //-----------------------------------------------------------------------------
  1215. // virtual
  1216. // isLocalTextureDataFinal()
  1217. // Returns true if the highest quality discard level exists for every texture
  1218. // in the layerset.
  1219. //-----------------------------------------------------------------------------
  1220. BOOL LLVOAvatarSelf::isLocalTextureDataFinal(const LLTexLayerSet* layerset) const
  1221. {
  1222. const U32 desired_tex_discard_level = gSavedSettings.getU32("TextureDiscardLevel");
  1223. // const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels.
  1224. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1225. {
  1226. if (layerset == mBakedTextureDatas[i].mTexLayerSet)
  1227. {
  1228. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture((EBakedTextureIndex)i);
  1229. for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
  1230. local_tex_iter != baked_dict->mLocalTextures.end();
  1231. ++local_tex_iter)
  1232. {
  1233. const ETextureIndex tex_index = *local_tex_iter;
  1234. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(tex_index);
  1235. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1236. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1237. {
  1238. if (getLocalDiscardLevel(*local_tex_iter, wearable_index) > (S32)(desired_tex_discard_level))
  1239. {
  1240. return FALSE;
  1241. }
  1242. }
  1243. }
  1244. return TRUE;
  1245. }
  1246. }
  1247. llassert(0);
  1248. return FALSE;
  1249. }
  1250. BOOL LLVOAvatarSelf::isAllLocalTextureDataFinal() const
  1251. {
  1252. const U32 desired_tex_discard_level = gSavedSettings.getU32("TextureDiscardLevel");
  1253. // const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels
  1254. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1255. {
  1256. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture((EBakedTextureIndex)i);
  1257. for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
  1258. local_tex_iter != baked_dict->mLocalTextures.end();
  1259. ++local_tex_iter)
  1260. {
  1261. const ETextureIndex tex_index = *local_tex_iter;
  1262. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(tex_index);
  1263. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1264. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1265. {
  1266. if (getLocalDiscardLevel(*local_tex_iter, wearable_index) > (S32)(desired_tex_discard_level))
  1267. {
  1268. return FALSE;
  1269. }
  1270. }
  1271. }
  1272. }
  1273. return TRUE;
  1274. }
  1275. BOOL LLVOAvatarSelf::isBakedTextureFinal(const LLVOAvatarDefines::EBakedTextureIndex index) const
  1276. {
  1277. const LLTexLayerSet *layerset = mBakedTextureDatas[index].mTexLayerSet;
  1278. if (!layerset) return FALSE;
  1279. const LLTexLayerSetBuffer *layerset_buffer = layerset->getComposite();
  1280. if (!layerset_buffer) return FALSE;
  1281. return !layerset_buffer->uploadNeeded();
  1282. }
  1283. BOOL LLVOAvatarSelf::isTextureDefined(LLVOAvatarDefines::ETextureIndex type, U32 index) const
  1284. {
  1285. LLUUID id;
  1286. BOOL isDefined = TRUE;
  1287. if (isIndexLocalTexture(type))
  1288. {
  1289. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(type);
  1290. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1291. if (index >= wearable_count)
  1292. {
  1293. // invalid index passed in. check all textures of a given type
  1294. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1295. {
  1296. id = getLocalTextureID(type, wearable_index);
  1297. isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
  1298. }
  1299. }
  1300. else
  1301. {
  1302. id = getLocalTextureID(type, index);
  1303. isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
  1304. }
  1305. }
  1306. else
  1307. {
  1308. id = getTEImage(type)->getID();
  1309. isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
  1310. }
  1311. return isDefined;
  1312. }
  1313. //virtual
  1314. BOOL LLVOAvatarSelf::isTextureVisible(LLVOAvatarDefines::ETextureIndex type, U32 index) const
  1315. {
  1316. if (isIndexBakedTexture(type))
  1317. {
  1318. return LLVOAvatar::isTextureVisible(type, (U32)0);
  1319. }
  1320. LLUUID tex_id = getLocalTextureID(type,index);
  1321. return (tex_id != IMG_INVISIBLE)
  1322. || (LLDrawPoolAlpha::sShowDebugAlpha);
  1323. }
  1324. //virtual
  1325. BOOL LLVOAvatarSelf::isTextureVisible(LLVOAvatarDefines::ETextureIndex type, LLWearable *wearable) const
  1326. {
  1327. if (isIndexBakedTexture(type))
  1328. {
  1329. return LLVOAvatar::isTextureVisible(type);
  1330. }
  1331. U32 index = gAgentWearables.getWearableIndex(wearable);
  1332. return isTextureVisible(type,index);
  1333. }
  1334. //-----------------------------------------------------------------------------
  1335. // requestLayerSetUploads()
  1336. //-----------------------------------------------------------------------------
  1337. void LLVOAvatarSelf::requestLayerSetUploads()
  1338. {
  1339. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1340. {
  1341. requestLayerSetUpload((EBakedTextureIndex)i);
  1342. }
  1343. }
  1344. void LLVOAvatarSelf::requestLayerSetUpload(LLVOAvatarDefines::EBakedTextureIndex i)
  1345. {
  1346. ETextureIndex tex_index = mBakedTextureDatas[i].mTextureIndex;
  1347. const BOOL layer_baked = isTextureDefined(tex_index, gAgentWearables.getWearableCount(tex_index));
  1348. if (!layer_baked && mBakedTextureDatas[i].mTexLayerSet)
  1349. {
  1350. mBakedTextureDatas[i].mTexLayerSet->requestUpload();
  1351. }
  1352. }
  1353. bool LLVOAvatarSelf::areTexturesCurrent() const
  1354. {
  1355. return !hasPendingBakedUploads() && gAgentWearables.areWearablesLoaded();
  1356. }
  1357. // virtual
  1358. bool LLVOAvatarSelf::hasPendingBakedUploads() const
  1359. {
  1360. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1361. {
  1362. LLTexLayerSet* layerset = mBakedTextureDatas[i].mTexLayerSet;
  1363. if (layerset && layerset->getComposite() && layerset->getComposite()->uploadPending())
  1364. {
  1365. return true;
  1366. }
  1367. }
  1368. return false;
  1369. }
  1370. void LLVOAvatarSelf::invalidateComposite( LLTexLayerSet* layerset, BOOL upload_result )
  1371. {
  1372. if( !layerset || !layerset->getUpdatesEnabled() )
  1373. {
  1374. return;
  1375. }
  1376. // llinfos << "LLVOAvatar::invalidComposite() " << layerset->getBodyRegionName() << llendl;
  1377. layerset->requestUpdate();
  1378. layerset->invalidateMorphMasks();
  1379. if( upload_result )
  1380. {
  1381. llassert(isSelf());
  1382. ETextureIndex baked_te = getBakedTE( layerset );
  1383. setTEImage( baked_te, LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR) );
  1384. layerset->requestUpload();
  1385. updateMeshTextures();
  1386. }
  1387. }
  1388. void LLVOAvatarSelf::invalidateAll()
  1389. {
  1390. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1391. {
  1392. invalidateComposite(mBakedTextureDatas[i].mTexLayerSet, TRUE);
  1393. }
  1394. mDebugSelfLoadTimer.reset();
  1395. }
  1396. //-----------------------------------------------------------------------------
  1397. // setCompositeUpdatesEnabled()
  1398. //-----------------------------------------------------------------------------
  1399. void LLVOAvatarSelf::setCompositeUpdatesEnabled( bool b )
  1400. {
  1401. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1402. {
  1403. setCompositeUpdatesEnabled(i, b);
  1404. }
  1405. }
  1406. void LLVOAvatarSelf::setCompositeUpdatesEnabled(U32 index, bool b)
  1407. {
  1408. if (mBakedTextureDatas[index].mTexLayerSet )
  1409. {
  1410. mBakedTextureDatas[index].mTexLayerSet->setUpdatesEnabled( b );
  1411. }
  1412. }
  1413. bool LLVOAvatarSelf::isCompositeUpdateEnabled(U32 index)
  1414. {
  1415. if (mBakedTextureDatas[index].mTexLayerSet)
  1416. {
  1417. return mBakedTextureDatas[index].mTexLayerSet->getUpdatesEnabled();
  1418. }
  1419. return false;
  1420. }
  1421. void LLVOAvatarSelf::setupComposites()
  1422. {
  1423. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1424. {
  1425. ETextureIndex tex_index = mBakedTextureDatas[i].mTextureIndex;
  1426. BOOL layer_baked = isTextureDefined(tex_index, gAgentWearables.getWearableCount(tex_index));
  1427. if (mBakedTextureDatas[i].mTexLayerSet)
  1428. {
  1429. mBakedTextureDatas[i].mTexLayerSet->setUpdatesEnabled(!layer_baked);
  1430. }
  1431. }
  1432. }
  1433. void LLVOAvatarSelf::updateComposites()
  1434. {
  1435. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1436. {
  1437. if (mBakedTextureDatas[i].mTexLayerSet
  1438. && ((i != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT)))
  1439. {
  1440. mBakedTextureDatas[i].mTexLayerSet->updateComposite();
  1441. }
  1442. }
  1443. }
  1444. // virtual
  1445. S32 LLVOAvatarSelf::getLocalDiscardLevel(ETextureIndex type, U32 wearable_index) const
  1446. {
  1447. if (!isIndexLocalTexture(type)) return FALSE;
  1448. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, wearable_index);
  1449. if (local_tex_obj)
  1450. {
  1451. if (type >= 0
  1452. && local_tex_obj->getID() != IMG_DEFAULT_AVATAR
  1453. && !local_tex_obj->getImage()->isMissingAsset())
  1454. {
  1455. return local_tex_obj->getImage()->getDiscardLevel();
  1456. }
  1457. else
  1458. {
  1459. // We don't care about this (no image associated with the layer) treat as fully loaded.
  1460. return 0;
  1461. }
  1462. }
  1463. return 0;
  1464. }
  1465. // virtual
  1466. // Counts the memory footprint of local textures.
  1467. void LLVOAvatarSelf::getLocalTextureByteCount(S32* gl_bytes) const
  1468. {
  1469. *gl_bytes = 0;
  1470. for (S32 type = 0; type < TEX_NUM_INDICES; type++)
  1471. {
  1472. if (!isIndexLocalTexture((ETextureIndex)type)) continue;
  1473. U32 max_tex = getNumWearables((ETextureIndex) type);
  1474. for (U32 num = 0; num < max_tex; num++)
  1475. {
  1476. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject((ETextureIndex) type, num);
  1477. if (local_tex_obj)
  1478. {
  1479. const LLViewerFetchedTexture* image_gl = local_tex_obj->getImage();
  1480. if (image_gl)
  1481. {
  1482. S32 bytes = (S32)image_gl->getWidth() * image_gl->getHeight() * image_gl->getComponents();
  1483. if (image_gl->hasGLTexture())
  1484. {
  1485. *gl_bytes += bytes;
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. // virtual
  1493. void LLVOAvatarSelf::setLocalTexture(ETextureIndex type, LLViewerTexture* src_tex, BOOL baked_version_ready, U32 index)
  1494. {
  1495. if (!isIndexLocalTexture(type)) return;
  1496. LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(src_tex, TRUE) ;
  1497. if(!tex)
  1498. {
  1499. return ;
  1500. }
  1501. S32 desired_discard = isSelf() ? 0 : 2;
  1502. LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
  1503. if (!local_tex_obj)
  1504. {
  1505. if (type >= TEX_NUM_INDICES)
  1506. {
  1507. llerrs << "Tried to set local texture with invalid type: (" << (U32) type << ", " << index << ")" << llendl;
  1508. return;
  1509. }
  1510. LLWearableType::EType wearable_type = LLVOAvatarDictionary::getInstance()->getTEWearableType(type);
  1511. if (!gAgentWearables.getWearable(wearable_type,index))
  1512. {
  1513. // no wearable is loaded, cannot set the texture.
  1514. return;
  1515. }
  1516. gAgentWearables.addLocalTextureObject(wearable_type,type,index);
  1517. local_tex_obj = getLocalTextureObject(type,index);
  1518. if (!local_tex_obj)
  1519. {
  1520. llerrs << "Unable to create LocalTextureObject for wearable type & index: (" << (U32) wearable_type << ", " << index << ")" << llendl;
  1521. return;
  1522. }
  1523. LLTexLayerSet *layer_set = getLayerSet(type);
  1524. if (layer_set)
  1525. {
  1526. layer_set->cloneTemplates(local_tex_obj, type, gAgentWearables.getWearable(wearable_type,index));
  1527. }
  1528. }
  1529. if (!baked_version_ready)
  1530. {
  1531. if (tex != local_tex_obj->getImage() || local_tex_obj->getBakedReady())
  1532. {
  1533. local_tex_obj->setDiscard(MAX_DISCARD_LEVEL+1);
  1534. }
  1535. if (tex->getID() != IMG_DEFAULT_AVATAR)
  1536. {
  1537. if (local_tex_obj->getDiscard() > desired_discard)
  1538. {
  1539. S32 tex_discard = tex->getDiscardLevel();
  1540. if (tex_discard >= 0 && tex_discard <= desired_discard)
  1541. {
  1542. local_tex_obj->setDiscard(tex_discard);
  1543. if (isSelf())
  1544. {
  1545. if (gAgentAvatarp->isUsingBakedTextures())
  1546. {
  1547. requestLayerSetUpdate(type);
  1548. }
  1549. else
  1550. {
  1551. LLVisualParamHint::requestHintUpdates();
  1552. }
  1553. }
  1554. }
  1555. else
  1556. {
  1557. tex->setLoadedCallback(onLocalTextureLoaded, desired_discard, TRUE, FALSE, new LLAvatarTexData(getID(), type), NULL);
  1558. }
  1559. }
  1560. tex->setMinDiscardLevel(desired_discard);
  1561. }
  1562. }
  1563. local_tex_obj->setImage(tex);
  1564. local_tex_obj->setID(tex->getID());
  1565. setBakedReady(type,baked_version_ready,index);
  1566. }
  1567. //virtual
  1568. void LLVOAvatarSelf::setBakedReady(LLVOAvatarDefines::ETextureIndex type, BOOL baked_version_exists, U32 index)
  1569. {
  1570. if (!isIndexLocalTexture(type)) return;
  1571. LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
  1572. if (local_tex_obj)
  1573. {
  1574. local_tex_obj->setBakedReady( baked_version_exists );
  1575. }
  1576. }
  1577. // virtual
  1578. void LLVOAvatarSelf::dumpLocalTextures() const
  1579. {
  1580. llinfos << "Local Textures:" << llendl;
  1581. /* ETextureIndex baked_equiv[] = {
  1582. TEX_UPPER_BAKED,
  1583. if (isTextureDefined(baked_equiv[i])) */
  1584. for (LLVOAvatarDictionary::Textures::const_iterator iter = LLVOAvatarDictionary::getInstance()->getTextures().begin();
  1585. iter != LLVOAvatarDictionary::getInstance()->getTextures().end();
  1586. ++iter)
  1587. {
  1588. const LLVOAvatarDictionary::TextureEntry *texture_dict = iter->second;
  1589. if (!texture_dict->mIsLocalTexture || !texture_dict->mIsUsedByBakedTexture)
  1590. continue;
  1591. const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
  1592. const ETextureIndex baked_equiv = LLVOAvatarDictionary::getInstance()->getBakedTexture(baked_index)->mTextureIndex;
  1593. const std::string &name = texture_dict->mName;
  1594. const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(iter->first, 0);
  1595. // index is baked texture - index is not relevant. putting in 0 as placeholder
  1596. if (isTextureDefined(baked_equiv, 0))
  1597. {
  1598. #if LL_RELEASE_FOR_DOWNLOAD
  1599. // End users don't get to trivially see avatar texture IDs, makes textures
  1600. // easier to steal. JC
  1601. llinfos << "LocTex " << name << ": Baked " << llendl;
  1602. #else
  1603. llinfos << "LocTex " << name << ": Baked " << getTEImage(baked_equiv)->getID() << llendl;
  1604. #endif
  1605. }
  1606. else if (local_tex_obj && local_tex_obj->getImage() != NULL)
  1607. {
  1608. if (local_tex_obj->getImage()->getID() == IMG_DEFAULT_AVATAR)
  1609. {
  1610. llinfos << "LocTex " << name << ": None" << llendl;
  1611. }
  1612. else
  1613. {
  1614. const LLViewerFetchedTexture* image = local_tex_obj->getImage();
  1615. llinfos << "LocTex " << name << ": "
  1616. << "Discard " << image->getDiscardLevel() << ", "
  1617. << "(" << image->getWidth() << ", " << image->getHeight() << ") "
  1618. #if !LL_RELEASE_FOR_DOWNLOAD
  1619. // End users don't get to trivially see avatar texture IDs,
  1620. // makes textures easier to steal
  1621. << image->getID() << " "
  1622. #endif
  1623. << "Priority: " << image->getDecodePriority()
  1624. << llendl;
  1625. }
  1626. }
  1627. else
  1628. {
  1629. llinfos << "LocTex " << name << ": No LLViewerTexture" << llendl;
  1630. }
  1631. }
  1632. }
  1633. //-----------------------------------------------------------------------------
  1634. // static
  1635. // onLocalTextureLoaded()
  1636. //-----------------------------------------------------------------------------
  1637. void LLVOAvatarSelf::onLocalTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src_raw, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
  1638. {
  1639. LLAvatarTexData *data = (LLAvatarTexData *)userdata;
  1640. LLVOAvatarSelf *self = (LLVOAvatarSelf *)gObjectList.findObject(data->mAvatarID);
  1641. if (self)
  1642. {
  1643. // We should only be handling local textures for ourself
  1644. self->localTextureLoaded(success, src_vi, src_raw, aux_src, discard_level, final, userdata);
  1645. }
  1646. // ensure data is cleaned up
  1647. if (final || !success)
  1648. {
  1649. delete data;
  1650. }
  1651. }
  1652. /*virtual*/ void LLVOAvatarSelf::setImage(const U8 te, LLViewerTexture *imagep, const U32 index)
  1653. {
  1654. if (isIndexLocalTexture((ETextureIndex)te))
  1655. {
  1656. setLocalTexture((ETextureIndex)te, imagep, FALSE ,index);
  1657. }
  1658. else
  1659. {
  1660. setTEImage(te,imagep);
  1661. }
  1662. }
  1663. /*virtual*/ LLViewerTexture* LLVOAvatarSelf::getImage(const U8 te, const U32 index) const
  1664. {
  1665. if (isIndexLocalTexture((ETextureIndex)te))
  1666. {
  1667. return getLocalTextureGL((ETextureIndex)te,index);
  1668. }
  1669. else
  1670. {
  1671. return getTEImage(te);
  1672. }
  1673. }
  1674. // static
  1675. void LLVOAvatarSelf::dumpTotalLocalTextureByteCount()
  1676. {
  1677. S32 gl_bytes = 0;
  1678. gAgentAvatarp->getLocalTextureByteCount(&gl_bytes);
  1679. llinfos << "Total Avatar LocTex GL:" << (gl_bytes/1024) << "KB" << llendl;
  1680. }
  1681. BOOL LLVOAvatarSelf::getIsCloud()
  1682. {
  1683. // do we have our body parts?
  1684. if (gAgentWearables.getWearableCount(LLWearableType::WT_SHAPE) == 0 ||
  1685. gAgentWearables.getWearableCount(LLWearableType::WT_HAIR) == 0 ||
  1686. gAgentWearables.getWearableCount(LLWearableType::WT_EYES) == 0 ||
  1687. gAgentWearables.getWearableCount(LLWearableType::WT_SKIN) == 0)
  1688. {
  1689. return TRUE;
  1690. }
  1691. if (!isTextureDefined(TEX_HAIR, 0))
  1692. {
  1693. return TRUE;
  1694. }
  1695. if (!mPreviousFullyLoaded)
  1696. {
  1697. if (!isLocalTextureDataAvailable(mBakedTextureDatas[BAKED_LOWER].mTexLayerSet) &&
  1698. (!isTextureDefined(TEX_LOWER_BAKED, 0)))
  1699. {
  1700. return TRUE;
  1701. }
  1702. if (!isLocalTextureDataAvailable(mBakedTextureDatas[BAKED_UPPER].mTexLayerSet) &&
  1703. (!isTextureDefined(TEX_UPPER_BAKED, 0)))
  1704. {
  1705. return TRUE;
  1706. }
  1707. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1708. {
  1709. if (i == BAKED_SKIRT && !isWearingWearableType(LLWearableType::WT_SKIRT))
  1710. continue;
  1711. const BakedTextureData& texture_data = mBakedTextureDatas[i];
  1712. if (!isTextureDefined(texture_data.mTextureIndex, 0))
  1713. continue;
  1714. // Check for the case that texture is defined but not sufficiently loaded to display anything.
  1715. const LLViewerTexture* baked_img = getImage( texture_data.mTextureIndex, 0 );
  1716. if (!baked_img || !baked_img->hasGLTexture())
  1717. {
  1718. return TRUE;
  1719. }
  1720. }
  1721. }
  1722. return FALSE;
  1723. }
  1724. /*static*/
  1725. void LLVOAvatarSelf::debugOnTimingLocalTexLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
  1726. {
  1727. gAgentAvatarp->debugTimingLocalTexLoaded(success, src_vi, src, aux_src, discard_level, final, userdata);
  1728. }
  1729. void LLVOAvatarSelf::debugTimingLocalTexLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
  1730. {
  1731. LLAvatarTexData *data = (LLAvatarTexData *)userdata;
  1732. if (!data)
  1733. {
  1734. return;
  1735. }
  1736. ETextureIndex index = data->mIndex;
  1737. if (index < 0 || index >= TEX_NUM_INDICES)
  1738. {
  1739. return;
  1740. }
  1741. if (discard_level >=0 && discard_level <= MAX_DISCARD_LEVEL) // ignore discard level -1, as it means we have no data.
  1742. {
  1743. mDebugTextureLoadTimes[(U32)index][(U32)discard_level] = mDebugSelfLoadTimer.getElapsedTimeF32();
  1744. }
  1745. if (final)
  1746. {
  1747. delete data;
  1748. }
  1749. }
  1750. void LLVOAvatarSelf::debugBakedTextureUpload(EBakedTextureIndex index, BOOL finished)
  1751. {
  1752. U32 done = 0;
  1753. if (finished)
  1754. {
  1755. done = 1;
  1756. }
  1757. mDebugBakedTextureTimes[index][done] = mDebugSelfLoadTimer.getElapsedTimeF32();
  1758. }
  1759. const std::string LLVOAvatarSelf::debugDumpLocalTextureDataInfo(const LLTexLayerSet* layerset) const
  1760. {
  1761. std::string text="";
  1762. text = llformat("[Final:%d Avail:%d] ",isLocalTextureDataFinal(layerset), isLocalTextureDataAvailable(layerset));
  1763. /* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
  1764. return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
  1765. for (LLVOAvatarDictionary::BakedTextures::const_iterator baked_iter = LLVOAvatarDictionary::getInstance()->getBakedTextures().begin();
  1766. baked_iter != LLVOAvatarDictionary::getInstance()->getBakedTextures().end();
  1767. ++baked_iter)
  1768. {
  1769. const EBakedTextureIndex baked_index = baked_iter->first;
  1770. if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
  1771. {
  1772. const LLVOAvatarDictionary::BakedEntry *baked_dict = baked_iter->second;
  1773. text += llformat("%d-%s ( ",baked_index, baked_dict->mName.c_str());
  1774. for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
  1775. local_tex_iter != baked_dict->mLocalTextures.end();
  1776. ++local_tex_iter)
  1777. {
  1778. const ETextureIndex tex_index = *local_tex_iter;
  1779. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(tex_index);
  1780. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1781. if (wearable_count > 0)
  1782. {
  1783. text += LLWearableType::getTypeName(wearable_type) + ":";
  1784. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1785. {
  1786. const U32 discard_level = getLocalDiscardLevel(tex_index, wearable_index);
  1787. std::string discard_str = llformat("%d ",discard_level);
  1788. text += llformat("%d ",discard_level);
  1789. }
  1790. }
  1791. }
  1792. text += ")";
  1793. break;
  1794. }
  1795. }
  1796. return text;
  1797. }
  1798. const std::string LLVOAvatarSelf::debugDumpAllLocalTextureDataInfo() const
  1799. {
  1800. std::string text;
  1801. const U32 override_tex_discard_level = gSavedSettings.getU32("TextureDiscardLevel");
  1802. for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
  1803. {
  1804. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture((EBakedTextureIndex)i);
  1805. BOOL is_texture_final = TRUE;
  1806. for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
  1807. local_tex_iter != baked_dict->mLocalTextures.end();
  1808. ++local_tex_iter)
  1809. {
  1810. const ETextureIndex tex_index = *local_tex_iter;
  1811. const LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(tex_index);
  1812. const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
  1813. for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
  1814. {
  1815. is_texture_final &= (getLocalDiscardLevel(*local_tex_iter, wearable_index) <= (S32)(override_tex_discard_level));
  1816. }
  1817. }
  1818. text += llformat("%s:%d ",baked_dict->mName.c_str(),is_texture_final);
  1819. }
  1820. return text;
  1821. }
  1822. const LLUUID& LLVOAvatarSelf::grabBakedTexture(EBakedTextureIndex baked_index) const
  1823. {
  1824. if (canGrabBakedTexture(baked_index))
  1825. {
  1826. ETextureIndex tex_index = LLVOAvatarDictionary::bakedToLocalTextureIndex(baked_index);
  1827. if (tex_index == TEX_NUM_INDICES)
  1828. {
  1829. return LLUUID::null;
  1830. }
  1831. return getTEImage( tex_index )->getID();
  1832. }
  1833. return LLUUID::null;
  1834. }
  1835. BOOL LLVOAvatarSelf::canGrabBakedTexture(EBakedTextureIndex baked_index) const
  1836. {
  1837. ETextureIndex tex_index = LLVOAvatarDictionary::bakedToLocalTextureIndex(baked_index);
  1838. if (tex_index == TEX_NUM_INDICES)
  1839. {
  1840. return FALSE;
  1841. }
  1842. // Check if the texture hasn't been baked yet.
  1843. if (!isTextureDefined(tex_index, 0))
  1844. {
  1845. lldebugs << "getTEImage( " << (U32) tex_index << " )->getID() == IMG_DEFAULT_AVATAR" << llendl;
  1846. return FALSE;
  1847. }
  1848. if (gAgent.isGodlikeWithoutAdminMenuFakery())
  1849. return TRUE;
  1850. // Check permissions of textures that show up in the
  1851. // baked texture. We don't want people copying people's
  1852. // work via baked textures.
  1853. const LLVOAvatarDictionary::BakedEntry *baked_dict = LLVOAvatarDictionary::getInstance()->getBakedTexture(baked_index);
  1854. for (texture_vec_t::const_iterator iter = baked_dict->mLocalTextures.begin();
  1855. iter != baked_dict->mLocalTextures.end();
  1856. ++iter)
  1857. {
  1858. const ETextureIndex t_index = (*iter);
  1859. LLWearableType::EType wearable_type = LLVOAvatarDictionary::getTEWearableType(t_index);
  1860. U32 count = gAgentWearables.getWearableCount(wearable_type);
  1861. lldebugs << "Checking index " << (U32) t_index << " count: " << count << llendl;
  1862. for (U32 wearable_index = 0; wearable_index < count; ++wearable_index)
  1863. {
  1864. LLWearable *wearable = gAgentWearables.getWearable(wearable_type, wearable_index);
  1865. if (wearable)
  1866. {
  1867. const LLLocalTextureObject *texture = wearable->getLocalTextureObject((S32)t_index);
  1868. const LLUUID& texture_id = texture->getID();
  1869. if (texture_id != IMG_DEFAULT_AVATAR)
  1870. {
  1871. // Search inventory for this texture.
  1872. LLViewerInventoryCategory::cat_array_t cats;
  1873. LLViewerInventoryItem::item_array_t items;
  1874. LLAssetIDMatches asset_id_matches(texture_id);
  1875. gInventory.collectDescendentsIf(LLUUID::null,
  1876. cats,
  1877. items,
  1878. LLInventoryModel::INCLUDE_TRASH,
  1879. asset_id_matches);
  1880. BOOL can_grab = FALSE;
  1881. lldebugs << "item count for asset " << texture_id << ": " << items.count() << llendl;
  1882. if (items.count())
  1883. {
  1884. // search for full permissions version
  1885. for (S32 i = 0; i < items.count(); i++)
  1886. {
  1887. LLViewerInventoryItem* itemp = items[i];
  1888. if (itemp->getIsFullPerm())
  1889. {
  1890. can_grab = TRUE;
  1891. break;
  1892. }
  1893. }
  1894. }
  1895. if (!can_grab) return FALSE;
  1896. }
  1897. }
  1898. }
  1899. }
  1900. return TRUE;
  1901. }
  1902. void LLVOAvatarSelf::addLocalTextureStats( ETextureIndex type, LLViewerFetchedTexture* imagep,
  1903. F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked, U32 index )
  1904. {
  1905. if (!isIndexLocalTexture(type)) return;
  1906. if (!covered_by_baked)
  1907. {
  1908. if (getLocalTextureID(type, index) != IMG_DEFAULT_AVATAR && imagep->getDiscardLevel() != 0)
  1909. {
  1910. F32 desired_pixels;
  1911. desired_pixels = llmin(mPixelArea, (F32)getTexImageArea());
  1912. imagep->setBoostLevel(getAvatarBoostLevel());
  1913. imagep->resetTextureStats();
  1914. imagep->setMaxVirtualSizeResetInterval(MAX_TEXTURE_VIRTURE_SIZE_RESET_INTERVAL);
  1915. imagep->addTextureStats( desired_pixels / texel_area_ratio );
  1916. imagep->setAdditionalDecodePriority(SELF_ADDITIONAL_PRI) ;
  1917. imagep->forceUpdateBindStats() ;
  1918. if (imagep->getDiscardLevel() < 0)
  1919. {
  1920. mHasGrey = TRUE; // for statistics gathering
  1921. }
  1922. }
  1923. else
  1924. {
  1925. // texture asset is missing
  1926. mHasGrey = TRUE; // for statistics gathering
  1927. }
  1928. }
  1929. }
  1930. LLLocalTextureObject* LLVOAvatarSelf::getLocalTextureObject(LLVOAvatarDefines::ETextureIndex i, U32 wearable_index) const
  1931. {
  1932. LLWearableType::EType type = LLVOAvata