From 0bbe8d73cb687e34d1b10c58b67c465df076739c Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Wed, 25 Jan 2012 15:37:36 -0600
Subject: [PATCH] SH-2565 Move resetVertexBuffer operation to a consistent
 location (also avoid redundant resetting of vertex buffers on detail
 switches).  Change assertion to a warning with count info.  Fix bytes pooled
 debug display.  Remove unused static vertex buffer.

---
 indra/llrender/llvertexbuffer.cpp   |  3 +--
 indra/newview/llviewerdisplay.cpp   |  3 +++
 indra/newview/llviewerjointmesh.cpp |  1 -
 indra/newview/pipeline.cpp          | 36 +++++++++++++----------------
 indra/newview/pipeline.h            |  3 +++
 5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index eb302392bb..518f3898a4 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -205,14 +205,13 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size)
 	rec.mGLName = name;
 	rec.mClientData = buffer;
 
-	sBytesPooled += size;
-	
 	if (!LLVertexBuffer::sDisableVBOMapping && mUsage == GL_DYNAMIC_DRAW_ARB)
 	{
 		glDeleteBuffersARB(1, &rec.mGLName);
 	}
 	else
 	{
+		sBytesPooled += size;
 		mFreeList[i].push_back(rec);
 	}
 }
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index cb40af7061..0adb187dd2 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -260,6 +260,9 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
 
 	gPipeline.disableLights();
 	
+	//reset vertex buffers if needed
+	gPipeline.doResetVertexBuffers();
+
 	stop_glerror();
 
 	// Don't draw if the window is hidden or minimized.
diff --git a/indra/newview/llviewerjointmesh.cpp b/indra/newview/llviewerjointmesh.cpp
index 76f4e18c27..e052e37393 100644
--- a/indra/newview/llviewerjointmesh.cpp
+++ b/indra/newview/llviewerjointmesh.cpp
@@ -63,7 +63,6 @@ extern PFNGLWEIGHTFVARBPROC glWeightfvARB;
 extern PFNGLVERTEXBLENDARBPROC glVertexBlendARB;
 #endif
 
-static LLPointer<LLVertexBuffer> sRenderBuffer = NULL;
 static const U32 sRenderMask = LLVertexBuffer::MAP_VERTEX |
 							   LLVertexBuffer::MAP_NORMAL |
 							   LLVertexBuffer::MAP_TEXCOORD0;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index c523a78b22..a64655960f 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -203,10 +203,6 @@ extern S32 gBoxFrame;
 extern BOOL gDisplaySwapBuffers;
 extern BOOL gDebugGL;
 
-// hack counter for rendering a fixed number of frames after toggling
-// fullscreen to work around DEV-5361
-static S32 sDelayedVBOEnable = 0;
-
 BOOL	gAvatarBacklight = FALSE;
 
 BOOL	gDebugPipeline = FALSE;
@@ -411,6 +407,7 @@ LLPipeline::LLPipeline() :
 	mOldRenderDebugMask(0),
 	mGroupQ1Locked(false),
 	mGroupQ2Locked(false),
+	mResetVertexBuffers(false),
 	mLastRebuildPool(NULL),
 	mAlphaPool(NULL),
 	mSkyPool(NULL),
@@ -692,8 +689,6 @@ void LLPipeline::destroyGL()
 
 	if (LLVertexBuffer::sEnableVBOs)
 	{
-		// render 30 frames after switching to work around DEV-5361
-		sDelayedVBOEnable = 30;
 		LLVertexBuffer::sEnableVBOs = FALSE;
 	}
 }
@@ -2523,15 +2518,6 @@ void LLPipeline::updateGeom(F32 max_dtime)
 
 	assertInitialized();
 
-	if (sDelayedVBOEnable > 0)
-	{
-		if (--sDelayedVBOEnable <= 0)
-		{
-			resetVertexBuffers();
-			LLVertexBuffer::sEnableVBOs = TRUE;
-		}
-	}
-
 	// notify various object types to reset internal cost metrics, etc.
 	// for now, only LLVOVolume does this to throttle LOD changes
 	LLVOVolume::preUpdateGeom();
@@ -6185,7 +6171,7 @@ LLSpatialPartition* LLPipeline::getSpatialPartition(LLViewerObject* vobj)
 
 void LLPipeline::resetVertexBuffers(LLDrawable* drawable)
 {
-	if (!drawable || drawable->isDead())
+	if (!drawable)
 	{
 		return;
 	}
@@ -6198,7 +6184,19 @@ void LLPipeline::resetVertexBuffers(LLDrawable* drawable)
 }
 
 void LLPipeline::resetVertexBuffers()
-{	
+{
+	mResetVertexBuffers = true;
+}
+
+void LLPipeline::doResetVertexBuffers()
+{
+	if (!mResetVertexBuffers)
+	{
+		return;
+	}
+	
+	mResetVertexBuffers = false;
+
 	for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); 
 			iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
 	{
@@ -6224,11 +6222,9 @@ void LLPipeline::resetVertexBuffers()
 
 	if (LLVertexBuffer::sGLCount > 0)
 	{
-		llwarns << "VBO wipe failed." << llendl;
+		llwarns << "VBO wipe failed -- " << LLVertexBuffer::sGLCount << " buffers remaining." << llendl;
 	}
 
-	llassert(LLVertexBuffer::sGLCount == 0);
-
 	LLVertexBuffer::unbind();	
 	
 	sRenderBump = gSavedSettings.getBOOL("RenderObjectBump");
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 9c78048c46..3c4e389ce0 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -111,6 +111,7 @@ public:
 	void destroyGL();
 	void restoreGL();
 	void resetVertexBuffers();
+	void doResetVertexBuffers();
 	void resizeScreenTexture();
 	void releaseGLBuffers();
 	void releaseScreenBuffers();
@@ -653,6 +654,8 @@ protected:
 	bool mGroupQ2Locked;
 	bool mGroupQ1Locked;
 
+	bool mResetVertexBuffers; //if true, clear vertex buffers on next update
+
 	LLViewerObject::vobj_list_t		mCreateQ;
 		
 	LLDrawable::drawable_set_t		mRetexturedList;
-- 
GitLab