PageRenderTime 34ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lllocaltextureobject.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 212 lines | 154 code | 34 blank | 24 comment | 16 complexity | 532bbbb2bcd1591b7fa934f3f3680333 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lllocaltextureobject.cpp
  3. *
  4. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "llviewerprecompiledheaders.h"
  26. #include "lllocaltextureobject.h"
  27. #include "lltexlayer.h"
  28. #include "llviewertexture.h"
  29. #include "lltextureentry.h"
  30. #include "lluuid.h"
  31. #include "llwearable.h"
  32. LLLocalTextureObject::LLLocalTextureObject() :
  33. mIsBakedReady(FALSE),
  34. mDiscard(MAX_DISCARD_LEVEL+1)
  35. {
  36. mImage = NULL;
  37. }
  38. LLLocalTextureObject::LLLocalTextureObject(LLViewerFetchedTexture* image, const LLUUID& id) :
  39. mIsBakedReady(FALSE),
  40. mDiscard(MAX_DISCARD_LEVEL+1)
  41. {
  42. mImage = image;
  43. gGL.getTexUnit(0)->bind(mImage);
  44. mID = id;
  45. }
  46. LLLocalTextureObject::LLLocalTextureObject(const LLLocalTextureObject& lto) :
  47. mImage(lto.mImage),
  48. mID(lto.mID),
  49. mIsBakedReady(lto.mIsBakedReady),
  50. mDiscard(lto.mDiscard)
  51. {
  52. U32 num_layers = lto.getNumTexLayers();
  53. mTexLayers.reserve(num_layers);
  54. for (U32 index = 0; index < num_layers; index++)
  55. {
  56. LLTexLayer* original_layer = lto.getTexLayer(index);
  57. if (!original_layer)
  58. {
  59. llerrs << "could not clone Local Texture Object: unable to extract texlayer!" << llendl;
  60. continue;
  61. }
  62. LLTexLayer* new_layer = new LLTexLayer(*original_layer);
  63. new_layer->setLTO(this);
  64. mTexLayers.push_back(new_layer);
  65. }
  66. }
  67. LLLocalTextureObject::~LLLocalTextureObject()
  68. {
  69. }
  70. LLViewerFetchedTexture* LLLocalTextureObject::getImage() const
  71. {
  72. return mImage;
  73. }
  74. LLTexLayer* LLLocalTextureObject::getTexLayer(U32 index) const
  75. {
  76. if (index >= getNumTexLayers())
  77. {
  78. return NULL;
  79. }
  80. return mTexLayers[index];
  81. }
  82. LLTexLayer* LLLocalTextureObject::getTexLayer(const std::string &name)
  83. {
  84. for( tex_layer_vec_t::iterator iter = mTexLayers.begin(); iter != mTexLayers.end(); iter++)
  85. {
  86. LLTexLayer *layer = *iter;
  87. if (layer->getName().compare(name) == 0)
  88. {
  89. return layer;
  90. }
  91. }
  92. return NULL;
  93. }
  94. U32 LLLocalTextureObject::getNumTexLayers() const
  95. {
  96. return mTexLayers.size();
  97. }
  98. LLUUID LLLocalTextureObject::getID() const
  99. {
  100. return mID;
  101. }
  102. S32 LLLocalTextureObject::getDiscard() const
  103. {
  104. return mDiscard;
  105. }
  106. BOOL LLLocalTextureObject::getBakedReady() const
  107. {
  108. return mIsBakedReady;
  109. }
  110. void LLLocalTextureObject::setImage(LLViewerFetchedTexture* new_image)
  111. {
  112. mImage = new_image;
  113. }
  114. BOOL LLLocalTextureObject::setTexLayer(LLTexLayer *new_tex_layer, U32 index)
  115. {
  116. if (index >= getNumTexLayers() )
  117. {
  118. return FALSE;
  119. }
  120. if (new_tex_layer == NULL)
  121. {
  122. return removeTexLayer(index);
  123. }
  124. LLTexLayer *layer = new LLTexLayer(*new_tex_layer);
  125. layer->setLTO(this);
  126. if (mTexLayers[index])
  127. {
  128. delete mTexLayers[index];
  129. }
  130. mTexLayers[index] = layer;
  131. return TRUE;
  132. }
  133. BOOL LLLocalTextureObject::addTexLayer(LLTexLayer *new_tex_layer, LLWearable *wearable)
  134. {
  135. if (new_tex_layer == NULL)
  136. {
  137. return FALSE;
  138. }
  139. LLTexLayer *layer = new LLTexLayer(*new_tex_layer, wearable);
  140. layer->setLTO(this);
  141. mTexLayers.push_back(layer);
  142. return TRUE;
  143. }
  144. BOOL LLLocalTextureObject::addTexLayer(LLTexLayerTemplate *new_tex_layer, LLWearable *wearable)
  145. {
  146. if (new_tex_layer == NULL)
  147. {
  148. return FALSE;
  149. }
  150. LLTexLayer *layer = new LLTexLayer(*new_tex_layer, this, wearable);
  151. layer->setLTO(this);
  152. mTexLayers.push_back(layer);
  153. return TRUE;
  154. }
  155. BOOL LLLocalTextureObject::removeTexLayer(U32 index)
  156. {
  157. if (index >= getNumTexLayers())
  158. {
  159. return FALSE;
  160. }
  161. tex_layer_vec_t::iterator iter = mTexLayers.begin();
  162. iter += index;
  163. delete *iter;
  164. mTexLayers.erase(iter);
  165. return TRUE;
  166. }
  167. void LLLocalTextureObject::setID(LLUUID new_id)
  168. {
  169. mID = new_id;
  170. }
  171. void LLLocalTextureObject::setDiscard(S32 new_discard)
  172. {
  173. mDiscard = new_discard;
  174. }
  175. void LLLocalTextureObject::setBakedReady(BOOL ready)
  176. {
  177. mIsBakedReady = ready;
  178. }