diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h
index da03230b473a65236ab9d84d5d89a2d37c55cb56..5eefa6a16b2f3f577f0c48e45885091d24f46efd 100644
--- a/indra/llcommon/llpreprocessor.h
+++ b/indra/llcommon/llpreprocessor.h
@@ -123,13 +123,15 @@
 #pragma warning( 3       : 4265 )	// "class has virtual functions, but destructor is not virtual"
 #pragma warning( 3      :  4266 )	// 'function' : no override available for virtual member function from base 'type'; function is hidden
 #pragma warning (disable : 4180)	// qualifier applied to function type has no meaning; ignored
-// Linker optimization with "extern template" generates this innocuous warning
-#pragma warning( disable : 4231 )	// nonstandard extension used : 'extern' before template explicit instantiation
 #pragma warning( disable : 4284 )	// silly MS warning deep inside their <map> include file
 #pragma warning( disable : 4503 )	// 'decorated name length exceeded, name was truncated'. Does not seem to affect compilation.
 #pragma warning( disable : 4800 )	// 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
 #pragma warning( disable : 4996 )	// warning: deprecated
 
+// Linker optimization with "extern template" generates these warnings
+#pragma warning( disable : 4231 )	// nonstandard extension used : 'extern' before template explicit instantiation
+#pragma warning( disable : 4506 )   // no definition for inline function
+
 // level 4 warnings that we need to disable:
 #pragma warning (disable : 4100) // unreferenced formal parameter
 #pragma warning (disable : 4127) // conditional expression is constant (e.g. while(1) )
diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h
index f55fafadd8dff8ea44e9b41eec191d86879a9053..ddeb4d148905bd19fc077bc982db000a6b2cbbc0 100644
--- a/indra/llcommon/llsingleton.h
+++ b/indra/llcommon/llsingleton.h
@@ -35,7 +35,6 @@
 
 #include <typeinfo>
 #include <boost/noncopyable.hpp>
-#include <boost/any.hpp>
 
 /// @brief A global registry of all singletons to prevent duplicate allocations
 /// across shared library boundaries
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp
index 617a97b6cf020665a650e8f92dcf629da0a3f3f2..7721137e291624a5628d10c15510d284614e9bda 100644
--- a/indra/llui/llbutton.cpp
+++ b/indra/llui/llbutton.cpp
@@ -32,6 +32,7 @@
 
 #include "linden_common.h"
 
+#define LLBUTTON_CPP
 #include "llbutton.h"
 
 // Linden library includes
@@ -57,8 +58,8 @@
 static LLDefaultChildRegistry::Register<LLButton> r("button");
 
 // Compiler optimization, generate extern template
-//template class LLButton* LLView::getChild<class LLButton>(
-//	const std::string& name, BOOL recurse) const;
+template class LLButton* LLView::getChild<class LLButton>(
+	const std::string& name, BOOL recurse) const;
 
 // globals loaded from settings.xml
 S32	LLBUTTON_H_PAD	= 0;
diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h
index 8c3b4bd859ea3bf7e008136b6c0eef39414df067..4c7400220d1883eeda4cb52ab25571683ec85aba 100644
--- a/indra/llui/llbutton.h
+++ b/indra/llui/llbutton.h
@@ -322,5 +322,10 @@ class LLButton
 	LLFrameTimer				mFlashingTimer;
 };
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLBUTTON_CPP
+extern template class LLButton* LLView::getChild<class LLButton>(
+	const std::string& name, BOOL recurse) const;
+#endif
 
 #endif  // LL_LLBUTTON_H
diff --git a/indra/llui/llcheckboxctrl.cpp b/indra/llui/llcheckboxctrl.cpp
index 3c5925f9657bc3851392cab31ff59a4b6b4a188d..cd10dfdb1c4d363a04c3380e5943565019b8576a 100644
--- a/indra/llui/llcheckboxctrl.cpp
+++ b/indra/llui/llcheckboxctrl.cpp
@@ -33,6 +33,7 @@
 // The mutants are coming!
 #include "linden_common.h"
 
+#define LLCHECKBOXCTRL_CPP
 #include "llcheckboxctrl.h"
 
 #include "llgl.h"
@@ -51,8 +52,8 @@ const U32 MAX_STRING_LENGTH = 10;
 static LLDefaultChildRegistry::Register<LLCheckBoxCtrl> r("check_box");
 
 // Compiler optimization, generate extern template
-//template class LLCheckBoxCtrl* LLView::getChild<class LLCheckBoxCtrl>(
-//	const std::string& name, BOOL recurse) const;
+template class LLCheckBoxCtrl* LLView::getChild<class LLCheckBoxCtrl>(
+	const std::string& name, BOOL recurse) const;
 
 LLCheckBoxCtrl::Params::Params()
 :	text_enabled_color("text_enabled_color"),
diff --git a/indra/llui/llcheckboxctrl.h b/indra/llui/llcheckboxctrl.h
index b14e66b91500dcbf698c98f226e29b8a358e4452..28d50f957d7d9b754a6dd22f8fbe9727a2e9682d 100644
--- a/indra/llui/llcheckboxctrl.h
+++ b/indra/llui/llcheckboxctrl.h
@@ -126,5 +126,10 @@ class LLCheckBoxCtrl
 	LLUIColor		mTextDisabledColor;
 };
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLCHECKBOXCTRL_CPP
+extern template class LLCheckBoxCtrl* LLView::getChild<class LLCheckBoxCtrl>(
+	const std::string& name, BOOL recurse) const;
+#endif
 
 #endif  // LL_LLCHECKBOXCTRL_H
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index 1551aab192faf344e551b9c8ad8e5a226c8bbd22..8a21155cc3a0ab4b58b787f4a55ca6f4c487c84e 100644
--- a/indra/llui/lllineeditor.cpp
+++ b/indra/llui/lllineeditor.cpp
@@ -34,6 +34,7 @@
 
 #include "linden_common.h"
  
+#define LLLINEEDITOR_CPP
 #include "lllineeditor.h"
 
 #include "lltexteditor.h"
