PageRenderTime 302ms CodeModel.GetById 141ms app.highlight 15ms RepoModel.GetById 125ms app.codeStats 1ms

/indra/llprimitive/lltextureentry.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 206 lines | 113 code | 34 blank | 59 comment | 0 complexity | ac42f3f5bfa509e65ec7f0aa0c0c616f MD5 | raw file
  1/** 
  2 * @file lltextureentry.h
  3 * @brief LLTextureEntry base class
  4 *
  5 * $LicenseInfo:firstyear=2001&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#ifndef LL_LLTEXTUREENTRY_H
 28#define LL_LLTEXTUREENTRY_H
 29
 30#include "lluuid.h"
 31#include "v4color.h"
 32#include "llsd.h"
 33
 34// These bits are used while unpacking TEM messages to tell which aspects of
 35// the texture entry changed.
 36const S32 TEM_CHANGE_NONE = 0x0;
 37const S32 TEM_CHANGE_COLOR = 0x1;
 38const S32 TEM_CHANGE_TEXTURE = 0x2;
 39const S32 TEM_CHANGE_MEDIA = 0x4;
 40const S32 TEM_INVALID = 0x8;
 41
 42const S32 TEM_BUMPMAP_COUNT = 32;
 43
 44// The Bump Shiny Fullbright values are bits in an eight bit field:
 45// +----------+
 46// | SSFBBBBB | S = Shiny, F = Fullbright, B = Bumpmap
 47// | 76543210 |
 48// +----------+
 49const S32 TEM_BUMP_MASK 		= 0x1f; // 5 bits
 50const S32 TEM_FULLBRIGHT_MASK 	= 0x01; // 1 bit
 51const S32 TEM_SHINY_MASK 		= 0x03; // 2 bits
 52const S32 TEM_BUMP_SHINY_MASK 	= (0xc0 | 0x1f);
 53const S32 TEM_FULLBRIGHT_SHIFT 	= 5;
 54const S32 TEM_SHINY_SHIFT 		= 6;
 55
 56// The Media Tex Gen values are bits in a bit field:
 57// +----------+
 58// | .....TTM | M = Media Flags (web page), T = LLTextureEntry::eTexGen, . = unused
 59// | 76543210 |
 60// +----------+
 61const S32 TEM_MEDIA_MASK		= 0x01;
 62const S32 TEM_TEX_GEN_MASK		= 0x06;
 63const S32 TEM_TEX_GEN_SHIFT		= 1;
 64
 65// forward declarations
 66class LLMediaEntry;
 67
 68class LLTextureEntry
 69{
 70public:	
 71	static LLTextureEntry* newTextureEntry();
 72
 73	typedef enum e_texgen
 74	{
 75		TEX_GEN_DEFAULT			= 0x00,
 76		TEX_GEN_PLANAR			= 0x02,
 77		TEX_GEN_SPHERICAL		= 0x04,
 78		TEX_GEN_CYLINDRICAL		= 0x06
 79	} eTexGen;
 80
 81	LLTextureEntry();
 82	LLTextureEntry(const LLUUID& tex_id);
 83	LLTextureEntry(const LLTextureEntry &rhs);
 84
 85	LLTextureEntry &operator=(const LLTextureEntry &rhs);
 86    virtual ~LLTextureEntry();
 87
 88	bool operator==(const LLTextureEntry &rhs) const;
 89	bool operator!=(const LLTextureEntry &rhs) const;
 90
 91	LLSD asLLSD() const;
 92	void asLLSD(LLSD& sd) const;
 93	operator LLSD() const { return asLLSD(); }
 94	bool fromLLSD(const LLSD& sd);
 95
 96	virtual LLTextureEntry* newBlank() const;
 97	virtual LLTextureEntry* newCopy() const;
 98
 99	void init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump);
100
101	// These return a TEM_ flag from above to indicate if something changed.
102	S32  setID (const LLUUID &tex_id);
103	S32  setColor(const LLColor4 &color);
104	S32  setColor(const LLColor3 &color);
105	S32  setAlpha(const F32 alpha);
106	S32  setScale(F32 s, F32 t);
107	S32  setScaleS(F32 s);
108	S32  setScaleT(F32 t);
109	S32  setOffset(F32 s, F32 t);
110	S32  setOffsetS(F32 s);
111	S32  setOffsetT(F32 t);
112	S32  setRotation(F32 theta);
113
114	S32  setBumpmap(U8 bump);
115	S32  setFullbright(U8 bump);
116	S32  setShiny(U8 bump);
117	S32  setBumpShiny(U8 bump);
118 	S32  setBumpShinyFullbright(U8 bump);
119
120	S32  setMediaFlags(U8 media_flags);
121	S32	 setTexGen(U8 texGen);
122	S32  setMediaTexGen(U8 media);
123    S32  setGlow(F32 glow);
124	
125	virtual const LLUUID &getID() const { return mID; }
126	const LLColor4 &getColor() const { return mColor; }
127	void getScale(F32 *s, F32 *t) const { *s = mScaleS; *t = mScaleT; }
128	void getOffset(F32 *s, F32 *t) const { *s = mOffsetS; *t = mOffsetT; }
129	F32  getRotation() const { return mRotation; }
130	void getRotation(F32 *theta) const { *theta = mRotation; }
131
132	U8	 getBumpmap() const { return mBump & TEM_BUMP_MASK; }
133	U8	 getFullbright() const { return (mBump>>TEM_FULLBRIGHT_SHIFT) & TEM_FULLBRIGHT_MASK; }
134	U8	 getShiny() const { return (mBump>>TEM_SHINY_SHIFT) & TEM_SHINY_MASK; }
135	U8	 getBumpShiny() const { return mBump & TEM_BUMP_SHINY_MASK; }
136 	U8	 getBumpShinyFullbright() const { return mBump; }
137
138	U8	 getMediaFlags() const { return mMediaFlags & TEM_MEDIA_MASK; }
139	U8	 getTexGen() const	{ return mMediaFlags & TEM_TEX_GEN_MASK; }
140	U8	 getMediaTexGen() const { return mMediaFlags; }
141    F32  getGlow() const { return mGlow; }
142
143    // *NOTE: it is possible for hasMedia() to return true, but getMediaData() to return NULL.
144    // CONVERSELY, it is also possible for hasMedia() to return false, but getMediaData()
145    // to NOT return NULL.  
146	bool hasMedia() const { return (bool)(mMediaFlags & MF_HAS_MEDIA); } 
147	LLMediaEntry* getMediaData() const { return mMediaEntry; }
148
149    // Completely change the media data on this texture entry.
150    void setMediaData(const LLMediaEntry &media_entry);
151	// Returns true if media data was updated, false if it was cleared
152	bool updateMediaData(const LLSD& media_data);
153    // Clears media data, and sets the media flags bit to 0
154    void clearMediaData();
155    // Merges the given LLSD of media fields with this media entry.
156    // Only those fields that are set that match the keys in
157    // LLMediaEntry will be affected.  If no fields are set or if
158    // the LLSD is undefined, this is a no-op.
159    void mergeIntoMediaData(const LLSD& media_fields);
160
161    // Takes a media version string (an empty string or a previously-returned string)
162    // and returns a "touched" string, touched by agent_id
163    static std::string touchMediaVersionString(const std::string &in_version, const LLUUID &agent_id);
164    // Given a media version string, return the version
165    static U32 getVersionFromMediaVersionString(const std::string &version_string);
166    // Given a media version string, return the UUID of the agent
167    static LLUUID getAgentIDFromMediaVersionString(const std::string &version_string);
168	// Return whether or not the given string is actually a media version
169	static bool isMediaVersionString(const std::string &version_string);
170	
171	// Media flags
172	enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 };
173
174public:
175	F32                 mScaleS;                // S, T offset
176	F32                 mScaleT;                // S, T offset
177	F32                 mOffsetS;               // S, T offset
178	F32                 mOffsetT;               // S, T offset
179	F32                 mRotation;              // anti-clockwise rotation in rad about the bottom left corner
180
181	static const LLTextureEntry null;
182
183	// LLSD key defines
184	static const char* OBJECT_ID_KEY;
185	static const char* OBJECT_MEDIA_DATA_KEY;
186    static const char* MEDIA_VERSION_KEY;
187	static const char* TEXTURE_INDEX_KEY;
188	static const char* TEXTURE_MEDIA_DATA_KEY;
189
190protected:
191	LLUUID				mID;					// Texture GUID
192	LLColor4			mColor;
193	U8					mBump;					// Bump map, shiny, and fullbright
194	U8					mMediaFlags;			// replace with web page, movie, etc.
195	F32                 mGlow;
196
197	// Note the media data is not sent via the same message structure as the rest of the TE
198	LLMediaEntry*		mMediaEntry;			// The media data for the face
199
200	// NOTE: when adding new data to this class, in addition to adding it to the serializers asLLSD/fromLLSD and the
201	// message packers (e.g. LLPrimitive::packTEMessage) you must also implement its copy in LLPrimitive::copyTEs()
202
203	
204};
205
206#endif