llvisualparamhint.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**
  2. * @file llvisualparamhint.cpp
  3. * @brief A dynamic texture class for displaying avatar visual params effects
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. // Note: probably because of obscure pre-historical reasons, this file is
  33. // named "lltoolmorph.cpp" in LL's viewer sources. I renamed it based on the
  34. // class it implements instead. HB
  35. #include "llviewerprecompiledheaders.h"
  36. #include "llvisualparamhint.h"
  37. #include "llrender.h"
  38. #include "llwearable.h"
  39. #include "llagent.h"
  40. #include "lldrawable.h"
  41. #include "lldrawpoolavatar.h"
  42. #include "llface.h"
  43. #include "llmorphview.h"
  44. #include "llpipeline.h"
  45. #include "llviewercamera.h"
  46. #include "llviewercontrol.h"
  47. #include "llviewershadermgr.h"
  48. #include "llviewertexturelist.h"
  49. #include "llvoavatarself.h"
  50. //static
  51. LLVisualParamHint::instance_list_t LLVisualParamHint::sInstances;
  52. bool LLVisualParamReset::sDirty = false;
  53. //-----------------------------------------------------------------------------
  54. // LLVisualParamHint() class
  55. //-----------------------------------------------------------------------------
  56. // static
  57. LLVisualParamHint::LLVisualParamHint(S32 pos_x, S32 pos_y,
  58. S32 width, S32 height,
  59. LLViewerJointMesh* meshp,
  60. LLViewerVisualParam* paramp,
  61. LLWearable* wearablep,
  62. F32 param_weight,
  63. LLJoint* jointp)
  64. : LLViewerDynamicTexture(width, height, 3,
  65. LLViewerDynamicTexture::ORDER_MIDDLE, true),
  66. mNeedsUpdate(true),
  67. mAllowsUpdates(true),
  68. mIsVisible(false),
  69. mJointMesh(meshp),
  70. mVisualParam(paramp),
  71. mWearablePtr(wearablep),
  72. mVisualParamWeight(param_weight),
  73. mDelayFrames(0),
  74. mRect(pos_x, pos_y + height, pos_x + width, pos_y),
  75. mLastParamWeight(0.f),
  76. mCamTargetJoint(jointp)
  77. {
  78. LLVisualParamHint::sInstances.insert(this);
  79. mBackgroundp = LLUI::getUIImage("avatar_thumb_bkgrnd.j2c");
  80. if (!mCamTargetJoint)
  81. {
  82. llwarns << "Missing camera target joint !" << llendl;
  83. }
  84. llassert(mCamTargetJoint);
  85. llassert(width != 0);
  86. llassert(height != 0);
  87. }
  88. LLVisualParamHint::~LLVisualParamHint()
  89. {
  90. LLVisualParamHint::sInstances.erase(this);
  91. }
  92. //virtual
  93. S8 LLVisualParamHint::getType() const
  94. {
  95. return LLViewerDynamicTexture::LL_VISUAL_PARAM_HINT;
  96. }
  97. // Requests updates for all instances (excluding two possible exceptions).
  98. // Grungy but efficient.
  99. //static
  100. void LLVisualParamHint::requestHintUpdates(LLVisualParamHint* exception1,
  101. LLVisualParamHint* exception2)
  102. {
  103. S32 delay_frames = 0;
  104. for (instance_list_t::iterator iter = sInstances.begin();
  105. iter != sInstances.end(); ++iter)
  106. {
  107. LLVisualParamHint* vphintp = *iter;
  108. if (vphintp != exception1 && vphintp != exception2)
  109. {
  110. vphintp->mNeedsUpdate = true;
  111. if (vphintp->mAllowsUpdates)
  112. {
  113. vphintp->mDelayFrames = delay_frames++;
  114. }
  115. else
  116. {
  117. vphintp->mDelayFrames = 0;
  118. }
  119. }
  120. }
  121. }
  122. bool LLVisualParamHint::needsRender()
  123. {
  124. return mNeedsUpdate && mDelayFrames-- <= 0 && mAllowsUpdates &&
  125. isAgentAvatarValid() && !gAgentAvatarp->getIsAppearanceAnimating();
  126. }
  127. void LLVisualParamHint::preRender(bool clear_depth)
  128. {
  129. if (isAgentAvatarValid())
  130. {
  131. mLastParamWeight = mVisualParam->getWeight();
  132. if (mWearablePtr)
  133. {
  134. mWearablePtr->setVisualParamWeight(mVisualParam->getID(),
  135. mVisualParamWeight, false);
  136. LLViewerWearable* wearable = mWearablePtr->asViewerWearable();
  137. if (wearable)
  138. {
  139. wearable->setVolatile(true);
  140. }
  141. }
  142. else
  143. {
  144. llwarns << "mWearablePtr is NULL: cannot set wearable visual param weight."
  145. << llendl;
  146. }
  147. gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(),
  148. mVisualParamWeight, false);
  149. gAgentAvatarp->setVisualParamWeight("Blink_Left", 0.f);
  150. gAgentAvatarp->setVisualParamWeight("Blink_Right", 0.f);
  151. gAgentAvatarp->updateComposites();
  152. gAgentAvatarp->updateVisualParams();
  153. #if 0 // This is a NOP !
  154. gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
  155. #endif
  156. gAgentAvatarp->updateLOD();
  157. LLViewerDynamicTexture::preRender(clear_depth);
  158. }
  159. }
  160. bool LLVisualParamHint::render()
  161. {
  162. if (!isAgentAvatarValid()) return true;
  163. LLVisualParamReset::sDirty = true;
  164. gGL.pushUIMatrix();
  165. gGL.loadUIIdentity();
  166. gGL.matrixMode(LLRender::MM_PROJECTION);
  167. gGL.pushMatrix();
  168. gGL.loadIdentity();
  169. gGL.ortho(0.f, mFullWidth, 0.f, mFullHeight, -1.f, 1.f);
  170. gGL.matrixMode(LLRender::MM_MODELVIEW);
  171. gGL.pushMatrix();
  172. gGL.loadIdentity();
  173. gUIProgram.bind();
  174. LLGLSUIDefault gls_ui;
  175. //LLGLState::verify(true);
  176. mBackgroundp->draw(0, 0, mFullWidth, mFullHeight);
  177. gGL.matrixMode(LLRender::MM_PROJECTION);
  178. gGL.popMatrix();
  179. gGL.matrixMode(LLRender::MM_MODELVIEW);
  180. gGL.popMatrix();
  181. mNeedsUpdate = false;
  182. mIsVisible = true;
  183. LLQuaternion avatar_rot;
  184. LLJoint* rootp = gAgentAvatarp->getRootJoint();
  185. if (rootp)
  186. {
  187. avatar_rot = rootp->getWorldRotation();
  188. }
  189. LLVector3 target_joint_pos;
  190. if (mCamTargetJoint)
  191. {
  192. target_joint_pos = mCamTargetJoint->getWorldPosition();
  193. }
  194. LLVector3 target_offset(0.f, 0.f, mVisualParam->getCameraElevation());
  195. LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rot);
  196. F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
  197. LLVector3 snapshot_offset(mVisualParam->getCameraDistance() *
  198. cosf(cam_angle_radians),
  199. mVisualParam->getCameraDistance() *
  200. sinf(cam_angle_radians),
  201. mVisualParam->getCameraElevation());
  202. LLVector3 camera_pos = target_joint_pos + snapshot_offset * avatar_rot;
  203. gGL.flush();
  204. gViewerCamera.setAspect((F32)mFullWidth / (F32)mFullHeight);
  205. gViewerCamera.setOriginAndLookAt(camera_pos, // Camera
  206. LLVector3::z_axis, // Up
  207. target_pos); // Point of interest
  208. gViewerCamera.setPerspective(false, mOrigin.mX, mOrigin.mY, mFullWidth,
  209. mFullHeight, false);
  210. // Do not let environment settings influence our scene lighting. HB
  211. HBPreviewLighting preview_light;
  212. gPipeline.previewAvatar(gAgentAvatarp);
  213. gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(),
  214. mLastParamWeight);
  215. if (mWearablePtr)
  216. {
  217. mWearablePtr->setVisualParamWeight(mVisualParam->getID(),
  218. mLastParamWeight, false);
  219. }
  220. else
  221. {
  222. llwarns << "mWearablePtr is NULL: cannot set wearable visual param weight."
  223. << llendl;
  224. }
  225. LLViewerWearable* wearablep = mWearablePtr->asViewerWearable();
  226. if (wearablep)
  227. {
  228. wearablep->setVolatile(false);
  229. }
  230. gAgentAvatarp->updateVisualParams();
  231. gGL.color4f(1.f, 1.f, 1.f, 1.f);
  232. mImageGLp->setGLTextureCreated(true);
  233. gGL.popUIMatrix();
  234. return true;
  235. }
  236. void LLVisualParamHint::draw()
  237. {
  238. if (!mIsVisible) return;
  239. LLTexUnit* unit0 = gGL.getTexUnit(0);
  240. unit0->bind(this);
  241. gGL.color4f(1.f, 1.f, 1.f, 1.f);
  242. LLGLSUIDefault gls_ui;
  243. gGL.begin(LLRender::TRIANGLES);
  244. {
  245. gGL.texCoord2i(0, 1);
  246. gGL.vertex2i(0, mFullHeight);
  247. gGL.texCoord2i(0, 0);
  248. gGL.vertex2i(0, 0);
  249. gGL.texCoord2i(1, 0);
  250. gGL.vertex2i(mFullWidth, 0);
  251. gGL.texCoord2i(0, 1);
  252. gGL.vertex2i(0, mFullHeight);
  253. gGL.texCoord2i(1, 0);
  254. gGL.vertex2i(mFullWidth, 0);
  255. gGL.texCoord2i(1, 1);
  256. gGL.vertex2i(mFullWidth, mFullHeight);
  257. }
  258. gGL.end();
  259. unit0->unbind(LLTexUnit::TT_TEXTURE);
  260. }
  261. void LLVisualParamHint::setWearable(LLWearable* wearablep,
  262. LLViewerVisualParam* paramp)
  263. {
  264. mWearablePtr = wearablep;
  265. mVisualParam = paramp;
  266. }
  267. //-----------------------------------------------------------------------------
  268. // LLVisualParamReset() class
  269. //-----------------------------------------------------------------------------
  270. LLVisualParamReset::LLVisualParamReset()
  271. : LLViewerDynamicTexture(1, 1, 1, ORDER_RESET, false)
  272. {
  273. }
  274. //virtual
  275. S8 LLVisualParamReset::getType() const
  276. {
  277. return LLViewerDynamicTexture::LL_VISUAL_PARAM_RESET;
  278. }
  279. bool LLVisualParamReset::render()
  280. {
  281. if (sDirty && isAgentAvatarValid())
  282. {
  283. gAgentAvatarp->updateComposites();
  284. gAgentAvatarp->updateVisualParams();
  285. #if 0 // This is a NOP ! HB
  286. gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
  287. #endif
  288. sDirty = false;
  289. }
  290. return false;
  291. }