@@ -72,8 +73,8 @@ const F32	TRIPLE_CLICK_INTERVAL = 0.3f;	// delay between double and triple click
 static LLDefaultChildRegistry::Register<LLLineEditor> r1("line_editor");
 
 // Compiler optimization, generate extern template
-//template class LLLineEditor* LLView::getChild<class LLLineEditor>(
-//	const std::string& name, BOOL recurse) const;
+template class LLLineEditor* LLView::getChild<class LLLineEditor>(
+	const std::string& name, BOOL recurse) const;
 
 //
 // Member functions
diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h
index b96220e0207bef8831f0ca36faf6a7d18356db63..49e9539b16d7265ccc81bca3277a23f43477f392 100644
--- a/indra/llui/lllineeditor.h
+++ b/indra/llui/lllineeditor.h
@@ -395,5 +395,10 @@ class LLLineEditor
 
 }; // end class LLLineEditor
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLLINEEDITOR_CPP
+extern template class LLLineEditor* LLView::getChild<class LLLineEditor>(
+	const std::string& name, BOOL recurse) const;
+#endif
 
 #endif  // LL_LINEEDITOR_
diff --git a/indra/llui/llpanel.cpp b/indra/llui/llpanel.cpp
index dc5db03a44f6675890d742dfdc059eaaff784076..750b1909538055bcdca79e5799250fcd4ff3979b 100644
--- a/indra/llui/llpanel.cpp
+++ b/indra/llui/llpanel.cpp
@@ -34,6 +34,7 @@
 
 #include "linden_common.h"
 
+#define LLPANEL_CPP
 #include "llpanel.h"
 
 #include "llalertdialog.h"
@@ -59,8 +60,8 @@
 static LLDefaultChildRegistry::Register<LLPanel> r1("panel", &LLPanel::fromXML);
 
 // Compiler optimization, generate extern template
-//template class LLPanel* LLView::getChild<class LLPanel>(
-//	const std::string& name, BOOL recurse) const;
+template class LLPanel* LLView::getChild<class LLPanel>(
+	const std::string& name, BOOL recurse) const;
 
 LLPanel::LocalizedString::LocalizedString()
 :	name("name"),
diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h
index 0a0fed82fbddc1b994f2dcf4fbe5fb5937846367..a8bd5fd5e549db3a633ee1f0b30a5de05d6cc37c 100644
--- a/indra/llui/llpanel.h
+++ b/indra/llui/llpanel.h
@@ -275,4 +275,10 @@ class LLPanel : public LLUICtrl
 
 }; // end class LLPanel
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLPANEL_CPP
+extern template class LLPanel* LLView::getChild<class LLPanel>(
+	const std::string& name, BOOL recurse) const;
+#endif
+
 #endif
diff --git a/indra/llui/lltextbox.cpp b/indra/llui/lltextbox.cpp
index 4bd9a32b1d7568eb6f2f6e222a9aaf25c278ba11..0bd0ab59fb1851b734f9e0ca494648388e18394b 100644
--- a/indra/llui/lltextbox.cpp
+++ b/indra/llui/lltextbox.cpp
@@ -31,7 +31,10 @@
  */
 
 #include "linden_common.h"
+
+#define LLTEXTBOX_CPP
 #include "lltextbox.h"
+
 #include "lluictrlfactory.h"
 #include "llfocusmgr.h"
 #include "llwindow.h"
@@ -41,8 +44,8 @@
 static LLDefaultChildRegistry::Register<LLTextBox> r("text");
 
 // Compiler optimization, generate extern template
-//template class LLTextBox* LLView::getChild<class LLTextBox>(
-//	const std::string& name, BOOL recurse) const;
+template class LLTextBox* LLView::getChild<class LLTextBox>(
+	const std::string& name, BOOL recurse) const;
 
 LLTextBox::LLTextBox(const LLTextBox::Params& p)
 :	LLTextBase(p),
diff --git a/indra/llui/lltextbox.h b/indra/llui/lltextbox.h
index 01b4bfa5ed68725d1e29e22af7b09ee4293b1277..3a045534d38d781b31fad0528a79d12fc627cb3f 100644
--- a/indra/llui/lltextbox.h
+++ b/indra/llui/lltextbox.h
@@ -79,4 +79,10 @@ class LLTextBox :
 	callback_t			mClickedCallback;
 };
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLTEXTBOX_CPP
+extern template class LLTextBox* LLView::getChild<class LLTextBox>(
+	const std::string& name, BOOL recurse) const;
+#endif
+
 #endif
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 6e07a890ade842a8803195fc3a4d682d11d77e30..e68affc36c605cd9f125518d93c7c69a1aa483c8 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -1,6 +1,5 @@
 /** 
  * @file lltexteditor.cpp
- * @brief LLTextEditor base class
  *
  * $LicenseInfo:firstyear=2001&license=viewergpl$
  * 
@@ -34,6 +33,7 @@
 
 #include "linden_common.h"
 
+#define LLTEXTEDITOR_CPP
 #include "lltexteditor.h"
 
 #include "llfontfreetype.h" // for LLFontFreetype::FIRST_CHAR
@@ -74,8 +74,8 @@
 static LLDefaultChildRegistry::Register<LLTextEditor> r("simple_text_editor");
 
 // Compiler optimization, generate extern template
-//template class LLTextEditor* LLView::getChild<class LLTextEditor>(
-//	const std::string& name, BOOL recurse) const;
+template class LLTextEditor* LLView::getChild<class LLTextEditor>(
+	const std::string& name, BOOL recurse) const;
 
 //
 // Constants
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h
index fb014b86bf873abcca1a88a72963d5bb0265c24a..043dda8fa6283de243f8556f4111178d46006c23 100644
--- a/indra/llui/lltexteditor.h
+++ b/indra/llui/lltexteditor.h
@@ -334,5 +334,10 @@ class LLTextEditor :
 	LLContextMenu* mContextMenu;
 }; // end class LLTextEditor
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLTEXTEDITOR_CPP
+extern template class LLTextEditor* LLView::getChild<class LLTextEditor>(
+	const std::string& name, BOOL recurse) const;
+#endif
 
 #endif  // LL_TEXTEDITOR_
diff --git a/indra/llui/lluictrl.cpp b/indra/llui/lluictrl.cpp
index 3cf592f35129f123fe2eb8bd50e29377f6064eb6..1e0af1201f6619e2dc6487049dec9aa4557491c7 100644
--- a/indra/llui/lluictrl.cpp
+++ b/indra/llui/lluictrl.cpp
@@ -31,9 +31,11 @@
  * $/LicenseInfo$
  */
 
