Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionQueriesQueryManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionQueriesQueryManager.h	(revision 370)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionQueriesQueryManager.h	(revision 925)
@@ -15,5 +15,5 @@
 		on different hierarchy types, while reusing the implementation of the query methods.
     */
-	OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp,
+	OcclusionQueriesQueryManager(GtpVisibility::HierarchyInterface *hierarchyInterface, Viewport *vp,
 								 int queryModes, int itemBufferMode);
     
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h	(revision 925)
@@ -51,10 +51,9 @@
 	GtpVisibility::VisibilityManager *getVisibilityManager();
 
-	/** Render a set of objects, see renderSingleObject for param definitions 
+	/** Render a queue group. 
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const QueuedRenderableCollection& objs, 
-			QueuedRenderableCollection::OrganisationMode om, 
-            bool doLightIteration, const LightList* manualLightList = 0);
+	void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 
+								 QueuedRenderableCollection::OrganisationMode om);
 
 	/** Writes out stats into the Ogre log file.
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 925)
@@ -52,10 +52,9 @@
 	GtpVisibility::VisibilityManager *getVisibilityManager();
 
-	/** Render a set of objects, see renderSingleObject for param definitions 
+	/** Render a queue group. 
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const QueuedRenderableCollection& objs, 
-			QueuedRenderableCollection::OrganisationMode om, 
-            bool doLightIteration, const LightList* manualLightList = 0);
+	void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 
+									  QueuedRenderableCollection::OrganisationMode om);
 
 	/** Writes out stats into the Ogre log file.
@@ -103,6 +102,7 @@
 		msz: Modified to reflect changes in Ogre::TerrainSceneManager
 	*/
+#if 1
 	virtual void setWorldGeometry( DataStreamPtr& stream, const String& typeName );
-
+#endif
 	
 	/** Loads view cells for this particular scene.
@@ -210,4 +210,5 @@
 	bool mUseViewCells;
 
+	
 	/// if the view cells are filtered
 	bool mUseVisibilityFilter;
@@ -218,4 +219,6 @@
 {
 protected:
+	typedef std::vector<TerrainPageSource*> TerrainPageSources;
+	TerrainPageSources mTerrainPageSources;
 	void initMetaData(void) const;
 	GtpVisibility::VisibilityManager *visManager;
@@ -225,5 +228,5 @@
 		visManager = vm;
 	}
-	~OcclusionCullingSceneManagerFactory() {}
+
 	/// Factory type name
 	static const String FACTORY_TYPE_NAME;
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 925)
@@ -55,10 +55,9 @@
 	GtpVisibility::VisibilityManager *getVisibilityManager();
 	
-	/** Render a set of objects, see renderSingleObject for param definitions 
+	/** Render a queue group. 
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const QueuedRenderableCollection& objs, 
-			QueuedRenderableCollection::OrganisationMode om, 
-            bool doLightIteration, const LightList* manualLightList = 0);
+	void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 
+								 QueuedRenderableCollection::OrganisationMode om);
 
 	/** Writes out stats into the Ogre log file.
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h	(revision 925)
@@ -4,5 +4,5 @@
 #include "VisibilityInfo.h"
 #include "QueryManager.h"
-#include "OgrePlatformHierarchyInterface.h"
+#include "HierarchyInterface.h"
 
 namespace Ogre {
@@ -17,5 +17,5 @@
 	    on different hierarchy types, while reusing the implementation of the query methods.
     */
-	PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, 
+	PlatformQueryManager(GtpVisibility::HierarchyInterface *hierarchyInterface, 
 		                 Viewport *vp, int queryModes);
     
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 925)
@@ -158,10 +158,4 @@
 					RelativePath="..\include\OgreTerrainContentGenerator.h">
 				</File>
-				<File
-					RelativePath="..\include\OgreVisibilityOctreeSceneManager.h">
-				</File>
-				<File
-					RelativePath="..\include\OgreVisibilityTerrainSceneManager.h">
-				</File>
 			</Filter>
 			<Filter
@@ -169,7 +163,4 @@
 				Filter="">
 				<File
