diff --git a/indra/deps/CMakeLists.txt b/indra/deps/CMakeLists.txt
index 8441942167c299685f0ba904031969678879a51a..2ce45871fb4dcf85a067517c988154a94200d287 100644
--- a/indra/deps/CMakeLists.txt
+++ b/indra/deps/CMakeLists.txt
@@ -34,7 +34,7 @@ FetchContent_Declare(
 FetchContent_Declare(
   absl
   GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
-  GIT_TAG        3c2bed2e77a8b77ce3092e3f75140dd21879bdba
+  GIT_TAG        1995c6a3c2f9080160d9d8716504dc004e5e1ec0
   )
 
 # This is a hack because absl has dumb cmake
diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp
index 563478eee0ca901522e3006c2e025e418f5eab69..d9a710bdef3403cc3e0b3cc25729c7049ad2103a 100644
--- a/indra/newview/llagentcamera.cpp
+++ b/indra/newview/llagentcamera.cpp
@@ -408,9 +408,9 @@ void LLAgentCamera::slamLookAt(const LLVector3 &look_at)
 //-----------------------------------------------------------------------------
 LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 original_focus_point, S32 x, S32 y)
 {
-	LLMatrix4 obj_matrix = object->getRenderMatrix();
-	LLQuaternion obj_rot = object->getRenderRotation();
-	LLVector3 obj_pos = object->getRenderPosition();
+	const LLMatrix4& obj_matrix = object->getRenderMatrix();
+	const LLQuaternion obj_rot = object->getRenderRotation();
+	const LLVector3 obj_pos = object->getRenderPosition();
 
 	BOOL is_avatar = object->isAvatar();
 	// if is avatar - don't do any funk heuristics to position the focal point
@@ -426,8 +426,11 @@ LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 origi
 	// make sure they object extents are non-zero
 	object_extents.clamp(0.001f, F32_MAX);
 
+	auto& viewerCamera = LLViewerCamera::instance();
+	const auto& viewer_camera_origin = viewerCamera.getOrigin();
+
 	// obj_to_cam_ray is unit vector pointing from object center to camera, in the coordinate frame of the object
-	LLVector3 obj_to_cam_ray = obj_pos - LLViewerCamera::getInstance()->getOrigin();
+	LLVector3 obj_to_cam_ray = obj_pos - viewer_camera_origin;
 	obj_to_cam_ray.rotVec(inv_obj_rot);
 	obj_to_cam_ray.normalize();
 
@@ -474,7 +477,7 @@ LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 origi
 	LLVector3 focus_pt = gAgent.getPosAgentFromGlobal(focus_pt_global);
 
 	// find vector from camera to focus point in object space
-	LLVector3 camera_to_focus_vec = focus_pt - LLViewerCamera::getInstance()->getOrigin();
+	LLVector3 camera_to_focus_vec = focus_pt - viewer_camera_origin;
 	camera_to_focus_vec.rotVec(inv_obj_rot);
 
 	// find vector from object origin to focus point in object coordinates
@@ -542,13 +545,13 @@ LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 origi
 	// is almost always "tumble about middle" and not "spin around surface point"
 	if (!is_avatar) 
 	{
-		LLVector3 obj_rel = original_focus_point - object->getRenderPosition();
+		LLVector3 obj_rel = original_focus_point - obj_pos;
 		
 		//now that we have the object relative position, we should bias toward the center of the object 
 		//based on the distance of the camera to the focus point vs. the distance of the camera to the focus
 
-		F32 relDist = llabs(obj_rel * LLViewerCamera::getInstance()->getAtAxis());
-		F32 viewDist = dist_vec(obj_pos + obj_rel, LLViewerCamera::getInstance()->getOrigin());
+		F32 relDist = llabs(obj_rel * viewerCamera.getAtAxis());
+		F32 viewDist = dist_vec(obj_pos + obj_rel, viewer_camera_origin);
 
 
 		LLBBox obj_bbox = object->getBoundingBoxAgent();
diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index 351adf366885eba8de463971013c3c18e517f804..8605962ae5ead1817a557f990ffcd6df3da9e969 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -471,12 +471,14 @@ void LLDrawPoolWater::renderReflection(LLFace* face)
 
 void LLDrawPoolWater::shade2(bool edge, LLGLSLShader* shader, const LLColor3& light_diffuse, const LLVector3& light_dir, F32 light_exp)
 {
-    F32  water_height  = LLEnvironment::instance().getWaterHeight(); 
-    F32  camera_height = LLViewerCamera::getInstance()->getOrigin().mV[2];
+	LLEnvironment& environment = LLEnvironment::instance();
+	LLViewerCamera& viewerCamera = LLViewerCamera::instance();
+
+	F32  water_height  = environment.getWaterHeight();
+    F32  camera_height = viewerCamera.getOrigin().mV[2];
     F32  eyedepth      = camera_height - water_height;
     bool underwater    = eyedepth <= 0.0f;
 
-    LLEnvironment& environment = LLEnvironment::instance();
     LLSettingsWater::ptr_t pwater = environment.getCurrentWater();
     LLSettingsSky::ptr_t   psky   = environment.getCurrentSky();
 
@@ -513,7 +515,7 @@ void LLDrawPoolWater::shade2(bool edge, LLGLSLShader* shader, const LLColor3& li
     LLViewerTexture* tex_a = mWaterNormp[0];
     LLViewerTexture* tex_b = mWaterNormp[1];
 
-    F32 blend_factor = LLEnvironment::instance().getCurrentWater()->getBlendFactor();
+    F32 blend_factor = pwater->getBlendFactor();
 	
     gGL.getTexUnit(bumpTex)->unbind(LLTexUnit::TT_TEXTURE);
     gGL.getTexUnit(bumpTex2)->unbind(LLTexUnit::TT_TEXTURE);
@@ -570,10 +572,10 @@ void LLDrawPoolWater::shade2(bool edge, LLGLSLShader* shader, const LLColor3& li
 	//shader->uniformMatrix4fv("inverse_ref", 1, GL_FALSE, (GLfloat*) gGLObliqueProjectionInverse.mMatrix);
 	shader->uniform1f(LLShaderMgr::WATER_WATERHEIGHT, eyedepth);
 	shader->uniform1f(LLShaderMgr::WATER_TIME, sTime);
-	shader->uniform3fv(LLShaderMgr::WATER_EYEVEC, 1, LLViewerCamera::getInstance()->getOrigin().mV);
+	shader->uniform3fv(LLShaderMgr::WATER_EYEVEC, 1, viewerCamera.getOrigin().mV);
 	shader->uniform3fv(LLShaderMgr::WATER_SPECULAR, 1, light_diffuse.mV);
 	shader->uniform1f(LLShaderMgr::WATER_SPECULAR_EXP, light_exp);
-    if (LLEnvironment::instance().isCloudScrollPaused())
+    if (environment.isCloudScrollPaused())
     {
         shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR1, 1, LLVector2::zero.mV);
         shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR2, 1, LLVector2::zero.mV);
@@ -598,11 +600,11 @@ void LLDrawPoolWater::shade2(bool edge, LLGLSLShader* shader, const LLColor3& li
 	shader->uniform1f(LLShaderMgr::WATER_SCALED_ANGLE, scaledAngle);
 	shader->uniform1f(LLShaderMgr::WATER_SUN_ANGLE2, 0.1f + 0.2f*sunAngle);
 
-    LLVector4 rotated_light_direction = LLEnvironment::instance().getRotatedLightNorm();
+    LLVector4 rotated_light_direction = environment.getRotatedLightNorm();
     shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, rotated_light_direction.mV);
-    shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
+    shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, viewerCamera.getOrigin().mV);
 
-	if (LLViewerCamera::getInstance()->cameraUnderWater())
+	if (viewerCamera.cameraUnderWater())
 	{
 		shader->uniform1f(LLShaderMgr::WATER_REFSCALE, pwater->getScaleBelow());
 	}
@@ -717,7 +719,7 @@ void LLDrawPoolWater::shade()
 	LLGLSLShader* shader = nullptr;
     LLGLSLShader* edge_shader = nullptr;
 
-	F32 eyedepth = LLViewerCamera::getInstance()->getOrigin().mV[2] - LLEnvironment::instance().getWaterHeight();
+	F32 eyedepth = LLViewerCamera::getInstance()->getOrigin().mV[2] - environment.getWaterHeight();
 	
 	if (eyedepth < 0.f && LLPipeline::sWaterReflections)
 	{
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 961d72c62eb7bc18b3680ba43fb4a75b84726654..35c3e0c7cba1d937e8ad9ecd30d700f82316e875 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -164,18 +164,14 @@ void LLDrawPoolWLSky::renderDome(const LLVector3& camPosLocal, F32 camHeightLoca
 	gGL.popMatrix();
 }
 
-void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 camHeightLocal) const
+void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal) const
 {
-    LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
-
 	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
 	{
         LLGLSPipelineDepthTestSkyBox sky(true, true);
 
         sky_shader->bind();
 
-        LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-
         LLViewerTexture* rainbow_tex = gSky.mVOSkyp->getRainbowTex();
         LLViewerTexture* halo_tex  = gSky.mVOSkyp->getHaloTex();
 
@@ -204,7 +200,7 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
         sky_shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1 : 0);
 
         /// Render the skydome
-        renderDome(origin, camHeightLocal, sky_shader);	
+        renderDome(camPosLocal, camHeightLocal, sky_shader);
 
 		sky_shader->unbind();
     }
@@ -212,20 +208,18 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
 
 void LLDrawPoolWLSky::renderSkyHaze(const LLVector3& camPosLocal, F32 camHeightLocal) const
 {
-    LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
-
 	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
 	{
         LLGLSPipelineDepthTestSkyBox sky(true, false);
         sky_shader->bind();
         sky_shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, 1);
         sky_shader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, 1.0f);
-        renderDome(origin, camHeightLocal, sky_shader);	
+        renderDome(camPosLocal, camHeightLocal, sky_shader);
 		sky_shader->unbind();
     }
 }
 
