PageRenderTime 578ms CodeModel.GetById 29ms app.highlight 372ms RepoModel.GetById 103ms app.codeStats 7ms

/indra/newview/lldrawable.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 353 lines | 249 code | 68 blank | 36 comment | 12 complexity | 5bf0f7256456b49fbfbb65045da1db29 MD5 | raw file
  1/** 
  2 * @file lldrawable.h
  3 * @brief LLDrawable class definition
  4 *
  5 * $LicenseInfo:firstyear=2002&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_DRAWABLE_H
 28#define LL_DRAWABLE_H
 29
 30#include <vector>
 31#include <map>
 32
 33#include "v2math.h"
 34#include "v3math.h"
 35#include "v4math.h"
 36#include "m4math.h"
 37#include "v4coloru.h"
 38#include "llvector4a.h"
 39#include "llquaternion.h"
 40#include "xform.h"
 41#include "llmemtype.h"
 42#include "lldarray.h"
 43#include "llviewerobject.h"
 44#include "llrect.h"
 45#include "llappviewer.h" // for gFrameTimeSeconds
 46
 47class LLCamera;
 48class LLDrawPool;
 49class LLDrawable;
 50class LLFace;
 51class LLFacePool;
 52class LLSpatialGroup;
 53class LLSpatialBridge;
 54class LLSpatialPartition;
 55class LLVOVolume;
 56class LLViewerTexture;
 57
 58// Can have multiple silhouettes for each object
 59const U32 SILHOUETTE_HIGHLIGHT = 0;
 60
 61// All data for new renderer goes into this class.
 62class LLDrawable : public LLRefCount
 63{
 64public:
 65	LLDrawable(const LLDrawable& rhs)
 66	{
 67		*this = rhs;
 68	}
 69
 70	const LLDrawable& operator=(const LLDrawable& rhs)
 71	{
 72		llerrs << "Illegal operation!" << llendl;
 73		return *this;
 74	}
 75
 76	static void initClass();
 77
 78	LLDrawable()				{ init(); }
 79	MEM_TYPE_NEW(LLMemType::MTYPE_DRAWABLE);
 80	
 81	void markDead();			// Mark this drawable as dead
 82	BOOL isDead() const			{ return isState(DEAD); }
 83	BOOL isNew() const			{ return !isState(BUILT); }
 84
 85	BOOL isLight() const;
 86
 87	BOOL isVisible() const;	
 88	BOOL isRecentlyVisible() const;	
 89	virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
 90
 91
 92	LLViewerRegion* getRegion()               const { return mVObjp->getRegion(); }
 93	const LLTextureEntry* getTextureEntry(U8 which) const { return mVObjp->getTE(which); }
 94	LLPointer<LLViewerObject>& getVObj()							  { return mVObjp; }
 95	const LLViewerObject *getVObj()	const						  { return mVObjp; }
 96	LLVOVolume*	getVOVolume() const; // cast mVObjp tp LLVOVolume if OK
 97
 98	const LLMatrix4&      getWorldMatrix() const		{ return mXform.getWorldMatrix(); }
 99	const LLMatrix4&	  getRenderMatrix() const;
100	void				  setPosition(LLVector3 v) const { }
101	const LLVector3&	  getPosition() const			{ return mXform.getPosition(); }
102	const LLVector3&      getWorldPosition() const		{ return mXform.getPositionW(); }
103	const LLVector3		  getPositionAgent() const;
104	const LLVector4a&	  getPositionGroup() const		{ return mPositionGroup; }
105	const LLVector3&	  getScale() const				{ return mCurrentScale; }
106	void				  setScale(const LLVector3& scale) { mCurrentScale = scale; }
107	const LLQuaternion&   getWorldRotation() const		{ return mXform.getWorldRotation(); }
108	const LLQuaternion&   getRotation() const			{ return mXform.getRotation(); }
109	F32			          getIntensity() const			{ return llmin(mXform.getScale().mV[0], 4.f); }
110	S32					  getLOD() const				{ return mVObjp ? mVObjp->getLOD() : 1; }
111	F32					  getBinRadius() const			{ return mBinRadius; }
112	void  getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
113	LLXformMatrix*		getXform() { return &mXform; }
114
115	U32					getState()           const { return mState; }
116	BOOL				isState   (U32 bits) const { return ((mState & bits) != 0); }
117	void                setState  (U32 bits)       { mState |= bits; }
118	void                clearState(U32 bits)       { mState &= ~bits; }
119
120	BOOL				isAvatar()	const			{ return mVObjp.notNull() && mVObjp->isAvatar(); }
121	BOOL				isRoot() const				{ return !mParent || mParent->isAvatar(); }
122	BOOL				isSpatialRoot() const		{ return !mParent || mParent->isAvatar(); }
123	virtual BOOL		isSpatialBridge() const		{ return FALSE; }
124	virtual LLSpatialPartition* asPartition()		{ return NULL; }
125	LLDrawable*			getParent() const			{ return mParent; }
126	
127	// must set parent through LLViewerObject::		()
128	//BOOL                setParent(LLDrawable *parent);
129	
130	inline LLFace*      getFace(const S32 i) const;
131	inline S32			getNumFaces()      	 const;
132
133	//void                removeFace(const S32 i); // SJB: Avoid using this, it's slow
134	LLFace*				addFace(LLFacePool *poolp, LLViewerTexture *texturep);
135	LLFace*				addFace(const LLTextureEntry *te, LLViewerTexture *texturep);
136	void				deleteFaces(S32 offset, S32 count);
137	void                setNumFaces(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
138	void                setNumFacesFast(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
139	void				mergeFaces(LLDrawable* src);
140
141	void init();
142	void destroy();
143
144	void update();
145	F32 updateXform(BOOL undamped);
146
147	virtual void makeActive();
148	/*virtual*/ void makeStatic(BOOL warning_enabled = TRUE);
149
150	BOOL isActive()	const							{ return isState(ACTIVE); }
151	BOOL isStatic() const							{ return !isActive(); }
152	BOOL isAnimating() const;
153
154	virtual BOOL updateMove();
155	virtual void movePartition();
156	
157	void updateTexture();
158	void updateMaterial();
159	virtual void updateDistance(LLCamera& camera, bool force_update);
160	BOOL updateGeometry(BOOL priority);
161	void updateFaceSize(S32 idx);
162		
163	void updateSpecialHoverCursor(BOOL enabled);
164
165	virtual void shiftPos(const LLVector4a &shift_vector);
166
167	S32 getGeneration() const					{ return mGeneration; }
168
169	BOOL getLit() const							{ return isState(UNLIT) ? FALSE : TRUE; }
170	void setLit(BOOL lit)						{ lit ? clearState(UNLIT) : setState(UNLIT); }
171
172	virtual void cleanupReferences();
173
174	void setRadius(const F32 radius);
175	F32 getRadius() const						{ return mRadius; }
176	F32 getVisibilityRadius() const;
177
178	void updateUVMinMax();	// Updates the cache of sun space bounding box.
179
180	const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
181	virtual void updateSpatialExtents();
182	virtual void updateBinRadius();
183	const LLVector4a* getSpatialExtents() const;
184	void setSpatialExtents(const LLVector3& min, const LLVector3& max);
185	void setSpatialExtents(const LLVector4a& min, const LLVector4a& max);
186
187	void setPositionGroup(const LLVector4a& pos);
188	
189	void setRenderType(S32 type) 				{ mRenderType = type; }
190	BOOL isRenderType(S32 type) 				{ return mRenderType == type; }
191	S32  getRenderType()						{ return mRenderType; }
192	
193	// Debugging methods
194	S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
195
196	void setSpatialGroup(LLSpatialGroup *groupp);
197	LLSpatialGroup *getSpatialGroup() const			{ return mSpatialGroupp; }
198	LLSpatialPartition* getSpatialPartition();
199	
200	// Statics
201	static void incrementVisible();
202	static void cleanupDeadDrawables();
203
204protected:
205	~LLDrawable() { destroy(); }
206	void moveUpdatePipeline(BOOL moved);
207	void updatePartition();
208	BOOL updateMoveDamped();
209	BOOL updateMoveUndamped();
210	
211public:
212	friend class LLPipeline;
213	friend class LLDrawPool;
214	friend class LLSpatialBridge;
215	
216	typedef std::set<LLPointer<LLDrawable> > drawable_set_t;
217	typedef std::vector<LLPointer<LLDrawable> > drawable_vector_t;
218	typedef std::list<LLPointer<LLDrawable> > drawable_list_t;
219	typedef std::queue<LLPointer<LLDrawable> > drawable_queue_t;
220	
221	struct CompareDistanceGreater
222	{
223		bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
224		{
225			return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
226		}
227	};
228
229	struct CompareDistanceGreaterVisibleFirst
230	{
231		bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
232		{
233			if (lhs->isVisible() && !rhs->isVisible())
234			{
235				return TRUE; //visible things come first
236			}
237			else if (!lhs->isVisible() && rhs->isVisible())
238			{
239				return FALSE; //rhs is visible, comes first
240			}
241			
242			return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
243		}
244	};
245	
246	typedef enum e_drawable_flags
247	{
248 		IN_REBUILD_Q1	= 0x00000001,
249 		IN_REBUILD_Q2	= 0x00000002,
250 		IN_LIGHT_Q		= 0x00000004,
251		EARLY_MOVE		= 0x00000008,
252		MOVE_UNDAMPED	= 0x00000010,
253		ON_MOVE_LIST	= 0x00000020,
254		USE_BACKLIGHT	= 0x00000040,
255		UV				= 0x00000080,
256		UNLIT			= 0x00000100,
257		LIGHT			= 0x00000200,
258		LIGHTING_BUILT	= 0x00000400,
259		REBUILD_VOLUME  = 0x00000800,	//volume changed LOD or parameters, or vertex buffer changed
260		REBUILD_TCOORD	= 0x00001000,	//texture coordinates changed
261		REBUILD_COLOR	= 0x00002000,	//color changed
262		REBUILD_POSITION= 0x00004000,	//vertex positions/normals changed
263		REBUILD_GEOMETRY= REBUILD_POSITION|REBUILD_TCOORD|REBUILD_COLOR,
264		REBUILD_MATERIAL= REBUILD_TCOORD|REBUILD_COLOR,
265		REBUILD_ALL		= REBUILD_GEOMETRY|REBUILD_VOLUME,
266		REBUILD_RIGGED	= 0x00008000,
267		ON_SHIFT_LIST	= 0x00010000,
268		BLOCKER			= 0x00020000,
269		ACTIVE			= 0x00040000,
270		DEAD			= 0x00080000,
271		INVISIBLE		= 0x00100000, // stay invisible until flag is cleared
272 		NEARBY_LIGHT	= 0x00200000, // In gPipeline.mNearbyLightSet
273		BUILT			= 0x00400000,
274		FORCE_INVISIBLE = 0x00800000, // stay invis until CLEAR_INVISIBLE is set (set of orphaned)
275		CLEAR_INVISIBLE = 0x01000000, // clear FORCE_INVISIBLE next draw frame
276		REBUILD_SHADOW =  0x02000000,
277		HAS_ALPHA		= 0x04000000,
278		RIGGED			= 0x08000000,
279		PARTITION_MOVE	= 0x10000000,
280	} EDrawableFlags;
281
282private: //aligned members
283	LLVector4a		mExtents[2];
284	LLVector4a		mPositionGroup;
285	
286public:
287	LLXformMatrix       mXform;
288
289	// vis data
290	LLPointer<LLDrawable> mParent;
291
292	F32				mDistanceWRTCamera;
293	
294	S32				mQuietCount;
295
296	static S32 getCurrentFrame() { return sCurVisible; }
297	static S32 getMinVisFrameRange();
298
299	void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
300	LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
301	
302	static F32 sCurPixelAngle; //current pixels per radian
303
304private:
305	typedef std::vector<LLFace*> face_list_t;
306	
307	U32				mState;
308	S32				mRenderType;
309	LLPointer<LLViewerObject> mVObjp;
310	face_list_t     mFaces;
311	LLSpatialGroup* mSpatialGroupp;
312	LLPointer<LLDrawable> mSpatialBridge;
313	
314	mutable U32		mVisible;
315	F32				mRadius;
316	F32				mBinRadius;
317	S32				mGeneration;
318	
319	LLVector3		mCurrentScale;
320	
321	static U32 sCurVisible; // Counter for what value of mVisible means currently visible
322
323	static U32 sNumZombieDrawables;
324	static LLDynamicArrayPtr<LLPointer<LLDrawable> > sDeadList;
325};
326
327
328inline LLFace* LLDrawable::getFace(const S32 i) const
329{
330	//switch these asserts to llerrs -- davep
331	//llassert((U32)i < mFaces.size());
332	//llassert(mFaces[i]);
333
334	if ((U32) i >= mFaces.size())
335	{
336		llerrs << "Invalid face index." << llendl;
337	}
338
339	if (!mFaces[i])
340	{
341		llerrs << "Null face found." << llendl;
342	}
343	
344	return mFaces[i];
345}
346
347
348inline S32 LLDrawable::getNumFaces()const
349{
350	return (S32)mFaces.size();
351}
352
353#endif