Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 903)
@@ -97,5 +97,5 @@
 	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
 		QueuedRenderableCollection::OrganisationMode om);
-
+	void loadVisibilityConfig(const String& filename);
 	/** Override standard function so octree boxes are always of equal side length.
 		This has advantages for CHC, because terrain tiles are in different octree nodes
@@ -127,5 +127,5 @@
 	/** Finds object corresponding to this bounding box in the scene.
 	*/
-	MovableObject *FindCorrespondingObject(const AxisAlignedBox &box);
+	Entity *FindCorrespondingObject(const AxisAlignedBox &box);
 
 	/** Identifies objects in the scene and gives them unique ids that
@@ -133,4 +133,16 @@
 	*/
 	void IdentifyObjects(GtpVisibilityPreprocessor::ObjectContainer &objects);
+
+	/** Loads / unloads pvs of the view cell to set the visibility in the scene.
+	*/
+	void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
+
+	/** updates pvs in current frame.
+	*/
+	void updatePvs(Camera *cam);
+
+	/** Sets all objects invisible.
+	*/
+	void SetObjectsVisible(const bool visible);
 
 	/// the interface to the scene hierarchy.
@@ -150,10 +162,10 @@
 	bool mRenderNodesContentForViz;
 
-	/// if we render transparents after the hierarchical traversal
+	/// render transparents after the hierarchical traversal
 	bool mDelayRenderTransparents;
 
-	/// if we use a depth pass (i.e., fill only the depth buffer in the first pass)
+	/// use a depth pass (i.e., fill only the depth buffer in the first pass)
 	bool mUseDepthPass;
-	/// if we currently rendering the depth pass
+	/// flag indicating if we currently render the depth pass
 	bool mIsDepthPassPhase;
 	
@@ -185,8 +197,40 @@
 	bool mIsHierarchicalCulling;
 
+	bool mViewCellsLoaded;
 	GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
+
+
+	/// Used to assign Ogre meshes to view cell entries.
+	GtpVisibilityPreprocessor::ObjectContainer mObjects;
+
+	GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
+	GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
+
+	/// If view cells are used.
+	bool mUseViewCells;
+
+	/// if the view cells are filtered
+	bool mUseVisibilityFilter;
 };
 
+/// Factory for VisibilityOctreeSceneManager
+class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
+{
+protected:
+	void initMetaData(void) const;
+	GtpVisibility::VisibilityManager *visManager;
+public:
+	OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
+	{
+		visManager = vm;
+	}
+	~OcclusionCullingSceneManagerFactory() {}
+	/// Factory type name
+	static const String FACTORY_TYPE_NAME;
+	SceneManager* createInstance(const String& instanceName);
+	void destroyInstance(SceneManager* instance);
+};
+
 } // namespace Ogre
 
-#endif // CullingTerrainSceneManager_H
+#endif // OcclusionCullingSceneManager_H
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 903)
@@ -11,4 +11,5 @@
 #include "OgrePlatformQueryManager.h"
 #include "VisibilityManager.h"
+#include "Containers.h"
 #include "ViewCellsManager.h"
 
@@ -76,5 +77,6 @@
 	void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
 #endif // ITEM_BUFFER
-	void _renderQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om);
+	void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
 
 	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
@@ -191,4 +193,5 @@
 	bool mViewCellsLoaded;
 	GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
+
 
 	/// Used to assign Ogre meshes to view cell entries.
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 903)
@@ -489,19 +489,4 @@
 	}
 
-	if (key == "UseArbQueries")
-	{
-		bool useArbQueries = (*static_cast<const bool *>(val));
-
-		if (useArbQueries)
-		{
-			mHierarchyInterface->ResetQueries();
-			mDestRenderSystem->setConfigOption("ArbQueries", "Yes");
-		}
-		else
-		{
-			mHierarchyInterface->ResetQueries();
-			mDestRenderSystem->setConfigOption("ArbQueries", "No");
-		}
-	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || TerrainSceneManager::setOption(key, val);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 903)
@@ -1,5 +1,4 @@
 #include "OgreOcclusionCullingSceneManager.h"
 #include "OgreVisibilityOptionsManager.h"
-#include "OgreTypeConverter.h"
 #include <OgreMath.h>
 #include <OgreIteratorWrappers.h>
@@ -15,5 +14,8 @@
 #include "Containers.h"
 #include "ViewCellsManager.h"
