From 00c5475a13b2bdc222afbaff152904cdff92d3be Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Mon, 15 Nov 2021 00:00:30 -0500
Subject: [PATCH] Cache rotation matrices in static vars

---
 indra/newview/lldrawpoolwlsky.cpp |  4 +++-
 indra/newview/llmaniprotate.cpp   | 16 +++++++++++-----
 indra/newview/pipeline.cpp        | 28 ----------------------------
 3 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 5eef6cbae72..f730af60aef 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -35,6 +35,7 @@
 #include "llenvironment.h" 
 #include "llglslshader.h"
 #include "llgl.h"
+#include "alglmath.h"
 
 #include "llviewerregion.h"
 #include "llviewershadermgr.h"
@@ -166,7 +167,8 @@ void LLDrawPoolWLSky::renderDome(LLGLSLShader * shader) const
 
 	// the windlight sky dome works most conveniently in a coordinate system
 	// where Y is up, so permute our basis vectors accordingly.
-	gGL.rotatef(120.f, 1.f / F_SQRT3, 1.f / F_SQRT3, 1.f / F_SQRT3);
+	static const LLMatrix4a rot = ALGLMath::genRot(120.f, 1.f / F_SQRT3, 1.f / F_SQRT3, 1.f / F_SQRT3);
+	gGL.rotatef(rot);
 
 	gGL.scalef(0.333f, 0.333f, 0.333f);
 
diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp
index e67716a475b..799cdb5a3ca 100644
--- a/indra/newview/llmaniprotate.cpp
+++ b/indra/newview/llmaniprotate.cpp
@@ -30,6 +30,7 @@
 
 // library includes
 #include "llmath.h"
+#include "alglmath.h"
 #include "llgl.h"
 #include "llrender.h"
 #include "v4color.h"
@@ -187,7 +188,8 @@ void LLManipRotate::render()
 
 				gGL.multMatrix( &mat.mMatrix[0][0] );
 
-				gGL.rotatef( -90, 0.f, 1.f, 0.f);
+				static const LLMatrix4a sphere_rot = ALGLMath::genRot(-90, 0.f, 1.f, 0.f);
+				gGL.rotatef(sphere_rot);
 				LLColor4 color;
 				if (mManipPart == LL_ROT_ROLL || mHighlightedPart == LL_ROT_ROLL)
 				{
@@ -255,7 +257,8 @@ void LLManipRotate::render()
 			mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
 			gGL.pushMatrix();
 			{
-				gGL.rotatef( 90.f, 1.f, 0.f, 0.f );
+				static const LLMatrix4a y_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
+				gGL.rotatef(y_rot);
 				gGL.scalef(mManipulatorScales.mV[VY], mManipulatorScales.mV[VY], mManipulatorScales.mV[VY]);
 				renderActiveRing( mRadiusMeters, width_meters, LLColor4( 0.f, 1.f, 0.f, 1.f), LLColor4( 0.f, 1.f, 0.f, 0.3f));
 			}
@@ -266,7 +269,8 @@ void LLManipRotate::render()
 			mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
 			gGL.pushMatrix();
 			{
-				gGL.rotatef( 90.f, 0.f, 1.f, 0.f );
+				static const LLMatrix4a x_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
+				gGL.rotatef(x_rot);
 				gGL.scalef(mManipulatorScales.mV[VX], mManipulatorScales.mV[VX], mManipulatorScales.mV[VX]);
 				renderActiveRing( mRadiusMeters, width_meters, LLColor4( 1.f, 0.f, 0.f, 1.f), LLColor4( 1.f, 0.f, 0.f, 0.3f));
 			}
@@ -289,6 +293,8 @@ void LLManipRotate::render()
 			LLGLDisable gls_stencil(GL_STENCIL_TEST);
 
 			// First pass: centers. Second pass: sides.
+			static const LLMatrix4a side1_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
+			static const LLMatrix4a side2_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
 			for( S32 i=0; i<2; i++ )
 			{
 				
@@ -311,7 +317,7 @@ void LLManipRotate::render()
 				
 				gGL.pushMatrix();
 				{
-					gGL.rotatef( 90.f, 1.f, 0.f, 0.f );
+					gGL.rotatef(side1_rot);
 					if (mHighlightedPart == LL_ROT_Y)
 					{
 						mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
@@ -329,7 +335,7 @@ void LLManipRotate::render()
 
 				gGL.pushMatrix();
 				{
-					gGL.rotatef( 90.f, 0.f, 1.f, 0.f );
+					gGL.rotatef(side2_rot);
 					if (mHighlightedPart == LL_ROT_X)
 					{
 						mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 4f9802c9574..2c251269043 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -7634,34 +7634,6 @@ void LLPipeline::renderFullbrightMaskedObjects(U32 type, U32 mask, bool texture,
 	gGLLastMatrix = NULL;		
 }
 
-void apply_cube_face_rotation(U32 face)
-{
-	switch (face)
-	{
-		case 0: 
-			gGL.rotatef(90.f, 0, 1, 0);
-			gGL.rotatef(180.f, 1, 0, 0);
-		break;
-		case 2: 
-			gGL.rotatef(-90.f, 1, 0, 0);
-		break;
-		case 4:
-			gGL.rotatef(180.f, 0, 1, 0);
-			gGL.rotatef(180.f, 0, 0, 1);
-		break;
-		case 1: 
-			gGL.rotatef(-90.f, 0, 1, 0);
-			gGL.rotatef(180.f, 1, 0, 0);
-		break;
-		case 3:
-			gGL.rotatef(90, 1, 0, 0);
-		break;
-		case 5: 
-			gGL.rotatef(180, 0, 0, 1);
-		break;
-	}
-}
-
 void validate_framebuffer_object()
 {                                                           
 	GLenum status;                                            
-- 
GitLab