From 0dee7a3ece05f418c1deb422771cfed8d89826b3 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Fri, 9 Apr 2010 22:02:32 -0600
Subject: [PATCH] debug code for EXT-6791: Intel 965 Crash in
 glCopyTexSubImage2D.

---
 indra/llrender/llimagegl.cpp            | 16 +++++++++++-----
 indra/llrender/llimagegl.h              |  2 +-
 indra/newview/lldynamictexture.cpp      |  2 ++
 indra/newview/lldynamictexture.h        | 13 +++++++++++++
 indra/newview/llfloateranimpreview.cpp  |  6 ++++++
 indra/newview/llfloateranimpreview.h    |  2 ++
 indra/newview/llfloaterimagepreview.cpp | 10 ++++++++++
 indra/newview/llfloaterimagepreview.h   |  4 ++++
 indra/newview/lltexlayer.cpp            |  6 ++++++
 indra/newview/lltexlayer.h              |  1 +
 indra/newview/lltoolmorph.cpp           | 12 ++++++++++++
 indra/newview/lltoolmorph.h             |  3 +++
 12 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 36ac3ff119a..68b556c3bb7 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -105,9 +105,9 @@ void check_all_images()
 	}
 }
 
-void LLImageGL::checkTexSize() const
+void LLImageGL::checkTexSize(bool forced) const
 {
-	if (gDebugGL && mTarget == GL_TEXTURE_2D)
+	if ((forced || gDebugGL) && mTarget == GL_TEXTURE_2D)
 	{
 		GLint texname;
 		glGetIntegerv(GL_TEXTURE_BINDING_2D, &texname);
@@ -129,6 +129,8 @@ void LLImageGL::checkTexSize() const
 		glGetTexLevelParameteriv(mTarget, 0, GL_TEXTURE_WIDTH, (GLint*)&x);
 		glGetTexLevelParameteriv(mTarget, 0, GL_TEXTURE_HEIGHT, (GLint*)&y) ;
 		stop_glerror() ;
+		llcallstacks << "w: " << x << " h: " << y << llcallstacksendl ;
+
 		if(!x || !y)
 		{
 			return ;
@@ -138,11 +140,13 @@ void LLImageGL::checkTexSize() const
 			error = TRUE;
 			if (gDebugSession)
 			{
-				gFailLog << "wrong texture size and discard level!" << std::endl;
+				gFailLog << "wrong texture size and discard level!" << 
+					mWidth << " Height: " << mHeight << " Current Level: " << mCurrentDiscardLevel << std::endl;
 			}
 			else
 			{
-				llerrs << "wrong texture size and discard level!" << llendl ;
+				llerrs << "wrong texture size and discard level: width: " << 
+					mWidth << " Height: " << mHeight << " Current Level: " << mCurrentDiscardLevel << llendl ;
 			}
 		}
 
@@ -1044,7 +1048,9 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_
 {
 	if (gGL.getTexUnit(0)->bind(this, false, true))
 	{
-		//checkTexSize() ;
+		checkTexSize(true) ;
+		llcallstacks << fb_x << " : " << fb_y << " : " << x_pos << " : " << y_pos << " : " << width << " : " << height << llcallstacksendl ;
+
 		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, fb_x, fb_y, x_pos, y_pos, width, height);
 		mGLTextureCreated = true;
 		stop_glerror();
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h
index f0870c3fc45..41239d24c89 100644
--- a/indra/llrender/llimagegl.h
+++ b/indra/llrender/llimagegl.h
@@ -157,7 +157,7 @@ class LLImageGL : public LLRefCount
 	void updatePickMask(S32 width, S32 height, const U8* data_in);
 	BOOL getMask(const LLVector2 &tc);
 
-	void checkTexSize() const ;
+	void checkTexSize(bool forced = false) const ;
 	
 	// Sets the addressing mode used to sample the texture 
 	//  (such as wrapping, mirrored wrapping, and clamp)
diff --git a/indra/newview/lldynamictexture.cpp b/indra/newview/lldynamictexture.cpp
index c7c79401a0f..c4234737401 100644
--- a/indra/newview/lldynamictexture.cpp
+++ b/indra/newview/lldynamictexture.cpp
@@ -167,6 +167,8 @@ void LLViewerDynamicTexture::postRender(BOOL success)
 			{
 				generateGLTexture() ;
 			}
+			llcallstacks << "class type: " << (S32)getType() << llcallstacksendl ;
+
 			success = mGLTexturep->setSubImageFromFrameBuffer(0, 0, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight);
 		}
 	}
diff --git a/indra/newview/lldynamictexture.h b/indra/newview/lldynamictexture.h
index 2a944eaada5..caf26035192 100644
--- a/indra/newview/lldynamictexture.h
+++ b/indra/newview/lldynamictexture.h
@@ -41,6 +41,19 @@
 
 class LLViewerDynamicTexture : public LLViewerTexture
 {
+public:
+	enum
+	{
+		LL_VIEWER_DYNAMIC_TEXTURE = LLViewerTexture::DYNAMIC_TEXTURE,
+		LL_TEX_LAYER_SET_BUFFER = LLViewerTexture::INVALID_TEXTURE_TYPE + 1,
+		LL_VISUAL_PARAM_HINT,
+		LL_VISUAL_PARAM_RESET,
+		LL_PREVIEW_ANIMATION,
+		LL_IMAGE_PREVIEW_SCULPTED,
+		LL_IMAGE_PREVIEW_AVATAR,
+		INVALID_DYNAMIC_TEXTURE
+	};
+
 protected:
 	/*virtual*/ ~LLViewerDynamicTexture();
 
diff --git a/indra/newview/llfloateranimpreview.cpp b/indra/newview/llfloateranimpreview.cpp
index 5ec58c8dd6a..72dc1824619 100644
--- a/indra/newview/llfloateranimpreview.cpp
+++ b/indra/newview/llfloateranimpreview.cpp
@@ -1069,6 +1069,12 @@ LLPreviewAnimation::~LLPreviewAnimation()
 	mDummyAvatar->markDead();
 }
 
+//virtual
+S8 LLPreviewAnimation::getType() const
+{
+	return LLViewerDynamicTexture::LL_PREVIEW_ANIMATION ;
+}
+
 //-----------------------------------------------------------------------------
 // update()
 //-----------------------------------------------------------------------------
diff --git a/indra/newview/llfloateranimpreview.h b/indra/newview/llfloateranimpreview.h
index 3ee1f419ab2..84f131a3221 100644
--- a/indra/newview/llfloateranimpreview.h
+++ b/indra/newview/llfloateranimpreview.h
@@ -50,6 +50,8 @@ class LLPreviewAnimation : public LLViewerDynamicTexture
 public:
 	LLPreviewAnimation(S32 width, S32 height);	
 
+	/*virtual*/ S8 getType() const ;
+
 	BOOL	render();
 	void	requestUpdate();
 	void	rotate(F32 yaw_radians, F32 pitch_radians);
diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp
index 6b754bd0653..ef9da30552e 100644
--- a/indra/newview/llfloaterimagepreview.cpp
+++ b/indra/newview/llfloaterimagepreview.cpp
@@ -629,6 +629,11 @@ LLImagePreviewAvatar::~LLImagePreviewAvatar()
 	mDummyAvatar->markDead();
 }
 
