From 0a333e9a039288969b3ce207772fee8cbeb2ca83 Mon Sep 17 00:00:00 2001
From: vyacheslavsproductengine <vyacheslavsproductengine@lindenlab.com>
Date: Tue, 19 May 2015 19:28:03 +0400
Subject: MAINT-3548 - FIXED-R2 Horizontal & vertical offset values for normal
 & specular maps still randomly revert to previous settings when building.

---
 indra/llprimitive/llprimitive.cpp       |  4 ++--
 indra/llprimitive/llprimitive.h         |  2 +-
 indra/llprimitive/llprimtexturelist.cpp | 11 +++++++++--
 indra/llprimitive/llprimtexturelist.h   |  2 +-
 indra/llprimitive/lltextureentry.cpp    |  4 ++++
 indra/llprimitive/lltextureentry.h      |  4 ++++
 indra/newview/llpanelface.h             |  2 +-
 indra/newview/llselectmgr.cpp           |  2 +-
 indra/newview/llviewerobject.cpp        |  9 +++++----
 indra/newview/llviewerobject.h          |  2 +-
 indra/newview/llvovolume.cpp            | 10 +++++-----
 indra/newview/llvovolume.h              |  2 +-
 12 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index 29747cb09c..8e009972d0 100755
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -317,9 +317,9 @@ S32 LLPrimitive::setTEMaterialID(const U8 index, const LLMaterialID& pMaterialID
 	return mTextureList.setMaterialID(index, pMaterialID);
 }
 
-S32 LLPrimitive::setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams)
+S32 LLPrimitive::setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams, bool isInitFromServer)
 {
-	return mTextureList.setMaterialParams(index, pMaterialParams);
+	return mTextureList.setMaterialParams(index, pMaterialParams, isInitFromServer);
 }
 
 LLMaterialPtr LLPrimitive::getTEMaterialParams(const U8 index)
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 1bf83e36b4..db7327e900 100755
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -385,7 +385,7 @@ public:
 	virtual S32 setTEMediaFlags(const U8 te, const U8 flags);
 	virtual S32 setTEGlow(const U8 te, const F32 glow);
 	virtual S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
-	virtual S32 setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
+	virtual S32 setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams, bool isInitFromServer);
 	virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
 	virtual void setTESelected(const U8 te, bool sel);
 
diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp
index f4f08248b8..6aae2f97c6 100755
--- a/indra/llprimitive/llprimtexturelist.cpp
+++ b/indra/llprimitive/llprimtexturelist.cpp
@@ -368,11 +368,18 @@ S32 LLPrimTextureList::setMaterialID(const U8 index, const LLMaterialID& pMateri
 	return TEM_CHANGE_NONE;
 }
 
-S32 LLPrimTextureList::setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams)
+S32 LLPrimTextureList::setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams, bool isInitFromServer)
 {
 	if (index < mEntryList.size())
 	{
-		return mEntryList[index]->setMaterialParams(pMaterialParams);
+		if (!isInitFromServer && mEntryList[index]->isMatParamsInitFromServer())
+		{
+			return TEM_CHANGE_NONE;
+		}
+		else
+		{
+			return mEntryList[index]->setMaterialParams(pMaterialParams);
+		}
 	}
 	return TEM_CHANGE_NONE;
 }
diff --git a/indra/llprimitive/llprimtexturelist.h b/indra/llprimitive/llprimtexturelist.h
index 49c636e40f..63e6372405 100755
--- a/indra/llprimitive/llprimtexturelist.h
+++ b/indra/llprimitive/llprimtexturelist.h
@@ -105,7 +105,7 @@ public:
 	S32 setMediaFlags(const U8 index, const U8 media_flags);
 	S32 setGlow(const U8 index, const F32 glow);
 	S32 setMaterialID(const U8 index, const LLMaterialID& pMaterialID);