-					RelativePath="..\src\OgreBspHierarchyInterface.cpp">
-				</File>
-				<File
 					RelativePath="..\src\OgreOcclusionCullingSceneManager.cpp">
 				</File>
@@ -179,10 +170,4 @@
 				<File
 					RelativePath="..\src\OgreTerrainContentGenerator.cpp">
-				</File>
-				<File
-					RelativePath="..\src\OgreVisibilityOctreeSceneManager.cpp">
-				</File>
-				<File
-					RelativePath="..\src\OgreVisibilityTerrainSceneManager.cpp">
 				</File>
 			</Filter>
@@ -195,7 +180,4 @@
 				Filter="h;hpp;hxx;hm;inl;inc">
 				<File
-					RelativePath="..\include\OgreBspHierarchyInterface.h">
-				</File>
-				<File
 					RelativePath="..\include\OgreMeshInstance.h">
 				</File>
@@ -229,7 +211,4 @@
 				<File
 					RelativePath="..\include\OgreVisibilityOptionsManager.h">
-				</File>
-				<File
-					RelativePath="..\include\OgreVisibilitySceneManager.h">
 				</File>
 			</Filter>
@@ -269,7 +248,4 @@
 				<File
 					RelativePath="..\src\OgreVisibilityOptionsManager.cpp">
-				</File>
-				<File
-					RelativePath="..\src\OgreVisibilitySceneManager.cpp">
 				</File>
 				<File
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 925)
@@ -341,7 +341,9 @@
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
+
 		// set all necessary parameters for 
 		// hierarchical visibility culling and rendering
 		InitVisibilityCulling(mCameraInProgress);
+
 
 		/** 
@@ -389,5 +391,5 @@
 	// HACK: set the new render level index, important to avoid cracks
 	// in terrain caused by LOD
-	TerrainRenderable::NextRenderLevelIndex();
+	//TerrainRenderable::NextRenderLevelIndex();
 	
 	// reset ambient light
@@ -395,5 +397,5 @@
 
 	getRenderQueue()->clear(); // finally clear render queue
-	if (0) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
+	if (1) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
 
 	if (0) WriteLog(); // write out stats
@@ -547,15 +549,34 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityTerrainSceneManager::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)
-	{
-		SceneManager::renderObjects(objs, om, doLightIteration, manualLightList);
-	}
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::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
 }
 //-----------------------------------------------------------------------
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;
 }
 //-----------------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 925)
@@ -32,12 +32,15 @@
 	bool isAvailable = true;
 
-	/*if (!waitForResult)
+	if (!waitForResult)
+	{
 		isAvailable = !mHardwareOcclusionQuery->isStillOutstanding();
-	*/
-//visiblePixels = 800;
+		//std::stringstream d; d << "available: " << isAvailable;
+		//Ogre::LogManager::getSingleton().logMessage(d.str());
+	}
+
 	if (isAvailable)
 		return mHardwareOcclusionQuery->pullOcclusionQuery(&visiblePixels);
-
-	return isAvailable;
+	
+	return false;
 }
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 925)
@@ -24,7 +24,7 @@
 */
 
-#include <OgreVisibilityTerrainSceneManager.h>
-#include <OgreVisibilityOctreeSceneManager.h>
-//#include <OgreVisibilityDotSceneManager.h>
+//#include <OgreVisibilityTerrainSceneManager.h>
+//#include <OgreVisibilityOctreeSceneManager.h>
+#include <OgreOcclusionCullingSceneManager.h>
 
 //#include <OgreHeightmapTerrainPageSource.h>