-
+#include <OgreConfigFile.h>
+#include "OgreTypeConverter.h"
+#include "OgreMeshInstance.h"
+#include "common.h"
 
 // normal terrain rendering
@@ -43,5 +45,10 @@
 mRenderTransparentsForItemBuffer(true),
 mExecuteVertexProgramForAllPasses(true),
-mIsHierarchicalCulling(false)
+mIsHierarchicalCulling(false),
+mViewCellsLoaded(false),
+mUseViewCells(false),
+mUseVisibilityFilter(false),
+mCurrentViewCell(NULL),
+mElementaryViewCell(NULL)
 {
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
@@ -82,4 +89,6 @@
 {
 	OGRE_DELETE(mHierarchyInterface);
+	CLEAR_CONTAINER(mObjects);
+	OGRE_DELETE(mCurrentViewCell);
 }
 //-----------------------------------------------------------------------
@@ -155,4 +164,5 @@
     }
 	// add bounding boxes of rendered objects
+	if (1)
 	for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
 	{
@@ -182,4 +192,5 @@
 				//(*it)->_addBoundingBoxToQueue(getRenderQueue());
 			}
+			// add renderables itself
 			if (mRenderNodesContentForViz) 
 			{
@@ -274,4 +285,5 @@
 	}
 
+
 	//-- show visible scene nodes and octree bounding boxes from last frame
 	if (mShowVisualization)
@@ -291,6 +303,11 @@
 			OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
 		}
+
 		// only shadow casters will be rendered in shadow texture pass
 		if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
+
+
+		//-- apply view cell pvs
+		updatePvs(cam);
 	}
 	
@@ -372,4 +389,5 @@
 		// exclude this queues from hierarchical rendering
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
+
 
 		// set all necessary parameters for 
@@ -522,20 +540,36 @@
 		return true;
 	}
-
-	if (key == "UseArbQueries")
-	{
-		bool useArbQueries = (*static_cast<const bool *>(val));
-
-		if (useArbQueries)
-		{
-			mHierarchyInterface->ResetQueries();
-			mDestRenderSystem->setConfigOption("ArbQueries", "Yes");
-		}
-		else
-		{
-			mHierarchyInterface->ResetQueries();
-			mDestRenderSystem->setConfigOption("ArbQueries", "No");
-		}
-	}
+	if (key == "LoadViewCells")
+	{ 
+		if (!mViewCellsLoaded)
+		{
+			LoadViewCells(static_cast<const char *>(val));
+			mViewCellsLoaded = true;	
+		}
+
+		return true;
+	}
+	if (key == "UseViewCells")
+	{ 
+		mUseViewCells = *static_cast<const bool *>(val);
+
+		// reset view cell
+		OGRE_DELETE(mCurrentViewCell);
+		if (mUseViewCells)
+			mCurrentViewCell =  mViewCellsManager->GenerateViewCell();
+		mElementaryViewCell = NULL;
+		// if using view cells, all objects are set to false initially
+		SetObjectsVisible(!mUseViewCells);
+		
+		return true;
+	}
+	if (key == "UseVisibilityFilter")
+	{
+		mUseVisibilityFilter = *static_cast<const bool *>(val);
+		// set null =>recomputation of the pvs
+        mElementaryViewCell = NULL;
+		return true;
+	}
+
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || TerrainSceneManager::setOption(key, val);
@@ -753,5 +787,5 @@
 
 
-	// Render a single object, this will set up auto params if required
+	// render a single object, this will set up auto params if required
 	renderSingleObject(rend, usedPass, false, &nullLightList);
 }
@@ -799,7 +833,8 @@
 			mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
 
-			// just render ambient stuff
+			// just render ambient passes
 			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
 			// mIlluminationStage = IRS_AMBIENT; 
+			getRenderQueue()->setSplitPassesByLightingType(true);
 		}
 	
@@ -885,7 +920,15 @@
 			// Also render any objects which have receive shadows disabled
 			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
-		}
-	}
-	else
+#if 0		
+			std::stringstream d; 
+			d << " solid size: " << (int)pPriorityGrp->_getSolidPasses().size()
+				<< " solid no shadow size: " << (int)pPriorityGrp->_getSolidPassesNoShadow().size()
+				<< "difspec size: " << (int)pPriorityGrp->_getSolidPassesDiffuseSpecular().size()
+				<< " decal size: " << (int)pPriorityGrp->_getSolidPassesDecal().size();
+			LogManager::getSingleton().logMessage(d.str());
+#endif
+		}
+	}
+	else // render the rest of the passes
 	{
 		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
@@ -917,21 +960,74 @@
    }
 }
