Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 155)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 156)
@@ -9,4 +9,5 @@
 #include <OgreEntity.h>
 #include <OgreSubEntity.h>
+
 
 namespace Ogre {
@@ -31,5 +32,6 @@
 mSkipTransparents(false),
 mSavedShadowTechnique(SHADOWTYPE_NONE),
-mRenderOnlyBoundingBoxes(false)
+mRenderHierarchyNodes(false)
+//mRenderHierarchyNodes(true)
 {
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
@@ -147,5 +149,5 @@
 	//Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass); 
 	
-	// set depth fill pass only if depth write enabled
+	// set depth fill pass if we currently do not make an aabb occlusion query
 	Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? 
 					  mDepthPass : pass);
@@ -208,4 +210,10 @@
 void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
 {
+	// clear list of solid boxes (used for item buffer hierarchy node rendering)
+	/*for (int i=0; i<(int)mSolidBoxes.size(); ++i)
+		delete mSolidBoxes[i];
+
+	mSolidBoxes.clear();*/
+
 	//-- show visible scene nodes and octree bounding boxes from last frame
 	if (mShowVisualization)
@@ -213,6 +221,28 @@
 		PrepareVisualization(cam);
 	}
-	else if (mRenderOnlyBoundingBoxes)
-	{
+	else if (mRenderHierarchyNodes)
+	{
+		AxisAlignedBox aab;
+		
+
+		// get rendered hierarchy nodes from last frame
+		GtpVisibility::HierarchyNodeList *nodeList = mHierarchyInterface->GetRenderedNodes();
+		GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end();
+
+		for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)		
+		{
+			SolidBoundingBox *solidBox = new SolidBoundingBox();
+			solidBox->SetupBoundingBox(aab);
+
+			Octree *octree = static_cast<Octree *>(*nodeIt);
+			solidBox->setId(octree->getId());
+			mSolidBoxes.push_back(solidBox);
+
+			aab = octree->_getWorldAABB();
+			std::stringstream d; d << "bounding box with id: " << octree->getId() << ", " << aab << "\n";
+			LogManager::getSingleton().logMessage(d.str());
+
+			getRenderQueue()->addRenderable(solidBox);	
+		}
 	}
 	else 
@@ -233,7 +263,7 @@
 	//TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
 	
+	// -- delete lists stored for visualization
 	mVisible.clear();
 	mBoxes.clear();
-
 }
 //-----------------------------------------------------------------------
@@ -246,11 +276,12 @@
     // e.g., visualization, shadow pass
 
-	if (mShowVisualization || mRenderOnlyBoundingBoxes ||
-	   (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && mIlluminationStage == IRS_RENDER_TO_TEXTURE))
+	if (mShowVisualization || mRenderHierarchyNodes ||
+	   (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
+	    mIlluminationStage == IRS_RENDER_TO_TEXTURE))
 	{	
 		IlluminationRenderStage savedStage = mIlluminationStage; 
 	
-		if (mShowVisualization) 
-			// disable illumination stage because we want no shadows in visualization
+		if (mShowVisualization || mRenderHierarchyNodes) 
+			// disable illumination stage because we want no shadows
 			mIlluminationStage = IRS_NONE;
 
@@ -416,4 +447,8 @@
 		mUseItemBuffer = (*static_cast<const bool *>(val));
 		return true;
+	}
+	if (key == "RenderHierarchyNodes")
+	{
+		mRenderHierarchyNodes = (*static_cast<const bool *>(val));
 	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
@@ -503,5 +538,6 @@
 	}
 
-	//--- item buffer
+	// --- item buffer
+
     // Iterate through priorities
     RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
@@ -604,11 +640,5 @@
 
 	Pass *usedPass = setPass(mItemBufferPass); 
-	
-	/*if (rend->getId() > 0)
-	{
-		std::stringstream d; d << "item buffer id: " << rend->getId() << ", col: " << col[0] <<
-			" " << col[1] << " " << col[2] << " " << col[3];
-		LogManager::getSingleton().logMessage(d.str());
-	}*/
+
 
 	// Render a single object, this will set up auto params if required
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 155)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 156)
@@ -41,5 +41,4 @@
 	if (depthMat.isNull())
     {
-		// Init
 		depthMat = MaterialManager::getSingleton().create(
                 "Visibility/DepthPass",
Index: trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 154)
+++ trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 156)
@@ -57,9 +57,11 @@
 		// prevent from initialising geometry / node array again
 		if (i > 0)
+		{
 			mWasInitialised = true;
+		}
 
 		ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);
 		
-		//mViewport->getTarget()->update(); for(int j=0; j<10000000; j++)	printf("wait");
+		mViewport->getTarget()->update(); for(int j=0; j<10000000; j++)	printf("wait");
 
 		// permute directions
Index: trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp	(revision 155)
+++ trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp	(revision 156)
@@ -32,5 +32,5 @@
 	SceneManager *sm = pfHierarchyInterface->GetSceneManager();
 
-	// ---- Render scene as item buffer (i.e., objects with their id as color codes)
+	// ---- Render scene with item buffer (i.e., objects with their id as color codes)
 
 	// const_cast allowed because camera is not changed in renderScene
@@ -52,15 +52,4 @@
 	// --- render item buffer
 	pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
-	
-
-
-	// reset old overlay status
-	mViewport->setOverlaysEnabled(overlayEnabled);
-	
-	mViewport->setBackgroundColour(bg);
-
-	// don't need item buffer anymore
-	useItemBuffer = false;
-	sm->setOption("UseItemBuffer", &useItemBuffer);
 
 
@@ -88,6 +77,48 @@
 	}
 
+	delete [] buf;
+
+	// ---- render visible nodes and collect node visibility
+	bool renderBoxes = true;
+	sm->setOption("RenderHierarchyNodes", &renderBoxes);
+
+
+	// --- render item buffer for visible nodes only
+	pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
+
+
+	// get frame buffer for node visibility
+	buf = mViewport->getTarget()->getBufferContents(dimx, dimy);
+
+	
+	// loop through frame buffer & collect visible pixels
+	for (int idx = 0; idx < dimy * dimx * 3; idx += 3)
+	{
+		// -- decode color code to receive id
+		int id = buf[idx] << 16;
+		id += buf[idx + 1] << 8;
+		id += buf[idx + 2];
+
+		// if valid id <= add visibility (id values start at 1
+		if ((id > 0) && (id < (int)visibleNodes->size()))
+		{
+			((*visibleNodes)[id]).AddVisibility(1, 1);
+		}
+	}
+
+	// don't need item buffer anymore
+	useItemBuffer = false;
+	//sm->setOption("UseItemBuffer", &useItemBuffer);
+
+	renderBoxes = false;
+	//sm->setOption("RenderHierarchyNodes", &renderBoxes);
+
 	// reset initialised - flag
 	mWasInitialised = false;
+
+	// reset old overlay status
+	mViewport->setOverlaysEnabled(overlayEnabled);
+	
+	mViewport->setBackgroundColour(bg);
 
 	delete [] buf;
@@ -99,5 +130,4 @@
 	if (mWasInitialised)
 		return;
-
 
 	mWasInitialised = true;
@@ -122,6 +152,9 @@
 	GtpVisibility::HierarchyNode *node = NULL;
 	
+	int i = 1;
+
 	while (node = mHierarchyInterface->GetNextNode())
 	{
+		mHierarchyInterface->SetNodeId(node, i++);
 		visibleNodes->push_back(GtpVisibility::NodeInfo(node, 0, 0));
 	}
