Commits

leslie_linden committed 44eee6f

SH-1618 FIX -- Lighting and shadows crash ATI macs

* Fixed ATI mac "lighting and shadows" related crash
* Fixed up numerous GL errors on macs related to multiple color formats,
the use of glEnable/glDisable on textures above the texture unit count
and old ATI-specific code that was not appropriate for Mac.
* Disabled SSAO for ATI macs due to it not working with shadows
* Ongoing work to properly get shadows and SSAO functioning on ATI macs is required.

Reviewed by davep

Comments (0)

Files changed (8)

indra/llrender/llgl.cpp

 	mHasShaderObjects(FALSE),
 	mHasVertexShader(FALSE),
 	mHasFragmentShader(FALSE),
+	mNumTextureImageUnits(0),
 	mHasOcclusionQuery(FALSE),
 	mHasOcclusionQuery2(FALSE),
 	mHasPointParameters(FALSE),
 		return false;
 	}
 	
+	if (mHasFragmentShader)
+	{
+		GLint num_tex_image_units;
+		glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &num_tex_image_units);
+		mNumTextureImageUnits = num_tex_image_units;
+	}
+	
 	setToDebugGPU();
 
 	initGLStates();
 		LL_INFOS("RenderInit") << "Disabling mip-map generation for Intel GPUs" << LL_ENDL;
 		mHasMipMapGeneration = FALSE;
 	}
+#if !LL_DARWIN
 	if (mIsATI && mHasMipMapGeneration)
 	{
 		LL_INFOS("RenderInit") << "Disabling mip-map generation for ATI GPUs (performance opt)" << LL_ENDL;
 		mHasMipMapGeneration = FALSE;
 	}
+#endif
 	
 	// Misc
 	glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*) &mGLMaxVertexRange);

indra/llrender/llgl.h

 	BOOL mHasShaderObjects;
 	BOOL mHasVertexShader;
 	BOOL mHasFragmentShader;
+	S32  mNumTextureImageUnits;
 	BOOL mHasOcclusionQuery;
 	BOOL mHasOcclusionQuery2;
 	BOOL mHasPointParameters;

indra/llrender/llrender.cpp

 	gGL.flush();
 	
 	glActiveTextureARB(GL_TEXTURE0_ARB + mIndex);
+
+	//
+	// Per apple spec, don't call glEnable/glDisable when index exceeds max texture units
+	// http://www.mailinglistarchive.com/html/mac-opengl@lists.apple.com/2008-07/msg00653.html
+	//
+	bool enableDisable = (mIndex < gGLManager.mNumTextureUnits);
+		
 	if (mCurrTexType != TT_NONE)
 	{
-		glEnable(sGLTextureType[mCurrTexType]);
+		if (enableDisable)
+		{
+			glEnable(sGLTextureType[mCurrTexType]);
+		}
+		
 		glBindTexture(sGLTextureType[mCurrTexType], mCurrTexture);
 	}
 	else
 	{
-		glDisable(GL_TEXTURE_2D);
+		if (enableDisable)
+		{
+			glDisable(GL_TEXTURE_2D);
+		}
+		
 		glBindTexture(GL_TEXTURE_2D, 0);	
 	}
 
 		mCurrTexType = type;
 
 		gGL.flush();
-		glEnable(sGLTextureType[type]);
+		
+		if (mIndex < gGLManager.mNumTextureUnits)
+		{
+			glEnable(sGLTextureType[type]);
+		}
 	}
 }
 
 		activate();
 		unbind(mCurrTexType);
 		gGL.flush();
-		glDisable(sGLTextureType[mCurrTexType]);
+		
+		if (mIndex < gGLManager.mNumTextureUnits)
+		{
+			glDisable(sGLTextureType[mCurrTexType]);
+		}
+		
 		mCurrTexType = TT_NONE;
 	}
 }

indra/llrender/llrendertarget.cpp

 		case GL_FRAMEBUFFER_COMPLETE:
 			break;
 		default:
+			llwarns << "check_framebuffer_status failed -- " << std::hex << status << llendl;
 			ll_fail("check_framebuffer_status failed");	
 			break;
 		}

indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl

 
 uniform int light_count;
 
-uniform vec4 light[16];
-uniform vec4 light_col[16];
+#define MAX_LIGHT_COUNT		16
+uniform vec4 light[MAX_LIGHT_COUNT];
+uniform vec4 light_col[MAX_LIGHT_COUNT];
 
 varying vec4 vary_fragcoord;
 uniform vec2 screen_res;
 	float noise = texture2D(noiseMap, frag.xy/128.0).b;
 	vec3 out_col = vec3(0,0,0);
 	vec3 npos = normalize(-pos);