+//virtual
+S8 LLImagePreviewAvatar::getType() const
+{
+	return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_AVATAR ;
+}
 
 void LLImagePreviewAvatar::setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male) 
 { 
@@ -808,6 +813,11 @@ LLImagePreviewSculpted::~LLImagePreviewSculpted()
 {
 }
 
+//virtual
+S8 LLImagePreviewSculpted::getType() const
+{
+	return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_SCULPTED ;
+}
 
 void LLImagePreviewSculpted::setPreviewTarget(LLImageRaw* imagep, F32 distance)
 { 
diff --git a/indra/newview/llfloaterimagepreview.h b/indra/newview/llfloaterimagepreview.h
index 4a12543650f..466bd1d0ec3 100644
--- a/indra/newview/llfloaterimagepreview.h
+++ b/indra/newview/llfloaterimagepreview.h
@@ -54,6 +54,8 @@ class LLImagePreviewSculpted : public LLViewerDynamicTexture
  public:
 	LLImagePreviewSculpted(S32 width, S32 height);	
 
+	/*virtual*/ S8 getType() const ;
+
 	void setPreviewTarget(LLImageRaw *imagep, F32 distance);
 	void setTexture(U32 name) { mTextureName = name; }
 
@@ -85,6 +87,8 @@ class LLImagePreviewAvatar : public LLViewerDynamicTexture
 public:
 	LLImagePreviewAvatar(S32 width, S32 height);	
 
+	/*virtual*/ S8 getType() const ;
+
 	void setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male);
 	void setTexture(U32 name) { mTextureName = name; }
 	void clearPreviewTexture(const std::string& mesh_name);
diff --git a/indra/newview/lltexlayer.cpp b/indra/newview/lltexlayer.cpp
index 386b636367a..8cb319b122d 100644
--- a/indra/newview/lltexlayer.cpp
+++ b/indra/newview/lltexlayer.cpp
@@ -98,6 +98,12 @@ LLTexLayerSetBuffer::~LLTexLayerSetBuffer()
 	}
 }
 
