Index: trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 134)
+++ trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 135)
@@ -25,9 +25,4 @@
 			    bool relativeVisibility)
 {
-	if (relativeVisibility)
-		LogManager::getSingleton().logMessage("relative");
-	else
-		LogManager::getSingleton().logMessage("absolute");
-
 	// we need access to the scene manager and the rendersystem
 	PlatformHierarchyInterface *pfHierarchyInterface = 
@@ -39,4 +34,6 @@
 	Camera *pCam = const_cast<Camera *>(&camera); 
 
+	bool overlayEnabled = mViewport->getOverlaysEnabled();
+	mViewport->setOverlaysEnabled(false);
 	pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
 
@@ -53,8 +50,21 @@
 	GtpVisibility::GeometryList geometryList;
 	
-	GtpVisibility::HierarchyNodeList::const_iterator nodeIt, nodeIt_end = nodeList->end();
+	GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end();
 	// geometry list has still do be built
 	GtpVisibility::GeometryList::iterator geometryIt, geometryIt_end;
 
+	// to obtain the correct number of projected pixels, depth write must be disabled
+
+	bool enableDepthWrite = false;
+	// this option must be provided by the scene manager
+	pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+
+	/* relative visiblity:
+		1) get visible pixels count of objects
+		2) clear frame buffer
+		3) get projected visible pixels count:
+		   test all objects again without depth write (set as option in scene manager)
+		4) calculate ratio between visible vs. projected pixels
+	*/
 	// for relative visibility we need 2 rendering passes
 	int n = relativeVisibility ? 2 : 1;
@@ -63,5 +73,5 @@
 	{
 		//-- queries for hierarchy nodes
-		for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)
+		for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)		
 		{
 			// TODO: DELETE QUERIES FROM PREVIOUS RENDER
@@ -69,5 +79,5 @@
 			
 			// store geometry of the hierarchy node in a geometry list (only once!)
-			if (i == n - 2)
+			if (i == 0)
 			{
 				mHierarchyInterface->GetGeometry(*nodeIt, &geometryList, false);
@@ -83,27 +93,16 @@
 		}
 
-		// --- relative visiblity
-		/* 
-			1) get visible pixels count of objects
-			2) clear frame buffer
-			3) get projected visible pixels count:
-			   test all objects again without depth write (set as option in scene manager)
-			4) calculate ratio between visible vs. projected pixels
-		*/
-		if (i == n - 2) // if relativeVisibility, between first and second loop
-		{
-			pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH);
-		}
-
-		// to obtain the correct number of projected pixels, depth write must be disabled
-		bool enableDepthWrite = (i != n - 2);
-
-		// this option must be provided by the scene manager
-		pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+	
+		pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH);
 	}
 
+	enableDepthWrite = true;
+	// this option must be provided by the scene manager
+	pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+	
+	mViewport->setOverlaysEnabled(overlayEnabled);
 
 	//---- collect results
-	unsigned int visiblePixels;
+	unsigned int visiblePixels = 0;
 
 	GtpVisibility::QueryList::iterator visQueryIt, projQueryIt;
@@ -111,9 +110,11 @@
 	visQueryIt = queryList[0].begin();
 	projQueryIt = queryList[1].begin();
+
 	
 	for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)
 	{
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
-
+	
+		
 		float vis = (float)visiblePixels;
 
@@ -121,7 +122,5 @@
 		{
 			(*projQueryIt)->GetQueryResult(visiblePixels, true);
-			std::stringstream d; d << "relativ " << visiblePixels;
-			LogManager::getSingleton().logMessage(d.str());
-
+	
 			if (visiblePixels > 0)
 			{				
@@ -132,5 +131,5 @@
 
 		++visQueryIt;
-
+		
 		// leave nodes with visibilty 0 in queue: 
 		// happens if node is intersected by near plane
@@ -141,7 +140,8 @@
 	geometryIt_end = geometryList.end();
 	
-	/*for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)
+	for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)
 	{
-		(*absQueryIt)->GetQueryResult(visiblePixels, true);
+		(*visQueryIt)->GetQueryResult(visiblePixels, true);
+		
 
 		float vis = (float)visiblePixels;
@@ -150,5 +150,5 @@
 		if (relativeVisibility)
 		{
-			(*relQueryIt)->GetQueryResult(visiblePixels, true);
+			(*projQueryIt)->GetQueryResult(visiblePixels, true);
 
 			if (visiblePixels)
@@ -156,8 +156,8 @@
 				vis /= (float) visiblePixels;
 			}
-			++relQueryIt;
+			++projQueryIt;
 		}
 
-		++absQueryIt;
+		++visQueryIt;
 
 		// approximate depth ordering during rendering => 
@@ -167,5 +167,5 @@
 			visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt, vis));
 		}
-	}*/
+	}
 
 }
@@ -176,5 +176,5 @@
 			       bool relativeVisibility)
 {
-	 visibleNodes->push_back(GtpVisibility::NodeInfo(mHierarchyInterface->GetSceneRoot(), 1.0f));
+	
 }
 //-----------------------------------------------------------------------
