PageRenderTime 54ms CodeModel.GetById 27ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llprimitive/llprimtexturelist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 418 lines | 314 code | 48 blank | 56 comment | 41 complexity | 8e5e09025a0045c5f604da69fa98e78e MD5 | raw file
  1/** 
  2 * @file lltexturelist.cpp
  3 * @brief LLPrimTextureList (virtual) base class
  4 *
  5 * $LicenseInfo:firstyear=2008&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
 27#include "linden_common.h"
 28
 29#include "llprimtexturelist.h"
 30#include "lltextureentry.h"
 31#include "llmemtype.h"
 32
 33// static 
 34//int (TMyClass::*pt2Member)(float, char, char) = NULL;                // C++
 35LLTextureEntry* (*LLPrimTextureList::sNewTextureEntryCallback)() = &(LLTextureEntry::newTextureEntry);
 36
 37// static
 38void LLPrimTextureList::setNewTextureEntryCallback( LLTextureEntry* (*callback)() )
 39{
 40	if (callback)
 41	{
 42		LLPrimTextureList::sNewTextureEntryCallback = callback;
 43	}
 44	else
 45	{
 46		LLPrimTextureList::sNewTextureEntryCallback = &(LLTextureEntry::newTextureEntry);
 47	}
 48}
 49
 50// static 
 51// call this to get a new texture entry
 52LLTextureEntry* LLPrimTextureList::newTextureEntry()
 53{
 54	return (*sNewTextureEntryCallback)();
 55}
 56
 57LLPrimTextureList::LLPrimTextureList()
 58{
 59}
 60
 61// virtual 
 62LLPrimTextureList::~LLPrimTextureList()
 63{
 64	clear();
 65}
 66
 67void LLPrimTextureList::clear()
 68{
 69	texture_list_t::iterator itr = mEntryList.begin();
 70	while (itr != mEntryList.end())
 71	{
 72		delete (*itr);
 73		(*itr) = NULL;
 74		++itr;
 75	}
 76	mEntryList.clear();
 77}
 78
 79
 80// clears current entries
 81// copies contents of other_list
 82// this is somewhat expensive, so it must be called explicitly
 83void LLPrimTextureList::copy(const LLPrimTextureList& other_list)
 84{
 85	// compare the sizes
 86	S32 this_size = mEntryList.size();
 87	S32 other_size = other_list.mEntryList.size();
 88
 89	if (this_size > other_size)
 90	{
 91		// remove the extra entries
 92		for (S32 index = this_size; index > other_size; --index)
 93		{
 94			delete mEntryList[index-1];
 95		}
 96		mEntryList.resize(other_size);
 97		this_size = other_size;
 98	}
 99
100	S32 index = 0;
101	// copy for the entries that already exist
102	for ( ; index < this_size; ++index)
103	{
104		delete mEntryList[index];
105		mEntryList[index] = other_list.getTexture(index)->newCopy();
106	}
107
108	// add new entires if needed
109	for ( ; index < other_size; ++index)
110	{
111		mEntryList.push_back( other_list.getTexture(index)->newCopy() );
112	}
113}
114
115// clears current copies
116// takes contents of other_list
117// clears other_list
118void LLPrimTextureList::take(LLPrimTextureList& other_list)
119{
120	clear();
121	mEntryList = other_list.mEntryList;
122	other_list.mEntryList.clear();
123}
124
125// virtual 
126// copies LLTextureEntry 'te'
127// returns TEM_CHANGE_TEXTURE if successful, otherwise TEM_CHANGE_NONE
128S32 LLPrimTextureList::copyTexture(const U8 index, const LLTextureEntry& te)
129{
130	if (S32(index) >= mEntryList.size())
131	{
132		S32 current_size = mEntryList.size();
133		llwarns << "ignore copy of index = " << S32(index) << " into texture entry list of size = " << current_size << llendl;
134		return TEM_CHANGE_NONE;
135	}
136
137		// we're changing an existing entry
138	llassert(mEntryList[index]);
139	delete (mEntryList[index]);
140	if  (&te)
141	{
142		mEntryList[index] = te.newCopy();
143	}
144	else
145	{
146		mEntryList[index] = LLPrimTextureList::newTextureEntry();
147	}
148	return TEM_CHANGE_TEXTURE;
149}
150
151// virtual 
152// takes ownership of LLTextureEntry* 'te'
153// returns TEM_CHANGE_TEXTURE if successful, otherwise TEM_CHANGE_NONE
154// IMPORTANT! -- if you use this function you must check the return value
155S32 LLPrimTextureList::takeTexture(const U8 index, LLTextureEntry* te)
156{
157	if (S32(index) >= mEntryList.size())
158	{
159		return TEM_CHANGE_NONE;
160	}
161
162	// we're changing an existing entry
163	llassert(mEntryList[index]);
164	delete (mEntryList[index]);
165	mEntryList[index] = te;
166	return TEM_CHANGE_TEXTURE;
167}
168
169// returns pointer to texture at 'index' slot
170LLTextureEntry* LLPrimTextureList::getTexture(const U8 index) const
171{
172	if (index < mEntryList.size())
173	{
174		return mEntryList[index];
175	}
176	return NULL;
177}
178
179//virtual 
180//S32 setTE(const U8 index, const LLTextureEntry& te) = 0;
181
182S32 LLPrimTextureList::setID(const U8 index, const LLUUID& id)
183{
184	if (index < mEntryList.size())
185	{
186		return mEntryList[index]->setID(id);
187	}
188	return TEM_CHANGE_NONE;
189}
190
191S32 LLPrimTextureList::setColor(const U8 index, const LLColor3& color)
192{
193	if (index < mEntryList.size())
194	{
195		return mEntryList[index]->setColor(color);
196	}
197	return TEM_CHANGE_NONE;
198}
199
200S32 LLPrimTextureList::setColor(const U8 index, const LLColor4& color)
201{
202	if (index < mEntryList.size())
203	{
204		return mEntryList[index]->setColor(color);
205	}
206	return TEM_CHANGE_NONE;
207}
208
209S32 LLPrimTextureList::setAlpha(const U8 index, const F32 alpha)
210{
211	if (index < mEntryList.size())
212	{
213		return mEntryList[index]->setAlpha(alpha);
214	}
215	return TEM_CHANGE_NONE;
216}
217
218S32 LLPrimTextureList::setScale(const U8 index, const F32 s, const F32 t)
219{
220	if (index < mEntryList.size())
221	{
222		return mEntryList[index]->setScale(s, t);
223	}
224	return TEM_CHANGE_NONE;
225}
226
227S32 LLPrimTextureList::setScaleS(const U8 index, const F32 s)
228{
229	if (index < mEntryList.size())
230	{
231		return mEntryList[index]->setScaleS(s);
232	}
233	return TEM_CHANGE_NONE;
234}
235
236S32 LLPrimTextureList::setScaleT(const U8 index, const F32 t)
237{
238	if (index < mEntryList.size())
239	{
240		return mEntryList[index]->setScaleT(t);
241	}
242	return TEM_CHANGE_NONE;
243}
244
245S32 LLPrimTextureList::setOffset(const U8 index, const F32 s, const F32 t)
246{
247	if (index < mEntryList.size())
248	{
249		return mEntryList[index]->setOffset(s, t);
250	}
251	return TEM_CHANGE_NONE;
252}
253
254S32 LLPrimTextureList::setOffsetS(const U8 index, const F32 s)
255{
256	if (index < mEntryList.size())
257	{
258		return mEntryList[index]->setOffsetS(s);
259	}
260	return TEM_CHANGE_NONE;
261}
262
263S32 LLPrimTextureList::setOffsetT(const U8 index, const F32 t)
264{
265	if (index < mEntryList.size())
266	{
267		return mEntryList[index]->setOffsetT(t);
268	}
269	return TEM_CHANGE_NONE;
270}
271
272S32 LLPrimTextureList::setRotation(const U8 index, const F32 r)
273{
274	if (index < mEntryList.size())
275	{
276		return mEntryList[index]->setRotation(r);
277	}
278	return TEM_CHANGE_NONE;
279}
280
281S32 LLPrimTextureList::setBumpShinyFullbright(const U8 index, const U8 bump)
282{
283	if (index < mEntryList.size())
284	{
285		return mEntryList[index]->setBumpShinyFullbright(bump);
286	}
287	return TEM_CHANGE_NONE;
288}
289
290S32 LLPrimTextureList::setMediaTexGen(const U8 index, const U8 media)
291{
292	if (index < mEntryList.size())
293	{
294		return mEntryList[index]->setMediaTexGen(media);
295	}
296	return TEM_CHANGE_NONE;
297}
298
299S32 LLPrimTextureList::setBumpMap(const U8 index, const U8 bump)
300{
301	if (index < mEntryList.size())
302	{
303		return mEntryList[index]->setBumpmap(bump);
304	}
305	return TEM_CHANGE_NONE;
306}
307
308S32 LLPrimTextureList::setBumpShiny(const U8 index, const U8 bump_shiny)
309{
310	if (index < mEntryList.size())
311	{
312		return mEntryList[index]->setBumpShiny(bump_shiny);
313	}
314	return TEM_CHANGE_NONE;
315}
316
317S32 LLPrimTextureList::setTexGen(const U8 index, const U8 texgen)
318{
319	if (index < mEntryList.size())
320	{
321		return mEntryList[index]->setTexGen(texgen);
322	}
323	return TEM_CHANGE_NONE;
324}
325
326S32 LLPrimTextureList::setShiny(const U8 index, const U8 shiny)
327{
328	if (index < mEntryList.size())
329	{
330		return mEntryList[index]->setShiny(shiny);
331	}
332	return TEM_CHANGE_NONE;
333}
334
335S32 LLPrimTextureList::setFullbright(const U8 index, const U8 fullbright)
336{
337	if (index < mEntryList.size())
338	{
339		return mEntryList[index]->setFullbright(fullbright);
340	}
341	return TEM_CHANGE_NONE;
342}
343
344S32 LLPrimTextureList::setMediaFlags(const U8 index, const U8 media_flags)
345{
346	if (index < mEntryList.size())
347	{
348		return mEntryList[index]->setMediaFlags(media_flags);
349	}
350	return TEM_CHANGE_NONE;
351}
352
353S32 LLPrimTextureList::setGlow(const U8 index, const F32 glow)
354{
355	if (index < mEntryList.size())
356	{
357		return mEntryList[index]->setGlow(glow);
358	}
359	return TEM_CHANGE_NONE;
360}
361
362S32 LLPrimTextureList::size() const
363{
364	return mEntryList.size();
365}
366
367// sets the size of the mEntryList container
368void LLPrimTextureList::setSize(S32 new_size)
369{
370	LLMemType m1(LLMemType::MTYPE_PRIMITIVE);
371	if (new_size < 0)
372	{
373		new_size = 0;
374	}
375
376	S32 current_size = mEntryList.size();
377
378	if (new_size > current_size)
379	{
380		mEntryList.resize(new_size);
381		for (S32 index = current_size; index < new_size; ++index)
382		{
383			if (current_size > 0
384				&& mEntryList[current_size - 1])
385			{
386				// copy the last valid entry for the new one
387				mEntryList[index] = mEntryList[current_size - 1]->newCopy();
388			}
389			else
390			{
391				// no valid enries to copy, so we new one up
392				LLTextureEntry* new_entry = LLPrimTextureList::newTextureEntry();
393				mEntryList[index] = new_entry;
394			}
395		}
396	}
397	else if (new_size < current_size)
398	{
399		for (S32 index = current_size-1; index >= new_size; --index)
400		{
401			delete mEntryList[index];
402		}
403		mEntryList.resize(new_size);
404	}
405}
406
407
408void LLPrimTextureList::setAllIDs(const LLUUID& id)
409{
410	texture_list_t::iterator itr = mEntryList.begin();
411	while (itr != mEntryList.end())
412	{
413		(*itr)->setID(id);
414		++itr;
415	}
416}
417
418