From f3952f9a8dc368c991d9aaac174bfee5a0dd90e9 Mon Sep 17 00:00:00 2001
From: Graham Linden <graham@lindenlab.com>
Date: Wed, 7 Aug 2013 13:35:08 -0700
Subject: [PATCH] NORSPEC-329 fix mangling of diffuse alpha mode by material
 edits when only one face really has alpha

---
 indra/newview/llpanelface.h      | 15 ++++++++++++++-
 indra/newview/llviewerobject.cpp | 24 ++++++++++++++++++++++++
 indra/newview/llviewerobject.h   |  2 ++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h
index 834ad9e14ca..06a45644d04 100755
--- a/indra/newview/llpanelface.h
+++ b/indra/newview/llpanelface.h
@@ -255,7 +255,20 @@ class LLPanelFace : public LLPanel
 					// Determine correct alpha mode for current diffuse texture
 					// (i.e. does it have an alpha channel that makes alpha mode useful)
 					//
-					U8 default_alpha_mode = (_panel->isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
+					// _panel->isAlpha() "lies" when one face has alpha and the rest do not (NORSPEC-329)
+					// need to get per-face answer to this question for sane alpha mode retention on updates.
+					//					
+					U8 default_alpha_mode = object->isImageAlphaBlended(face) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+					
+					if (!current_material.isNull())
+					{
+						default_alpha_mode = current_material->getDiffuseAlphaMode();
+					}
+
+					// Insure we don't inherit the default of blend by accident...
+					// this will be stomped by a legit request to change the alpha mode by the apply() below
+					//
+					new_material->setDiffuseAlphaMode(default_alpha_mode);
 
 					// Do "It"!
 					//
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index f29a00e4c49..00702408039 100755
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -4517,6 +4517,30 @@ LLViewerTexture *LLViewerObject::getTEImage(const U8 face) const
 }
 
 
+bool LLViewerObject::isImageAlphaBlended(const U8 te) const
+{
+	LLViewerTexture* image = getTEImage(te);
+	LLGLenum format = image ? image->getPrimaryFormat() : GL_RGB;
+	switch (format)
+	{
+		case GL_RGBA:
+		case GL_ALPHA:
+		{
+			return true;
+		}
+		break;
+
+		case GL_RGB: break;
+		default:
+		{
+			llwarns << "Unexpected tex format in LLViewerObject::isImageAlphaBlended...returning no alpha." << llendl;
+		}
+		break;
+	}
+
+	return false;
+}
+
 LLViewerTexture *LLViewerObject::getTENormalMap(const U8 face) const
 {
 	//	llassert(mTEImages);
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index ea0d55cda53..16f1f403d34 100755
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -339,6 +339,8 @@ class LLViewerObject : public LLPrimitive, public LLRefCount, public LLGLUpdate
 	LLViewerTexture		*getTENormalMap(const U8 te) const;
 	LLViewerTexture		*getTESpecularMap(const U8 te) const;
 	
+	bool						isImageAlphaBlended(const U8 te) const;
+
 	void fitFaceTexture(const U8 face);
 	void sendTEUpdate() const;			// Sends packed representation of all texture entry information
 	
-- 
GitLab