@@ -40,6 +40,7 @@
 namespace Ogre {
 
-VisibilityOctreeSceneManagerFactory *visibilityOctreePlugin;
-VisibilityTerrainSceneManagerFactory *visibilityTerrainPlugin;
+//VisibilityOctreeSceneManagerFactory *visibilityOctreePlugin;
+//VisibilityTerrainSceneManagerFactory *visibilityTerrainPlugin;
+OcclusionCullingSceneManagerFactory *occlusionCullingPlugin;
 
 //-----------------------------------------------------------------------
@@ -47,22 +48,25 @@
 {
 	visEnv = new GtpVisibility::VisibilityEnvironment();
-	visEnv->LoadEnvironment("vienna_simple.env");
+	visEnv->LoadEnvironment("simple.env");
 	visManager = new GtpVisibility::VisibilityManager(visEnv);
 
 	// Create new scene manager
-	visibilityOctreePlugin = new VisibilityOctreeSceneManagerFactory(visManager);
-	visibilityTerrainPlugin = new VisibilityTerrainSceneManagerFactory(visManager);
+	//visibilityOctreePlugin = new VisibilityOctreeSceneManagerFactory(visManager);
+	//visibilityTerrainPlugin = new VisibilityTerrainSceneManagerFactory(visManager);
+	occlusionCullingPlugin = new OcclusionCullingSceneManagerFactory(visManager);
 	// Construct listener manager singleton
 	new TerrainPageSourceListenerManager();
 
 	// Register
-	Root::getSingleton().addSceneManagerFactory(visibilityOctreePlugin);
-	Root::getSingleton().addSceneManagerFactory(visibilityTerrainPlugin);
+	//Root::getSingleton().addSceneManagerFactory(visibilityOctreePlugin);
+	//Root::getSingleton().addSceneManagerFactory(visibilityTerrainPlugin);
+	Root::getSingleton().addSceneManagerFactory(occlusionCullingPlugin);
 }
 //-----------------------------------------------------------------------
 extern "C" void __declspec(dllexport) dllShutdownPlugin()
 {
-	Root::getSingleton().removeSceneManagerFactory(visibilityOctreePlugin);
-	Root::getSingleton().removeSceneManagerFactory(visibilityTerrainPlugin);
+	//Root::getSingleton().removeSceneManagerFactory(visibilityOctreePlugin);
+	//Root::getSingleton().removeSceneManagerFactory(visibilityTerrainPlugin);
+	Root::getSingleton().removeSceneManagerFactory(occlusionCullingPlugin);
 	// destroy listener manager
 	delete TerrainPageSourceListenerManager::getSingletonPtr();
@@ -75,7 +79,7 @@
 	// (HACK: crashes on delete!!!! FIX this 
 	//delete visibilityOctreePlugin;
-	//delete visibilityTerrainPlugin;
-	//delete occlusionDotPlugin;
-	
+    //delete visibilityTerrainPlugin;
+	delete occlusionCullingPlugin;
+
 	delete visManager;
 	delete visEnv;
@@ -83,3 +87,4 @@
 
 
+
 } //namespace Ogre
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp	(revision 925)
@@ -13,8 +13,10 @@
 VisibilitySceneManager::VisibilitySceneManager(const String& name, 
 											   GtpVisibility::VisibilityManager *visManager)
-:SceneManager(name), mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false)
+:SceneManager(name), 
+mVisibilityManager(visManager), 
+mUseDepthPass(false), 
+mShowVisualization(false)
 {
-	mHierarchyInterface = 
-		new SceneNodeHierarchyInterface(this, mDestRenderSystem);
+	mHierarchyInterface = new SceneNodeHierarchyInterface(this, mDestRenderSystem);
 }
 //-----------------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp	(revision 880)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp	(revision 925)
@@ -1,4 +1,4 @@
 #include "OgreOctreeHierarchyInterface.h"
-#include "OgreVisibilityOctreeSceneManager.h"
+//#include "OgreVisibilityOctreeSceneManager.h"
 #include <OgreOctree.h>
 #include <OgreLogManager.h>
@@ -25,4 +25,5 @@
 		RenderNode(node);
 	}
+	
 	
 	// if not all subtrees are empty