-
 //-------------------------------------------------------------------------
-MovableObject *OcclusionCullingSceneManager::FindCorrespondingObject(const AxisAlignedBox &box)
+void OcclusionCullingSceneManager::SetObjectsVisible(const bool visible)
+{
+	GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
+
+	for (it = mObjects.begin(); it != it_end; ++ it)
+	{
+		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*it);
+		Entity *ent = omi->GetMesh();
+		ent->setVisible(visible);
+	}
+}
+//-------------------------------------------------------------------------
+void OcclusionCullingSceneManager::loadVisibilityConfig(const String& filename)
+{
+	// TODO matt
+	// Set up the options
+	ConfigFile config;
+	String val;
+
+	config.load(filename);
+
+	val = config.getSetting("Algorithm");
+
+    if (!val.empty())
+	{
+		 VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).setOption("Algorithm", val.c_str());
+	}
+
+	val = config.getSetting("UseDepthPass");
+
+	if (!val.empty())
+	{
+		 setOption("UseDepthPass", val.c_str());
+	}
+}
+//-------------------------------------------------------------------------
+inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box)
+{
+	const float eps = 1e-3f;
+	const Vector3 veps(eps, eps, eps);
+	Vector3 max = box.getMaximum();
+	Vector3 min = box.getMinimum();
+
+	return AxisAlignedBox(min - veps, max + veps);
+}
+//-----------------------------------------------------------------------
+Entity *OcclusionCullingSceneManager::FindCorrespondingObject(const AxisAlignedBox &box)
 {
 	list<SceneNode *> sceneNodeList;
-
-	findNodesIn(box, sceneNodeList, NULL);
+	AxisAlignedBox mybox = EnlargeBox(box);
+	//AxisAlignedBox dummy(Vector3(-50000, -50000, -50000), Vector3(50000, 50000, 50000));
+	
+	// get intersecting scene nodes
+	findNodesIn(mybox, sceneNodeList, NULL);
+	
 
 	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
 
-	bool overlap = false;
-
-	MovableObject *bestFittingObj = NULL;
-	float bestFit = 0.0;
-	
+	float overlap = 0;//GtpVisibilityPreprocessor::Limits::Small;
+
+	Entity *bestFittingObj = NULL;
+	float bestFit = overlap;
+
+	// perfect fit threshold
+	const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small;
+
+
 	// find the bbox which is closest to the current bbox
-	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(), !overlap; ++ sit)
+	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
 	{
 		SceneNode *sn = *sit;
@@ -940,38 +1036,63 @@
         while (oit.hasMoreElements())
 		{
-			 MovableObject *mo = oit.getNext();
-			 const AxisAlignedBox bbox = mo->getWorldBoundingBox();
+			MovableObject *mo = oit.getNext();
+
+			// we are only interested in scene entities
+			if (mo->getMovableType() != "Entity")
+			{
+				continue;
+			}
 			 
-			 const float overlap = GtpVisibilityPreprocessor::RatioOfOverlap(
-				 OgreTypeConverter::ConvertFromOgre(bbox), 
-				 OgreTypeConverter::ConvertFromOgre(box));
-
+			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
+					
+
+			// compute measure how much aabbs overlap
+			overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox),
+									 OgreTypeConverter::ConvertFromOgre(bbox));
+	
 			 if (overlap > bestFit)
 			 {
 				 bestFit = overlap;
-				 bestFittingObj = mo;
-					
-				 // perfect fit => object found
-				 if (overlap > (1.0 - GtpVisibilityPreprocessor::Limits::Small))
-					break;
+			
+				 bestFittingObj = static_cast<Entity *>(mo);
+
+				 // perfect fit => object found, eraly exit
+				 if (overlap >= thresh)
+					 return bestFittingObj;				
 			 }
 		}
 	}
 
+	if (0)
+	{
+		std::stringstream d; 
+		if (bestFittingObj)
+			d << "best fit: " << bestFit;     
+		else
+			d << "warning, objects do not fit\n" << box;
+	
+		Ogre::LogManager::getSingleton().logMessage(d.str());
+	}
+
 	return bestFittingObj;
 }