+//virtual 
+S8 LLTexLayerSetBuffer::getType() const 
+{
+	return LLViewerDynamicTexture::LL_TEX_LAYER_SET_BUFFER ;
+}
+
 //virtual 
 void LLTexLayerSetBuffer::restoreGLTexture() 
 {	
diff --git a/indra/newview/lltexlayer.h b/indra/newview/lltexlayer.h
index 5be58f64a9d..ae280dd0633 100644
--- a/indra/newview/lltexlayer.h
+++ b/indra/newview/lltexlayer.h
@@ -325,6 +325,7 @@ class LLTexLayerSetBuffer : public LLViewerDynamicTexture
 	LLTexLayerSetBuffer(LLTexLayerSet* const owner, S32 width, S32 height);
 	virtual ~LLTexLayerSetBuffer();
 
+	/*virtual*/ S8          getType() const ;
 	virtual void			preRender(BOOL clear_depth);
 	virtual void			postRender(BOOL success);
 	virtual BOOL			render();
diff --git a/indra/newview/lltoolmorph.cpp b/indra/newview/lltoolmorph.cpp
index 5f825b461ed..79846b91606 100644
--- a/indra/newview/lltoolmorph.cpp
+++ b/indra/newview/lltoolmorph.cpp
@@ -108,6 +108,12 @@ LLVisualParamHint::~LLVisualParamHint()
 	LLVisualParamHint::sInstances.erase( this );
 }
 
+//virtual
+S8 LLVisualParamHint::getType() const
+{
+	return LLViewerDynamicTexture::LL_VISUAL_PARAM_HINT ;
+}
+
 //-----------------------------------------------------------------------------
 // static
 // requestHintUpdates()
@@ -290,6 +296,12 @@ LLVisualParamReset::LLVisualParamReset() : LLViewerDynamicTexture(1, 1, 1, ORDER
 {	
 }
 
+//virtual
+S8 LLVisualParamReset::getType() const
+{
+	return LLViewerDynamicTexture::LL_VISUAL_PARAM_RESET ;
+}
+
 //-----------------------------------------------------------------------------
 // render()
 //-----------------------------------------------------------------------------
diff --git a/indra/newview/lltoolmorph.h b/indra/newview/lltoolmorph.h
index b7df718ba2a..c332c296bd4 100644
--- a/indra/newview/lltoolmorph.h
+++ b/indra/newview/lltoolmorph.h
@@ -64,6 +64,8 @@ class LLVisualParamHint : public LLViewerDynamicTexture
 		LLViewerVisualParam *param,
 		F32 param_weight);	
 
+	/*virtual*/ S8 getType() const ;
+
 	BOOL					needsRender();
 	void					preRender(BOOL clear_depth);
 	BOOL					render();
@@ -107,6 +109,7 @@ class LLVisualParamReset : public LLViewerDynamicTexture
 public:
 	LLVisualParamReset();
 	/*virtual */ BOOL render();
+	/*virtual*/ S8 getType() const ;
 
 	static BOOL sDirty;
 };
-- 
GitLab