@@ -141,5 +142,7 @@
 AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
 {
-	if (node != mSavedNode)
+	// reuse box if node is the same
+	// only create renderable bounding box for new node
+	if (1 || (node != mSavedNode))
 	{
 		mSavedNode = node;
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 925)
@@ -365,5 +365,4 @@
 		InitVisibilityCulling(mCameraInProgress);
 	
-	
 		/** 
 		* the hierarchical culling algorithm
@@ -411,8 +410,8 @@
 
 	// reset ambient light
-	//setAmbientLight(savedAmbient);
+	setAmbientLight(savedAmbient);
 
 	getRenderQueue()->clear(); // finally clear render queue
-	if (0) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
+	if (1) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
 
 	if (0) WriteLog(); // write out stats
@@ -595,16 +594,35 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityOctreeSceneManager::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 VisibilityOctreeSceneManager::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 VisibilityOctreeSceneManager::validatePassForRendering(Pass* pass)
@@ -770,5 +788,6 @@
 	mIsDepthPassPhase = mUseDepthPass;
 
-	mIsHierarchicalCulling = true; // during hierarchical culling
+	// from now on we are during hierarchical culling
+	mIsHierarchicalCulling = true; 
 
 	// item buffer needs full ambient lighting to use item colors as unique id
@@ -828,6 +847,6 @@
 	// possible two cameras (one for culling, one for rendering)
 	mHierarchyInterface->InitTraversal(mCameraInProgress, 
-							mCullCamera ? getCamera("CullCamera") : NULL,
-							mLeavePassesInQueue);
+									   mCullCamera ? getCamera("CullCamera") : NULL,
+                                       mLeavePassesInQueue);
 		
 	//std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;
@@ -1135,5 +1154,5 @@
 			//-- compute new filtered cell
 			GtpVisibilityPreprocessor::PrVs prvs;
-			mViewCellsManager->GetPrVS(viewPoint, prvs);
+			mViewCellsManager->GetPrVS(viewPoint, prvs, 5);
 			viewCell = prvs.mViewCell;
 		}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 925)
@@ -123,5 +123,5 @@
 	if (mCurrentTestIdx >= (int)mOcclusionQueries.size())
 	{
-		mCurrentTestIdx == (int)mOcclusionQueries.size();
+		mCurrentTestIdx = (int)mOcclusionQueries.size();
 		mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
 	}
@@ -139,4 +139,5 @@
 
 	mCamera = cam;
+	// set culling camera for visualization
 	mCullCamera = cullCam ? cullCam : cam;
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp	(revision 925)
@@ -6,10 +6,10 @@
 #include <vector>
 #include <OgreSubEntity.h>
-
+#include "OgrePlatformHierarchyInterface.h"
 
 namespace Ogre {
 
 //----------------------------------------------------------------------- 
-PlatformQueryManager::PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, 
+PlatformQueryManager::PlatformQueryManager(GtpVisibility::HierarchyInterface *hierarchyInterface, 
 										   Viewport *vp, int queryModes):
 QueryManager(hierarchyInterface, queryModes), 
@@ -19,5 +19,7 @@
 }
 //-----------------------------------------------------------------------
-bool PlatformQueryManager::ShootRay(const Ray &ray, std::vector<Mesh *> *visibleMeshes, bool isGlobalLine)
+bool PlatformQueryManager::ShootRay(const Ray &ray, 
+									std::vector<Mesh *> *visibleMeshes, 
+									bool isGlobalLine)
 {
     // run OGRE ray shooting query
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 903)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 925)
@@ -74,6 +74,6 @@
 	 mRenderOp.indexData->indexBuffer = ibuf;
 	 // set material with no lighting, no color, no depth write
-	 //SetOcclusionQueryMaterial();
-	 setMaterial("BaseWhiteNoLighting");
+	 SetOcclusionQueryMaterial();
+	 //setMaterial("BaseWhiteNoLighting");
 }
 //-----------------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 726)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 925)
@@ -4,5 +4,5 @@
 #include <vector>
 #include <OgreSubEntity.h>
-
+#include "OgrePlatformHierarchyInterface.h"
 
 namespace Ogre {
@@ -10,5 +10,5 @@
 //----------------------------------------------------------------------- 
 OcclusionQueriesQueryManager::OcclusionQueriesQueryManager(
-							PlatformHierarchyInterface *hierarchyInterface, 
+							GtpVisibility::HierarchyInterface *hierarchyInterface, 
 							Viewport *vp,
 							int queryModes,