-//#include "llviewerprecompiledheaders.h"
 #include "linden_common.h"
+
+#define LLUICTRL_CPP
 #include "lluictrl.h"
+
 #include "llfocusmgr.h"
 #include "llpanel.h"
 #include "lluictrlfactory.h"
@@ -41,8 +43,8 @@
 static LLDefaultChildRegistry::Register<LLUICtrl> r("ui_ctrl");
 
 // Compiler optimization, generate extern template
-//template class LLUICtrl* LLView::getChild<class LLUICtrl>(
-//	const std::string& name, BOOL recurse) const;
+template class LLUICtrl* LLView::getChild<class LLUICtrl>(
+	const std::string& name, BOOL recurse) const;
 
 LLUICtrl::Params::Params()
 :	tab_stop("tab_stop", true),
diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h
index aef1bcd5194341e7d545956f2b155628e63d6398..ac916c9a4324a89fa37e5a97263f9b0fd0eeac85 100644
--- a/indra/llui/lluictrl.h
+++ b/indra/llui/lluictrl.h
@@ -328,4 +328,10 @@ class LLUICtrl
 	class DefaultTabGroupFirstSorter;
 };
 
+// Build time optimization, generate once in .cpp file
+#ifndef LLUICTRL_CPP
+extern template class LLUICtrl* LLView::getChild<class LLUICtrl>(
+	const std::string& name, BOOL recurse) const;
+#endif
+
 #endif  // LL_LLUICTRL_H
diff --git a/indra/llui/lluictrlfactory.cpp b/indra/llui/lluictrlfactory.cpp
index 49182be328c27fe8b85af50f03c8dcd789bac4f9..3643bf44f792478a4fea8797841d7c1a9dd2b9eb 100644
--- a/indra/llui/lluictrlfactory.cpp
+++ b/indra/llui/lluictrlfactory.cpp
@@ -32,6 +32,7 @@
 
 #include "linden_common.h"
 
+#define LLUICTRLFACTORY_CPP
 #include "lluictrlfactory.h"
 
 #include "llxmlnode.h"
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index e021c04ad64c4704442af505fd29f7e493b6d7c3..55d7d745ebbec0123f25b29da280e43c6e23e0e4 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -109,7 +109,9 @@ extern LLFastTimer::DeclareTimer FTM_WIDGET_CONSTRUCTION;
 extern LLFastTimer::DeclareTimer FTM_INIT_FROM_PARAMS;
 
 // Build time optimization, generate this once in .cpp file
-//extern template class LLUICtrlFactory* LLSingleton<class LLUICtrlFactory>::getInstance();
+#ifndef LLUICTRLFACTORY_CPP
+extern template class LLUICtrlFactory* LLSingleton<class LLUICtrlFactory>::getInstance();
+#endif
 
 class LLUICtrlFactory : public LLSingleton<LLUICtrlFactory>
 {
diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp
index ef23268a143bcc8f17441d9b303b5fd15e991d44..e7e8b1b858acdca90bec68f06dc11857da22c443 100644
--- a/indra/llui/llview.cpp
+++ b/indra/llui/llview.cpp
@@ -33,6 +33,7 @@
 
 #include "linden_common.h"
 
+#define LLVIEW_CPP
 #include "llview.h"
 
 #include <cassert>
@@ -77,7 +78,8 @@ BOOL LLView::sIsDrawing = FALSE;
 #endif
 
 // Compiler optimization, generate extern template
-//template class LLView* LLView::getChild<class LLView>(const std::string& name, BOOL recurse) const;
+template class LLView* LLView::getChild<class LLView>(
+	const std::string& name, BOOL recurse) const;
 
 static LLDefaultChildRegistry::Register<LLView> r("view");
 
diff --git a/indra/llui/llview.h b/indra/llui/llview.h
index 1b12e785099db82b65944e308286a63ece425bcb..8ee05675c19125d76d1a2daa5129f1b075e84fc9 100644
--- a/indra/llui/llview.h
+++ b/indra/llui/llview.h
@@ -661,21 +661,9 @@ template <class T> T* LLView::getChild(const std::string& name, BOOL recurse) co
 
 // Compiler optimization - don't generate these specializations inline,
 // require explicit specialization.  See llbutton.cpp for an example.
-//extern template class LLButton* LLView::getChild<class LLButton>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLCheckBoxCtrl* LLView::getChild<class LLCheckBoxCtrl>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLLineEditor* LLView::getChild<class LLLineEditor>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLPanel* LLView::getChild<class LLPanel>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLTextBox* LLView::getChild<class LLTextBox>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLTextEditor* LLView::getChild<class LLTextEditor>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLUICtrl* LLView::getChild<class LLUICtrl>(
-//	const std::string& name, BOOL recurse) const;
-//extern template class LLView* LLView::getChild<class LLView>(
-//	const std::string& name, BOOL recurse) const;
+#ifndef LLVIEW_CPP
+extern template class LLView* LLView::getChild<class LLView>(
+	const std::string& name, BOOL recurse) const;
+#endif
 
 #endif //LL_LLVIEW_H
diff --git a/indra/newview/llbottomtray.cpp b/indra/newview/llbottomtray.cpp
index 4823932951b2e56d11d37cc5e5cc3913b584b8c5..c44b0b533199bc510de71e5d8f27e6d3b72d8d5b 100644
--- a/indra/newview/llbottomtray.cpp
+++ b/indra/newview/llbottomtray.cpp
@@ -31,6 +31,8 @@
  */
 
 #include "llviewerprecompiledheaders.h" // must be first include
+
+#define LLBOTTOMTRAY_CPP
 #include "llbottomtray.h"
 
 #include "llagent.h"
@@ -46,7 +48,7 @@
 #include "llsyswellwindow.h"
 #include "llfloatercamera.h"
 
-// Build time optimization, generate this once in .cpp file
+// Build time optimization, generate extern template once in .cpp file
 template class LLBottomTray* LLSingleton<class LLBottomTray>::getInstance();
 
 LLBottomTray::LLBottomTray(const LLSD&)
diff --git a/indra/newview/llbottomtray.h b/indra/newview/llbottomtray.h
index 30f5f88cce9ef4ea38800a8c108892d2037f0c5d..728a4203247a5f1d815b083da8713dae93efe88a 100644
--- a/indra/newview/llbottomtray.h
+++ b/indra/newview/llbottomtray.h
@@ -47,8 +47,10 @@ class LLSpeakButton;
 class LLNearbyChatBar;
 class LLIMChiclet;
 
-// Build time optimization, generate this once in .cpp file
-//extern template class LLBottomTray* LLSingleton<class LLBottomTray>::getInstance();
+// Build time optimization, generate once in .cpp file
+#ifndef LLBOTTOMTRAY_CPP
+extern template class LLBottomTray* LLSingleton<class LLBottomTray>::getInstance();
+#endif
 
 class LLBottomTray 
 	: public LLSingleton<LLBottomTray>
diff --git a/indra/newview/lldynamictexture.cpp b/indra/newview/lldynamictexture.cpp
index 9bc7221dc87487bfe851f8023e8cdcea690f56d6..c7c79401a0fa843a61588f6cf2f04d51fd7e7233 100644
--- a/indra/newview/lldynamictexture.cpp
+++ b/indra/newview/lldynamictexture.cpp
@@ -141,11 +141,12 @@ void LLViewerDynamicTexture::preRender(BOOL clear_depth)
 		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 	}
 	// Set up camera
