Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2183)
@@ -25,4 +25,6 @@
 #include "ObjReader.h"
 #include "OgreOcclusionQueriesQueryManager.h"
+#include "VisibilityInfo.h"
+#include "Preprocessor.h"
 
 
@@ -706,25 +708,22 @@
 
 	// standard rendering in first pass
-	if (!mNormalExecution && mUseDepthPass)
+	// hierarchical culling interleaves identification 
+	// and rendering of objects in _renderVisibibleObjects
+
+	// for the shadow pass we use only standard rendering
+	// because shadows have low occlusion anyway
+	if ((mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
+		 mIlluminationStage == IRS_RENDER_TO_TEXTURE) ||
+		mNormalExecution)
+	{
+		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
+	}
+	else if (mUseDepthPass)
 	{
 		RenderDepthPass();
 	}
-	else
-	{
-		// hierarchical culling interleaves identification 
-		// and rendering of objects in _renderVisibibleObjects
-
-		// for the shadow pass we use only standard rendering
-		// because shadows have low occlusion anyway
-		if ((mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
-			 mIlluminationStage == IRS_RENDER_TO_TEXTURE) ||
-			mNormalExecution)
-		{
-			OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-		}
-
-		// only shadow casters will be rendered in shadow texture pass
-		//if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
-	}
+	
+	// only shadow casters will be rendered in shadow texture pass
+	//if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
 }
 //-----------------------------------------------------------------------
@@ -1087,5 +1086,5 @@
 			return false;
 
-		const bool fromPoint = true;
+		const bool fromPoint = false;
 		const bool nodeVisibility = true;
 		
@@ -1397,5 +1396,5 @@
 	
 	// possible two cameras (one for culling, one for rendering)
-	mHierarchyInterface->InitTraversal(mCameraInProgress, 
+	mHierarchyInterface->InitTraversal(cam, 
 									   mCullCamera ? getCamera("CullCamera") : NULL,
 									   mLeavePassesInQueue);
@@ -2311,4 +2310,131 @@
 }
 //-----------------------------------------------------------------------
+void OcclusionCullingSceneManager::AddVisibleMeshGeometryToQueue(const GtpVisibility::MeshInfoContainer &visibleGeometry,
+																 Camera *cam)
+{
+	GtpVisibility::MeshInfoContainer::const_iterator geomIt, geomIt_end = visibleGeometry.end();
+
+	for (geomIt = visibleGeometry.begin(); geomIt != geomIt_end; ++geomIt)
+	{
+		MovableObject *mo = (*geomIt).GetSource();
+
+		// add if not 0
+		if (!(*geomIt).GetVisiblePixels())
+			continue;
+
+		mo->_notifyCurrentCamera(cam);
+
+		if (mo->isVisible())
+		{
+			mo->_updateRenderQueue(getRenderQueue());
+		}
+	}
+}
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManager::AddVisibleNodeGeometryToQueue(const GtpVisibility::NodeInfoContainer &visibleNodes,
+																 Camera *cam)
+{
+	////////////////
+	//-- apply queries on node level
+
+	GtpVisibility::NodeInfoContainer::const_iterator nodesIt, nodesIt_end = visibleNodes.end();
+
+	for (nodesIt = visibleNodes.begin(); nodesIt != nodesIt_end; ++ nodesIt)
+	{
+		if (!(*nodesIt).GetVisiblePixels())
+			continue;
+
+		Octree *octree = static_cast<Octree *>((*nodesIt).GetSource());
+
+		NodeList::iterator nIt, nIt_end = octree->mNodes.end();
+
+		for (nIt = octree->mNodes.begin(); nIt != nIt_end; ++ nIt)
+		{
+			(*nIt)->_addToRenderQueue(cam, getRenderQueue(), false);
+		}
+	}
+}
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam,
+													   bool onlyShadowCasters)										 
+{
+	// lists only used for visualization
+	mVisible.clear();
+	mBoxes.clear();
+
+	const bool fromPoint = false;
+	const bool nodeVisibility = false;
+
+	const int itemBufferMode = 0;
+	const bool relativeVisibility = false;
+
+	int queryModes = 0;
+
+	if (nodeVisibility)
+		queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
+	else
+		queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
+
+	OcclusionQueriesQueryManager *queryManager = 
+		new OcclusionQueriesQueryManager(mHierarchyInterface,
+										 mCurrentViewport,
+										 queryModes, 
+										 itemBufferMode);
+
+	mVisibilityManager->SetQueryManager(queryManager);
+
+	GtpVisibility::NodeInfoContainer visibleNodes;
+	GtpVisibility::MeshInfoContainer visibleGeometry;
+	GtpVisibility::PatchInfoContainer visiblePatches;
+
+	if (fromPoint)
+	{
+		queryManager->ComputeFromPointVisibility(cam->getDerivedPosition(), 
+												 &visibleNodes, 
+												 &visibleGeometry, 
+												 &visiblePatches, 
+												 relativeVisibility);
+	}
+	else
+	{
+		queryManager->ComputeCameraVisibility(*cam,
+											  &visibleNodes, 
+											  &visibleGeometry, 
+											  &visiblePatches, 
+											  relativeVisibility);
+	}
+		
+	if (0)
+	{
+		std::stringstream d; 
+		d << "Query mode: " << queryModes 
+		  << " visible nodes: " << (int)visibleNodes.size() 
+		  << " visible geometry: " << (int)visibleGeometry.size();
+
+		LogManager::getSingleton().logMessage(d.str());
+	}
+
+	///////////////////////
+	//-- put items in render queue
+	//////////
+
+	//getRenderQueue()->clear();
+
+	//////////////////////
+	//-- apply queries on geometry level
+
+	if (!nodeVisibility)
+	{
+		AddVisibleMeshGeometryToQueue(visibleGeometry, cam);
+	}
+	else
+	{
+		AddVisibleNodeGeometryToQueue(visibleNodes, cam);
+	}
+		
+	delete queryManager;
+}
+
+//-----------------------------------------------------------------------
 void OcclusionCullingSceneManagerFactory::destroyInstance(SceneManager* instance)
 {