-void LLDrawPoolWLSky::renderStars(void) const
+void LLDrawPoolWLSky::renderStars(const LLSettingsSky::ptr_t& psky) const
 {
     LLGLSPipelineBlendSkyBox gls_skybox(true, false);
 	
@@ -238,7 +232,7 @@ void LLDrawPoolWLSky::renderStars(void) const
 	// clamping and allow the star_alpha param to brighten the stars.
 	LLColor4 star_alpha(LLColor4::black);
 
-    star_alpha.mV[3] = LLEnvironment::instance().getCurrentSky()->getStarBrightness() / 512.f;
+    star_alpha.mV[3] = psky->getStarBrightness() / 512.f;
     
 	// If star brightness is not set, exit
 	if( star_alpha.mV[3] < 0.001 )
@@ -295,13 +289,13 @@ void LLDrawPoolWLSky::renderStars(void) const
 	}
 }
 
-void LLDrawPoolWLSky::renderStarsDeferred(void) const
+void LLDrawPoolWLSky::renderStarsDeferred(const LLSettingsSky::ptr_t& psky) const
 {
 	LLGLSPipelineBlendSkyBox gls_sky(true, false);
 
 	gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
 
-    F32 star_alpha = LLEnvironment::instance().getCurrentSky()->getStarBrightness() / 500.0f;
+    F32 star_alpha = psky->getStarBrightness() / 500.0f;
 
 	// If start_brightness is not set, exit
 	if(star_alpha < 0.001f)
@@ -315,7 +309,7 @@ void LLDrawPoolWLSky::renderStarsDeferred(void) const
     LLViewerTexture* tex_a = gSky.mVOSkyp->getBloomTex();
     LLViewerTexture* tex_b = gSky.mVOSkyp->getBloomTexNext();
 
-    F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor();
+    F32 blend_factor = psky->getBlendFactor();
 	
     if (tex_a && (!tex_b || (tex_a == tex_b)))
     {
@@ -356,12 +350,10 @@ void LLDrawPoolWLSky::renderStarsDeferred(void) const
     gDeferredStarProgram.unbind();
 }
 
-void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const
+void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const
 {
 	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp->getCloudNoiseTex())
 	{
-        LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-
 		LLGLSPipelineBlendSkyBox pipeline(true, true);
 		
 		cloudshader->bind();
@@ -412,12 +404,10 @@ void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32
 	}
 }
 