-	S32 setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
+	S32 setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams, bool isInitFromServer);
 
 	LLMaterialPtr getMaterialParams(const U8 index);
 
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 284dfc15f4..6020031099 100755
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -63,6 +63,7 @@ LLTextureEntry::LLTextureEntry()
   : mMediaEntry(NULL)
   , mSelected(false)
   , mMaterialUpdatePending(false)
+  , mInitMatParamsFromServer(false)
 {
 	init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
 }
@@ -71,6 +72,7 @@ LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
   : mMediaEntry(NULL)
   , mSelected(false)
   , mMaterialUpdatePending(false)
+  , mInitMatParamsFromServer(false)
 {
 	init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
 }
@@ -79,6 +81,7 @@ LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
   : mMediaEntry(NULL)
   , mSelected(false)
   , mMaterialUpdatePending(false)
+  , mInitMatParamsFromServer(false)
 {
 	mID = rhs.mID;
 	mScaleS = rhs.mScaleS;
@@ -562,6 +565,7 @@ S32 LLTextureEntry::setMaterialParams(const LLMaterialPtr pMaterialParams)
 		mMaterialUpdatePending = true;
 	}
 	mMaterial = pMaterialParams;
+	this->mInitMatParamsFromServer = TRUE;
 	return TEM_CHANGE_TEXTURE;
 }
 
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h
index 19edcaa27d..3fe23d6c9f 100755
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -156,6 +156,8 @@ public:
 	const LLMaterialID& getMaterialID() const { return mMaterialID; };
 	const LLMaterialPtr getMaterialParams() const { return mMaterial; };
 
+	bool isMatParamsInitFromServer() const { return mInitMatParamsFromServer; };
+
     // *NOTE: it is possible for hasMedia() to return true, but getMediaData() to return NULL.
     // CONVERSELY, it is also possible for hasMedia() to return false, but getMediaData()
     // to NOT return NULL.  
@@ -213,6 +215,8 @@ protected:
 	bool                mMaterialUpdatePending;
 	LLMaterialID        mMaterialID;
 	LLMaterialPtr		mMaterial;
+	bool                mInitMatParamsFromServer; // Flag to identification when material paramas initialized from 
+
 
 	// Note the media data is not sent via the same message structure as the rest of the TE
 	LLMediaEntry*		mMediaEntry;			// The media data for the face
diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h
index 9823e84cd9..d7e89b4832 100755
--- a/indra/newview/llpanelface.h
+++ b/indra/newview/llpanelface.h
@@ -307,7 +307,7 @@ private:
 						LLMaterialMgr::getInstance()->put(object->getID(),face,*new_material);
 					}
 
-					object->setTEMaterialParams(face, new_material);
+					object->setTEMaterialParams(face, new_material, TRUE);
 					return new_material;
 				}
 				return NULL;
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index cbc00d8b53..fa7674f772 100755
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -2134,7 +2134,7 @@ void LLSelectMgr::selectionRemoveMaterial()
 			{
 			        LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL;
 				LLMaterialMgr::getInstance()->remove(object->getID(),face);
-				object->setTEMaterialParams(face, NULL);
+				object->setTEMaterialParams(face, NULL, FALSE);
 			}
 			return true;
 		}
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index a2c0a91ea6..b8ed17f382 100755
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -4632,7 +4632,7 @@ S32 LLViewerObject::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID
 	return retval;
 }
 
-S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams)
+S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams, bool isInitFromServer)
 {
 	S32 retval = 0;
 	const LLTextureEntry *tep = getTE(te);
@@ -4642,13 +4642,14 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri
 		return 0;
 	}
 
-	retval = LLPrimitive::setTEMaterialParams(te, pMaterialParams);
+	setTENormalMap(te, (pMaterialParams) ? pMaterialParams->getNormalID() : LLUUID::null);
+	setTESpecularMap(te, (pMaterialParams) ? pMaterialParams->getSpecularID() : LLUUID::null);
+
+	retval = LLPrimitive::setTEMaterialParams(te, pMaterialParams, isInitFromServer);
 	LL_DEBUGS("Material") << "Changing material params for te " << (S32)te
 							<< ", object " << mID
 			               << " (" << retval << ")"
 							<< LL_ENDL;
