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