-void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const
+void LLDrawPoolWLSky::renderSkyClouds(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const
 {
 	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp->getCloudNoiseTex())
 	{
-        LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-
         LLGLSPipelineBlendSkyBox pipeline(true, true);
 		
 		cloudshader->bind();
@@ -468,17 +458,16 @@ void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeigh
 	}
 }
 
-void LLDrawPoolWLSky::renderHeavenlyBodies()
+void LLDrawPoolWLSky::renderHeavenlyBodies(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal)
 {
 	LLGLSPipelineBlendSkyBox gls_skybox(true, false);
 
-    LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
 	gGL.pushMatrix();
-	gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);	        
+	gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
 
 	LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_SUN];
 
-    F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor();
+    F32 blend_factor = psky->getBlendFactor();
     bool can_use_vertex_shaders = gPipeline.canUseVertexShaders();
     bool can_use_windlight_shaders = gPipeline.canUseWindLightShaders();
 
@@ -531,7 +520,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
         }
 	}
 
-    blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor();
+    blend_factor = psky->getBlendFactor();
 
 	face = gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON];
 
@@ -563,8 +552,6 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
                 moon_shader->bindTexture(LLShaderMgr::ALTERNATE_DIFFUSE_MAP, tex_b, LLTexUnit::TT_TEXTURE);
             }
 
-            LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-
             F32 moon_brightness = (float)psky->getMoonBrightness();
 
             moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness);
@@ -592,7 +579,9 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
 	}
 	LL_RECORD_BLOCK_TIME(FTM_RENDER_WL_SKY);
 
-    const F32 camHeightLocal = LLEnvironment::instance().getCamHeight();
+    LLEnvironment& environment = LLEnvironment::instance();
+
+    const F32 camHeightLocal = environment.getCamHeight();
 
 	gGL.setColorMask(true, false);
 
@@ -600,10 +589,12 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
 
     if (gPipeline.canUseWindLightShaders())
     {
-        renderSkyHazeDeferred(origin, camHeightLocal);
-        renderStarsDeferred();
-        renderHeavenlyBodies();
-        renderSkyCloudsDeferred(origin, camHeightLocal, cloud_shader);
+        LLSettingsSky::ptr_t psky = environment.getCurrentSky();
+
+        renderSkyHazeDeferred(psky, origin, camHeightLocal);
+        renderStarsDeferred(psky);
+        renderHeavenlyBodies(psky, origin);
+        renderSkyCloudsDeferred(psky, origin, camHeightLocal, cloud_shader);
     }
     gGL.setColorMask(true, true);
 }
@@ -616,13 +607,17 @@ void LLDrawPoolWLSky::render(S32 pass)
 	}
 	LL_RECORD_BLOCK_TIME(FTM_RENDER_WL_SKY);
 
-    const F32 camHeightLocal = LLEnvironment::instance().getCamHeight();
+    LLEnvironment& environment = LLEnvironment::instance();
+
+    const F32 camHeightLocal = environment.getCamHeight();
     LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
+
+    LLSettingsSky::ptr_t psky = environment.getCurrentSky();
     
 	renderSkyHaze(origin, camHeightLocal);    
-    renderStars();
-    renderHeavenlyBodies();	
-	renderSkyClouds(origin, camHeightLocal, cloud_shader);
+    renderStars(psky);
+    renderHeavenlyBodies(psky, origin);
+	renderSkyClouds(psky, origin, camHeightLocal, cloud_shader);
 
 	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 }
diff --git a/indra/newview/lldrawpoolwlsky.h b/indra/newview/lldrawpoolwlsky.h
index 905c7eebdce72a03e15ccd90eb7b71e6d351c684..a51e8c9cb4e60773f51c1839af99185fc3bd05a5 100644
--- a/indra/newview/lldrawpoolwlsky.h
+++ b/indra/newview/lldrawpoolwlsky.h
@@ -29,6 +29,8 @@
 
 #include "lldrawpool.h"
 
