aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llprimitive/lltextureentry.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llprimitive/lltextureentry.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llprimitive/lltextureentry.cpp')
-rw-r--r--linden/indra/llprimitive/lltextureentry.cpp367
1 files changed, 367 insertions, 0 deletions
diff --git a/linden/indra/llprimitive/lltextureentry.cpp b/linden/indra/llprimitive/lltextureentry.cpp
new file mode 100644
index 0000000..5099eef
--- /dev/null
+++ b/linden/indra/llprimitive/lltextureentry.cpp
@@ -0,0 +1,367 @@
1/**
2 * @file lltextureentry.cpp
3 * @brief LLTextureEntry base class
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29
30#include "lltextureentry.h"
31#include "llsdutil.h"
32
33const U8 DEFAULT_BUMP_CODE = 0; // no bump or shininess
34
35const LLTextureEntry LLTextureEntry::null;
36
37//===============================================================
38LLTextureEntry::LLTextureEntry()
39{
40 init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
41}
42
43LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
44{
45 init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
46}
47
48LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
49{
50 mID = rhs.mID;
51 mScaleS = rhs.mScaleS;
52 mScaleT = rhs.mScaleT;
53 mOffsetS = rhs.mOffsetS;
54 mOffsetT = rhs.mOffsetT;
55 mRotation = rhs.mRotation;
56 mColor = rhs.mColor;
57 mBump = rhs.mBump;
58 mMediaFlags = rhs.mMediaFlags;
59}
60
61LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
62{
63 if (this != &rhs)
64 {
65 mID = rhs.mID;
66 mScaleS = rhs.mScaleS;
67 mScaleT = rhs.mScaleT;
68 mOffsetS = rhs.mOffsetS;
69 mOffsetT = rhs.mOffsetT;
70 mRotation = rhs.mRotation;
71 mColor = rhs.mColor;
72 mBump = rhs.mBump;
73 mMediaFlags = rhs.mMediaFlags;
74 }
75
76 return *this;
77}
78
79void LLTextureEntry::init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump)
80{
81 setID(tex_id);
82
83 mScaleS = scale_s;
84 mScaleT = scale_t;
85 mOffsetS = offset_s;
86 mOffsetT = offset_t;
87 mRotation = rotation;
88 mBump = bump;
89 mMediaFlags = 0x0;
90
91 setColor(LLColor4(1.f, 1.f, 1.f, 1.f));
92}
93
94LLTextureEntry::~LLTextureEntry()
95{
96}
97
98bool LLTextureEntry::operator!=(const LLTextureEntry &rhs) const
99{
100 if (mID != rhs.mID) return(true);
101 if (mScaleS != rhs.mScaleS) return(true);
102 if (mScaleT != rhs.mScaleT) return(true);
103 if (mOffsetS != rhs.mOffsetS) return(true);
104 if (mOffsetT != rhs.mOffsetT) return(true);
105 if (mRotation != rhs.mRotation) return(true);
106 if (mColor != rhs.mColor) return (true);
107 if (mBump != rhs.mBump) return (true);
108 if (mMediaFlags != rhs.mMediaFlags) return true;
109 return(false);
110}
111
112bool LLTextureEntry::operator==(const LLTextureEntry &rhs) const
113{
114 if (mID != rhs.mID) return(false);
115 if (mScaleS != rhs.mScaleS) return(false);
116 if (mScaleT != rhs.mScaleT) return(false);
117 if (mOffsetS != rhs.mOffsetS) return(false);
118 if (mOffsetT != rhs.mOffsetT) return(false);
119 if (mRotation != rhs.mRotation) return(false);
120 if (mColor != rhs.mColor) return (false);
121 if (mBump != rhs.mBump) return (false);
122 if (mMediaFlags != rhs.mMediaFlags) return false;
123 return(true);
124}
125
126LLSD LLTextureEntry::asLLSD() const
127{
128 LLSD sd;
129
130 sd["imageid"] = getID();
131 sd["colors"] = ll_sd_from_color4(getColor());
132 sd["scales"] = mScaleS;
133 sd["scalet"] = mScaleT;
134 sd["offsets"] = mOffsetS;
135 sd["offsett"] = mOffsetT;
136 sd["imagerot"] = getRotation();
137 sd["bump"] = getBumpShiny();
138 sd["fullbright"] = getFullbright();
139 sd["media_flags"] = getMediaTexGen();
140
141 return sd;
142}
143
144bool LLTextureEntry::fromLLSD(LLSD& sd)
145{
146 const char *w, *x;
147 w = "imageid";
148 if (sd.has(w))
149 {
150 setID( sd[w] );
151 } else goto fail;
152 w = "colors";
153 if (sd.has(w))
154 {
155 setColor( ll_color4_from_sd(sd["colors"]) );
156 } else goto fail;
157 w = "scales";
158 x = "scalet";
159 if (sd.has(w) && sd.has(x))
160 {
161 setScale( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
162 } else goto fail;
163 w = "offsets";
164 x = "offsett";
165 if (sd.has(w) && sd.has(x))
166 {
167 setOffset( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
168 } else goto fail;
169 w = "imagerot";
170 if (sd.has(w))
171 {
172 setRotation( (F32)sd[w].asReal() );
173 } else goto fail;
174 w = "bump";
175 if (sd.has(w))
176 {
177 setBumpShiny( sd[w].asInteger() );
178 } else goto fail;
179 w = "fullbright";
180 if (sd.has(w))
181 {
182 setFullbright( sd[w].asInteger() );
183 } else goto fail;
184 w = "media_flags";
185 if (sd.has(w))
186 {
187 setMediaTexGen( sd[w].asInteger() );
188 } else goto fail;
189
190 return true;
191fail:
192 return false;
193}
194
195S32 LLTextureEntry::setID(const LLUUID &tex_id)
196{
197 if (mID != tex_id)
198 {
199 mID = tex_id;
200 return TEM_CHANGE_TEXTURE;
201 }
202 return 0;
203}
204
205S32 LLTextureEntry::setScale(F32 s, F32 t)
206{
207 S32 retval = 0;
208
209 if ( (mScaleS != s)
210 ||(mScaleT != t))
211 {
212 mScaleS = s;
213 mScaleT = t;
214
215 retval = TEM_CHANGE_TEXTURE;
216 }
217 return retval;
218}
219
220S32 LLTextureEntry::setColor(const LLColor4 &color)
221{
222 if (mColor != color)
223 {
224 mColor = color;
225 return TEM_CHANGE_COLOR;
226 }
227 return 0;
228}
229
230S32 LLTextureEntry::setColor(const LLColor3 &color)
231{
232 if (mColor != color)
233 {
234 // This preserves alpha.
235 mColor.setVec(color);
236 return TEM_CHANGE_COLOR;
237 }
238 return 0;
239}
240
241S32 LLTextureEntry::setAlpha(const F32 alpha)
242{
243 if (mColor.mV[VW] != alpha)
244 {
245 mColor.mV[VW] = alpha;
246 return TEM_CHANGE_COLOR;
247 }
248 return 0;
249}
250
251S32 LLTextureEntry::setOffset(F32 s, F32 t)
252{
253 S32 retval = 0;
254
255 if ( (mOffsetS != s)
256 ||(mOffsetT != t))
257 {
258 mOffsetS = s;
259 mOffsetT = t;
260
261 retval = TEM_CHANGE_TEXTURE;
262 }
263 return retval;
264}
265
266S32 LLTextureEntry::setRotation(F32 theta)
267{
268 if (mRotation != theta)
269 {
270 mRotation = theta;
271 return TEM_CHANGE_TEXTURE;
272 }
273 return 0;
274}
275
276S32 LLTextureEntry::setBumpShinyFullbright(U8 bump)
277{
278 if (mBump != bump)
279 {
280 mBump = bump;
281 return TEM_CHANGE_TEXTURE;
282 }
283 return 0;
284}
285
286S32 LLTextureEntry::setMediaTexGen(U8 media)
287{
288 if (mMediaFlags != media)
289 {
290 mMediaFlags = media;
291 return TEM_CHANGE_TEXTURE;
292 }
293 return 0;
294}
295
296S32 LLTextureEntry::setBumpmap(U8 bump)
297{
298 bump &= TEM_BUMP_MASK;
299 if (getBumpmap() != bump)
300 {
301 mBump &= ~TEM_BUMP_MASK;
302 mBump |= bump;
303 return TEM_CHANGE_TEXTURE;
304 }
305 return 0;
306}
307
308S32 LLTextureEntry::setFullbright(U8 fullbright)
309{
310 fullbright &= TEM_FULLBRIGHT_MASK;
311 if (getFullbright() != fullbright)
312 {
313 mBump &= ~(TEM_FULLBRIGHT_MASK<<TEM_FULLBRIGHT_SHIFT);
314 mBump |= fullbright << TEM_FULLBRIGHT_SHIFT;
315 return TEM_CHANGE_TEXTURE;
316 }
317 return 0;
318}
319
320S32 LLTextureEntry::setShiny(U8 shiny)
321{
322 shiny &= TEM_SHINY_MASK;
323 if (getShiny() != shiny)
324 {
325 mBump &= ~(TEM_SHINY_MASK<<TEM_SHINY_SHIFT);
326 mBump |= shiny << TEM_SHINY_SHIFT;
327 return TEM_CHANGE_TEXTURE;
328 }
329 return 0;
330}
331
332S32 LLTextureEntry::setBumpShiny(U8 bump_shiny)
333{
334 bump_shiny &= TEM_BUMP_SHINY_MASK;
335 if (getBumpShiny() != bump_shiny)
336 {
337 mBump &= ~TEM_BUMP_SHINY_MASK;
338 mBump |= bump_shiny;
339 return TEM_CHANGE_TEXTURE;
340 }
341 return 0;
342}
343
344S32 LLTextureEntry::setMediaFlags(U8 media_flags)
345{
346 media_flags &= TEM_MEDIA_MASK;
347 if (getMediaFlags() != media_flags)
348 {
349 mMediaFlags &= ~TEM_MEDIA_MASK;
350 mMediaFlags |= media_flags;
351 return TEM_CHANGE_TEXTURE;
352 }
353 return 0;
354}
355
356S32 LLTextureEntry::setTexGen(U8 tex_gen)
357{
358 tex_gen &= TEM_TEX_GEN_MASK;
359 if (getTexGen() != tex_gen)
360 {
361 mMediaFlags &= ~TEM_TEX_GEN_MASK;
362 mMediaFlags |= tex_gen;
363 return TEM_CHANGE_TEXTURE;
364 }
365 return 0;
366}
367