Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2505)
@@ -19,6 +19,5 @@
 							int queryModes,
 							int itemBufferMode)
-:PlatformQueryManager(hierarchyInterface, vp, queryModes), 
-mItemBufferMode(itemBufferMode)
+:PlatformQueryManager(hierarchyInterface, vp, queryModes)
 {
 }*/
@@ -39,59 +38,36 @@
 	bool overlayEnabled = mViewport->getOverlaysEnabled();
 
-	//mItemBufferMode = 0;
-	if (0 && (mItemBufferMode && mQueryModes) != 0)
-	{
-		///////////
-		//-- render scene with item buffer (ids are used as color codes)
-
-		int savedQueryModes = mQueryModes;
-		mQueryModes = mItemBufferMode;
-		
-		PlatformQueryManager::ComputeCameraVisibility(camera, 
-													  visibleNodes,
-													  visibleGeometry, 
-													  visiblePatches, 
-													  relativeVisibility,
-													  approximateVisibility);
-		
-		// overlays cause false visibility
-		mViewport->setOverlaysEnabled(false);
-		mQueryModes = savedQueryModes;
-	}
-	else
-	{
-   		// const_cast allowed because camera is not changed in renderScene
-		Camera *pCam = const_cast<Camera *>(&camera); 
-		mViewport->setOverlaysEnabled(false);
-
-		////////////////////////
-		//-- Render scene to get conservative visibility and fill depth buffer
-
-		OcclusionCullingSceneManager *occlusionSceneMgr = 
-			static_cast<OcclusionCullingSceneManager *>(pfHierarchyInterface->GetSceneManager());
-
-		// no visibility manager available => no visibility scene manager, return
-		GtpVisibility::VisibilityManager *visManager = NULL;	
-		
-		if (!occlusionSceneMgr->getOption("VisibilityManager", &visManager))
-		{
-			Ogre::LogManager::getSingleton().logMessage("no vismanager found");
-			return;
-		}
-
-		// use stop and wait culling for from view point queries because probably
-		// no temporal coherence
-		GtpVisibility::VisibilityEnvironment::CullingManagerType occlusionType = 
-			visManager->GetCullingManagerType();
-
-		visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING);
-
-		if (1)
-			occlusionSceneMgr->RenderDepthForQuery(pCam, mViewport);
-		else
-			pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
-
-		visManager->SetCullingManager(occlusionType);
-	}
+	// const_cast allowed because camera is not changed in renderScene
+	Camera *pCam = const_cast<Camera *>(&camera); 
+	mViewport->setOverlaysEnabled(false);
+
+	////////////////////////
+	//-- Render scene to get conservative visibility and fill depth buffer
+
+	OcclusionCullingSceneManager *occlusionSceneMgr = 
+		static_cast<OcclusionCullingSceneManager *>(pfHierarchyInterface->GetSceneManager());
+
+	// no visibility manager available => no visibility scene manager, return
+	GtpVisibility::VisibilityManager *visManager = NULL;	
+
+	if (!occlusionSceneMgr->getOption("VisibilityManager", &visManager))
+	{
+		Ogre::LogManager::getSingleton().logMessage("no vismanager found");
+		return;
+	}
+
+	// use stop and wait culling for from view point queries because
+	// of issues with temporal coherence
+	GtpVisibility::VisibilityEnvironment::CullingManagerType occlusionType = 
+		visManager->GetCullingManagerType();
+
+	visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING);
+
+	// rendert the scene once to fill depth buffer and to get a first approximation
+	// of visible objects
+	occlusionSceneMgr->RenderDepthForQuery(pCam, mViewport);
+
+	// reset occlusion culling manager
+	visManager->SetCullingManager(occlusionType);
 
 	
@@ -164,18 +140,16 @@
 	// for relative visibility we need 2 rendering passes
 	int n = relativeVisibility ? 2 : 1;