+#include "llsettingssky.h"
+
 class LLGLSLShader;
 
 class LLDrawPoolWLSky final : public LLDrawPool {
@@ -75,14 +77,14 @@ class LLDrawPoolWLSky final : public LLDrawPool {
 	void renderDome(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader * shader) const;
 
     void renderSkyHaze(const LLVector3& camPosLocal, F32 camHeightLocal) const;
-    void renderSkyClouds(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const;
+    void renderSkyClouds(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const;
 
-	void renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 camHeightLocal) const;
-    void renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const;
+	void renderSkyHazeDeferred(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal) const;
+    void renderSkyCloudsDeferred(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const;
 
-    void renderStarsDeferred(void) const;
-	void renderStars(void) const;
-	void renderHeavenlyBodies();    
+    void renderStarsDeferred(const LLSettingsSky::ptr_t& psky) const;
+	void renderStars(const LLSettingsSky::ptr_t& psky) const;
+	void renderHeavenlyBodies(const LLSettingsSky::ptr_t& psky, const LLVector3& camPosLocal);
 };
 
 #endif // LL_DRAWPOOLWLSKY_H
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 832552310d1d632b13f2240f743d6aaf330d747b..5b8b17c0ad01c8d1c93d11f4b878b6a64da39139 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -2513,12 +2513,13 @@ F32 LLFace::calcImportanceToCamera(F32 cos_angle_to_view_dir, F32 dist)
 {
 	F32 importance = 0.f ;
 	
-	if(cos_angle_to_view_dir > LLViewerCamera::getInstance()->getCosHalfFov() && 
+	LLViewerCamera& camera = LLViewerCamera::instance();
+
+	if(cos_angle_to_view_dir > camera.getCosHalfFov() &&
 		dist < FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL - 1][0]) 
 	{
-		LLViewerCamera* camera = LLViewerCamera::getInstance();
-		F32 camera_moving_speed = camera->getAverageSpeed() ;
-		F32 camera_angular_speed = camera->getAverageAngularSpeed();
+		F32 camera_moving_speed = camera.getAverageSpeed() ;
+		F32 camera_angular_speed = camera.getAverageAngularSpeed();
 
 		if(camera_moving_speed > 10.0f || camera_angular_speed > 1.0f)
 		{
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index 24cd09b3d9d043d7a5092a2510f8489b1673df0c..26b5026eacd6770589dc1ea071bbac331c546aec 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -604,13 +604,13 @@ BOOL LLSelectMgr::removeObjectFromSelections(const LLUUID &id)
 
 bool LLSelectMgr::linkObjects()
 {
-	if (!LLSelectMgr::getInstance()->selectGetAllRootsValid())
+	if (!selectGetAllRootsValid())
 	{
 		LLNotificationsUtil::add("UnableToLinkWhileDownloading");
 		return true;
 	}
 
-	S32 object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
+	S32 object_count = getSelection()->getObjectCount();
 	if (object_count > MAX_CHILDREN_PER_TASK + 1)
 	{
 		LLSD args;
@@ -621,19 +621,19 @@ bool LLSelectMgr::linkObjects()
 		return true;
 	}
 
-	if (LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() < 2)
+	if (getSelection()->getRootObjectCount() < 2)
 	{
 		LLNotificationsUtil::add("CannotLinkIncompleteSet");
 		return true;
 	}
 
-	if (!LLSelectMgr::getInstance()->selectGetRootsModify())
+	if (!selectGetRootsModify())
 	{
 		LLNotificationsUtil::add("CannotLinkModify");
 		return true;
 	}
 
-	if (!LLSelectMgr::getInstance()->selectGetRootsNonPermanentEnforced())
+	if (!selectGetRootsNonPermanentEnforced())
 	{
 		LLNotificationsUtil::add("CannotLinkPermanent");
 		return true;
@@ -641,7 +641,7 @@ bool LLSelectMgr::linkObjects()
 
 	LLUUID owner_id;
 	std::string owner_name;
-	if (!LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name))
+	if (!selectGetOwner(owner_id, owner_name))
 	{
 		// we don't actually care if you're the owner, but novices are
 		// the most likely to be stumped by this one, so offer the
@@ -650,13 +650,13 @@ bool LLSelectMgr::linkObjects()
 		return true;
 	}
 
-	if (!LLSelectMgr::getInstance()->selectGetSameRegion())
+	if (!selectGetSameRegion())
 	{
 		LLNotificationsUtil::add("CannotLinkAcrossRegions");
 		return true;
 	}
 
-	LLSelectMgr::getInstance()->sendLink();
+	sendLink();
 
 	return true;
 }
@@ -673,7 +673,7 @@ bool LLSelectMgr::unlinkObjects()
 		return true;
 	}
 
-	LLSelectMgr::getInstance()->sendDelink();
+	sendDelink();
 	return true;
 }
 
@@ -686,7 +686,7 @@ void LLSelectMgr::confirmUnlinkObjects(const LLSD& notification, const LLSD& res
 		return;
 	}
 
-	LLSelectMgr::getInstance()->sendDelink();
+	sendDelink();
 	return;
 }
 
@@ -711,7 +711,7 @@ bool LLSelectMgr::enableLinkObjects()
 	// in component mode, can't link
 	if (!ALControlCache::EditLinkedParts)
 	{
-		if(LLSelectMgr::getInstance()->selectGetAllRootsValid() && LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() >= 2)
+		if(selectGetAllRootsValid() && getSelection()->getRootObjectCount() >= 2)
 		{
 			struct f : public LLSelectedObjectFunctor
 			{
@@ -723,10 +723,10 @@ bool LLSelectMgr::enableLinkObjects()
 				}
 			} func;
 			const bool firstonly = true;
-			new_value = LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func, firstonly);
+			new_value = getSelection()->applyToRootObjects(&func, firstonly);
 		}
 	}
-    if (!LLSelectMgr::getInstance()->getSelection()->checkAnimatedObjectLinkable())
+    if (!getSelection()->checkAnimatedObjectLinkable())
     {
         new_value = false;
     }
@@ -734,7 +734,7 @@ bool LLSelectMgr::enableLinkObjects()
 	if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
 	{
 		// Allow only if the avie isn't sitting on any of the selected objects
-		LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
+		LLObjectSelectionHandle hSel = getSelection();
 		RlvSelectIsSittingOn f(gAgentAvatarp);
 		if (hSel->getFirstRootNode(&f, TRUE) != NULL)
 			new_value = false;
@@ -745,10 +745,10 @@ bool LLSelectMgr::enableLinkObjects()
 
 bool LLSelectMgr::enableUnlinkObjects()
 {
-	LLViewerObject* first_editable_object = LLSelectMgr::getInstance()->getSelection()->getFirstEditableObject();
+	LLViewerObject* first_editable_object = getSelection()->getFirstEditableObject();
 	LLViewerObject *root_object = (first_editable_object == NULL) ? NULL : first_editable_object->getRootEdit();
 
-	bool new_value = LLSelectMgr::getInstance()->selectGetAllRootsValid() &&
+	bool new_value = selectGetAllRootsValid() &&
 		first_editable_object &&
 		!first_editable_object->isAttachment() && !first_editable_object->isPermanentEnforced() &&
 		((root_object == NULL) || !root_object->isPermanentEnforced());
@@ -756,7 +756,7 @@ bool LLSelectMgr::enableUnlinkObjects()
 	if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
 	{
 		// Allow only if the avie isn't sitting on any of the selected objects
-		LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
+		LLObjectSelectionHandle hSel = getSelection();
 		RlvSelectIsSittingOn f(gAgentAvatarp);
 		if (hSel->getFirstRootNode(&f, TRUE) != NULL)
 			new_value = false;
@@ -891,7 +891,7 @@ void LLSelectMgr::addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to
 		
 		// Can't select yourself
 		if (objectp->mID == gAgentID
-			&& !LLSelectMgr::getInstance()->mAllowSelectAvatar)
+			&& !mAllowSelectAvatar)
 		{
 			continue;
 		}
@@ -5856,6 +5856,7 @@ void LLSelectMgr::updateSilhouettes()
 		num_sils_genned	= 0;
 
 		// render silhouettes for highlighted objects
+		const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
 		//BOOL subtracting_from_selection = (gKeyboard->currentMask(TRUE) == MASK_CONTROL);
 		for (S32 pass = 0; pass < 2; pass++)
 		{
@@ -5881,7 +5882,7 @@ void LLSelectMgr::updateSilhouettes()
 				{
 					if (num_sils_genned++ < MAX_SILS_PER_FRAME)
 					{
-						generateSilhouette(node, LLViewerCamera::getInstance()->getOrigin());
+						generateSilhouette(node, viewer_cam_origin);
 						changed_objects.push_back(objectp);			
 					}
 					else if (objectp->isAttachment() && objectp->getRootEdit()->mDrawable.notNull())
@@ -5934,7 +5935,7 @@ void LLSelectMgr::updateSelectionSilhouette(LLObjectSelectionHandle object_handl
 
 		//mSilhouetteImagep->bindTexture();
 		//glAlphaFunc(GL_GREATER, sHighlightAlphaTest);
-
+		const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
 		for (S32 pass = 0; pass < 2; pass++)
 		{
 			for (LLObjectSelection::iterator iter = object_handle->begin();
@@ -5958,7 +5959,7 @@ void LLSelectMgr::updateSelectionSilhouette(LLObjectSelectionHandle object_handl
 				{
 					if (num_sils_genned++ < MAX_SILS_PER_FRAME)// && objectp->mDrawable->isVisible())
 					{
-						generateSilhouette(node, LLViewerCamera::getInstance()->getOrigin());
+						generateSilhouette(node, viewer_cam_origin);
 						changed_objects.push_back(objectp);
 					}
 					else if (objectp->isAttachment())
@@ -5999,7 +6000,8 @@ void LLSelectMgr::renderSilhouettes(BOOL for_hud)
 		gGL.pushMatrix();
 		gGL.loadIdentity();
 		F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
-		gGL.ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, depth);
+		auto& viewerCamera = LLViewerCamera::instance();
+		gGL.ortho(-0.5f * viewerCamera.getAspect(), 0.5f * viewerCamera.getAspect(), -0.5f, 0.5f, 0.f, depth);
 
 		gGL.matrixMode(LLRender::MM_MODELVIEW);
 		gGL.pushMatrix();
@@ -6012,7 +6014,7 @@ void LLSelectMgr::renderSilhouettes(BOOL for_hud)
 	}
 
 	bool wireframe_selection = (gFloaterTools && gFloaterTools->getVisible()) || LLSelectMgr::sRenderHiddenSelections;
-	F32 fogCfx = (F32)llclamp((LLSelectMgr::getInstance()->getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (LLSelectMgr::getInstance()->getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0);
+	F32 fogCfx = (F32)llclamp((getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0);
 
 	static LLColor4 sParentColor = LLColor4(sSilhouetteParentColor[VRED], sSilhouetteParentColor[VGREEN], sSilhouetteParentColor[VBLUE], LLSelectMgr::sHighlightAlpha);
 	static LLColor4 sChildColor = LLColor4(sSilhouetteChildColor[VRED], sSilhouetteChildColor[VGREEN], sSilhouetteChildColor[VBLUE], LLSelectMgr::sHighlightAlpha);
@@ -6619,6 +6621,8 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
 	LLVolume *volume = objectp->getVolume();
 	if (volume)
 	{
+		auto& viewerCamera = LLViewerCamera::instance();
+
 		F32 silhouette_thickness;
 		if (isAgentAvatarValid() && is_hud_object)
 		{
@@ -6626,8 +6630,8 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
 		}
 		else
 		{
-			LLVector3 view_vector = LLViewerCamera::getInstance()->getOrigin() - objectp->getRenderPosition();
-			silhouette_thickness = view_vector.magVec() * LLSelectMgr::sHighlightThickness * (LLViewerCamera::getInstance()->getView() / LLViewerCamera::getInstance()->getDefaultFOV());
+			LLVector3 view_vector = viewerCamera.getOrigin() - objectp->getRenderPosition();
+			silhouette_thickness = view_vector.magVec() * LLSelectMgr::sHighlightThickness * (viewerCamera.getView() / viewerCamera.getDefaultFOV());
 		}		
 		F32 animationTime = (F32)LLFrameTimer::getElapsedSeconds();
 
@@ -6641,10 +6645,10 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
 			gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
 			LLGLEnable fog(GL_FOG);
 			glFogi(GL_FOG_MODE, GL_LINEAR);
-			float d = (LLViewerCamera::getInstance()->getPointOfInterest()-LLViewerCamera::getInstance()->getOrigin()).magVec();
+			float d = (viewerCamera.getPointOfInterest()-viewerCamera.getOrigin()).magVec();
 			LLColor4 fogCol = color * (F32)llclamp((LLSelectMgr::getInstance()->getSelectionCenterGlobal()-gAgentCamera.getCameraPositionGlobal()).magVec()/(LLSelectMgr::getInstance()->getBBoxOfSelection().getExtentLocal().magVec()*4), 0.0, 1.0);
 			glFogf(GL_FOG_START, d);
-			glFogf(GL_FOG_END, d*(1 + (LLViewerCamera::getInstance()->getView() / LLViewerCamera::getInstance()->getDefaultFOV())));
+			glFogf(GL_FOG_END, d*(1 + (viewerCamera.getView() / viewerCamera.getDefaultFOV())));
 			glFogfv(GL_FOG_COLOR, fogCol.mV);
 
 			LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL);
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index 0f85b25e36eff228396fc80b445e17b6bbe73db8..27f14061908fd02a5ea3632a96c3caa973650b02 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -4380,7 +4380,7 @@ const LLQuaternion LLViewerObject::getRenderRotation() const
 	return ret;
 }
 
-const LLMatrix4 LLViewerObject::getRenderMatrix() const
+const LLMatrix4& LLViewerObject::getRenderMatrix() const
 {
 	return mDrawable->getWorldMatrix();
 }
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index 1ded01ee292a4cc5acb8ee2ccb0e582ca45526d7..cc20a021df56fa65bddea08e97cc20a9ef736b92 100644
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -307,7 +307,7 @@ class LLViewerObject
 	const LLQuaternion getRotationRegion() const;
 	const LLQuaternion getRotationEdit() const;
 	const LLQuaternion getRenderRotation() const;
-	virtual	const LLMatrix4 getRenderMatrix() const;
+	virtual	const LLMatrix4& getRenderMatrix() const;
 
 	void setPosition(const LLVector3 &pos, BOOL damped = FALSE);
 	void setPositionGlobal(const LLVector3d &position, BOOL damped = FALSE);
diff --git a/indra/newview/llviewerpartsource.cpp b/indra/newview/llviewerpartsource.cpp
index 8cbb700f4a12b07fdc32eeae60b6576fa74da009..661ceba7261d6e8b1a7e63a1c79e42c5570a44da 100644
--- a/indra/newview/llviewerpartsource.cpp
+++ b/indra/newview/llviewerpartsource.cpp
@@ -141,10 +141,12 @@ void LLViewerPartSourceScript::update(const F32 dt)
 		return;
 	}
 			
+	LLViewerPartSim& vwrPartSim = LLViewerPartSim::instance();
+
 	F32 old_update_time = mLastUpdateTime;
 	mLastUpdateTime += dt;
 
-	F32 ref_rate_travelspeed = llmin(LLViewerPartSim::getInstance()->getRefRate(), 1.f);
+	F32 ref_rate_travelspeed = llmin(vwrPartSim.getRefRate(), 1.f);
 	
 	F32 dt_update = mLastUpdateTime - mLastPartTime;
 
@@ -213,6 +215,8 @@ void LLViewerPartSourceScript::update(const F32 dt)
 		first_run = TRUE;
 	}
 
+	LLViewerCamera& vwrCamera = LLViewerCamera::instance();
+
 	F32 max_time = llmax(1.f, 10.f*mPartSysData.mBurstRate);
 	dt_update = llmin(max_time, dt_update);
 	while ((dt_update > mPartSysData.mBurstRate) || first_run)
@@ -234,7 +238,7 @@ void LLViewerPartSourceScript::update(const F32 dt)
 			mRotation.setQuat(0, 0, 0);
 		}
 		
-		if (LLViewerPartSim::getInstance()->aboveParticleLimit())
+		if (vwrPartSim.aboveParticleLimit())
 		{
 			// Don't bother doing any more updates if we're above the particle limit,
 			// just give up.
@@ -256,7 +260,7 @@ void LLViewerPartSourceScript::update(const F32 dt)
 				    (mPartSysData.mPartData.mStartScale[1]
 				     + mPartSysData.mPartData.mEndScale[1])/2));
 		
-		F32 pixel_meter_ratio = LLViewerCamera::getInstance()->getPixelMeterRatio();
+		F32 pixel_meter_ratio = vwrCamera.getPixelMeterRatio();
 
 		// Maximum distance at which spawned particles will be viewable
 		F32 max_dist = max_short_side * pixel_meter_ratio; 
@@ -271,7 +275,7 @@ void LLViewerPartSourceScript::update(const F32 dt)
 		}
 
 		// Distance from camera
-		F32 dist = (mPosAgent - LLViewerCamera::getInstance()->getOrigin()).magVec();
+		F32 dist = (mPosAgent - vwrCamera.getOrigin()).magVec();
 
 		// Particle size vs distance vs maxage throttling
 
@@ -295,7 +299,7 @@ void LLViewerPartSourceScript::update(const F32 dt)
 		S32 i;
 		for (i = 0; i < mPartSysData.mBurstPartCount; i++)
 		{
-			if (ll_frand() < llmax(1.0f - LLViewerPartSim::getInstance()->getBurstRate(), limited_rate))
+			if (ll_frand() < llmax(1.0f - vwrPartSim.getBurstRate(), limited_rate))
 			{
 				// Limit particle generation
 				continue;
@@ -436,7 +440,7 @@ void LLViewerPartSourceScript::update(const F32 dt)
 				mPartSysData.mBurstRadius = 0.f; 
 			}
 
-			LLViewerPartSim::getInstance()->addPart(part);
+			vwrPartSim.addPart(part);
 		}
 
 		mLastPartTime = mLastUpdateTime;
@@ -636,7 +640,9 @@ void LLViewerPartSourceSpiral::update(const F32 dt)
 	if (dt_update > RATE)
 	{
 		mLastPartTime = mLastUpdateTime;
-		if (!LLViewerPartSim::getInstance()->shouldAddPart())
+
+		LLViewerPartSim& vwrPartSim = LLViewerPartSim::instance();
+		if (!vwrPartSim.shouldAddPart())
 		{
 			// Particle simulation says we have too many particles, skip all this
 			return;
@@ -664,7 +670,7 @@ void LLViewerPartSourceSpiral::update(const F32 dt)
 		part->mEndGlow = 0.f;
 		part->mGlow = LLColor4U(0, 0, 0, 0);
 
-		LLViewerPartSim::getInstance()->addPart(part);
+		vwrPartSim.addPart(part);
 	}
 }
 
@@ -783,7 +789,9 @@ void LLViewerPartSourceBeam::update(const F32 dt)
 	if (dt_update > RATE)
 	{
 		mLastPartTime = mLastUpdateTime;
-		if (!LLViewerPartSim::getInstance()->shouldAddPart())
+
+		LLViewerPartSim& vwrPartSim = LLViewerPartSim::instance();
+		if (!vwrPartSim.shouldAddPart())
 		{
 			// Particle simulation says we have too many particles, skip all this
 			return;
@@ -820,7 +828,7 @@ void LLViewerPartSourceBeam::update(const F32 dt)
 		part->mEndGlow = 0.f;
 		part->mGlow = LLColor4U(0, 0, 0, 0);
 
-		LLViewerPartSim::getInstance()->addPart(part);
+		vwrPartSim.addPart(part);
 	}
 }
 
@@ -902,7 +910,9 @@ void LLViewerPartSourceChat::update(const F32 dt)
 	if (dt_update > RATE)
 	{
 		mLastPartTime = mLastUpdateTime;
-		if (!LLViewerPartSim::getInstance()->shouldAddPart())
+
+		LLViewerPartSim& vwrPartSim = LLViewerPartSim::instance();
+		if (!vwrPartSim.shouldAddPart())
 		{
 			// Particle simulation says we have too many particles, skip all this
 			return;
@@ -931,7 +941,7 @@ void LLViewerPartSourceChat::update(const F32 dt)
 		part->mGlow = LLColor4U(0, 0, 0, 0);
 
 
-		LLViewerPartSim::getInstance()->addPart(part);
+		vwrPartSim.addPart(part);
 	}
 }
 
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 97158408e86abf05230ce254643032ff0a927d0c..4b48ba048f4b4716e7015dcf5499e352c11c1ddb 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -10268,11 +10268,13 @@ void LLVOAvatar::getImpostorValues(LLVector4a* extents, LLVector3& angle, F32& d
 	extents[0] = ext[0];
 	extents[1] = ext[1];
 
-	LLVector3 at = LLViewerCamera::getInstance()->getOrigin()-(getRenderPosition()+mImpostorOffset);
+	auto& vwrCamera = LLViewerCamera::instance();
+
+	LLVector3 at = vwrCamera.getOrigin()-(getRenderPosition()+mImpostorOffset);
 	distance = at.normalize();
-	F32 da = 1.f - (at*LLViewerCamera::getInstance()->getAtAxis());
-	angle.mV[0] = LLViewerCamera::getInstance()->getYaw()*da;
-	angle.mV[1] = LLViewerCamera::getInstance()->getPitch()*da;
+	F32 da = 1.f - (at* vwrCamera.getAtAxis());
+	angle.mV[0] = vwrCamera.getYaw()*da;
+	angle.mV[1] = vwrCamera.getPitch()*da;
 	angle.mV[2] = da;
 }
 
diff --git a/indra/newview/llvograss.cpp b/indra/newview/llvograss.cpp
index bead7a9599c3f82f6173bac7f6c07af40c1fed57..ba4f2fcc48b43f3c4f0743f4782877addaa65520 100644
--- a/indra/newview/llvograss.cpp
+++ b/indra/newview/llvograss.cpp
@@ -314,7 +314,8 @@ void LLVOGrass::setPixelAreaAndAngle(LLAgent &agent)
 	mAppAngle = (F32) atan2( max_scale, range) * RAD_TO_DEG;
 
 	// Compute pixels per meter at the given range
-	F32 pixels_per_meter = LLViewerCamera::getInstance()->getViewHeightInPixels() / (tan(LLViewerCamera::getInstance()->getView()) * range);
+	auto& viewerCamera = LLViewerCamera::instance();
+	F32 pixels_per_meter = viewerCamera.getViewHeightInPixels() / (tan(viewerCamera.getView()) * range);
 
 	// Assume grass texture is a 5 meter by 5 meter sprite at the grass object's center
 	mPixelArea = (pixels_per_meter) * (pixels_per_meter) * 25.f;
@@ -454,7 +455,8 @@ void LLVOGrass::plantBlades()
 		face->mCenterLocal = mPosition + mRegionp->getOriginAgent();
 	}
 
-	mDepth = (face->mCenterLocal - LLViewerCamera::getInstance()->getOrigin())*LLViewerCamera::getInstance()->getAtAxis();
+	auto& viewerCamera = LLViewerCamera::instance();
+	mDepth = (face->mCenterLocal - viewerCamera.getOrigin())* viewerCamera.getAtAxis();
 	mDrawable->setPosition(face->mCenterLocal);
 	mDrawable->movePartition();
 	LLPipeline::sCompiles++;
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index 8e46ccd555d866fc246536b5ad2aace5b3411635..f37f623a11b3898b2df9c7af32f2e07307afd4a3 100644
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -403,11 +403,13 @@ void LLVOTree::render(LLAgent &agent)
 
 void LLVOTree::setPixelAreaAndAngle(LLAgent &agent)
 {
+	auto& viewerCamera = LLViewerCamera::instance();
+
 	LLVector3 center = getPositionAgent();//center of tree.
 	LLVector3 viewer_pos_agent = gAgentCamera.getCameraPositionAgent();
 	LLVector3 lookAt = center - viewer_pos_agent;
 	F32 dist = lookAt.normVec() ;	
-	F32 cos_angle_to_view_dir = lookAt * LLViewerCamera::getInstance()->getXAxis() ;	
+	F32 cos_angle_to_view_dir = lookAt * viewerCamera.getXAxis() ;
 	
 	F32 range = dist - getMinScale()/2;
 	if (range < F_ALMOST_ZERO || isHUDAttachment())		// range == zero
@@ -422,12 +424,12 @@ void LLVOTree::setPixelAreaAndAngle(LLAgent &agent)
 	F32 max_scale = mBillboardScale * getMaxScale();
 	F32 area = max_scale * (max_scale*mBillboardRatio);
 	// Compute pixels per meter at the given range
-	F32 pixels_per_meter = LLViewerCamera::getInstance()->getViewHeightInPixels() / (tan(LLViewerCamera::getInstance()->getView()) * dist);
+	F32 pixels_per_meter = viewerCamera.getViewHeightInPixels() / (tan(viewerCamera.getView()) * dist);
 	mPixelArea = pixels_per_meter * pixels_per_meter * area ;	
 
 	F32 importance = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
 	mPixelArea = LLFace::adjustPixelArea(importance, mPixelArea) ;
-	if (mPixelArea > LLViewerCamera::getInstance()->getScreenPixelArea())
+	if (mPixelArea > viewerCamera.getScreenPixelArea())
 	{
 		mAppAngle = 180.f;
 	}
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index a562bb0c55bb65fc53b6b7278fc584ff55010773..84f2b609afe39e239c89311d119aaa0a31a25bf5 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -3866,7 +3866,7 @@ BOOL LLVOVolume::isHUDAttachment() const
 }
 
 
-const LLMatrix4 LLVOVolume::getRenderMatrix() const
+const LLMatrix4& LLVOVolume::getRenderMatrix() const
 {
 	if (mDrawable->isActive() && !mDrawable->isRoot())
 	{
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index 9d6095261919f05d8a452443476b8fa6881ca4ec..06a7d24bc2aab4b8f55d7f9b5155fdc71dc1eb04 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -138,7 +138,7 @@ class LLVOVolume final : public LLViewerObject
 	const LLVector3		getPivotPositionAgent() const;
 	const LLMatrix4&	getRelativeXform() const				{ return mRelativeXform; }
 	const LLMatrix3&	getRelativeXformInvTrans() const		{ return mRelativeXformInvTrans; }
-	/*virtual*/	const LLMatrix4	getRenderMatrix() const;
+	/*virtual*/	const LLMatrix4&	getRenderMatrix() const;
 				typedef std::map<LLUUID, S32> texture_cost_t;
 				U32 	getRenderCost(texture_cost_t &textures) const;
     /*virtual*/	F32		getEstTrianglesMax() const;