PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 1ms 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
  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
 26#include "llviewerprecompiledheaders.h"
 27
 28#include "lllocaltextureobject.h"
 29
 30#include "lltexlayer.h"
 31#include "llviewertexture.h"
 32#include "lltextureentry.h"
 33#include "lluuid.h"
 34#include "llwearable.h"
 35
 36
 37LLLocalTextureObject::LLLocalTextureObject() :
 38	mIsBakedReady(FALSE),
 39	mDiscard(MAX_DISCARD_LEVEL+1)
 40{
 41	mImage = NULL;
 42}
 43
 44LLLocalTextureObject::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
 53LLLocalTextureObject::LLLocalTextureObject(const LLLocalTextureObject& lto) :
 54	mImage(lto.mImage),
 55	mID(lto.mID),
 56	mIsBakedReady(lto.mIsBakedReady),
 57	mDiscard(lto.mDiscard)
 58{
 59	U32 num_layers = lto.getNumTexLayers();
 60	mTexLayers.reserve(num_layers);
 61	for (U32 index = 0; index < num_layers; index++)
 62	{
 63		LLTexLayer* original_layer = lto.getTexLayer(index);
 64		if (!original_layer)
 65		{
 66			llerrs << "could not clone Local Texture Object: unable to extract texlayer!" << llendl;
 67			continue;
 68		}
 69
 70		LLTexLayer* new_layer = new LLTexLayer(*original_layer);
 71		new_layer->setLTO(this);
 72		mTexLayers.push_back(new_layer);
 73	}
 74}
 75
 76LLLocalTextureObject::~LLLocalTextureObject()
 77{
 78}
 79
 80LLViewerFetchedTexture* LLLocalTextureObject::getImage() const
 81{
 82	return mImage;
 83}
 84
 85LLTexLayer* LLLocalTextureObject::getTexLayer(U32 index) const
 86{
 87	if (index >= getNumTexLayers())
 88	{
 89		return NULL;
 90	}
 91
 92	return mTexLayers[index];
 93}
 94
 95LLTexLayer* LLLocalTextureObject::getTexLayer(const std::string &name)
 96{
 97	for( tex_layer_vec_t::iterator iter = mTexLayers.begin(); iter != mTexLayers.end(); iter++)
 98	{
 99		LLTexLayer *layer = *iter;
100		if (layer->getName().compare(name) == 0)
101		{
102			return layer;
103		}
104	}
105
106	return NULL;
107}
108
109U32 LLLocalTextureObject::getNumTexLayers() const
110{
111	return mTexLayers.size();
112}
113
114LLUUID LLLocalTextureObject::getID() const
115{
116	return mID;
117}
118
119S32 LLLocalTextureObject::getDiscard() const
120{
121	return mDiscard;
122}
123
124BOOL LLLocalTextureObject::getBakedReady() const
125{
126	return mIsBakedReady;
127}
128
129void LLLocalTextureObject::setImage(LLViewerFetchedTexture* new_image)
130{
131	mImage = new_image;
132}
133
134BOOL LLLocalTextureObject::setTexLayer(LLTexLayer *new_tex_layer, U32 index)
135{
136	if (index >= getNumTexLayers() )
137	{
138		return FALSE;
139	}
140
141	if (new_tex_layer == NULL)
142	{
143		return removeTexLayer(index);
144	}
145
146	LLTexLayer *layer = new LLTexLayer(*new_tex_layer);
147	layer->setLTO(this);
148
149	if (mTexLayers[index])
150	{
151		delete mTexLayers[index];
152	}
153	mTexLayers[index] = layer;
154
155	return TRUE;
156}
157
158BOOL LLLocalTextureObject::addTexLayer(LLTexLayer *new_tex_layer, LLWearable *wearable)
159{
160	if (new_tex_layer == NULL)
161	{
162		return FALSE;
163	}
164
165	LLTexLayer *layer = new LLTexLayer(*new_tex_layer, wearable);
166	layer->setLTO(this);
167	mTexLayers.push_back(layer);
168	return TRUE;
169}
170
171BOOL LLLocalTextureObject::addTexLayer(LLTexLayerTemplate *new_tex_layer, LLWearable *wearable)
172{
173	if (new_tex_layer == NULL)
174	{
175		return FALSE;
176	}
177
178	LLTexLayer *layer = new LLTexLayer(*new_tex_layer, this, wearable);
179	layer->setLTO(this);
180	mTexLayers.push_back(layer);
181	return TRUE;
182}
183
184BOOL LLLocalTextureObject::removeTexLayer(U32 index)
185{
186	if (index >= getNumTexLayers())
187	{
188		return FALSE;
189	}
190	tex_layer_vec_t::iterator iter = mTexLayers.begin();
191	iter += index;
192
193	delete *iter;
194	mTexLayers.erase(iter);
195	return TRUE;
196}
197
198void LLLocalTextureObject::setID(LLUUID new_id)
199{
200	mID = new_id;
201}
202
203void LLLocalTextureObject::setDiscard(S32 new_discard)
204{
205	mDiscard = new_discard;
206}
207
208void LLLocalTextureObject::setBakedReady(BOOL ready)
209{
210	mIsBakedReady = ready;
211}
212