-	mCamera.setOrigin(*LLViewerCamera::getInstance());
-	mCamera.setAxes(*LLViewerCamera::getInstance());
-	mCamera.setAspect(LLViewerCamera::getInstance()->getAspect());
-	mCamera.setView(LLViewerCamera::getInstance()->getView());
-	mCamera.setNear(LLViewerCamera::getInstance()->getNear());
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
+	mCamera.setOrigin(*camera);
+	mCamera.setAxes(*camera);
+	mCamera.setAspect(camera->getAspect());
+	mCamera.setView(camera->getView());
+	mCamera.setNear(camera->getNear());
 
 	glViewport(mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight);
 	if (clear_depth)
@@ -174,11 +175,12 @@ void LLViewerDynamicTexture::postRender(BOOL success)
 	gViewerWindow->setup2DViewport();
 
 	// restore camera
-	LLViewerCamera::getInstance()->setOrigin(mCamera);
-	LLViewerCamera::getInstance()->setAxes(mCamera);
-	LLViewerCamera::getInstance()->setAspect(mCamera.getAspect());
-	LLViewerCamera::getInstance()->setView(mCamera.getView());
-	LLViewerCamera::getInstance()->setNear(mCamera.getNear());
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
+	camera->setOrigin(mCamera);
+	camera->setAxes(mCamera);
+	camera->setAspect(mCamera.getAspect());
+	camera->setView(mCamera.getView());
+	camera->setNear(mCamera.getNear());
 }
 
 //-----------------------------------------------------------------------------
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 31f1462a12b72581c09c922b09927c3b861a44e9..eef774426a0a0ae530ea23891e1e5a91d0ca43cb 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1378,7 +1378,8 @@ F32 LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
 	LLVector3 center = getPositionAgent();
 	LLVector3 size = (mExtents[1] - mExtents[0]) * 0.5f;
 	
-	LLVector3 lookAt = center - LLViewerCamera::getInstance()->getOrigin();
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
+	LLVector3 lookAt = center - camera->getOrigin();
 	F32 dist = lookAt.normVec() ;
 
 	//get area of circle around node
@@ -1393,7 +1394,7 @@ F32 LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
 	}
 	else
 	{
-		cos_angle_to_view_dir = lookAt * LLViewerCamera::getInstance()->getXAxis() ;	
+		cos_angle_to_view_dir = lookAt * camera->getXAxis() ;	
 		mImportanceToCamera = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
 	}
 
