From c686407731751ababecf01569fa02eb5ba62337d Mon Sep 17 00:00:00 2001
From: ruslantproductengine <ruslantproductengine@lindenlab.com>
Date: Thu, 13 Nov 2014 18:47:57 +0200
Subject: [PATCH] MAINT-4092 FIXED Prim faces with opaque diffuse maps, with
 material set to ALPHA_MODE_BLEND, do not render MAINT-4645 FIXED
 [viewer-lion] The build tool shows normal or specular map as 'none' when one
 exists

---
 indra/llprimitive/llprimitive.cpp       |  5 +++++
 indra/llprimitive/llprimitive.h         |  2 ++
 indra/llprimitive/llprimtexturelist.cpp | 10 ++++++++++
 indra/llprimitive/llprimtexturelist.h   |  2 ++
 indra/newview/llface.cpp                | 16 ++++++++--------
 indra/newview/llvovolume.cpp            | 19 ++++++++++---------
 6 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index a505ea04a74..aa44dc67d5e 100755
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -324,6 +324,11 @@ S32 LLPrimitive::setTEMaterialParams(const U8 index, const LLMaterialPtr pMateri
 	return mTextureList.setMaterialParams(index, pMaterialParams);
 }
 
+LLMaterialPtr LLPrimitive::getTEMaterialParams(const U8 index)
+{
+	return mTextureList.getMaterialParams(index);
+}
+
 //===============================================================
 S32  LLPrimitive::setTEBumpShinyFullbright(const U8 index, const U8 bump)
 {
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index cdb3f273c21..1bf83e36b4f 100755
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -389,6 +389,8 @@ class LLPrimitive : public LLXform
 	virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
 	virtual void setTESelected(const U8 te, bool sel);
 
+	LLMaterialPtr getTEMaterialParams(const U8 index);
+
 	void copyTEs(const LLPrimitive *primitive);
 	S32 packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const;
 	S32 unpackTEField(U8 *cur_ptr, U8 *buffer_end, U8 *data_ptr, U8 data_size, U8 face_count, EMsgVariableType type);
diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp
index dfae9699eca..f4f08248b82 100755
--- a/indra/llprimitive/llprimtexturelist.cpp
+++ b/indra/llprimitive/llprimtexturelist.cpp
@@ -377,6 +377,16 @@ S32 LLPrimTextureList::setMaterialParams(const U8 index, const LLMaterialPtr pMa
 	return TEM_CHANGE_NONE;
 }
 
+LLMaterialPtr LLPrimTextureList::getMaterialParams(const U8 index)
+{
+	if (index < mEntryList.size())
+	{
+		return mEntryList[index]->getMaterialParams();
+	}
+	
+	return LLMaterialPtr();
+}
+
 S32 LLPrimTextureList::size() const
 {
 	return mEntryList.size();
diff --git a/indra/llprimitive/llprimtexturelist.h b/indra/llprimitive/llprimtexturelist.h
index d7fabbbb79a..49c636e40f1 100755
--- a/indra/llprimitive/llprimtexturelist.h
+++ b/indra/llprimitive/llprimtexturelist.h
@@ -107,6 +107,8 @@ class LLPrimTextureList
 	S32 setMaterialID(const U8 index, const LLMaterialID& pMaterialID);
 	S32 setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
 
+	LLMaterialPtr getMaterialParams(const U8 index);
+
 	S32 size() const;
 
 //	void forceResize(S32 new_size);
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 2182b619be1..dc74f4a6ef2 100755
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1303,15 +1303,15 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 			}
 
 			if (shiny_in_alpha)
-		{
-
-			GLfloat alpha[4] =
 			{
-				0.00f,
-				0.25f,
-				0.5f,
-				0.75f
-			};
+
+				static const GLfloat alpha[4] =
+				{
+					0.00f,
+					0.25f,
+					0.5f,
+					0.75f
+				};
 			
 				llassert(tep->getShiny() <= 3);
 				color.mV[3] = U8 (alpha[tep->getShiny()] * 255);
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 35893a03547..f2199b51899 100755
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -2040,18 +2040,19 @@ S32 LLVOVolume::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID)
 
 S32 LLVOVolume::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams)
 {
-	S32 res = 0;
-	
-	if (pMaterialParams && getTEImage(te) && 3 == getTEImage(te)->getComponents() && pMaterialParams->getDiffuseAlphaMode()) 
-	{
-		LLViewerObject::setTEMaterialID(te, LLMaterialID::null);
-		res = LLViewerObject::setTEMaterialParams(te, NULL);
-	}
-	else 
+	if(pMaterialParams)
 	{
-		res = LLViewerObject::setTEMaterialParams(te, pMaterialParams);
+		LLViewerTexture* image = getTEImage(te);
+		LLGLenum image_format = image ? image->getPrimaryFormat() : GL_RGB;
+		LLMaterialPtr current_material = getTEMaterialParams(te);
+		const_cast<LLMaterialPtr&>(pMaterialParams)->setDiffuseAlphaMode(
+			current_material.isNull() ? (GL_RGB == image_format ? LLMaterial::DIFFUSE_ALPHA_MODE_NONE : LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) 
+									  : current_material->getDiffuseAlphaMode()
+		);
 	}
 
+	S32 res = LLViewerObject::setTEMaterialParams(te, pMaterialParams);
+
 	LL_DEBUGS("MaterialTEs") << "te " << (S32)te << " material " << ((pMaterialParams) ? pMaterialParams->asLLSD() : LLSD("null")) << " res " << res
 							 << ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
 							 << LL_ENDL;
-- 
GitLab