Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2145)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2160)
@@ -175,7 +175,12 @@
 	/** Load a scene.
 	*/
-	bool LoadScene(const String &filename, const String &viewCellsFilename);
+	bool LoadScene(const String &filename, 
+				   const String &viewCellsFilename);
 
 	void loadConfig(DataStreamPtr& stream);
+
+	void RenderDepthPass();
+
+	void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays);
 
 	//////////////////////////////////////////
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2145)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2160)
@@ -613,38 +613,41 @@
 	// set depth fill pass if we currently do not make an aabb occlusion query
 	const bool useDepthPass = 
-		(mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery());
+		mUseDepthPass && mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery();
 
 	const IlluminationRenderStage savedStage = mIlluminationStage; 
 	
-	// set illumination stage to NONE so no shadow material is used 
-	// for depth pass or for occlusion query
-	if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
-	{
-		mIlluminationStage = IRS_NONE;
-	}
-	
-	// --- set vertex program of current pass in order to set correct depth
-	if (mExecuteVertexProgramForAllPasses && 
-		mIsDepthPassPhase && 
-		pass->hasVertexProgram())
-	{
-		// add vertex program of current pass to depth pass
-		mDepthPass->setVertexProgram(pass->getVertexProgramName());
-
-		if (mDepthPass->hasVertexProgram())
-		{
-			const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
-			// Load this program if not done already
-			if (!prg->isLoaded())
-				prg->load();
-			// Copy params
-			mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
-		}
-	}
-	else if (mDepthPass->hasVertexProgram()) // reset vertex program
-	{
-		mDepthPass->setVertexProgram("");
-	}
-	
+	if (useDepthPass)
+	{
+		// set illumination stage to NONE so no shadow material is used 
+		// for depth pass or for occlusion query
+		if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
+		{
+			mIlluminationStage = IRS_NONE;
+		}
+	
+		//--- set vertex program of current pass in order to set correct depth
+		if (mExecuteVertexProgramForAllPasses && 
+			mIsDepthPassPhase && 
+			pass->hasVertexProgram())
+		{
+			// add vertex program of current pass to depth pass
+			mDepthPass->setVertexProgram(pass->getVertexProgramName());
+
+			if (mDepthPass->hasVertexProgram())
+			{
+				const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
+				// Load this program if not done already
+				if (!prg->isLoaded())
+					prg->load();
+				// Copy params
+				mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
+			}
+		}
+		else if (mDepthPass->hasVertexProgram()) 
+		{	// reset vertex program
+			mDepthPass->setVertexProgram("");
+		}
+	}
+
 	const Pass *usedPass = useDepthPass ? mDepthPass : pass;
 
@@ -682,42 +685,51 @@
 		//////////////
 		//-- show visible scene nodes and octree bounding boxes from last frame
+
 		PrepareVisualization(cam);
-	}
-	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)
-		{
-			OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-		}
-
-		// only shadow casters will be rendered in shadow texture pass
-		if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
-
-		///////////
-		//-- set visibility according to pvs of current view cell
-
-		UpdatePvs(cam);
-
-		if (mNormalExecution)
-		{
-			OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-			//return;
-		}
-	}
-		
+		
+		// lists only used for visualization
+		mVisible.clear();
+		mBoxes.clear();
+
+		return;
+	}
+	
 	// lists only used for visualization
 	mVisible.clear();
 	mBoxes.clear();
+
+	///////////
+	//-- set visibility according to pvs of current view cell
+
+	UpdatePvs(cam);
+
+	// standard rendering in first pass
+	if (!mNormalExecution && 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);
+	}
 }
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::_renderVisibleObjects()
 {
-	const bool flushQueue = mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
+	const bool flushQueue = 
+		mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
 	++ mCurrentFrame;
 
@@ -730,5 +742,4 @@
 	}
 
-	InitDepthPass(); 	  // create material for depth pass
 	InitItemBufferPass(); // create material for item buffer pass
 
@@ -740,5 +751,5 @@
 	//-- (e.g., the visualization mode, the shadow pass)
 