-	
-	for (int i = 0; i < light_count; ++i)
+
+	// As of OSX 10.6.7 ATI Apple's crash when using a variable size loop
+	for (int i = 0; i < MAX_LIGHT_COUNT; ++i)
 	{
+		bool light_contrib = (i < light_count);
+		
 		vec3 lv = light[i].xyz-pos;
 		float dist2 = dot(lv,lv);
 		dist2 /= light[i].w;
 		if (dist2 > 1.0)
 		{
-			continue;
+			light_contrib = false;
 		}
 		
 		float da = dot(norm, lv);
 		if (da < 0.0)
 		{
-			continue;
-		}
-				
-		lv = normalize(lv);
-		da = dot(norm, lv);
-				
-		float fa = light_col[i].a+1.0;
-		float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
-		dist_atten *= noise;
-
-		float lit = da * dist_atten;
-		
-		vec3 col = light_col[i].rgb*lit*diff;
-		//vec3 col = vec3(dist2, light_col[i].a, lit);
-		
-		if (spec.a > 0.0)
-		{
-			//vec3 ref = dot(pos+lv, norm);
-			
-			float sa = dot(normalize(lv+npos),norm);
-			
-			if (sa > 0.0)
-			{
-				sa = texture2D(lightFunc,vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0);
-				sa *= noise;
-				col += da*sa*light_col[i].rgb*spec.rgb;
-			}
+			light_contrib = false;
 		}
 		
-		out_col += col;	
+		if (light_contrib)
+		{
+			lv = normalize(lv);
+			da = dot(norm, lv);
+					
+			float fa = light_col[i].a+1.0;
+			float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
+			dist_atten *= noise;
+
+			float lit = da * dist_atten;
+			
+			vec3 col = light_col[i].rgb*lit*diff;
+			//vec3 col = vec3(dist2, light_col[i].a, lit);
+			
+			if (spec.a > 0.0)
+			{
+				//vec3 ref = dot(pos+lv, norm);
+				
+				float sa = dot(normalize(lv+npos),norm);
+				
+				if (sa > 0.0)
+				{
+					sa = texture2D(lightFunc,vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0);
+					sa *= noise;
+					col += da*sa*light_col[i].rgb*spec.rgb;
+				}
+			}
+			
+			out_col += col;
+		}
 	}
 	
 	if (dot(out_col, out_col) <= 0.0)

indra/newview/featuretable_mac.txt

 list TexUnit8orLess
 RenderDeferredSSAO			0	0
 
+list ATI
+RenderDeferredSSAO			0	0
+
 list Intel
 RenderAnisotropic			1	0
 RenderLocalLights			1	0

indra/newview/llfeaturemanager.cpp

 	{
 		maskFeatures("OpenGLPre30");
 	}
-	if (gGLManager.mNumTextureUnits <= 8)
+	if (gGLManager.mNumTextureImageUnits <= 8)
 	{
 		maskFeatures("TexUnit8orLess");
 	}

indra/newview/pipeline.cpp

 		mDeferredDepth.allocate(resX, resY, 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);
 		addDeferredAttachments(mDeferredScreen);
 	
-		mScreen.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);		
+		mScreen.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);
+		
+#if LL_DARWIN
+		// As of OS X 10.6.7, Apple doesn't support multiple color formats in a single FBO
+		mEdgeMap.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);
+#else
 		mEdgeMap.allocate(resX, resY, GL_ALPHA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);
+#endif
 
 		if (shadow_detail > 0 || ssao)
 		{ //only need mDeferredLight[0] for shadows OR ssao
 			mDeferredLight[2].allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE);
 			for (U32 i = 0; i < 2; i++)
 			{
+#if LL_DARWIN
+				// As of OS X 10.6.7, Apple doesn't support multiple color formats in a single FBO
+				mGIMapPost[i].allocate(resX,resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE);
+#else
 				mGIMapPost[i].allocate(resX,resY, GL_RGB, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE);
+#endif
 			}
 		}
 		else
 
 		F32 scale = gSavedSettings.getF32("RenderShadowResolutionScale");
 
+#if LL_DARWIN
+		U32 shadow_fmt = 0;
+#else
 		//HACK: make alpha masking work on ATI depth shadows (work around for ATI driver bug)
 		U32 shadow_fmt = gGLManager.mIsATI ? GL_ALPHA : 0;
+#endif
 
 		if (shadow_detail > 0)
 		{ //allocate 4 sun shadow maps