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