@@ -1443,8 +1444,9 @@ F32 LLFace::calcImportanceToCamera(F32 cos_angle_to_view_dir, F32 dist)
 	if(cos_angle_to_view_dir > LLViewerCamera::getInstance()->getCosHalfFov() && 
 		dist < FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL - 1][0]) 
 	{
-		F32 camera_moving_speed = LLViewerCamera::getInstance()->getAverageSpeed() ;
-		F32 camera_angular_speed = LLViewerCamera::getInstance()->getAverageAngularSpeed();
+		LLViewerCamera* camera = LLViewerCamera::getInstance();
+		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/llhudicon.cpp b/indra/newview/llhudicon.cpp
index 040027c70d6e509d59b3b9ebcf20f48a5d773a18..28b0e7356a1e50ef14d929e8a5a88f2ccbde1573 100644
--- a/indra/newview/llhudicon.cpp
+++ b/indra/newview/llhudicon.cpp
@@ -103,28 +103,29 @@ void LLHUDIcon::renderIcon(BOOL for_select)
 
 	// put icon above object, and in front
 	// RN: don't use drawable radius, it's fricking HUGE
-	LLVector3 icon_relative_pos = (LLViewerCamera::getInstance()->getUpAxis() * ~mSourceObject->getRenderRotation());
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
+	LLVector3 icon_relative_pos = (camera->getUpAxis() * ~mSourceObject->getRenderRotation());
 	icon_relative_pos.abs();
 
 	F32 distance_scale = llmin(mSourceObject->getScale().mV[VX] / icon_relative_pos.mV[VX], 
 		mSourceObject->getScale().mV[VY] / icon_relative_pos.mV[VY], 
 		mSourceObject->getScale().mV[VZ] / icon_relative_pos.mV[VZ]);
 	F32 up_distance = 0.5f * distance_scale;
-	LLVector3 icon_position = obj_position + (up_distance * LLViewerCamera::getInstance()->getUpAxis()) * 1.2f;
+	LLVector3 icon_position = obj_position + (up_distance * camera->getUpAxis()) * 1.2f;
 
 	LLVector3 icon_to_cam = LLViewerCamera::getInstance()->getOrigin() - icon_position;
 	icon_to_cam.normVec();
 
 	icon_position += icon_to_cam * mSourceObject->mDrawable->getRadius() * 1.1f;
 
-	mDistance = dist_vec(icon_position, LLViewerCamera::getInstance()->getOrigin());
+	mDistance = dist_vec(icon_position, camera->getOrigin());
 
 	F32 alpha_factor = for_select ? 1.f : clamp_rescale(mDistance, DIST_START_FADE, DIST_END_FADE, 1.f, 0.f);
 
 	LLVector3 x_pixel_vec;
 	LLVector3 y_pixel_vec;
 	
-	LLViewerCamera::getInstance()->getPixelVectors(icon_position, y_pixel_vec, x_pixel_vec);
+	camera->getPixelVectors(icon_position, y_pixel_vec, x_pixel_vec);
 
 	F32 scale_factor = 1.f;
 	if (mAnimTimer.getElapsedTimeF32() < ANIM_TIME)
@@ -226,26 +227,27 @@ BOOL LLHUDIcon::lineSegmentIntersect(const LLVector3& start, const LLVector3& en
 
 	// put icon above object, and in front
 	// RN: don't use drawable radius, it's fricking HUGE
-	LLVector3 icon_relative_pos = (LLViewerCamera::getInstance()->getUpAxis() * ~mSourceObject->getRenderRotation());
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
+	LLVector3 icon_relative_pos = (camera->getUpAxis() * ~mSourceObject->getRenderRotation());
 	icon_relative_pos.abs();
 
 	F32 distance_scale = llmin(mSourceObject->getScale().mV[VX] / icon_relative_pos.mV[VX], 
 		mSourceObject->getScale().mV[VY] / icon_relative_pos.mV[VY], 
 		mSourceObject->getScale().mV[VZ] / icon_relative_pos.mV[VZ]);
 	F32 up_distance = 0.5f * distance_scale;
-	LLVector3 icon_position = obj_position + (up_distance * LLViewerCamera::getInstance()->getUpAxis()) * 1.2f;
+	LLVector3 icon_position = obj_position + (up_distance * camera->getUpAxis()) * 1.2f;
 
 	LLVector3 icon_to_cam = LLViewerCamera::getInstance()->getOrigin() - icon_position;
 	icon_to_cam.normVec();
 
 	icon_position += icon_to_cam * mSourceObject->mDrawable->getRadius() * 1.1f;
 
-	mDistance = dist_vec(icon_position, LLViewerCamera::getInstance()->getOrigin());
+	mDistance = dist_vec(icon_position, camera->getOrigin());
 
 	LLVector3 x_pixel_vec;
 	LLVector3 y_pixel_vec;
 	
-	LLViewerCamera::getInstance()->getPixelVectors(icon_position, y_pixel_vec, x_pixel_vec);
+	camera->getPixelVectors(icon_position, y_pixel_vec, x_pixel_vec);
 
 	F32 scale_factor = 1.f;
 	if (mAnimTimer.getElapsedTimeF32() < ANIM_TIME)
diff --git a/indra/newview/llhudrender.cpp b/indra/newview/llhudrender.cpp
index ab0be90defa82611b96f3ad214b782b8049da093..a02dc3355b12c197b1ae38ef9bee785b698774e7 100644
--- a/indra/newview/llhudrender.cpp
+++ b/indra/newview/llhudrender.cpp
@@ -64,11 +64,12 @@ void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
 					const LLColor4& color,
 					const BOOL orthographic)
 {
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	// Do cheap plane culling
-	LLVector3 dir_vec = pos_agent - LLViewerCamera::getInstance()->getOrigin();
+	LLVector3 dir_vec = pos_agent - camera->getOrigin();
 	dir_vec /= dir_vec.magVec();
 
-	if (wstr.empty() || (!orthographic && dir_vec * LLViewerCamera::getInstance()->getAtAxis() <= 0.f))
+	if (wstr.empty() || (!orthographic && dir_vec * camera->getAtAxis() <= 0.f))
 	{
 		return;
 	}
@@ -82,15 +83,15 @@ void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
 	}
 	else
 	{
-		LLViewerCamera::getInstance()->getPixelVectors(pos_agent, up_axis, right_axis);
+		camera->getPixelVectors(pos_agent, up_axis, right_axis);
 	}
-	LLCoordFrame render_frame = *LLViewerCamera::getInstance();
+	LLCoordFrame render_frame = *camera;
 	LLQuaternion rot;
 	if (!orthographic)
 	{
 		rot = render_frame.getQuaternion();
-		rot = rot * LLQuaternion(-F_PI_BY_TWO, LLViewerCamera::getInstance()->getYAxis());
-		rot = rot * LLQuaternion(F_PI_BY_TWO, LLViewerCamera::getInstance()->getXAxis());
+		rot = rot * LLQuaternion(-F_PI_BY_TWO, camera->getYAxis());
+		rot = rot * LLQuaternion(F_PI_BY_TWO, camera->getXAxis());
 	}
 	else
 	{
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index 4394271ec42f2af588d5d0e50782694dc2566198..1605838b94943c168aa42ba592305c3fa27bc9b0 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -33,6 +33,7 @@
 #include "llviewerprecompiledheaders.h"
 
 // file include
+#define LLSELECTMGR_CPP
 #include "llselectmgr.h"
 
 // library includes
diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h
index 57e0ee4e0e10320bc0cc2e6da37f999d16268b98..6641be335a9840ec5d91d8f3ea1f86c51c015a07 100644
--- a/indra/newview/llselectmgr.h
+++ b/indra/newview/llselectmgr.h
@@ -324,7 +324,9 @@ class LLObjectSelection : public LLRefCount
 typedef LLSafeHandle<LLObjectSelection> LLObjectSelectionHandle;
 
 // Build time optimization, generate this once in .cpp file
-//extern template class LLSelectMgr* LLSingleton<class LLSelectMgr>::getInstance();
+#ifndef LLSELECTMGR_CPP
+extern template class LLSelectMgr* LLSingleton<class LLSelectMgr>::getInstance();
+#endif
 
 class LLSelectMgr : public LLEditMenuHandler, public LLSingleton<LLSelectMgr>
 {
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index 221db2defae0bcc0e95fe16679dd4a65f30e9156..bd4f17290734a233cadad7cd8069c0ae4a965f21 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -32,6 +32,7 @@
 
 #include "llviewerprecompiledheaders.h"
 
+#define LLVIEWERCAMERA_CPP
 #include "llviewercamera.h"
 
 // Viewer includes
diff --git a/indra/newview/llviewercamera.h b/indra/newview/llviewercamera.h
index bf561c3e4d875a1e9f6de93936f7871c0d717c78..cd67af5fef74988f7baac552d9b1e3f1a46a3eee 100644
--- a/indra/newview/llviewercamera.h
+++ b/indra/newview/llviewercamera.h
@@ -53,7 +53,9 @@ const BOOL FOR_SELECTION = TRUE;
 const BOOL NOT_FOR_SELECTION = FALSE;
 
 // Build time optimization, generate this once in .cpp file
-//extern template class LLViewerCamera* LLSingleton<class LLViewerCamera>::getInstance();
+#ifndef LLVIEWERCAMERA_CPP
+extern template class LLViewerCamera* LLSingleton<class LLViewerCamera>::getInstance();
+#endif
 
 class LLViewerCamera : public LLCamera, public LLSingleton<LLViewerCamera>
 {
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index e491e119601e10c75344bc475e490284c22027ce..3c79045cc588c6a72ec49a89cbf8bdfe3c0fa00a 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -2767,22 +2767,23 @@ void LLViewerObject::setPixelAreaAndAngle(LLAgent &agent)
 	// I don't think there's a better way to do this without calculating distance per-poly
 	F32 range = sqrt(dx*dx + dy*dy + dz*dz) - min_scale/2;
 
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	if (range < 0.001f || isHUDAttachment())		// range == zero
 	{
 		mAppAngle = 180.f;
-		mPixelArea = (F32)LLViewerCamera::getInstance()->getScreenPixelArea();
+		mPixelArea = (F32)camera->getScreenPixelArea();
 	}
 	else
 	{
 		mAppAngle = (F32) atan2( max_scale, range) * RAD_TO_DEG;
 
-		F32 pixels_per_meter = LLViewerCamera::getInstance()->getPixelMeterRatio() / range;
+		F32 pixels_per_meter = camera->getPixelMeterRatio() / range;
 
 		mPixelArea = (pixels_per_meter * max_scale) * (pixels_per_meter * mid_scale);
-		if (mPixelArea > LLViewerCamera::getInstance()->getScreenPixelArea())
+		if (mPixelArea > camera->getScreenPixelArea())
 		{
 			mAppAngle = 180.f;
-			mPixelArea = (F32)LLViewerCamera::getInstance()->getScreenPixelArea();
+			mPixelArea = (F32)camera->getScreenPixelArea();
 		}
 	}
 }
diff --git a/indra/newview/llviewerparceloverlay.cpp b/indra/newview/llviewerparceloverlay.cpp
index 9896adad9745e2e3474b4ab589397f096f6e357e..9de1ef719059701d84194d8253bb7305fe0487d3 100644
--- a/indra/newview/llviewerparceloverlay.cpp
+++ b/indra/newview/llviewerparceloverlay.cpp
@@ -808,6 +808,7 @@ S32 LLViewerParcelOverlay::renderPropertyLines	()
 	S32 drawn = 0;
 	F32* vertexp;
 	U8* colorp;
+	bool render_hidden = LLSelectMgr::sRenderHiddenSelections && LLFloaterReg::instanceVisible("build");
 
 	const F32 PROPERTY_LINE_CLIP_DIST = 256.f;
 
@@ -849,7 +850,7 @@ S32 LLViewerParcelOverlay::renderPropertyLines	()
 
 		gGL.end();
 		
-		if (LLSelectMgr::sRenderHiddenSelections && LLFloaterReg::instanceVisible("build"))
+		if (render_hidden)
 		{
 			LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
 			
diff --git a/indra/newview/llviewerpartsim.cpp b/indra/newview/llviewerpartsim.cpp
index cfb83404620703f0d3c945863d42f851f5896d3b..841a7ccc5e88439a088e0cf826463fcadb3d08d2 100644
--- a/indra/newview/llviewerpartsim.cpp
+++ b/indra/newview/llviewerpartsim.cpp
@@ -71,9 +71,9 @@ const F32 LLViewerPartSim::PART_ADAPT_RATE_MULT_RECIP = 1.0f/PART_ADAPT_RATE_MUL
 
 U32 LLViewerPart::sNextPartID = 1;
 
-F32 calc_desired_size(LLVector3 pos, LLVector2 scale)
+F32 calc_desired_size(LLViewerCamera* camera, LLVector3 pos, LLVector2 scale)
 {
-	F32 desired_size = (pos-LLViewerCamera::getInstance()->getOrigin()).magVec();
+	F32 desired_size = (pos - camera->getOrigin()).magVec();
 	desired_size /= 4;
 	return llclamp(desired_size, scale.magVec()*0.5f, PART_SIM_BOX_SIDE*2);
 }
@@ -273,6 +273,7 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt)
 
 	LLViewerPartSim::checkParticleCount(mParticles.size());
 
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	LLViewerRegion *regionp = getRegion();
 	S32 end = (S32) mParticles.size();
 	for (S32 i = 0 ; i < (S32)mParticles.size();)
@@ -394,7 +395,7 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt)
 		}
 		else 
 		{
-			F32 desired_size = calc_desired_size(part->mPosAgent, part->mScale);
+			F32 desired_size = calc_desired_size(camera, part->mPosAgent, part->mScale);
 			if (!posInGroup(part->mPosAgent, desired_size))
 			{
 				// Transfer particles between groups
@@ -557,7 +558,8 @@ LLViewerPartGroup *LLViewerPartSim::put(LLViewerPart* part)
 	}
 	else
 	{	
-		F32 desired_size = calc_desired_size(part->mPosAgent, part->mScale);
+		LLViewerCamera* camera = LLViewerCamera::getInstance();
+		F32 desired_size = calc_desired_size(camera, part->mPosAgent, part->mScale);
 
 		S32 count = (S32) mViewerPartGroups.size();
 		for (S32 i = 0; i < count; i++)
diff --git a/indra/newview/llvoicevisualizer.cpp b/indra/newview/llvoicevisualizer.cpp
index e777d7362f7ec18abe2a2c7dbf7bc3154e2d96cf..4794cab32e51cb70ddedd413a544d352d9af5f53 100644
--- a/indra/newview/llvoicevisualizer.cpp
+++ b/indra/newview/llvoicevisualizer.cpp
@@ -369,8 +369,9 @@ void LLVoiceVisualizer::render()
 		//-------------------------------------------------------------
 		// create coordinates of the geometry for the dot
 		//-------------------------------------------------------------
-		LLVector3 l	= LLViewerCamera::getInstance()->getLeftAxis() * DOT_SIZE;
-		LLVector3 u	= LLViewerCamera::getInstance()->getUpAxis()   * DOT_SIZE;
+		LLViewerCamera* camera = LLViewerCamera::getInstance();
+		LLVector3 l	= camera->getLeftAxis() * DOT_SIZE;
+		LLVector3 u	= camera->getUpAxis()   * DOT_SIZE;
 
 		LLVector3 bottomLeft	= mSoundSymbol.mPosition + l - u;
 		LLVector3 bottomRight	= mSoundSymbol.mPosition - l - u;
@@ -496,8 +497,8 @@ void LLVoiceVisualizer::render()
 				F32 width	= i * WAVE_WIDTH_SCALE  * mSoundSymbol.mWaveExpansion[i];
 				F32 height	= i * WAVE_HEIGHT_SCALE * mSoundSymbol.mWaveExpansion[i];
 
-				LLVector3 l	= LLViewerCamera::getInstance()->getLeftAxis() * width;
-				LLVector3 u	= LLViewerCamera::getInstance()->getUpAxis()   * height;
+				LLVector3 l	= camera->getLeftAxis() * width;
+				LLVector3 u	= camera->getUpAxis()   * height;
 
 				LLVector3 bottomLeft	= mSoundSymbol.mPosition + l - u;
 				LLVector3 bottomRight	= mSoundSymbol.mPosition - l - u;
diff --git a/indra/newview/llvopartgroup.cpp b/indra/newview/llvopartgroup.cpp
index 9dd0b598dc549d08c1d4f9c4ee631c252dbe7c7d..139d2fbd8837aed320db6344967e56b4d1c22a78 100644
--- a/indra/newview/llvopartgroup.cpp
+++ b/indra/newview/llvopartgroup.cpp
@@ -386,6 +386,7 @@ void LLParticlePartition::addGeometryCount(LLSpatialGroup* group, U32& vertex_co
 
 	mFaceList.clear();
 
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i)
 	{
 		LLDrawable* drawablep = *i;
@@ -415,7 +416,7 @@ void LLParticlePartition::addGeometryCount(LLSpatialGroup* group, U32& vertex_co
 			}
 			
 			count++;
-			facep->mDistance = (facep->mCenterLocal - LLViewerCamera::getInstance()->getOrigin()) * LLViewerCamera::getInstance()->getAtAxis();
+			facep->mDistance = (facep->mCenterLocal - camera->getOrigin()) * camera->getAtAxis();
 			obj->mDepth += facep->mDistance;
 			
 			mFaceList.push_back(facep);
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 48bd3870226b59e4854bec13648a43fd808a3ff6..1ee0811ba646916ae397cd99757bdcdf0bd60b9b 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -622,6 +622,7 @@ void LLVOVolume::updateTextureVirtualSize()
 
 	const S32 num_faces = mDrawable->getNumFaces();
 	F32 min_vsize=999999999.f, max_vsize=0.f;
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	for (S32 i = 0; i < num_faces; i++)
 	{
 		LLFace* face = mDrawable->getFace(i);
@@ -638,7 +639,7 @@ void LLVOVolume::updateTextureVirtualSize()
 
 		if (isHUDAttachment())
 		{
-			F32 area = (F32) LLViewerCamera::getInstance()->getScreenPixelArea();
+			F32 area = (F32) camera->getScreenPixelArea();
 			vsize = area;
 			imagep->setBoostLevel(LLViewerTexture::BOOST_HUD);
  			face->setPixelArea(area); // treat as full screen
@@ -704,9 +705,9 @@ void LLVOVolume::updateTextureVirtualSize()
 			
 				//if the sculpty very close to the view point, load first
 				{				
-					LLVector3 lookAt = getPositionAgent() - LLViewerCamera::getInstance()->getOrigin();
+					LLVector3 lookAt = getPositionAgent() - camera->getOrigin();
 					F32 dist = lookAt.normVec() ;
-					F32 cos_angle_to_view_dir = lookAt * LLViewerCamera::getInstance()->getXAxis() ;				
+					F32 cos_angle_to_view_dir = lookAt * camera->getXAxis() ;				
 					mSculptTexture->setAdditionalDecodePriority(0.8f * LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist)) ;
 				}
 			}
@@ -741,7 +742,7 @@ void LLVOVolume::updateTextureVirtualSize()
 			F32 rad = getLightRadius();
 			mLightTexture->addTextureStats(gPipeline.calcPixelArea(getPositionAgent(), 
 																	LLVector3(rad,rad,rad),
-																	*LLViewerCamera::getInstance()));
+																	*camera));
 		}	
 	}
 
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index f908a015df86e6fe6e25ba5ffb5b7e6603d68522..21b297c4eef91a2a7a75313ad6928c0bf2f5ae15 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -3768,9 +3768,10 @@ void LLPipeline::renderForSelect(std::set<LLViewerObject*>& objects, BOOL render
 	gGL.setColorMask(true, false);
 	gPipeline.resetDrawOrders();
 
+	LLViewerCamera* camera = LLViewerCamera::getInstance();
 	for (std::set<LLViewerObject*>::iterator iter = objects.begin(); iter != objects.end(); ++iter)
 	{
-		stateSort((*iter)->mDrawable, *LLViewerCamera::getInstance());
+		stateSort((*iter)->mDrawable, *camera);
 	}
 
 	LLMemType mt(LLMemType::MTYPE_PIPELINE_RENDER_SELECT);
@@ -6248,6 +6249,7 @@ void LLPipeline::renderDeferredLighting()
 	{
 		LLFastTimer ftm(FTM_RENDER_DEFERRED);
 
+		LLViewerCamera* camera = LLViewerCamera::getInstance();
 		{
 			LLGLDepthTest depth(GL_TRUE);
 			mDeferredDepth.copyContents(mDeferredScreen, 0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight(),
@@ -6641,7 +6643,7 @@ void LLPipeline::renderDeferredLighting()
 						continue;
 					}
 
-					if (LLViewerCamera::getInstance()->AABBInFrustumNoFarClip(center, LLVector3(s,s,s)) == 0)
+					if (camera->AABBInFrustumNoFarClip(center, LLVector3(s,s,s)) == 0)
 					{
 						continue;
 					}
@@ -6665,12 +6667,12 @@ void LLPipeline::renderDeferredLighting()
 					v[18] = c[0]+s; v[19] = c[1]+s; v[20] = c[2]-s; // 6 - 0110
 					v[21] = c[0]+s; v[22] = c[1]+s; v[23] = c[2]+s; // 7 - 0111
 
-					if (LLViewerCamera::getInstance()->getOrigin().mV[0] > c[0] + s + 0.2f ||
-						LLViewerCamera::getInstance()->getOrigin().mV[0] < c[0] - s - 0.2f ||
-						LLViewerCamera::getInstance()->getOrigin().mV[1] > c[1] + s + 0.2f ||
-						LLViewerCamera::getInstance()->getOrigin().mV[1] < c[1] - s - 0.2f ||
-						LLViewerCamera::getInstance()->getOrigin().mV[2] > c[2] + s + 0.2f ||
-						LLViewerCamera::getInstance()->getOrigin().mV[2] < c[2] - s - 0.2f)
+					if (camera->getOrigin().mV[0] > c[0] + s + 0.2f ||
+						camera->getOrigin().mV[0] < c[0] - s - 0.2f ||
+						camera->getOrigin().mV[1] > c[1] + s + 0.2f ||
+						camera->getOrigin().mV[1] < c[1] - s - 0.2f ||
+						camera->getOrigin().mV[2] > c[2] + s + 0.2f ||
+						camera->getOrigin().mV[2] < c[2] - s - 0.2f)
 					{ //draw box if camera is outside box
 						if (render_local)
 						{
@@ -6685,7 +6687,7 @@ void LLPipeline::renderDeferredLighting()
 							glTexCoord4f(tc.v[0], tc.v[1], tc.v[2], s*s);
 							glColor4f(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f);
 							glDrawRangeElements(GL_TRIANGLE_FAN, 0, 7, 8,
-								GL_UNSIGNED_BYTE, get_box_fan_indices(LLViewerCamera::getInstance(), center));
+								GL_UNSIGNED_BYTE, get_box_fan_indices(camera, center));
 							stop_glerror();
 						}
 					}
@@ -6750,7 +6752,7 @@ void LLPipeline::renderDeferredLighting()
 					glTexCoord4f(tc.v[0], tc.v[1], tc.v[2], s*s);
 					glColor4f(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f);
 					glDrawRangeElements(GL_TRIANGLE_FAN, 0, 7, 8,
-							GL_UNSIGNED_BYTE, get_box_fan_indices(LLViewerCamera::getInstance(), center));
+							GL_UNSIGNED_BYTE, get_box_fan_indices(camera, center));
 				}
 				gDeferredSpotLightProgram.disableTexture(LLViewerShaderMgr::DEFERRED_PROJECTION);
 				unbindDeferredShader(gDeferredSpotLightProgram);
