Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 29)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 30)
@@ -15,5 +15,6 @@
 	OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 
 	mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0),
-	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT)
+	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
+	mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), mNumRenderedGeometry(0)
 	{		
 		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
@@ -36,10 +37,12 @@
 	void OcclusionCullingSceneManager::_renderVisibleObjects(void)
 	{
+		mNumTraversedNodes = 0;
+		mNumQueryCulledNodes = 0;
+		mNumFrustumCulledNodes = 0;
+		mNumRenderedGeometry = 0;
+		
 		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress));
-		
 		mDistanceQueue->push(mSceneRoot);
-
 		mCurrentTestIdx = 0;
-
 		//renderZPass();
 
@@ -62,12 +65,4 @@
 		delete mDistanceQueue;
 
-		/*mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS);
-		  SceneManager::_renderVisibleObjects();
-		  mDestRenderSystem->_setDepthBufferParams();
-          mDistanceQueue.push(mSceneRoot);
-		  Preprocess();
-		  //ResetQueries();
-		*/
-		
 		mFrameId ++;
 	}
@@ -102,4 +97,8 @@
 					traverseNode(node);
 				}
+				else
+				{
+					mNumQueryCulledNodes ++;
+				}
 			}	
 
@@ -108,5 +107,4 @@
 			{
 				SceneNode *node = mDistanceQueue->top();
-
 				mDistanceQueue->pop();
 	
@@ -134,5 +132,11 @@
 					// always traverse a node if it was visible
 					if(wasVisible)
+					{
 						traverseNode(node);
+					}
+				}
+				else
+				{
+					mNumFrustumCulledNodes ++;
 				}
 			}
@@ -157,4 +161,8 @@
 				traverseNode(node);
 			}
+			else
+			{			
+				mNumFrustumCulledNodes ++;
+			}
 		}
 	}	
@@ -179,7 +187,4 @@
 				query->pullOcclusionQuery(&visiblePixels);
 				
-				//char str[100]; sprintf(str, "number: %d, id: %d", (int)visiblePixels, mCurrentTestIdx);
-				//MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
-
 				// node visible
 				if(visiblePixels > mVisibilityThreshold)
@@ -187,5 +192,13 @@
 					traverseNode(node);
 				}
-			}					
+				else
+				{
+					mNumQueryCulledNodes ++;
+				}
+			}
+			else
+			{
+				mNumFrustumCulledNodes ++;
+			}
 		}
 	}
@@ -203,8 +216,5 @@
 		/*
 		static RenderOperation ro;
-
-		// Issue view / projection changes if any
 		useRenderableViewProjMode(&box);
-
 		box.getRenderOperation(ro);
 		ro.srcRenderable = &box; 
@@ -237,24 +247,25 @@
 	void OcclusionCullingSceneManager::traverseNode(SceneNode *node)
 	{
-		if(isLeaf(node))
+		mNumTraversedNodes ++;
+
+		if(node->numAttachedObjects() > 0)
 		{
 			render(node);
 		}
-		else // internal node: add children to priority queue for further processing
-		{
-			Node::ChildNodeIterator it = node->getChildIterator();
+
+		// internal node: add children to priority queue for further processing
+		Node::ChildNodeIterator it = node->getChildIterator();
 					
-			while (it.hasMoreElements())
-			{ 
-				SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-				mDistanceQueue->push(sceneChild);
-			}
-		 }
+		while (it.hasMoreElements())			
+		{ 
+			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
+			mDistanceQueue->push(sceneChild);
+		}
 	}
 	//-----------------------------------------------------------------------
 	void OcclusionCullingSceneManager::render(SceneNode *node)
 	{
-		//setRenderingMode(MODE_RENDER);
-		//MessageBox( NULL, "harhar", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
+		setRenderingMode(MODE_RENDER);
+		
 		//HACK (too slow)
 		node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, 
@@ -266,17 +277,17 @@
 	void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)
 	{
-		int numnodes = countSceneNodes(mSceneRoot);
-		
+		unsigned int numnodes = countSceneNodes(mSceneRoot);
+	
 		//-- initialise occlusion queries.
 		if(numnodes != mNumSceneNodes)
 		{
 			deleteQueries();
+			
 			mNumSceneNodes = numnodes;
 
 			for(unsigned int i=0; i < mNumSceneNodes; i++)
 			{
-				HardwareOcclusionQuery *hw = mDestRenderSystem->createHardwareOcclusionQuery();
-				mOcclusionQueries.push_back(hw);
-			}
+				mOcclusionQueries.push_back(mDestRenderSystem->createHardwareOcclusionQuery());
+			}	
 		}
 
@@ -284,12 +295,8 @@
 	}
 	//-----------------------------------------------------------------------
-	int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node)
-	{
-		int num = 1;
-		if(isLeaf(node))
-		{
-			return num;
-		}
-
+	unsigned int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node)
+	{
+		unsigned int result = 1;
+		
 		Node::ChildNodeIterator it = node->getChildIterator();
 		
@@ -297,11 +304,11 @@
 		{ 
 			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-			num += countSceneNodes(sceneChild);
+			result += countSceneNodes(sceneChild);
         }
 
-		return num;
-	}
-	//-----------------------------------------------------------------------
-	int OcclusionCullingSceneManager::isLeaf(SceneNode *node)
+		return result;
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingSceneManager::isLeaf(SceneNode *node)
 	{
 		return (node->numChildren() == 0);
@@ -353,5 +360,10 @@
 			return true;
 		}
-	
+		if ( key == "Threshold" )
+		{
+			mCurrentAlgorithm = * static_cast < const int * > ( val );
+			return true;
+		}
+		
 		return SceneManager::setOption( key, val );
 	}
@@ -362,4 +374,29 @@
 		{
 			* static_cast < int * > ( val ) = mCurrentAlgorithm;
+			return true;
+		}
+		if ( key == "Threshold" )
+		{
+			* static_cast < int * > ( val ) = mVisibilityThreshold;
+			return true;
+		}
+		if ( key == "NumSceneNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumSceneNodes;
+			return true;
+		}
+		if ( key == "NumTraversedNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumTraversedNodes;
+			return true;
+		}
+		if ( key == "NumQueryCulledNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumQueryCulledNodes;
+			return true;
+		}
+		if ( key == "NumFrustumCulledNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumFrustumCulledNodes;
 			return true;
 		}
@@ -377,5 +414,10 @@
 		SceneManager::getOptionKeys( refKeys );
 		refKeys.push_back( "Algorithm" );
-	
+		refKeys.push_back( "Threshold" );
+		refKeys.push_back( "NumSceneNodes" );
+		refKeys.push_back( "NumTraversedNodes" );
+		refKeys.push_back( "NumQueryCulledNodes" );
+		refKeys.push_back( "NumFrustumCulledNodes" );
+		//refKeys.push_back( "mNumRenderedGeometry" );
 		return true;
 	}
