Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3041)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3043)
@@ -8,4 +8,6 @@
 namespace CHCDemoEngine 
 { 
+
+static float sCurrentTimer = 0;
 
 
@@ -222,6 +224,13 @@
 	{
 		static PerfTimer mytimer;
-		mProgram->SetValue1f(mTimer, mytimer.Elapsedms(false) * M_PI / 180.0f);
-	}
+		mProgram->SetValue1f(mTimer, sCurrentTimer);
+	}
+}
+
+
+void GPUProgramParameters::InitFrame()
+{
+	static PerfTimer mytimer;
+	sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3042)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3043)
@@ -17,5 +17,5 @@
 
 RenderState::RenderState():
-mRenderType(FIXED),
+mRenderType(FORWARD),
 mUseAlphaToCoverage(true),
 mLockCullFaceEnabled(false)
@@ -67,7 +67,11 @@
 	ResourceManager::GetSingleton()->DisableFragmentProfile();
 	ResourceManager::GetSingleton()->DisableVertexProfile();
-}
-
-
+
+	mFragmentProgramEnabled = false;
+	mVertexProgramEnabled = false;
+}
+
+// q matt: is this function really necessary or would it be better
+// to just create a query material and use the setstate function?
 bool RenderState::SetMode(Mode mode)
 {
@@ -85,12 +89,16 @@
 			glDisable(GL_LIGHTING);
 			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
-			if (mRenderType == DEFERRED)
-			{
-				ResourceManager::GetSingleton()->DisableFragmentProfile();
-				ResourceManager::GetSingleton()->DisableFragmentProfile();
-			}
-		}
-
+		}
+
+		if (mFragmentProgramEnabled)
+		{
+			ResourceManager::GetSingleton()->DisableFragmentProfile();
+		}
+			
+		if (mVertexProgramEnabled)
+		{
+			ResourceManager::GetSingleton()->DisableVertexProfile();
+		}
+		
 		glDepthMask(GL_FALSE);
 
@@ -107,10 +115,14 @@
 			glEnable(GL_LIGHTING);
 			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
-			if (mRenderType == DEFERRED)
-			{
-				ResourceManager::GetSingleton()->EnableFragmentProfile();
-				ResourceManager::GetSingleton()->EnableVertexProfile();
-			}
+		}
+		
+		if (mFragmentProgramEnabled)
+		{
+			ResourceManager::GetSingleton()->EnableFragmentProfile();
+		}
+			
+		if (mVertexProgramEnabled)
+		{
+			ResourceManager::GetSingleton()->EnableVertexProfile();
 		}
 
@@ -168,5 +180,5 @@
 		mTexturesEnabled = false;
 
-		if (mRenderType != DEFERRED)//!mat->mFragmentProgram)
+		if (!tech->GetFragmentProgram())
 			glDisable(GL_TEXTURE_2D);
 
@@ -180,5 +192,5 @@
 			mTexturesEnabled = true;
 
-			if (mRenderType != DEFERRED)//!mat->mFragmentProgram)
+			if (!tech->GetFragmentProgram())
 				glEnable(GL_TEXTURE_2D);
 
@@ -187,36 +199,64 @@
 	}
 