@@ -8684,7 +8686,8 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 	sShadowRender = TRUE;
 	sImpostorRender = TRUE;
 
-	markVisible(avatar->mDrawable, *LLViewerCamera::getInstance());
+	LLViewerCamera* viewer_camera = LLViewerCamera::getInstance();
+	markVisible(avatar->mDrawable, *viewer_camera);
 	LLVOAvatar::sUseImpostors = FALSE;
 
 	LLVOAvatar::attachment_map_t::iterator iter;
@@ -8699,7 +8702,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 		{
 			if (LLViewerObject* attached_object = (*attachment_iter))
 			{
-				markVisible(attached_object->mDrawable->getSpatialBridge(), *LLViewerCamera::getInstance());
+				markVisible(attached_object->mDrawable->getSpatialBridge(), *viewer_camera);
 			}
 		}
 	}
@@ -8709,9 +8712,9 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 	const LLVector3* ext = avatar->mDrawable->getSpatialExtents();
 	LLVector3 pos(avatar->getRenderPosition()+avatar->getImpostorOffset());
 
-	LLCamera camera = *LLViewerCamera::getInstance();
+	LLCamera camera = *viewer_camera;
 
-	camera.lookAt(LLViewerCamera::getInstance()->getOrigin(), pos, LLViewerCamera::getInstance()->getUpAxis());
+	camera.lookAt(viewer_camera->getOrigin(), pos, viewer_camera->getUpAxis());
 	
 	LLVector2 tdim;
 
@@ -8754,7 +8757,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 	glClearStencil(0);
 
 	// get the number of pixels per angle
-	F32 pa = gViewerWindow->getWindowHeightRaw() / (RAD_TO_DEG * LLViewerCamera::getInstance()->getView());
+	F32 pa = gViewerWindow->getWindowHeightRaw() / (RAD_TO_DEG * viewer_camera->getView());
 
 	//get resolution based on angle width and height of impostor (double desired resolution to prevent aliasing)
 	U32 resY = llmin(nhpo2((U32) (fov*pa)), (U32) 512);