-
-
+//-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::LoadViewCells(string filename)
 {
-	GtpVisibilityPreprocessor::ObjectContainer objects;
+	// the objects are set to invisible a prioriy
+	SetObjectsVisible(false);
+
 	// identify the corresponding Ogre meshes using the bounding boxes
-	IdentifyObjects(objects);
-	
+	IdentifyObjects(mObjects);
+
 	// load the view cells assigning the found objects to the pvss
-	mViewCellsManager->LoadViewCells(filename, &objects);
-}
-
-
+	mViewCellsManager = 
+		GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects);
+
+	std::stringstream d;
+	d << "view cells loaded" << endl;
+	Ogre::LogManager::getSingleton().logMessage(d.str());
+}
+//-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::IdentifyObjects(GtpVisibilityPreprocessor::ObjectContainer &objects)
 {
@@ -988,8 +1109,110 @@
 		  const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second;
 		  const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box);
+		 
+		  Entity *ent = FindCorrespondingObject(currentBox);
+
+		  // create new mesh instance
+		  OgreMeshInstance *omi = new OgreMeshInstance(ent);
+		  omi->SetId((*iit).first);
+		  objects.push_back(omi);
+	}
+}
+//-------------------------------------------------------------------------
+void OcclusionCullingSceneManager::applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 
+													const bool load)
+{	// NOTE: should not happen, rather apply view cell representing unbounded space then
+	if (!vc) 
+	{	
+		// set everything visible for savety
+		SetObjectsVisible(true);
+
+		return;
+	}
 		  
-		  MovableObject *mo = FindCorrespondingObject(currentBox);
-		  //objects.push_back(mi);
-	}
+	GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator oit,
+			oit_end = vc->GetPvs().mEntries.end();
+
+	//-- PVS of view cell
+	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
+	{
+		if (!(*oit).first) continue;
+
+		OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance*>((*oit).first);
+		omi->GetMesh()->setVisible(load);
+		//GtpVisibilityPreprocessor::Debug << "here45 " << omi->GetId() << endl;
+	}
+}
+//-------------------------------------------------------------------------
+void OcclusionCullingSceneManager::updatePvs(Camera *cam)
+{
+	if (mViewCellsLoaded && mUseViewCells)
+	{
+		const GtpVisibilityPreprocessor::Vector3 viewPoint = 
+			OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
+
+		GtpVisibilityPreprocessor::ViewCell *newElementary = 
+			mViewCellsManager->GetViewCell(viewPoint);
+
+		// elementary view cell did not change => apply same pvs
+		if (mElementaryViewCell == newElementary)
+			return;
+
+		mElementaryViewCell = newElementary;
+
+		//-- unload old pvs
+		applyViewCellPvs(mCurrentViewCell, false);
+
+
+		//-- the new view cell
+		
+		GtpVisibilityPreprocessor::ViewCell *viewCell;
+
+		
+		if (mUseVisibilityFilter)
+		{
+			//-- compute new filtered cell
+			GtpVisibilityPreprocessor::PrVs prvs;
+			mViewCellsManager->GetPrVS(viewPoint, prvs);
+			viewCell = prvs.mViewCell;
+		}
+		else
+		{
+			viewCell = newElementary;
+		}
+			
+		//-- load new pvs
+		applyViewCellPvs(viewCell, true);
+
+		// store pvs
+		mCurrentViewCell->SetPvs(viewCell->GetPvs());
+
+		// delete merge tree of filtered view cell
+		if (mUseVisibilityFilter)
+			mViewCellsManager->DeleteLocalMergeTree(viewCell);
+	}
+}
+
+
+
+//-----------------------------------------------------------------------
+const String OcclusionCullingSceneManagerFactory::FACTORY_TYPE_NAME = "OcclusionCullingSceneManager";
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManagerFactory::initMetaData(void) const
+{
+	mMetaData.typeName = FACTORY_TYPE_NAME;
+	mMetaData.description = "Scene manager organising the scene on the basis of an octree with advanced occlusion culling (TM).";
+	mMetaData.sceneTypeMask = 0xFFFF; // support all types
+	mMetaData.worldGeometrySupported = false;
+}
+//-----------------------------------------------------------------------
+SceneManager* OcclusionCullingSceneManagerFactory::createInstance(
+	const String& instanceName)
+{
+	return new OcclusionCullingSceneManager(instanceName, visManager);
+}
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManagerFactory::destroyInstance(SceneManager* instance)
+{
+	delete instance;
 }
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 903)
@@ -12,5 +12,5 @@
 PlatformOcclusionQuery::~PlatformOcclusionQuery()
 {
-	delete mHardwareOcclusionQuery;
+	//delete mHardwareOcclusionQuery;
 }
 //-----------------------------------------------------------------------