-	if (mRenderType == DEFERRED)
-	{
-		ShaderProgram *frag = tech->GetFragmentProgram();
-
-		if (frag)
-		{
-			if (frag != mCurrentFragmentProgram)
-			{			
-				mCurrentFragmentProgram = frag;
-				mCurrentFragmentProgram->Bind();			
-			}
+	//////////
+	//-- fragment and vertex programs
+	
+	ShaderProgram *frag = tech->GetFragmentProgram();
+
+	if (frag)
+	{
+		if (!mFragmentProgramEnabled)
+		{
+			mFragmentProgramEnabled = true;
+			ResourceManager::GetSingleton()->EnableFragmentProfile();
+		}
+
+		if (frag != mCurrentFragmentProgram)
+		{			
+			mCurrentFragmentProgram = frag;
+			mCurrentFragmentProgram->Bind();			
+		}
 			
-			tech->GetFragmentProgramParameters()->UpdateParameters();
-
-		}
-
-		ShaderProgram *vert = tech->GetVertexProgram();
-
-		if (vert)
-		{
-			if (vert != mCurrentVertexProgram)
-			{
-				mCurrentVertexProgram = vert;
-				mCurrentVertexProgram->Bind();
-			}
-		
-			tech->GetVertexProgramParameters()->UpdateParameters();
-		}
+		tech->GetFragmentProgramParameters()->UpdateParameters();
 	}
 	else
 	{
-		// set fixed texture
+		if (mFragmentProgramEnabled)
+		{
+			mFragmentProgramEnabled = false;
+			ResourceManager::GetSingleton()->DisableFragmentProfile();
+		}
+	}
+
+	ShaderProgram *vert = tech->GetVertexProgram();
+
+	if (vert)
+	{
+		if (!mVertexProgramEnabled)
+		{
+			mVertexProgramEnabled = true;
+			ResourceManager::GetSingleton()->EnableVertexProfile();
+		}
+
+		if (vert != mCurrentVertexProgram)
+		{
+			mCurrentVertexProgram = vert;
+			mCurrentVertexProgram->Bind();
+		}
+		
+		tech->GetVertexProgramParameters()->UpdateParameters();
+	}
+	else
+	{
+		if (mVertexProgramEnabled)
+		{
+			mVertexProgramEnabled = false;
+			ResourceManager::GetSingleton()->DisableVertexProfile();
+		}
+	}
+
+	if (!mFragmentProgramEnabled)
+	{
+		// set FORWARD texture
 		if (tex)
 		{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3042)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3043)
@@ -140,5 +140,5 @@
 		vtxParams->SetValue1f(8, 8e-5f);
 	}
-
+/*
 	tech->GetVertexProgramParameters()->UpdateParameters();
 	tech->GetVertexProgram()->Bind();
@@ -146,9 +146,9 @@
 	tech->GetFragmentProgramParameters()->UpdateParameters();
 	tech->GetFragmentProgram()->Bind();
-
-	// Render sky dome.
+*/
+	// render sky dome
 	mSkyDome->Render(state);
 
-	// Render additively blended sun disc.
+	// render additively blended sun disc.
 	//RenderSunDisk(sunDir, camera);
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3041)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3043)
@@ -86,4 +86,5 @@
 
 
+	static void InitFrame();
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3042)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3043)
@@ -28,5 +28,5 @@
 	enum RenderPassType
 	{
-		FIXED,
+		FORWARD,
 		DEPTH_PASS,
 		DEFERRED
@@ -95,4 +95,7 @@
 	ShaderProgram *mCurrentVertexProgram;
 	ShaderProgram *mCurrentFragmentProgram;
+
+	bool mFragmentProgramEnabled;
+	bool mVertexProgramEnabled;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3041)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3043)
@@ -112,5 +112,5 @@
 enum RenderMethod
 {
-	RENDER_FIXED,
+	RENDER_FORWARD,
 	RENDER_DEPTH_PASS,
 	RENDER_DEFERRED,
@@ -120,5 +120,5 @@
 
 /// one of four possible render methods
-int renderMethod = RENDER_FIXED;
+int renderMethod = RENDER_FORWARD;
 
 
@@ -485,12 +485,10 @@
 	visualization = new Visualization(bvh, camera, NULL, &state);
 	
-	state.SetRenderPassType(RenderState::FIXED);
+	state.SetRenderPassType(RenderState::FORWARD);
 
 	// frame time is restarted every frame
 	frameTimer.Start();
-
 	// the rendering loop
 	glutMainLoop();
-
 	// clean up
 	CleanUp();
@@ -870,4 +868,5 @@
 	}
 	
+	GPUProgramParameters::InitFrame();
 
 
@@ -889,5 +888,5 @@
 
 	if (renderLightView)
-		renderMethod = RenderState::FIXED;
+		renderMethod = RenderState::FORWARD;
 
 	glEnableClientState(GL_VERTEX_ARRAY);
@@ -897,9 +896,9 @@
 	switch (renderMethod)
 	{
-	case RENDER_FIXED:
+	case RENDER_FORWARD:
 	
 		glEnable(GL_MULTISAMPLE_ARB);
 		
-		state.SetRenderPassType(RenderState::FIXED);
+		state.SetRenderPassType(RenderState::FORWARD);
 		glEnable(GL_LIGHTING);
 
@@ -1053,5 +1052,5 @@
 
 
-	state.SetRenderPassType(RenderState::FIXED);
+	state.SetRenderPassType(RenderState::FORWARD);
 	state.Reset();
 
@@ -1904,5 +1903,5 @@
 	{
 		glEnable(GL_LIGHTING);
-		state.SetRenderPassType(RenderState::FIXED);
+		state.SetRenderPassType(RenderState::FORWARD);
 		state.Reset();
 	}
