lllocaltextureobject.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:5k
源码类别:

游戏引擎

开发平台:

C++ Builder

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