lllocaltextureobject.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * @file lllocaltextureobject.cpp
  3. * @brief LLLocalTextureObject class implementation
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "lllocaltextureobject.h"
  34. #include "llgltexture.h"
  35. #include "llimage.h"
  36. #include "llrender.h"
  37. #include "lltexlayer.h"
  38. #include "llwearable.h"
  39. //static
  40. bool LLLocalTextureObject::sMarkNoDelete = false;
  41. LLLocalTextureObject::LLLocalTextureObject()
  42. : mIsBakedReady(false),
  43. mDiscard(MAX_DISCARD_LEVEL + 1),
  44. mImage(NULL)
  45. {
  46. }
  47. LLLocalTextureObject::LLLocalTextureObject(LLGLTexture* texp, const LLUUID& id)
  48. : mID(id),
  49. mIsBakedReady(false),
  50. mDiscard(MAX_DISCARD_LEVEL + 1),
  51. mImage(texp)
  52. {
  53. if (texp)
  54. {
  55. // Make sure this texture (which could belong to the agent's outfit)
  56. // will not get deleted via LLImageGL::activateStaleTextures() before
  57. // it gets baked. This is only necessary in OpenSim. *TODO: track
  58. // LLLocalTextureObject instances belonging to the agent avatar, and
  59. // only mark those as not deletable. HB
  60. if (sMarkNoDelete)
  61. {
  62. texp->setBoostLevel(LLGLTexture::BOOST_AVATAR_SELF);
  63. #if !LL_IMPLICIT_SETNODELETE
  64. texp->setNoDelete();
  65. #endif
  66. }
  67. gGL.getTexUnit(0)->bind(texp);
  68. }
  69. }
  70. LLLocalTextureObject::LLLocalTextureObject(const LLLocalTextureObject& lto)
  71. : mImage(lto.mImage),
  72. mID(lto.mID),
  73. mIsBakedReady(lto.mIsBakedReady),
  74. mDiscard(lto.mDiscard)
  75. {
  76. U32 num_layers = lto.mTexLayers.size();
  77. mTexLayers.reserve(num_layers);
  78. for (U32 index = 0; index < num_layers; ++index)
  79. {
  80. LLTexLayer* layerp = lto.getTexLayerByIdx(index);
  81. if (!layerp)
  82. {
  83. llerrs << "Could not clone Local Texture Object: unable to extract texlayer !"
  84. << llendl;
  85. continue;
  86. }
  87. LLTexLayer* new_layerp = new LLTexLayer(*layerp);
  88. new_layerp->setLTO(this);
  89. mTexLayers.push_back(new_layerp);
  90. }
  91. }
  92. LLLocalTextureObject::~LLLocalTextureObject()
  93. {
  94. for (U32 i = 0, count = mTexLayers.size(); i < count; ++i)
  95. {
  96. delete mTexLayers[i];
  97. }
  98. mTexLayers.clear();
  99. }
  100. void LLLocalTextureObject::setImage(LLGLTexture* texp)
  101. {
  102. mImage = texp;
  103. if (texp && sMarkNoDelete)
  104. {
  105. // Make sure this texture (which could belong to the agent's outfit)
  106. // will not get deleted via LLImageGL::activateStaleTextures() before
  107. // it gets baked. This is only necessary in OpenSim. *TODO: track
  108. // LLLocalTextureObject instances belonging to the agent avatar, and
  109. // only mark those as not deletable. HB
  110. texp->setBoostLevel(LLGLTexture::BOOST_AVATAR_SELF);
  111. #if !LL_IMPLICIT_SETNODELETE
  112. texp->setNoDelete();
  113. #endif
  114. }
  115. }
  116. LLTexLayer* LLLocalTextureObject::getTexLayerByIdx(U32 index) const
  117. {
  118. return index < (U32)mTexLayers.size() ? mTexLayers[index] : NULL;
  119. }
  120. LLTexLayer* LLLocalTextureObject::getTexLayer(const std::string& name) const
  121. {
  122. for (size_t i = 0, count = mTexLayers.size(); i < count; ++i)
  123. {
  124. LLTexLayer* layerp = mTexLayers[i];
  125. if (layerp && layerp->getName().compare(name) == 0)
  126. {
  127. return layerp;
  128. }
  129. }
  130. return NULL;
  131. }
  132. bool LLLocalTextureObject::setTexLayer(LLTexLayer* layerp, U32 index)
  133. {
  134. if (index >= mTexLayers.size())
  135. {
  136. return false;
  137. }
  138. if (!layerp)
  139. {
  140. return removeTexLayer(index);
  141. }
  142. LLTexLayer* new_layerp = new LLTexLayer(*layerp);
  143. new_layerp->setLTO(this);
  144. if (mTexLayers[index])
  145. {
  146. delete mTexLayers[index];
  147. }
  148. mTexLayers[index] = new_layerp;
  149. return true;
  150. }
  151. bool LLLocalTextureObject::addTexLayer(LLTexLayer* layerp,
  152. LLWearable* wearablep)
  153. {
  154. if (!layerp)
  155. {
  156. return false;
  157. }
  158. LLTexLayer* new_layerp = new LLTexLayer(*layerp, wearablep);
  159. new_layerp->setLTO(this);
  160. mTexLayers.push_back(new_layerp);
  161. return true;
  162. }
  163. bool LLLocalTextureObject::addTexLayer(LLTexLayerTemplate* layerp,
  164. LLWearable* wearablep)
  165. {
  166. if (!layerp)
  167. {
  168. return false;
  169. }
  170. LLTexLayer* new_layerp = new LLTexLayer(*layerp, this, wearablep);
  171. new_layerp->setLTO(this);
  172. mTexLayers.push_back(new_layerp);
  173. return true;
  174. }
  175. bool LLLocalTextureObject::removeTexLayer(U32 index)
  176. {
  177. if (index >= mTexLayers.size())
  178. {
  179. return false;
  180. }
  181. tex_layer_vec_t::iterator iter = mTexLayers.begin();
  182. iter += index;
  183. if (*iter)
  184. {
  185. delete *iter;
  186. }
  187. mTexLayers.erase(iter);
  188. return true;
  189. }