-	if (mShowVisualization ||
+	if (mUseDepthPass || mShowVisualization ||
 	    (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
 	     mIlluminationStage == IRS_RENDER_TO_TEXTURE))
@@ -795,5 +806,5 @@
 		addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
 	
-		// exclude this queues from hierarchical rendering
+		// exclude these queues from hierarchical rendering
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
@@ -819,7 +830,6 @@
 
 		/////////////
-		//-- reset parameters needed for special rendering
-		
-		mIsDepthPassPhase = false;
+		//-- reset parameters needed during hierarchical rendering
+		
 		mIsItemBufferPhase = false;
 		mSkipTransparents = false;
@@ -827,18 +837,5 @@
 		
 		mLeavePassesInQueue = 0;
-		
-		 // the shaded geometry is rendered in a second pass
-		if (mUseDepthPass)
-		{
-			// add visible nodes found by the visibility culling algorithm
-			NodeList::const_iterator it, it_end = mVisible.end();
-
-			//getRenderQueue()->clear();
-			for (it = mVisible.begin(); it != it_end; ++ it)
-			{
-				(*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
-			}
-		}
-		
+			
 		/////////////
 		//-- now we can render all remaining queue objects
@@ -868,5 +865,5 @@
 	if (mNormalExecution)
 	{
-		OctreeSceneManager::_updateSceneGraph(cam);
+		TerrainSceneManager::_updateSceneGraph(cam);
 		return;
 	}
@@ -1326,5 +1323,6 @@
 	mIsDepthPassPhase = mUseDepthPass;
 
-	mIsHierarchicalCulling = true; // during hierarchical culling
+	// indicates that we use hierarchical culling from now on
+	mIsHierarchicalCulling = true; 
 
 	// item buffer needs full ambient lighting to use item colors as unique id
@@ -1342,5 +1340,5 @@
 	mLeavePassesInQueue = 0;
 
-	// if we have the depth pass or use an item buffer, no passes are left in the queue
+	// if we have the depth pass or use an item buffer, we leave no passes in the queue
 	if (1 && !mUseDepthPass && !mUseItemBuffer)
 	{
@@ -1819,4 +1817,108 @@
 	return false;
 }
+
+
+#if 0
+void OcclusionCullingSceneManager::RenderDepthPass()
+{
+	////////////////////
+	//-- hierarchical culling
+
+	// exclude these queues from hierarchical rendering
+	clearSpecialCaseRenderQueues();
+	addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
+	addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
+	addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
+	addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
+	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
+
+	// set all necessary parameters for 
+	// hierarchical visibility culling and rendering
+	InitVisibilityCulling(mCameraInProgress);
+
+
+	/** 
+	* the hierarchical culling algorithm
+	* for depth pass: we just find objects and update depth buffer
+	* for "delayed" rendering: we render some passes afterwards
+	* e.g., transparents, because they need front-to-back sorting
+	**/
+		
+	mVisibilityManager->ApplyVisibilityCulling();
+
+	// delete remaining renderables from queue:
+	// all which are not in mLeavePassesInQueue)
+	_deleteRenderedQueueGroups(mLeavePassesInQueue);
+
+	/////////////
+	//-- reset parameters needed for special rendering
+		
+	mIsDepthPassPhase = false;
+	mIsItemBufferPhase = false;
+	mSkipTransparents = false;
+	mIsHierarchicalCulling = false;
+		
+	mLeavePassesInQueue = 0;
+		
+	/////////////
+	//-- now we can render all remaining queue objects
+	//-- used for depth pass, transparents, overlay
+    clearSpecialCaseRenderQueues();
+
+	// the shaded geometry is rendered in a second pass
+	// add visible nodes found by the visibility culling algorithm
+	NodeList::const_iterator it, it_end = mVisible.end();
+
+	if(1) 
+	for (it = mVisible.begin(); it != it_end; ++ it)
+	{
+		(*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
+	}
+}
+#endif
+void OcclusionCullingSceneManager::RenderDepthPass()
+{
+	InitDepthPass(); // create material for depth pass
+
+	////////////////////
+	//-- hierarchical culling
+
+	// set all necessary parameters for 
+	// hierarchical visibility culling and rendering
+	InitVisibilityCulling(mCameraInProgress);
+
+
+	/** 
+	* the hierarchical culling algorithm
+	* for depth pass: we just find objects and update depth buffer
+	* for "delayed" rendering: we render some passes afterwards
+	* e.g., transparents, because they need front-to-back sorting
+	**/
+		
+	mVisibilityManager->ApplyVisibilityCulling();
+
+	// delete remaining renderables from queue
+	//_deleteRenderedQueueGroups();
+	getRenderQueue()->clear();
+
+	/////////////
+	//-- reset parameters needed for special rendering
+		
+	mIsDepthPassPhase = false;
+	mIsItemBufferPhase = false;
+	mSkipTransparents = false;
+	mIsHierarchicalCulling = false;
+	mLeavePassesInQueue = 0;
+		
+	// the shaded geometry is rendered in a second pass
+	// add visible nodes found by the visibility culling algorithm
+	NodeList::const_iterator it, it_end = mVisible.end();
+
+	if(1) 
+	for (it = mVisible.begin(); it != it_end; ++ it)
+	{
+		(*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
+	}
+}
 //-----------------------------------------------------------------------
 bool OcclusionCullingSceneManager::LoadSceneObj(const String &filename,
@@ -1841,4 +1943,177 @@
 	return true;
 }
+
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManager::_renderScene(Camera* camera, Viewport* vp, bool includeOverlays)
+{
+    Root::getSingleton()._setCurrentSceneManager(this);
+	mActiveQueuedRenderableVisitor->targetSceneMgr = this;
+
+    if (isShadowTechniqueInUse())
+    {
+        // Prepare shadow materials
+        initShadowVolumeMaterials();
+    }
+
+    // Perform a quick pre-check to see whether we should override far distance
+    // When using stencil volumes we have to use infinite far distance
+    // to prevent dark caps getting clipped
+    if (isShadowTechniqueStencilBased() && 
+        camera->getProjectionType() == PT_PERSPECTIVE &&
+        camera->getFarClipDistance() != 0 && 
+        mDestRenderSystem->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE) && 
+        mShadowUseInfiniteFarPlane)
+    {
+        // infinite far distance
+        camera->setFarClipDistance(0);
+    }
+
+    mCameraInProgress = camera;
+
+
+    // Update controllers 
+    ControllerManager::getSingleton().updateAllControllers();
+
+    // Update the scene, only do this once per frame
+    unsigned long thisFrameNumber = Root::getSingleton().getCurrentFrameNumber();
+    if (thisFrameNumber != mLastFrameNumber)
+    {
+        // Update animations
+        _applySceneAnimations();
+        mLastFrameNumber = thisFrameNumber;
+    }
+
+    // Update scene graph for this camera (can happen multiple times per frame)
+    _updateSceneGraph(camera);
+
+    // Auto-track nodes
+    AutoTrackingSceneNodes::iterator atsni, atsniend;
+    atsniend = mAutoTrackingSceneNodes.end();
+    for (atsni = mAutoTrackingSceneNodes.begin(); atsni != atsniend; ++atsni)
+    {
+        (*atsni)->_autoTrack();
+    }
+    // Auto-track camera if required
+    camera->_autoTrack();
+
+
+    // Are we using any shadows at all?
+    if (isShadowTechniqueInUse() && 
+        mIlluminationStage != IRS_RENDER_TO_TEXTURE &&
+		vp->getShadowsEnabled() &&
+		mFindVisibleObjects)
+    {
+        // Locate any lights which could be affecting the frustum
+        findLightsAffectingFrustum(camera);
+        if (isShadowTechniqueTextureBased())
+        {
+            // *******
+            // WARNING
+            // *******
+            // This call will result in re-entrant calls to this method
+            // therefore anything which comes before this is NOT 
+            // guaranteed persistent. Make sure that anything which 
+            // MUST be specific to this camera / target is done 
+            // AFTER THIS POINT
+            prepareShadowTextures(camera, vp);
+            // reset the cameras because of the re-entrant call
+            mCameraInProgress = camera;
+        }
+    }
+
+    // Invert vertex winding?
+    if (camera->isReflected())
+    {
+        mDestRenderSystem->setInvertVertexWinding(true);
+    }
+    else
+    {
+        mDestRenderSystem->setInvertVertexWinding(false);
+    }
+
+    // Tell params about viewport
+    mAutoParamDataSource.setCurrentViewport(vp);
+    // Set the viewport
+    setViewport(vp);
+
+    // Tell params about camera
+    mAutoParamDataSource.setCurrentCamera(camera);
+    // Set autoparams for finite dir light extrusion
+    mAutoParamDataSource.setShadowDirLightExtrusionDistance(mShadowDirLightExtrudeDist);
+
+    // Tell params about current ambient light
+    mAutoParamDataSource.setAmbientLightColour(mAmbientLight);
+	// Tell rendersystem
+	mDestRenderSystem->setAmbientLight(mAmbientLight.r, mAmbientLight.g, mAmbientLight.b);
+
+    // Tell params about render target
+    mAutoParamDataSource.setCurrentRenderTarget(vp->getTarget());
+
+
+    // Set camera window clipping planes (if any)
+    if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES))
+    {
+        if (camera->isWindowSet())  
+        {
+            const std::vector<Plane>& planeList = 
+                camera->getWindowPlanes();
+            for (ushort i = 0; i < 4; ++i)
+            {
+                mDestRenderSystem->enableClipPlane(i, true);
+                mDestRenderSystem->setClipPlane(i, planeList[i]);
+            }
+        }
+        else
+        {
+            for (ushort i = 0; i < 4; ++i)
+            {
+                mDestRenderSystem->enableClipPlane(i, false);
+            }
+        }
+    }
+
+	// Prepare render queue for receiving new objects
+	prepareRenderQueue();
+
+	mDestRenderSystem->_beginGeometryCount();
+    // Begin the frame
+    mDestRenderSystem->_beginFrame();
+
+    // Set rasterisation mode
+    mDestRenderSystem->_setPolygonMode(camera->getPolygonMode());
+
+	// Set initial camera state
+	mDestRenderSystem->_setProjectionMatrix(mCameraInProgress->getProjectionMatrixRS());
+	mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true));
+
+
+    if (mFindVisibleObjects)
+    {
+        // Parse the scene and tag visibles
+        _findVisibleObjects(camera, 
+            mIlluminationStage == IRS_RENDER_TO_TEXTURE? true : false);
+    }
+    // Add overlays, if viewport deems it
+    if (vp->getOverlaysEnabled() && mIlluminationStage != IRS_RENDER_TO_TEXTURE)
+    {
+        OverlayManager::getSingleton()._queueOverlaysForRendering(camera, getRenderQueue(), vp);
+    }
+    // Queue skies, if viewport seems it
+    if (vp->getSkiesEnabled() && mFindVisibleObjects && mIlluminationStage != IRS_RENDER_TO_TEXTURE)
+    {
+        _queueSkiesForRendering(camera);
+    }
+
+ 
+    // Render scene content 
+    _renderVisibleObjects();
+
+    // End frame
+    mDestRenderSystem->_endFrame();
+
+    // Notify camera or vis faces
+    camera->_notifyRenderedFaces(mDestRenderSystem->_getFaceCount());
+}
+
 //-----------------------------------------------------------------------
 const String OcclusionCullingSceneManagerFactory::FACTORY_TYPE_NAME = "OcclusionCullingSceneManager";
@@ -1862,5 +2137,5 @@
 	mTerrainPageSources.push_back(ps);
 	tsm->registerPageSource("Heightmap", ps);
-LogManager::getSingleton().logMessage("here4");
+
 	return tsm;
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2146)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2160)
@@ -21,5 +21,5 @@
 				Optimization="0"
 				AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;Timer"
-				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_BIT_PVS"
+				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
