PageRenderTime 50ms CodeModel.GetById 30ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llvotextbubble.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 272 lines | 195 code | 49 blank | 28 comment | 22 complexity | c19a6ea5eb1bc94fc11ed29c22e49b85 MD5 | raw file
  1/** 
  2 * @file llvotextbubble.cpp
  3 * @brief Viewer-object text bubble.
  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#include "llviewerprecompiledheaders.h"
 28
 29#include "llvotextbubble.h"
 30
 31#include "imageids.h"
 32#include "llviewercontrol.h"
 33#include "llprimitive.h"
 34#include "llrendersphere.h"
 35
 36#include "llbox.h"
 37#include "lldrawable.h"
 38#include "llface.h"
 39#include "llviewertexturelist.h"
 40#include "llvolume.h"
 41#include "pipeline.h"
 42#include "llvector4a.h"
 43#include "llviewerregion.h"
 44
 45LLVOTextBubble::LLVOTextBubble(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
 46:	LLAlphaObject(id, pcode, regionp)
 47{
 48	setScale(LLVector3(1.5f, 1.5f, 0.25f));
 49	mbCanSelect = FALSE;
 50	mLOD = MIN_LOD;
 51	mVolumeChanged = TRUE;
 52	setVelocity(LLVector3(0.f, 0.f, 0.75f));
 53	LLVolumeParams volume_params;
 54	volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_LINE);
 55	volume_params.setBeginAndEndS(0.f, 1.f);
 56	volume_params.setBeginAndEndT(0.f, 1.f);
 57	volume_params.setRatio(0.25f, 0.25f);
 58	volume_params.setShear(0.f, 0.f);
 59	setVolume(volume_params, 0);
 60	mColor = LLColor4(1.0f, 0.0f, 0.0f, 1.f);
 61	S32 i;
 62	for (i = 0; i < getNumTEs(); i++)
 63	{
 64		setTEColor(i, mColor);
 65		setTETexture(i, LLUUID(IMG_DEFAULT));
 66	}
 67}
 68
 69
 70LLVOTextBubble::~LLVOTextBubble()
 71{
 72}
 73
 74
 75BOOL LLVOTextBubble::isActive() const
 76{
 77	return TRUE;
 78}
 79
 80BOOL LLVOTextBubble::idleUpdate(LLAgent &agent, LLWorld	&world, const F64 &time)
 81{
 82	static LLFastTimer::DeclareTimer ftm("Text Bubble");
 83	LLFastTimer t(ftm);
 84
 85	F32 dt = mUpdateTimer.getElapsedTimeF32();
 86	// Die after a few seconds.
 87	if (dt > 1.5f)
 88	{
 89		return FALSE;
 90	}
 91
 92	LLViewerObject::idleUpdate(agent, world, time);
 93
 94	setScale(0.5f * (1.f+dt) * LLVector3(1.5f, 1.5f, 0.5f));
 95
 96	F32 alpha = 0.35f*dt;
 97
 98	LLColor4 color = mColor;
 99	color.mV[VALPHA] -= alpha;
100	if (color.mV[VALPHA] <= 0.05f)
101	{
102		return FALSE;
103	}
104	S32 i;
105	for (i = 0; i < getNumTEs(); i++)
106	{
107		setTEColor(i, color);
108		setTEFullbright(i, TRUE);
109	}
110
111	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
112	return TRUE;
113}
114
115
116void LLVOTextBubble::updateTextures()
117{
118	// Update the image levels of all textures...
119
120	for (U32 i = 0; i < getNumTEs(); i++)
121	{
122		const LLTextureEntry *te = getTE(i);
123		F32 texel_area_ratio = fabs(te->mScaleS * te->mScaleT);
124		texel_area_ratio = llclamp(texel_area_ratio, .125f, 16.f);
125		LLViewerTexture *imagep = getTEImage(i);
126		if (imagep)
127		{
128			imagep->addTextureStats(mPixelArea / texel_area_ratio);
129		}
130	}
131}
132
133
134LLDrawable *LLVOTextBubble::createDrawable(LLPipeline *pipeline)
135{
136	pipeline->allocDrawable(this);
137	mDrawable->setLit(FALSE);
138	mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
139	
140	for (U32 i = 0; i < getNumTEs(); i++)
141	{
142		LLViewerTexture *imagep;
143		const LLTextureEntry *texture_entry = getTE(i);
144		imagep = LLViewerTextureManager::getFetchedTexture(texture_entry->getID());
145
146		mDrawable->addFace((LLFacePool*) NULL, imagep);
147	}
148
149	return mDrawable;
150}
151
152// virtual
153BOOL LLVOTextBubble::setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume)
154{
155	if (LLPrimitive::setVolume(volume_params, mLOD))
156	{
157		if (mDrawable)
158		{
159			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
160			mVolumeChanged = TRUE;
161		}
162		return TRUE;
163	}
164	return FALSE;
165}
166
167
168BOOL LLVOTextBubble::updateLOD()
169{
170	return FALSE;
171}
172
173BOOL LLVOTextBubble::updateGeometry(LLDrawable *drawable)
174{
175 	if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_VOLUME)))
176		return TRUE;
177	
178	if (mVolumeChanged)
179	{
180		LLVolumeParams volume_params = getVolume()->getParams();
181		setVolume(volume_params, 0);
182
183		LLPipeline::sCompiles++;
184
185		drawable->setNumFaces(getVolume()->getNumFaces(), drawable->getFace(0)->getPool(), getTEImage(0));
186	}
187
188	LLMatrix4 identity4;
189	LLMatrix3 identity3;
190	for (S32 i = 0; i < drawable->getNumFaces(); i++)
191	{
192		LLFace *face = drawable->getFace(i);
193		face->setTEOffset(i);
194		face->setTexture(LLViewerFetchedTexture::sSmokeImagep);
195		face->setState(LLFace::FULLBRIGHT);
196	}
197
198	mVolumeChanged = FALSE;
199
200	mDrawable->movePartition();
201	return TRUE;
202}
203
204void LLVOTextBubble::updateFaceSize(S32 idx)
205{
206	LLFace* face = mDrawable->getFace(idx);
207	
208	if (idx == 0 || idx == 2)
209	{
210		face->setSize(0,0);
211	}
212	else
213	{
214		const LLVolumeFace& vol_face = getVolume()->getVolumeFace(idx);
215		face->setSize(vol_face.mNumVertices, vol_face.mNumIndices);
216	}
217}
218
219void LLVOTextBubble::getGeometry(S32 idx,
220								LLStrider<LLVector3>& verticesp,
221								LLStrider<LLVector3>& normalsp, 
222								LLStrider<LLVector2>& texcoordsp,
223								LLStrider<LLColor4U>& colorsp, 
224								LLStrider<U16>& indicesp) 
225{
226	if (idx == 0 || idx == 2)
227	{
228		return;
229	}
230
231	const LLVolumeFace& face = getVolume()->getVolumeFace(idx);
232	
233	LLVector4a pos;
234	pos.load3(getPositionAgent().mV);
235
236	LLVector4a scale;
237	scale.load3(getScale().mV);
238
239	LLColor4U color = LLColor4U(getTE(idx)->getColor());
240	U32 offset = mDrawable->getFace(idx)->getGeomIndex();
241	
242	LLVector4a* dst_pos = (LLVector4a*) verticesp.get();
243	LLVector4a* src_pos = (LLVector4a*) face.mPositions;
244	
245	LLVector4a* dst_norm = (LLVector4a*) normalsp.get();
246	LLVector4a* src_norm  = (LLVector4a*) face.mNormals;
247	
248	LLVector2* dst_tc = (LLVector2*) texcoordsp.get();
249	LLVector2* src_tc = (LLVector2*) face.mTexCoords;
250
251	LLVector4a::memcpyNonAliased16((F32*) dst_norm, (F32*) src_norm, face.mNumVertices*4*sizeof(F32));
252	LLVector4a::memcpyNonAliased16((F32*) dst_tc, (F32*) src_tc, face.mNumVertices*2*sizeof(F32));
253	
254	
255	for (U32 i = 0; i < face.mNumVertices; i++)
256	{
257		LLVector4a t;
258		t.setMul(src_pos[i], scale);
259		dst_pos[i].setAdd(t, pos);
260		*colorsp++ = color;
261	}
262	
263	for (U32 i = 0; i < face.mNumIndices; i++)
264	{
265		*indicesp++ = face.mIndices[i] + offset;
266	}
267}
268
269U32 LLVOTextBubble::getPartitionType() const
270{ 
271	return LLViewerRegion::PARTITION_PARTICLE; 
272}