-	setTENormalMap(te, (pMaterialParams) ? pMaterialParams->getNormalID() : LLUUID::null);
-	setTESpecularMap(te, (pMaterialParams) ? pMaterialParams->getSpecularID() : LLUUID::null);
 
 	refreshMaterials();
 	return retval;
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index 05c87c153b..db2749f413 100755
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -330,7 +330,7 @@ public:
 	/*virtual*/	S32		setTEMediaFlags(const U8 te, const U8 media_flags );
 	/*virtual*/ S32     setTEGlow(const U8 te, const F32 glow);
 	/*virtual*/ S32     setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
-	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
+	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams, bool isInitFromServer);
 
 	// Used by Materials update functions to properly kick off rebuilds
 	// of VBs etc when materials updates require changes.
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 0432f6f27c..f435fd754b 100755
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -2010,7 +2010,7 @@ void LLVOVolume::setTEMaterialParamsCallbackTE(const LLUUID& objectID, const LLM
 		LLTextureEntry* texture_entry = pVol->getTE(te);
 		if (texture_entry && (texture_entry->getMaterialID() == pMaterialID))
 		{
-			pVol->setTEMaterialParams(te, pMaterialParams);
+			pVol->setTEMaterialParams(te, pMaterialParams, FALSE);
 		}
 	}
 }
@@ -2081,7 +2081,7 @@ bool LLVOVolume::notifyAboutCreatingTexture(LLViewerTexture *texture)
 	for(map_te_material::const_iterator it = new_material.begin(), end = new_material.end(); it != end; ++it)
 	{
 		LLMaterialMgr::getInstance()->put(getID(), it->first, *it->second);
-		LLViewerObject::setTEMaterialParams(it->first, it->second);
+		LLViewerObject::setTEMaterialParams(it->first, it->second, FALSE);
 	}
 
 	//clear wait-list
@@ -2158,7 +2158,7 @@ bool LLVOVolume::notifyAboutMissingAsset(LLViewerTexture *texture)
 	for(map_te_material::const_iterator it = new_material.begin(), end = new_material.end(); it != end; ++it)
 	{
 		LLMaterialMgr::getInstance()->put(getID(), it->first, *it->second);
-		LLViewerObject::setTEMaterialParams(it->first, it->second);
+		LLViewerObject::setTEMaterialParams(it->first, it->second, FALSE);
 	}
 
 	//clear wait-list
@@ -2167,7 +2167,7 @@ bool LLVOVolume::notifyAboutMissingAsset(LLViewerTexture *texture)
 	return 0 != new_material.size();
 }
 
-S32 LLVOVolume::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams)
+S32 LLVOVolume::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams, bool isInitFromServer)
 {
 	LLMaterialPtr pMaterial = const_cast<LLMaterialPtr&>(pMaterialParams);
 
@@ -2264,7 +2264,7 @@ S32 LLVOVolume::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialPa
 		}
 	}
 
-	S32 res = LLViewerObject::setTEMaterialParams(te, pMaterial);
+	S32 res = LLViewerObject::setTEMaterialParams(te, pMaterial, isInitFromServer);
 
 	LL_DEBUGS("MaterialTEs") << "te " << (S32)te << " material " << ((pMaterial) ? pMaterial->asLLSD() : LLSD("null")) << " res " << res
 							 << ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index bbaca316b0..3e33bbd71c 100755
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -192,7 +192,7 @@ public:
 	
 	static void	setTEMaterialParamsCallbackTE(const LLUUID& objectID, const LLMaterialID& pMaterialID, const LLMaterialPtr pMaterialParams, U32 te);
 
-	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
+	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams, bool isInitFromServer);
 	/*virtual*/ S32		setTEScale(const U8 te, const F32 s, const F32 t);
 	/*virtual*/ S32		setTEScaleS(const U8 te, const F32 s);
 	/*virtual*/ S32		setTEScaleT(const U8 te, const F32 t);
-- 
cgit v1.2.3