Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 925)
@@ -11,4 +11,5 @@
 #include <OgreMaterialManager.h>
 #include <OgreIteratorWrappers.h>
+#include <OgreHeightmapTerrainPageSource.h>
 #include "VspBspTree.h"
 #include "Containers.h"
@@ -44,5 +45,6 @@
 mSkipTransparents(false),
 mRenderTransparentsForItemBuffer(true),
-mExecuteVertexProgramForAllPasses(true),
+//mExecuteVertexProgramForAllPasses(true),
+mExecuteVertexProgramForAllPasses(false),
 mIsHierarchicalCulling(false),
 mViewCellsLoaded(false),
@@ -56,11 +58,15 @@
 	if (0)
 	{
-	mDisplayNodes = true;
-	mShowBoundingBoxes = true;
-	mShowBoxes = true;
+		mDisplayNodes = true;
+		mShowBoundingBoxes = true;
+		mShowBoxes = true;
 	}
 
 	// TODO: set maxdepth to reasonable value
 	mMaxDepth = 50;
+
+	//loadVisibilityConfig("GtpVisibility.cfg");
+	//LoadViewCells("");
+	//mViewCellsLoaded = true;
 }
 //-----------------------------------------------------------------------
@@ -117,4 +123,5 @@
 }
 //-------------------------------------------------------------------------
+#if 1
 void OcclusionCullingSceneManager::setWorldGeometry( DataStreamPtr& stream, const String& typeName )
 {
@@ -146,5 +153,5 @@
 
  }
-
+#endif
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::PrepareVisualization(Camera *cam)
@@ -183,6 +190,8 @@
 			{
 				// render the leaf nodes
-				if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) && 
-					 (*it)->getAttachedObject(0)->getMovableType() == "Entity")
+				if ((*it)->numAttachedObjects() && 
+					!(*it)->numChildren() && 
+					((*it)->getAttachedObject(0)->getMovableType() == "Entity") &&
+					(*it)->getAttachedObject(0)->isVisible())
 				{
 					getRenderQueue()->addRenderable((*it));
@@ -217,5 +226,6 @@
 	Pass *usedPass = useDepthPass ? mDepthPass : pass;
 		
-	IlluminationRenderStage savedStage = mIlluminationStage; 
+
+	const IlluminationRenderStage savedStage = mIlluminationStage; 
 	
 	// set illumination stage to NONE so no shadow material is used 
@@ -583,5 +593,17 @@
 		return true;
 	}
-	
+	if (key == "VisibilityManager")
+	{
+		* static_cast<GtpVisibility::VisibilityManager **>(val) = 
+			(GtpVisibility::VisibilityManager *)mVisibilityManager;
+		return true;
+	}
+	if (key == "HierarchInterface")
+	{
+		* static_cast<GtpVisibility::HierarchyInterface **>(val) = 
+			(GtpVisibility::HierarchyInterface *)mHierarchyInterface;
+		return true;
+	}
+
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		getOption(key, val) && TerrainSceneManager::getOption(key, val);
@@ -630,16 +652,35 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::renderObjects(
-	const QueuedRenderableCollection& objs,
-	QueuedRenderableCollection::OrganisationMode om,
-    bool doLightIteration, const LightList* manualLightList)
-{
-	// for correct rendering, transparents must be rendered after hierarchical culling
-	// => do nothing
-	if (NORMAL_RENDER_HACK || !mSkipTransparents)
-	{
-		OctreeSceneManager::renderObjects(objs, om, doLightIteration, manualLightList);
-	}
-}
+void OcclusionCullingSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 
+																QueuedRenderableCollection::OrganisationMode om)
+{
+    // Basic render loop
+    // Iterate through priorities
+    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
+
+    while (groupIt.hasMoreElements())
+    {
+        RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
+
+        // Sort the queue first
+        pPriorityGrp->sort(mCameraInProgress);
+
+        // Do solids
+        renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
+
+		// for correct rendering, transparents must be rendered after hierarchical culling
+		// => do nothing
+
+        // Do transparents (always descending)
+		if (NORMAL_RENDER_HACK || !mSkipTransparents)
+		{
+			renderObjects(pPriorityGrp->getTransparents(), 
+			QueuedRenderableCollection::OM_SORT_DESCENDING, true);
+		}
+
+
+    }// for each priority
+}
+
 //-----------------------------------------------------------------------
 bool OcclusionCullingSceneManager::validatePassForRendering(Pass* pass)
@@ -836,5 +877,5 @@
 			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
 			// mIlluminationStage = IRS_AMBIENT; 
-			getRenderQueue()->setSplitPassesByLightingType(true);
+			//getRenderQueue()->setSplitPassesByLightingType(true);
 		}
 	
@@ -1173,5 +1214,5 @@
 			//-- compute new filtered cell
 			GtpVisibilityPreprocessor::PrVs prvs;
-			mViewCellsManager->GetPrVS(viewPoint, prvs);
+			mViewCellsManager->GetPrVS(viewPoint, prvs, 5);
 			viewCell = prvs.mViewCell;
 		}
@@ -1206,8 +1247,15 @@
 }
 //-----------------------------------------------------------------------
-SceneManager* OcclusionCullingSceneManagerFactory::createInstance(
-	const String& instanceName)
-{
-	return new OcclusionCullingSceneManager(instanceName, visManager);
+SceneManager *OcclusionCullingSceneManagerFactory::createInstance(
+		const String& instanceName)
+{
+	OcclusionCullingSceneManager* tsm = new OcclusionCullingSceneManager(instanceName, visManager);
+	
+	// Create & register default sources (one per manager)
+	HeightmapTerrainPageSource* ps = new HeightmapTerrainPageSource();
+	mTerrainPageSources.push_back(ps);
+	tsm->registerPageSource("Heightmap", ps);
+
+	return tsm;
 }
 //-----------------------------------------------------------------------