-	if (mItemBufferMode > 0)
-		LogManager::getSingleton().logMessage("using item buffer");
+	
 
 	for (int i = 0; i < n; ++ i)
 	{
-		//-- queries for hierarchy nodes
+		//-- query the hierarchy nodes
 		for (nodeIt = nodeList.begin(); nodeIt != nodeIt_end; ++ nodeIt)		
 		{
 			// TODO: DELETE QUERIES FROM PREVIOUS RENDER
 			bool intersects = false;
-
 			pfHierarchyInterface->CheckFrustumVisible(*nodeIt, intersects);
 
-			// always push back if only checking approximate visibility or intersects
+			// always add node if only checking for approximate visibility or intersects
 			if (approximateVisibility || intersects)
 			{
@@ -195,50 +169,45 @@
 		///////////////
 		//-- queries for geometry
-		
-		// note: for item buffer we can capture only projected visibility
-
-		if ((mItemBufferMode != GEOMETRY_VISIBILITY) || (i == 1))
-		{			
-			for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++ geometryIt)
-			{
-				if (approximateVisibility)
-				{
-					// no more information available
-					const int visPixels = 1;
-					const int projPixels = 1;
-
-					visibleGeometry->push_back(MeshInfo(*geometryIt, visPixels, projPixels));
-				}
-				else
-				{
-					queryList[i].push_back(pfHierarchyInterface->IssueMeshOcclusionQuery(*geometryIt));
-				}
-			}
-		}
-		
+
+		for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++ geometryIt)
+		{
+			if (approximateVisibility)
+			{
+				// no more information available
+				const int visPixels = 1;
+				const int projPixels = 1;
+
+				visibleGeometry->push_back(MeshInfo(*geometryIt, visPixels, projPixels));
+			}
+			else
+			{
+				queryList[i].push_back(pfHierarchyInterface->IssueMeshOcclusionQuery(*geometryIt));
+			}
+		}
+
 		///////////////
 		//-- queries for patches
 
-		if ((mItemBufferMode != PATCH_VISIBILITY) || (i == 1))
-		{
-			for (patchIt = patchList.begin(); patchIt != patchIt_end; ++patchIt)
-			{
-				if (approximateVisibility)
-				{
-					// no more information available
-					const int visPixels = 1;
-					const int projPixels = 1;
-
-					visiblePatches->push_back(PatchInfo(*patchIt, visPixels, projPixels));
-				}
-				else
-				{
-					queryList[i].push_back(pfHierarchyInterface->IssuePatchOcclusionQuery(*patchIt));
-				}
-			}
-		}
-
+		for (patchIt = patchList.begin(); patchIt != patchIt_end; ++patchIt)
+		{
+			if (approximateVisibility)
+			{
+				// there is not more information available
+				const int visPixels = 1;
+				const int projPixels = 1;
+
+				visiblePatches->push_back(PatchInfo(*patchIt, visPixels, projPixels));
+			}
+			else
+			{
+				queryList[i].push_back(pfHierarchyInterface->IssuePatchOcclusionQuery(*patchIt));
+			}
+		}
+
+		// the second time we have to render against the cleared depth buffer to obtain
+		// projected pixels
 		pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH);
 	}
+
 
 	///////////////	
@@ -248,46 +217,33 @@
 	GtpVisibility::QueryList::iterator projQueryIt = queryList[1].begin();
 	
