00001
00032 #include "linden_common.h"
00033
00034 #include "lltextureentry.h"
00035 #include "llsdutil.h"
00036
00037 const U8 DEFAULT_BUMP_CODE = 0;
00038
00039 const LLTextureEntry LLTextureEntry::null;
00040
00041
00042 LLTextureEntry::LLTextureEntry()
00043 {
00044 init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
00045 }
00046
00047 LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
00048 {
00049 init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
00050 }
00051
00052 LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
00053 {
00054 mID = rhs.mID;
00055 mScaleS = rhs.mScaleS;
00056 mScaleT = rhs.mScaleT;
00057 mOffsetS = rhs.mOffsetS;
00058 mOffsetT = rhs.mOffsetT;
00059 mRotation = rhs.mRotation;
00060 mColor = rhs.mColor;
00061 mBump = rhs.mBump;
00062 mMediaFlags = rhs.mMediaFlags;
00063 mGlow = rhs.mGlow;
00064 }
00065
00066 LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
00067 {
00068 if (this != &rhs)
00069 {
00070 mID = rhs.mID;
00071 mScaleS = rhs.mScaleS;
00072 mScaleT = rhs.mScaleT;
00073 mOffsetS = rhs.mOffsetS;
00074 mOffsetT = rhs.mOffsetT;
00075 mRotation = rhs.mRotation;
00076 mColor = rhs.mColor;
00077 mBump = rhs.mBump;
00078 mMediaFlags = rhs.mMediaFlags;
00079 mGlow = rhs.mGlow;
00080 }
00081
00082 return *this;
00083 }
00084
00085 void LLTextureEntry::init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump)
00086 {
00087 setID(tex_id);
00088
00089 mScaleS = scale_s;
00090 mScaleT = scale_t;
00091 mOffsetS = offset_s;
00092 mOffsetT = offset_t;
00093 mRotation = rotation;
00094 mBump = bump;
00095 mMediaFlags = 0x0;
00096 mGlow = 0;
00097
00098 setColor(LLColor4(1.f, 1.f, 1.f, 1.f));
00099 }
00100
00101 LLTextureEntry::~LLTextureEntry()
00102 {
00103 }
00104
00105 bool LLTextureEntry::operator!=(const LLTextureEntry &rhs) const
00106 {
00107 if (mID != rhs.mID) return(true);
00108 if (mScaleS != rhs.mScaleS) return(true);
00109 if (mScaleT != rhs.mScaleT) return(true);
00110 if (mOffsetS != rhs.mOffsetS) return(true);
00111 if (mOffsetT != rhs.mOffsetT) return(true);
00112 if (mRotation != rhs.mRotation) return(true);
00113 if (mColor != rhs.mColor) return (true);
00114 if (mBump != rhs.mBump) return (true);
00115 if (mMediaFlags != rhs.mMediaFlags) return (true);
00116 if (mGlow != rhs.mGlow) return (true);
00117 return(false);
00118 }
00119
00120 bool LLTextureEntry::operator==(const LLTextureEntry &rhs) const
00121 {
00122 if (mID != rhs.mID) return(false);
00123 if (mScaleS != rhs.mScaleS) return(false);
00124 if (mScaleT != rhs.mScaleT) return(false);
00125 if (mOffsetS != rhs.mOffsetS) return(false);
00126 if (mOffsetT != rhs.mOffsetT) return(false);
00127 if (mRotation != rhs.mRotation) return(false);
00128 if (mColor != rhs.mColor) return (false);
00129 if (mBump != rhs.mBump) return (false);
00130 if (mMediaFlags != rhs.mMediaFlags) return false;
00131 if (mGlow != rhs.mGlow) return false;
00132 return(true);
00133 }
00134
00135 LLSD LLTextureEntry::asLLSD() const
00136 {
00137 LLSD sd;
00138
00139 sd["imageid"] = getID();
00140 sd["colors"] = ll_sd_from_color4(getColor());
00141 sd["scales"] = mScaleS;
00142 sd["scalet"] = mScaleT;
00143 sd["offsets"] = mOffsetS;
00144 sd["offsett"] = mOffsetT;
00145 sd["imagerot"] = getRotation();
00146 sd["bump"] = getBumpShiny();
00147 sd["fullbright"] = getFullbright();
00148 sd["media_flags"] = getMediaTexGen();
00149 sd["glow"] = getGlow();
00150
00151 return sd;
00152 }
00153
00154 bool LLTextureEntry::fromLLSD(LLSD& sd)
00155 {
00156 const char *w, *x;
00157 w = "imageid";
00158 if (sd.has(w))
00159 {
00160 setID( sd[w] );
00161 } else goto fail;
00162 w = "colors";
00163 if (sd.has(w))
00164 {
00165 setColor( ll_color4_from_sd(sd["colors"]) );
00166 } else goto fail;
00167 w = "scales";
00168 x = "scalet";
00169 if (sd.has(w) && sd.has(x))
00170 {
00171 setScale( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
00172 } else goto fail;
00173 w = "offsets";
00174 x = "offsett";
00175 if (sd.has(w) && sd.has(x))
00176 {
00177 setOffset( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
00178 } else goto fail;
00179 w = "imagerot";
00180 if (sd.has(w))
00181 {
00182 setRotation( (F32)sd[w].asReal() );
00183 } else goto fail;
00184 w = "bump";
00185 if (sd.has(w))
00186 {
00187 setBumpShiny( sd[w].asInteger() );
00188 } else goto fail;
00189 w = "fullbright";
00190 if (sd.has(w))
00191 {
00192 setFullbright( sd[w].asInteger() );
00193 } else goto fail;
00194 w = "media_flags";
00195 if (sd.has(w))
00196 {
00197 setMediaTexGen( sd[w].asInteger() );
00198 } else goto fail;
00199 w = "glow";
00200 if (sd.has(w))
00201 {
00202 setGlow((F32)sd[w].asReal() );
00203 }
00204
00205 return true;
00206 fail:
00207 return false;
00208 }
00209
00210 S32 LLTextureEntry::setID(const LLUUID &tex_id)
00211 {
00212 if (mID != tex_id)
00213 {
00214 mID = tex_id;
00215 return TEM_CHANGE_TEXTURE;
00216 }
00217 return 0;
00218 }
00219
00220 S32 LLTextureEntry::setScale(F32 s, F32 t)
00221 {
00222 S32 retval = 0;
00223
00224 if ( (mScaleS != s)
00225 ||(mScaleT != t))
00226 {
00227 mScaleS = s;
00228 mScaleT = t;
00229
00230 retval = TEM_CHANGE_TEXTURE;
00231 }
00232 return retval;
00233 }
00234
00235 S32 LLTextureEntry::setColor(const LLColor4 &color)
00236 {
00237 if (mColor != color)
00238 {
00239 mColor = color;
00240 return TEM_CHANGE_COLOR;
00241 }
00242 return 0;
00243 }
00244
00245 S32 LLTextureEntry::setColor(const LLColor3 &color)
00246 {
00247 if (mColor != color)
00248 {
00249
00250 mColor.setVec(color);
00251 return TEM_CHANGE_COLOR;
00252 }
00253 return 0;
00254 }
00255
00256 S32 LLTextureEntry::setAlpha(const F32 alpha)
00257 {
00258 if (mColor.mV[VW] != alpha)
00259 {
00260 mColor.mV[VW] = alpha;
00261 return TEM_CHANGE_COLOR;
00262 }
00263 return 0;
00264 }
00265
00266 S32 LLTextureEntry::setOffset(F32 s, F32 t)
00267 {
00268 S32 retval = 0;
00269
00270 if ( (mOffsetS != s)
00271 ||(mOffsetT != t))
00272 {
00273 mOffsetS = s;
00274 mOffsetT = t;
00275
00276 retval = TEM_CHANGE_TEXTURE;
00277 }
00278 return retval;
00279 }
00280
00281 S32 LLTextureEntry::setRotation(F32 theta)
00282 {
00283 if (mRotation != theta)
00284 {
00285 mRotation = theta;
00286 return TEM_CHANGE_TEXTURE;
00287 }
00288 return 0;
00289 }
00290
00291 S32 LLTextureEntry::setBumpShinyFullbright(U8 bump)
00292 {
00293 if (mBump != bump)
00294 {
00295 mBump = bump;
00296 return TEM_CHANGE_TEXTURE;
00297 }
00298 return 0;
00299 }
00300
00301 S32 LLTextureEntry::setMediaTexGen(U8 media)
00302 {
00303 if (mMediaFlags != media)
00304 {
00305 mMediaFlags = media;
00306 return TEM_CHANGE_TEXTURE;
00307 }
00308 return 0;
00309 }
00310
00311 S32 LLTextureEntry::setBumpmap(U8 bump)
00312 {
00313 bump &= TEM_BUMP_MASK;
00314 if (getBumpmap() != bump)
00315 {
00316 mBump &= ~TEM_BUMP_MASK;
00317 mBump |= bump;
00318 return TEM_CHANGE_TEXTURE;
00319 }
00320 return 0;
00321 }
00322
00323 S32 LLTextureEntry::setFullbright(U8 fullbright)
00324 {
00325 fullbright &= TEM_FULLBRIGHT_MASK;
00326 if (getFullbright() != fullbright)
00327 {
00328 mBump &= ~(TEM_FULLBRIGHT_MASK<<TEM_FULLBRIGHT_SHIFT);
00329 mBump |= fullbright << TEM_FULLBRIGHT_SHIFT;
00330 return TEM_CHANGE_TEXTURE;
00331 }
00332 return 0;
00333 }
00334
00335 S32 LLTextureEntry::setShiny(U8 shiny)
00336 {
00337 shiny &= TEM_SHINY_MASK;
00338 if (getShiny() != shiny)
00339 {
00340 mBump &= ~(TEM_SHINY_MASK<<TEM_SHINY_SHIFT);
00341 mBump |= shiny << TEM_SHINY_SHIFT;
00342 return TEM_CHANGE_TEXTURE;
00343 }
00344 return 0;
00345 }
00346
00347 S32 LLTextureEntry::setBumpShiny(U8 bump_shiny)
00348 {
00349 bump_shiny &= TEM_BUMP_SHINY_MASK;
00350 if (getBumpShiny() != bump_shiny)
00351 {
00352 mBump &= ~TEM_BUMP_SHINY_MASK;
00353 mBump |= bump_shiny;
00354 return TEM_CHANGE_TEXTURE;
00355 }
00356 return 0;
00357 }
00358
00359 S32 LLTextureEntry::setMediaFlags(U8 media_flags)
00360 {
00361 media_flags &= TEM_MEDIA_MASK;
00362 if (getMediaFlags() != media_flags)
00363 {
00364 mMediaFlags &= ~TEM_MEDIA_MASK;
00365 mMediaFlags |= media_flags;
00366 return TEM_CHANGE_TEXTURE;
00367 }
00368 return 0;
00369 }
00370
00371 S32 LLTextureEntry::setTexGen(U8 tex_gen)
00372 {
00373 tex_gen &= TEM_TEX_GEN_MASK;
00374 if (getTexGen() != tex_gen)
00375 {
00376 mMediaFlags &= ~TEM_TEX_GEN_MASK;
00377 mMediaFlags |= tex_gen;
00378 return TEM_CHANGE_TEXTURE;
00379 }
00380 return 0;
00381 }
00382
00383 S32 LLTextureEntry::setGlow(F32 glow)
00384 {
00385 if (mGlow != glow)
00386 {
00387 mGlow = glow;
00388 return TEM_CHANGE_TEXTURE;
00389 }
00390 return 0;
00391 }
00392