PageRenderTime 99ms CodeModel.GetById 66ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llface.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 370 lines | 273 code | 62 blank | 35 comment | 9 complexity | 58d7f1b203887a31c7a47e32748744bd MD5 | raw file
  1/** 
  2 * @file llface.h
  3 * @brief LLFace class definition
  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_LLFACE_H
 28#define LL_LLFACE_H
 29
 30#include "llstrider.h"
 31
 32#include "llrender.h"
 33#include "v2math.h"
 34#include "v3math.h"
 35#include "v4math.h"
 36#include "m4math.h"
 37#include "v4coloru.h"
 38#include "llquaternion.h"
 39#include "xform.h"
 40#include "lldarrayptr.h"
 41#include "llvertexbuffer.h"
 42#include "llviewertexture.h"
 43#include "lldrawable.h"
 44#include "lltextureatlasmanager.h"
 45
 46class LLFacePool;
 47class LLVolume;
 48class LLViewerTexture;
 49class LLTextureEntry;
 50class LLVertexProgram;
 51class LLViewerTexture;
 52class LLGeometryManager;
 53class LLTextureAtlasSlot;
 54
 55const F32 MIN_ALPHA_SIZE = 1024.f;
 56const F32 MIN_TEX_ANIM_SIZE = 512.f;
 57
 58class LLFace
 59{
 60public:
 61
 62	LLFace(const LLFace& rhs)
 63	{
 64		*this = rhs;
 65	}
 66
 67	const LLFace& operator=(const LLFace& rhs)
 68	{
 69		llerrs << "Illegal operation!" << llendl;
 70		return *this;
 71	}
 72
 73	enum EMasks
 74	{
 75		LIGHT			= 0x0001,
 76		GLOBAL			= 0x0002,
 77		FULLBRIGHT		= 0x0004,
 78		HUD_RENDER		= 0x0008,
 79		USE_FACE_COLOR	= 0x0010,
 80		TEXTURE_ANIM	= 0x0020, 
 81		RIGGED			= 0x0040,
 82	};
 83
 84	static void initClass();
 85
 86public:
 87	LLFace(LLDrawable* drawablep, LLViewerObject* objp)   { init(drawablep, objp); }
 88	~LLFace()  { destroy(); }
 89
 90	const LLMatrix4& getWorldMatrix()	const	{ return mVObjp->getWorldMatrix(mXform); }
 91	const LLMatrix4& getRenderMatrix() const;
 92	U32				getIndicesCount()	const	{ return mIndicesCount; };
 93	S32				getIndicesStart()	const	{ return mIndicesIndex; };
 94	U16				getGeomCount()		const	{ return mGeomCount; }		// vertex count for this face
 95	U16				getGeomIndex()		const	{ return mGeomIndex; }		// index into draw pool
 96	U16				getGeomStart()		const	{ return mGeomIndex; }		// index into draw pool
 97	void			setTextureIndex(U8 index);
 98	U8				getTextureIndex() const		{ return mTextureIndex; }
 99	void			setTexture(LLViewerTexture* tex) ;
100	void            switchTexture(LLViewerTexture* new_texture);
101	void            dirtyTexture();
102	LLXformMatrix*	getXform()			const	{ return mXform; }
103	BOOL			hasGeometry()		const	{ return mGeomCount > 0; }
104	LLVector3		getPositionAgent()	const;
105	LLVector2       surfaceToTexture(LLVector2 surface_coord, LLVector3 position, LLVector3 normal);
106	void 			getPlanarProjectedParams(LLQuaternion* face_rot, LLVector3* face_pos, F32* scale) const;
107	bool			calcAlignedPlanarTE(const LLFace* align_to, LLVector2* st_offset,
108										LLVector2* st_scale, F32* st_rot) const;
109	
110	U32				getState()			const	{ return mState; }
111	void			setState(U32 state)			{ mState |= state; }
112	void			clearState(U32 state)		{ mState &= ~state; }
113	BOOL			isState(U32 state)	const	{ return ((mState & state) != 0) ? TRUE : FALSE; }
114	void			setVirtualSize(F32 size) { mVSize = size; }
115	void			setPixelArea(F32 area)	{ mPixelArea = area; }
116	F32				getVirtualSize() const { return mVSize; }
117	F32				getPixelArea() const { return mPixelArea; }
118
119	S32             getIndexInTex() const {return mIndexInTex ;}
120	void            setIndexInTex(S32 index) { mIndexInTex = index ;}
121
122	void			renderSetColor() const;
123	S32				renderElements(const U16 *index_array) const;
124	S32				renderIndexed ();
125	S32				renderIndexed (U32 mask);
126	S32				pushVertices(const U16* index_array) const;
127	
128	void			setWorldMatrix(const LLMatrix4& mat);
129	const LLTextureEntry* getTextureEntry()	const { return mVObjp->getTE(mTEOffset); }
130
131	LLFacePool*		getPool()			const	{ return mDrawPoolp; }
132	U32				getPoolType()		const	{ return mPoolType; }
133	LLDrawable*		getDrawable()		const	{ return mDrawablep; }
134	LLViewerObject*	getViewerObject()	const	{ return mVObjp; }
135	S32				getLOD()			const	{ return mVObjp.notNull() ? mVObjp->getLOD() : 0; }
136	void			setPoolType(U32 type)		{ mPoolType = type; }
137	S32				getTEOffset()				{ return mTEOffset; }
138	LLViewerTexture*	getTexture() const;
139
140	void			setViewerObject(LLViewerObject* object);
141	void			setPool(LLFacePool *pool, LLViewerTexture *texturep);
142	void			setPool(LLFacePool* pool);
143
144	void			setDrawable(LLDrawable *drawable);
145	void			setTEOffset(const S32 te_offset);
146	
147
148	void			setFaceColor(const LLColor4& color); // override material color
149	void			unsetFaceColor(); // switch back to material color
150	const LLColor4&	getFaceColor() const { return mFaceColor; } 
151	const LLColor4& getRenderColor() const;
152
153	//for volumes
154	void updateRebuildFlags();
155	bool canRenderAsMask(); // logic helper
156	BOOL getGeometryVolume(const LLVolume& volume,
157						const S32 &f,
158						const LLMatrix4& mat_vert, const LLMatrix3& mat_normal,
159						const U16 &index_offset,
160						bool force_rebuild = false);
161
162	// For avatar
163	U16			 getGeometryAvatar(
164									LLStrider<LLVector3> &vertices,
165									LLStrider<LLVector3> &normals,
166								    LLStrider<LLVector2> &texCoords,
167									LLStrider<F32>		 &vertex_weights,
168									LLStrider<LLVector4> &clothing_weights);
169
170	// For volumes, etc.
171	U16				getGeometry(LLStrider<LLVector3> &vertices,  
172								LLStrider<LLVector3> &normals,
173								LLStrider<LLVector2> &texCoords, 
174								LLStrider<U16>  &indices);
175
176	S32 getColors(LLStrider<LLColor4U> &colors);
177	S32 getIndices(LLStrider<U16> &indices);
178
179	void		setSize(S32 numVertices, S32 num_indices = 0, bool align = false);
180	
181	BOOL		genVolumeBBoxes(const LLVolume &volume, S32 f,
182								   const LLMatrix4& mat, const LLMatrix3& inv_trans_mat, BOOL global_volume = FALSE);
183	
184	void		init(LLDrawable* drawablep, LLViewerObject* objp);
185	void		destroy();
186	void		update();
187
188	void		updateCenterAgent(); // Update center when xform has changed.
189	void		renderSelectedUV();
190
191	void		renderSelected(LLViewerTexture *image, const LLColor4 &color);
192
193	F32			getKey()					const	{ return mDistance; }
194
195	S32			getReferenceIndex() 		const	{ return mReferenceIndex; }
196	void		setReferenceIndex(const S32 index)	{ mReferenceIndex = index; }
197
198	BOOL		verify(const U32* indices_array = NULL) const;
199	void		printDebugInfo() const;
200
201	void		setGeomIndex(U16 idx); 
202	void		setIndicesIndex(S32 idx);
203	void		setDrawInfo(LLDrawInfo* draw_info);
204
205	F32         getTextureVirtualSize() ;
206	F32         getImportanceToCamera()const {return mImportanceToCamera ;}
207
208	void        setHasMedia(bool has_media)  { mHasMedia = has_media ;}
209	BOOL        hasMedia() const ;
210
211	//for atlas
212	LLTextureAtlasSlot*   getAtlasInfo() ;
213	void                  setAtlasInUse(BOOL flag);
214	void                  setAtlasInfo(LLTextureAtlasSlot* atlasp);
215	BOOL                  isAtlasInUse()const;
216	BOOL                  canUseAtlas() const;
217	const LLVector2*      getTexCoordScale() const ;
218	const LLVector2*      getTexCoordOffset()const;
219	const LLTextureAtlas* getAtlas()const ;
220	void                  removeAtlas() ;
221	BOOL                  switchTexture() ;
222
223	//vertex buffer tracking
224	void setVertexBuffer(LLVertexBuffer* buffer);
225	void clearVertexBuffer(); //sets mVertexBuffer and mLastVertexBuffer to NULL
226	LLVertexBuffer* getVertexBuffer()	const	{ return mVertexBuffer; }
227	U32 getRiggedVertexBufferDataMask() const;
228	S32 getRiggedIndex(U32 type) const;
229	void setRiggedIndex(U32 type, S32 index);
230
231	static U32 getRiggedDataMask(U32 type);
232
233public: //aligned members
234	LLVector4a		mExtents[2];
235
236private:	
237	F32         adjustPartialOverlapPixelArea(F32 cos_angle_to_view_dir, F32 radius );
238	BOOL        calcPixelArea(F32& cos_angle_to_view_dir, F32& radius) ;
239public:
240	static F32 calcImportanceToCamera(F32 to_view_dir, F32 dist);
241	static F32 adjustPixelArea(F32 importance, F32 pixel_area) ;
242
243public:
244	
245	LLVector3		mCenterLocal;
246	LLVector3		mCenterAgent;
247	
248	LLVector2		mTexExtents[2];
249	F32				mDistance;
250	F32			mLastUpdateTime;
251	F32			mLastSkinTime;
252	F32			mLastMoveTime;
253	LLMatrix4*	mTextureMatrix;
254	LLDrawInfo* mDrawInfo;
255
256private:
257	LLPointer<LLVertexBuffer> mVertexBuffer;
258	LLPointer<LLVertexBuffer> mLastVertexBuffer;
259	
260	U32			mState;
261	LLFacePool*	mDrawPoolp;
262	U32			mPoolType;
263	LLColor4	mFaceColor;			// overrides material color if state |= USE_FACE_COLOR
264	
265	U16			mGeomCount;			// vertex count for this face
266	U16			mGeomIndex;			// index into draw pool
267	U8			mTextureIndex;		// index of texture channel to use for pseudo-atlasing
268	U32			mIndicesCount;
269	U32			mIndicesIndex;		// index into draw pool for indices (yeah, I know!)
270	S32         mIndexInTex ;
271
272	//previous rebuild's geometry info
273	U16			mLastGeomCount;
274	U16			mLastGeomIndex;
275	U32			mLastIndicesCount;
276	U32			mLastIndicesIndex;
277
278	LLXformMatrix* mXform;
279	LLPointer<LLViewerTexture> mTexture;
280	LLPointer<LLDrawable> mDrawablep;
281	LLPointer<LLViewerObject> mVObjp;
282	S32			mTEOffset;
283
284	S32			mReferenceIndex;
285	std::vector<S32> mRiggedIndex;
286	
287	F32			mVSize;
288	F32			mPixelArea;
289
290	//importance factor, in the range [0, 1.0].
291	//1.0: the most important.
292	//based on the distance from the face to the view point and the angle from the face center to the view direction.
293	F32         mImportanceToCamera ; 
294	F32         mBoundingSphereRadius ;
295	bool        mHasMedia ;
296
297	//atlas
298	LLPointer<LLTextureAtlasSlot> mAtlasInfop ;
299	BOOL                          mUsingAtlas ;
300	
301protected:
302	static BOOL	sSafeRenderSelect;
303	
304public:
305	struct CompareDistanceGreater
306	{
307		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
308		{
309			return !lhs || (rhs && (lhs->mDistance > rhs->mDistance)); // farthest = first
310		}
311	};
312	
313	struct CompareTexture
314	{
315		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
316		{
317			return lhs->getTexture() < rhs->getTexture();
318		}
319	};
320
321	struct CompareBatchBreaker
322	{
323		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
324		{
325			const LLTextureEntry* lte = lhs->getTextureEntry();
326			const LLTextureEntry* rte = rhs->getTextureEntry();
327
328			if(lhs->getTexture() != rhs->getTexture())
329			{
330				return lhs->getTexture() < rhs->getTexture();
331			}
332			else 
333			{
334				return lte->getBumpShinyFullbright() < rte->getBumpShinyFullbright();
335			}
336		}
337	};
338
339	struct CompareTextureAndGeomCount
340	{
341		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
342		{
343			return lhs->getTexture() == rhs->getTexture() ? 
344				lhs->getGeomCount() < rhs->getGeomCount() :  //smallest = first
345				lhs->getTexture() > rhs->getTexture();
346		}
347	};
348
349	struct CompareTextureAndLOD
350	{
351		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
352		{
353			return lhs->getTexture() == rhs->getTexture() ? 
354				lhs->getLOD() < rhs->getLOD() :
355				lhs->getTexture() < rhs->getTexture();
356		}
357	};
358
359	struct CompareTextureAndTime
360	{
361		bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
362		{
363			return lhs->getTexture() == rhs->getTexture() ? 
364				lhs->mLastUpdateTime < rhs->mLastUpdateTime :
365				lhs->getTexture() < rhs->getTexture();
366		}
367	};
368};
369
370#endif // LL_LLFACE_H