@@ -32,7 +32,8 @@
 	bool isAvailable = true;
 
-	if (!waitForResult)
+	/*if (!waitForResult)
 		isAvailable = !mHardwareOcclusionQuery->isStillOutstanding();
-
+	*/
+//visiblePixels = 800;
 	if (isAvailable)
 		return mHardwareOcclusionQuery->pullOcclusionQuery(&visiblePixels);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 903)
@@ -16,5 +16,5 @@
 	{
 		// delete old queries (not needed for e.g., view frustum culling)
-		mHierarchyInterface->ResetQueries();
+		//mHierarchyInterface->ResetQueries();
 		mVisibilityManager->SetCullingManager(*static_cast<const 
 			GtpVisibility::VisibilityEnvironment::CullingManagerType *>(val));
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 903)
@@ -404,15 +404,12 @@
 		//-- now we can render all remaining queue objects
 		//-- used for depth pass, transparents, overlay
+
 		clearSpecialCaseRenderQueues();
 	
-		//-- we render all remaining queue objects
-		// used for depth pass, transparents, overlay 
-		clearSpecialCaseRenderQueues();
 		OctreeSceneManager::_renderVisibleObjects();
-	
 	}   // hierarchical culling
 
 	// reset ambient light
-	setAmbientLight(savedAmbient);
+	//setAmbientLight(savedAmbient);
 
 	getRenderQueue()->clear(); // finally clear render queue
@@ -641,5 +638,6 @@
 	}
 #ifdef ITEM_BUFFER
-	//-- renders item buffer
+	//-- item buffer
+	//-- item buffer: render objects using false colors
 
     // Iterate through priorities
@@ -657,5 +655,5 @@
 {
 	// Do solids
-	RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
+	QueuedRenderableCollection solidObjs = pGroup->getSolidsBasic();//msz
 
 	// ----- SOLIDS LOOP -----
@@ -697,6 +695,5 @@
 	if (mRenderTransparentsForItemBuffer)
 	{
-		RenderPriorityGroup::TransparentRenderablePassList transpObjs = 
-			pGroup->_getTransparentPasses();
+		QueuedRenderableCollection transpObjs = pGroup->getTransparents(); //msz
 		RenderPriorityGroup::TransparentRenderablePassList::const_iterator 
 			itrans, itransend;
@@ -752,5 +749,5 @@
 	}
 
-	Pass *usedPass = setPass(mItemBufferPass); 
+	const Pass *usedPass = _setPass(mItemBufferPass); 
 
 
@@ -789,5 +786,6 @@
 	mLeavePassesInQueue = 0;
 
-	if (!mUseDepthPass && !mUseItemBuffer)
+	// if we have the depth pass or use an item buffer, no passes are left in the queue
+	if (1 && !mUseDepthPass && !mUseItemBuffer)
 	{
 		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 903)
@@ -81,8 +81,8 @@
 void PlatformHierarchyInterface::ResetQueries()
 {
-//	for (int i = 0; i < (int)mOcclusionQueries.size(); ++ i) OGRE_DELETE(mOcclusionQueries[i]);
+	for (int i = 0; i < (int)mOcclusionQueries.size(); ++ i) OGRE_DELETE(mOcclusionQueries[i]);
 
 	mCurrentTestIdx = 0;
-    //mOcclusionQueries.clear();
+    mOcclusionQueries.clear();
 }
 //-----------------------------------------------------------------------
@@ -97,6 +97,6 @@
 	
 	// set no depth write, no color, no lighting material
-	//mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
-	mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
+	mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
+	//mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
 	//SetOcclusionPass();
 
@@ -121,6 +121,7 @@
 {
 	// create new query if there is no query left
-	if (mCurrentTestIdx == (int)mOcclusionQueries.size())
-	{
+	if (mCurrentTestIdx >= (int)mOcclusionQueries.size())
+	{
+		mCurrentTestIdx == (int)mOcclusionQueries.size();
 		mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
 	}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 736)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp	(revision 903)
@@ -74,6 +74,6 @@
 	 mRenderOp.indexData->indexBuffer = ibuf;
 	 // set material with no lighting, no color, no depth write
-	 SetOcclusionQueryMaterial();
-	 //setMaterial("BaseWhiteNoLighting");
+	 //SetOcclusionQueryMaterial();
+	 setMaterial("BaseWhiteNoLighting");
 }
 //-----------------------------------------------------------------------