-	// collect occlusion queries for hierarchy nodes
-	CollectNodeVisibility(visQueryIt, 
-						  projQueryIt, 
-						  &nodeList, 
-						  visibleNodes, 
-						  relativeVisibility);
-
-
-	// collect occlusion queries for geometry
-	if ((mItemBufferMode == GEOMETRY_VISIBILITY) && relativeVisibility)
-	{
-		// if visibility was established using the item buffer,
-		// the array is organized different (e.g., ordered by id, all possible objects)
-		CollectRelativeGeometryVisibilityForItemBuffer(projQueryIt, 
-													   &geometryList, 
-													   visibleGeometry);
-	}
-	else if (mItemBufferMode != GEOMETRY_VISIBILITY)
-	{
+	if (1)
+	{	
+		// collect occlusion queries for hierarchy nodes
+		CollectNodeVisibility(visQueryIt, 
+			projQueryIt, 
+			&nodeList, 
+			visibleNodes, 
+			relativeVisibility);
+	}
+
+	if (1)
+	{	
 		CollectGeometryVisibility(visQueryIt, 
-								  projQueryIt, 
-								  &geometryList, 
-								  visibleGeometry, 
-								  relativeVisibility);
-	}
-
-
-	// collect occlusion queries for patches
-	if ((mItemBufferMode == PATCH_VISIBILITY) && relativeVisibility)
-	{
-		CollectRelativePatchVisibilityForItemBuffer(projQueryIt, 
-													&patchList, 
-													visiblePatches);
-	}
-	else if (mItemBufferMode != PATCH_VISIBILITY)
-	{
+			projQueryIt, 
+			&geometryList, 
+			visibleGeometry, 
+			relativeVisibility);
+	}
+
+	if (1)
+	{
+		// collect occlusion queries for patches
 		CollectPatchVisibility(visQueryIt, 
-							   projQueryIt, 
-							   &patchList, 
-							   visiblePatches, 
-							   relativeVisibility);
-	}	
+			projQueryIt, 
+			&patchList, 
+			visiblePatches, 
+			relativeVisibility);
+	}
+
 
 	////////////
@@ -321,14 +277,6 @@
 	// (duplicates occur if an object is on the edge of the viewport)
 	RemoveDuplicateNodes(visibleNodes);
-
-	if (mItemBufferMode != GEOMETRY_VISIBILITY)
-	{
-		RemoveDuplicateGeometry(visibleGeometry);
-	}
-
-	if (mItemBufferMode != PATCH_VISIBILITY)
-	{
-		RemoveDuplicatePatches(visiblePatches);
-	}
+	RemoveDuplicateGeometry(visibleGeometry);
+	RemoveDuplicatePatches(visiblePatches);
 }
 //------------------------------------------------------------------------
@@ -374,52 +322,4 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionQueriesQueryManager::CollectRelativeGeometryVisibilityForItemBuffer(
-									GtpVisibility::QueryList::iterator &projQueryIt,
-									GeometryVector *geometryList, 
-									MeshInfoContainer *visibleGeometry)
-{
-	GeometryVector::iterator geometryIt;
-
-	//-- queries for geometry
-	for (geometryIt = geometryList->begin(); geometryIt != geometryList->end(); ++ geometryIt)
-	{
-		unsigned int projectedPixels = 0;
-
-		(*projQueryIt)->GetQueryResult(projectedPixels, true);
-
-		++projQueryIt;
-		int id = (*geometryIt)->getSubEntity(0)->getId();
-
-		if ((id > 0) && (id < (int)visibleGeometry->size()))
-		{
-			(*visibleGeometry)[id].AddVisibility(0, projectedPixels);
-		}
-	}
-}
-//-----------------------------------------------------------------------
-void OcclusionQueriesQueryManager::CollectRelativePatchVisibilityForItemBuffer(
-									GtpVisibility::QueryList::iterator &projQueryIt,
-									PatchVector *patchList, 
-									PatchInfoContainer *visiblePatches)
-{
-	PatchVector::iterator patchIt;
-
-	//-- queries for geometry
-	for (patchIt = patchList->begin(); patchIt != patchList->end(); ++ patchIt)
-	{
-		unsigned int projectedPixels = 0;
-
-		(*projQueryIt)->GetQueryResult(projectedPixels, true);
-
-		++projQueryIt;
-		int id = (*patchIt)->getId();
-
-		if ((id > 0) && (id < (int)visiblePatches->size()))
-		{
-			(*visiblePatches)[id].AddVisibility(0, projectedPixels);
-		}
-	}
-}
-//-----------------------------------------------------------------------
 void  OcclusionQueriesQueryManager::CollectGeometryVisibility(
 							GtpVisibility::QueryList::iterator &visQueryIt, 
