From 06a2d4eb274b1cd02b82bf2e5ffb458880ae8517 Mon Sep 17 00:00:00 2001
From: Leslie Linden <leslie@lindenlab.com>
Date: Mon, 28 Nov 2011 17:13:42 -0800
Subject: [PATCH] SH-2038 PROGRESS -- Hacked the code to not render alpha using
 VBO's on OS X since everything renders faster using VBO's except alpha for
 some mysterious reason.

---
 indra/llrender/llshadermgr.cpp     | 54 +++++++++++++++++++-----------
 indra/newview/featuretable_mac.txt |  4 +--
 indra/newview/llvovolume.cpp       | 21 +++++++++---
 3 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index eea768a3eae..ac9dc9544d5 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -845,28 +845,42 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors)
 		LL_WARNS("ShaderLoading") << "GLSL Linker Error:" << LL_ENDL;
 	}
 
-// NOTE: Removing LL_DARWIN block as it doesn't seem to actually give the correct answer, 
-// but want it for reference once I move it.
-#if 0
-	// Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software
-	// per Apple's suggestion   
-	glBegin(gGL.mMode);
-	glEnd();
-
-	// Query whether the shader can or cannot run in hardware
-	// http://developer.apple.com/qa/qa2007/qa1502.html
-	long vertexGPUProcessing;
-	CGLContextObj ctx = CGLGetCurrentContext();
-	CGLGetParameter (ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing);	
-	long fragmentGPUProcessing;
-	CGLGetParameter (ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing);
-	if (!fragmentGPUProcessing || !vertexGPUProcessing)
+#if LL_DARWIN
+
+	// For some reason this absolutely kills the frame rate when VBO's are enabled
+	if (0)
 	{
-		LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL;
-		success = GL_FALSE;
-		suppress_errors = FALSE;		
+		// Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software
+		// per Apple's suggestion
+		LLGLSLShader::sNoFixedFunction = false;
+		
+		glUseProgramObjectARB(obj);
+
+		gGL.begin(LLRender::TRIANGLES);
+		gGL.vertex3f(0.0f, 0.0f, 0.0f);
+		gGL.vertex3f(0.0f, 0.0f, 0.0f);
+		gGL.vertex3f(0.0f, 0.0f, 0.0f);
+		gGL.end();
+		gGL.flush();
+		
+		glUseProgramObjectARB(0);
+		
+		LLGLSLShader::sNoFixedFunction = true;
+
+		// Query whether the shader can or cannot run in hardware
+		// http://developer.apple.com/qa/qa2007/qa1502.html
+		GLint vertexGPUProcessing, fragmentGPUProcessing;
+		CGLContextObj ctx = CGLGetCurrentContext();
+		CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing);	
+		CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing);
+		if (!fragmentGPUProcessing || !vertexGPUProcessing)
+		{
+			LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL;
+			success = GL_FALSE;
+			suppress_errors = FALSE;		
+		}
 	}
-	
+
 #else
 	std::string log = get_object_log(obj);
 	LLStringUtil::toLower(log);
diff --git a/indra/newview/featuretable_mac.txt b/indra/newview/featuretable_mac.txt
index 390da2273d9..1e2fbc677d5 100644
--- a/indra/newview/featuretable_mac.txt
+++ b/indra/newview/featuretable_mac.txt
@@ -1,4 +1,4 @@
-version 31
+version 32
 // The version number above should be implemented IF AND ONLY IF some
 // change has been made that is sufficiently important to justify
 // resetting the graphics preferences of all users to the recommended
@@ -67,7 +67,7 @@ RenderDeferred				1	1
 RenderDeferredSSAO			1	1
 RenderShadowDetail			1	2
 WatchdogDisabled				1	1
-RenderUseStreamVBO			1	0
+RenderUseStreamVBO			1	1
 RenderFSAASamples			1	16
 RenderMaxTextureIndex		1	16
 
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 3d013f286c6..20f86746550 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -4624,6 +4624,19 @@ struct CompareBatchBreakerModified
 
 void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::vector<LLFace*>& faces, BOOL distance_sort, BOOL batch_textures)
 {
+	U32 buffer_usage = group->mBufferUsage;
+	
+#if LL_DARWIN
+	// HACK from Leslie:
+	// Disable VBO usage for alpha on Mac OS X because it kills the framerate
+	// due to implicit calls to glTexSubImage that are beyond our control.
+	// (this works because the only calls here that sort by distance are alpha)
+	if (distance_sort)
+	{
+		buffer_usage = 0x0;
+	}
+#endif
+	
 	//calculate maximum number of vertices to store in a single buffer
 	U32 max_vertices = (gSavedSettings.getS32("RenderMaxVBOSize")*1024)/LLVertexBuffer::calcVertexSize(group->mSpatialPartition->mVertexDataMask);
 	max_vertices = llmin(max_vertices, (U32) 65535);
@@ -4805,17 +4818,15 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
 						
 		if (!buffer)
 		{ //create new buffer if needed
-			buffer = createVertexBuffer(mask, 
-											group->mBufferUsage);
+			buffer = createVertexBuffer(mask, buffer_usage);
 			buffer->allocateBuffer(geom_count, index_count, TRUE);
 		}
 		else 
 		{ //resize pre-existing buffer
-			if (LLVertexBuffer::sEnableVBOs && buffer->getUsage() != group->mBufferUsage ||
+			if (LLVertexBuffer::sEnableVBOs && buffer->getUsage() != buffer_usage ||
 				buffer->getTypeMask() != mask)
 			{
-				buffer = createVertexBuffer(mask, 
-											group->mBufferUsage);
+				buffer = createVertexBuffer(mask, buffer_usage);
 				buffer->allocateBuffer(geom_count, index_count, TRUE);
 			}
 			else
-- 
GitLab