Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2792)
@@ -21,8 +21,9 @@
 {
 public:
-int id;
 	/** Creates a scene entity.
 	*/
 	SceneEntity(Geometry *geometry, Material *mat, Matrix4x4 *trafo);
+
+	~SceneEntity();
 	/** Renders this node.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.h	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.h	(revision 2792)
@@ -18,4 +18,9 @@
 	
 protected:
+	/** Optimized query querying the node geometry instead
+		of the bounding box
+	*/
+	OcclusionQuery *IssueOcclusionQueryWithGeometry(BvhNode *node);
+
 	/** Traverses and renders the scene with the specified method
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2792)
@@ -25,5 +25,4 @@
 	mNumRenderedNodes = 0;
 
-	mNumPreviouslyVisibleNodeQueries = 0;
 	mNumIssuedQueries = 0;
 	mNumStateChanges = 0;
@@ -166,5 +165,5 @@
 {
 	mUseRenderQueue = useRenderQueue;
-	std::cout << "using render queue: " << mUseRenderQueue << std::endl;
+	//std::cout << "using render queue: " << mUseRenderQueue << std::endl;
 }
 
@@ -179,4 +178,5 @@
 {
 	mUseOptimization = useOptimization;
+	//cout << "using optimization: " << mUseOptimization << endl;
 }
 
@@ -214,10 +214,10 @@
 
 
-OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible)
+OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node)
 {
 	OcclusionQuery *query = mQueryHandler.RequestQuery();
 	query->AddNode(node);
 
-	IssueOcclusionQuery(*query, wasVisible);
+	IssueOcclusionQuery(*query);
 
 	return query;
@@ -225,5 +225,5 @@
 
 
-void RenderTraverser::IssueOcclusionQuery(const OcclusionQuery &query, bool wasVisible)
+void RenderTraverser::IssueOcclusionQuery(const OcclusionQuery &query)
 {
 	++ mStats.mNumIssuedQueries;
@@ -238,23 +238,10 @@
 	query.BeginQuery();
 
-	if (wasVisible)
-		++ mStats.mNumPreviouslyVisibleNodeQueries;
-
-	// if this node is a previous visible leaf:
-	// leaves will be rendered anyway => we can also test with the real geometry 
-	if (wasVisible && mUseOptimization)
-	{
-		for (size_t i = 0; i < query.GetSize(); ++ i)
-			RenderNode(query.GetNodes()[i]);
-	}
-	else
-	{
-		// change to query mode and render box
-		if (mRenderState->SetState(RenderState::QUERY))
-			++ mStats.mNumStateChanges;
-
-		mBvh->RenderBounds(query.GetNodes(), mRenderState, mUseTightBounds);
-	}
-
+	// change to query mode and render box
+	if (mRenderState->SetState(RenderState::QUERY))
+		++ mStats.mNumStateChanges;
+
+	mBvh->RenderBounds(query.GetNodes(), mRenderState, mUseTightBounds);
+	
 	query.EndQuery();
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2792)
@@ -79,5 +79,4 @@
 mTestNodesIdx(-1),
 mIndicesPtr(-1),
-mIndices(NULL),
 mId(0),
 mIsMaxDepthForVirtualLeaf(false),
@@ -95,5 +94,4 @@
 {
 	mVisibility.Reset();
-
 	mLastRenderedFrame = -999;
 }
@@ -111,4 +109,11 @@
 
 
+BvhInterior::~BvhInterior() 
+{
+	DEL_PTR(mBack);
+	DEL_PTR(mFront); 
+}
+
+
 BvhLeaf::~BvhLeaf()
 {
@@ -151,5 +156,5 @@
 Bvh::~Bvh() 
 {
-	if (mVertices) delete []mVertices; 
+	if (mVertices) delete [] mVertices; 
 	if (mIndices) delete [] mIndices;
 	if (mTestIndices) delete [] mTestIndices;
@@ -157,4 +162,7 @@
 
 	if (mRoot) delete mRoot;
+
+	// delete vbo
+	glDeleteBuffersARB(1, &mVboId);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2792)
@@ -15,4 +15,12 @@
 mGeometry(geometry), mMaterial(mat), mTransform(trafo)
 {
+}
+
+
+SceneEntity::~SceneEntity()
+{
+	// delete only trafo here, the other members could be shared
+	// among several entities and are therefore handled separately
+	DEL_PTR(mTransform);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp	(revision 2792)
@@ -35,5 +35,5 @@
 			else
 			{
-				OcclusionQuery *query = IssueOcclusionQuery(node, false);
+				OcclusionQuery *query = IssueOcclusionQuery(node);
 
 				int visiblePixels = query->GetQueryResult();
@@ -60,4 +60,11 @@
 		}	
 	}
+
+	/// Empty render queue.
+	if (mUseRenderQueue)
+	{
+		mRenderQueue.Render();
+		mRenderQueue.Clear();
+	}
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp	(revision 2792)
@@ -8,4 +8,27 @@
 CHCTraverser::CHCTraverser() 
 {}
+
+
+OcclusionQuery *CHCTraverser::IssueOcclusionQueryWithGeometry(BvhNode *node)
+{
+	OcclusionQuery *query = mQueryHandler.RequestQuery();
+	query->AddNode(node);
+
+	++ mStats.mNumIssuedQueries;
+
+	query->BeginQuery();
+
+	RenderNode(node);
+
+	if (mUseRenderQueue)
+	{
+		mRenderQueue.Render();
+		mRenderQueue.Clear();
+	}
+
+	query->EndQuery();
+
+	return query;
+}
 
 
@@ -65,5 +88,5 @@
 					
 					// identify nodes that we cannot skip queries for
-					const bool testFeasible = (!wasVisible || 
+					const bool queryFeasible = (!wasVisible || 
 						(node->IsVirtualLeaf() && (node->GetAssumedVisibleFrameId() <= mFrameId)));
 
@@ -72,7 +95,15 @@
 					
 					// skip testing previously visible interior nodes
-					if (testFeasible)
+					if (queryFeasible)
 					{
-						OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible);
+						OcclusionQuery *query;
+
+						// if this node is a previous visible leaf:
+						// leaves will be rendered anyway => we can directly query the real geometry 
+						if (wasVisible && mUseOptimization)
+							query = IssueOcclusionQueryWithGeometry(node);
+						else
+							query = IssueOcclusionQuery(node);
+
 						mQueryQueue.push(query);
 					}
@@ -103,4 +134,11 @@
 		}
 	}
+
+	/// Empty render queue.
+	if (mUseRenderQueue)
+	{
+		mRenderQueue.Render();
+		mRenderQueue.Clear();
+	}
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2792)
@@ -51,5 +51,5 @@
 
 const float keyForwardMotion = 1.0f;
-const float keyRotation = 0.2f;
+const float keyRotation = 0.05f;
 
 int winWidth = 1024;
@@ -76,6 +76,7 @@
 bool visMode = false;
 
-//mouse navigation state
-int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0;
+// mouse navigation state
+int xEyeBegin, yEyeBegin, yMotionBegin = 0;
+int verticalMotionBegin, horizontalMotionBegin = 0;
 
 bool useOptimization = false;
@@ -88,4 +89,8 @@
 Matrix4x4 visView = IdentityMatrix();
 
+bool leftKeyPressed = false;
+bool rightKeyPressed = false;
+bool upKeyPressed = false;
+bool downKeyPressed = false;
 
 void InitExtensions();
@@ -100,20 +105,24 @@
 void DrawHelpMessage();
 
-void begin2D();
-void end2D();
-void keyboard(unsigned char c, int x, int y);
-void drawStatistics();
-void display(void);
-void special(int c, int x, int y);
-void reshape(int w, int h);
-void mouse(int button, int state, int x, int y);
-void leftMotion(int x, int y);
-void rightMotion(int x, int y);
-void middleMotion(int x, int y);
-void drawEyeView();
-void setupVisView();
-void CalcDecimalPoint(std::string &str, int d);
+void Begin2D();
+void End2D();
+void KeyBoard(unsigned char c, int x, int y);
+void DrawStatistics();
+void Display();
+void Special(int c, int x, int y);
+void KeyUp(unsigned char c, int x, int y);
+void SpecialKeyUp(int c, int x, int y);
+void Reshape(int w, int h);
+void Mouse(int button, int state, int x, int y);
+void LeftMotion(int x, int y);
+void RightMotion(int x, int y);
+void MiddleMotion(int x, int y);
+void SetupVisView();
+void CalcDecimalPoint(string &str, int d);
 void ResetTraverser();
 
+void KeyHorizontalMotion(float shift);
+void KeyRotate(float angle);
+
 
 
@@ -122,5 +131,5 @@
 	int returnCode = 0;
 
-#ifdef _CRT_SET
+//#ifdef _CRT_SET
 
 	//Now just call this function at the start of your program and if you're
@@ -133,5 +142,5 @@
 	_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
 	_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
-#endif
+//#endif
 
 
@@ -145,16 +154,19 @@
 	glutCreateWindow("Coherent Hierarchical Culling");
 
-	glutDisplayFunc(display);
-	glutKeyboardFunc(keyboard);
-	glutSpecialFunc(special);
-	glutReshapeFunc(reshape);
-	glutMouseFunc(mouse);
-	glutIdleFunc(display);
-	
+	glutDisplayFunc(Display);
+	glutKeyboardFunc(KeyBoard);
+	glutSpecialFunc(Special);
+	glutReshapeFunc(Reshape);
+	glutMouseFunc(Mouse);
+	glutIdleFunc(Display);
+	glutKeyboardUpFunc(KeyUp);
+	glutSpecialUpFunc(SpecialKeyUp);
+	glutIgnoreKeyRepeat(true);
+
 	InitExtensions();
 	InitGLstate();
 
-	leftMotion(0, 0);
-	middleMotion(0, 0);
+	LeftMotion(0, 0);
+	MiddleMotion(0, 0);
 
 	BinaryLoader loader;
@@ -168,6 +180,9 @@
 	{
 		cerr << "loading scene " << filename << " failed" << endl;
+		CleanUp();
 		exit(0);
 	}
+	CleanUp();
+		exit(0);
 
 	const string bvh_filename = string(model_path + "city.bvh");
@@ -179,4 +194,5 @@
 	{
 		cerr << "loading bvh " << bvh_filename << " failed" << endl;
+		CleanUp();
 		exit(0);
 	}
@@ -268,4 +284,5 @@
 		"'B'            - use tight bounds",
 		"'M'            - use multiqueries",
+		"'O'            - use CHC optimization (geometry queries for leaves)",
 		0,
 	};
@@ -297,5 +314,4 @@
 		}
 	}
-
 }
 
@@ -345,7 +361,4 @@
 	glEnable(GL_LIGHT1);
 
-	//glDisable(GL_LIGHT1);
-	//glDisable(GL_LIGHTING);
-
 	//GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0};
 	GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
@@ -405,6 +418,37 @@
 
 
-void display(void) 
-{
+void KeyRotate(float angle)
+{
+	Vector3 viewDir = camera->GetDirection();
+	// rotate view vector
+	Matrix4x4 rot = RotationZMatrix(angle);
+	viewDir = rot * viewDir;
+	camera->SetDirection(viewDir);
+}
+
+
+void KeyHorizontalMotion(float shift)
+{
+	Vector3 hvec = camera->GetDirection();
+	hvec.z = 0;
+
+	Vector3 pos = camera->GetPosition();
+	pos += hvec * shift;
+	
+	camera->SetPosition(pos);
+}
+
+
+void Display() 
+{
+	if (leftKeyPressed)
+		KeyRotate(keyRotation);
+	if (rightKeyPressed)
+		KeyRotate(-keyRotation);
+	if (upKeyPressed)
+		KeyHorizontalMotion(keyForwardMotion);
+	if (downKeyPressed)
+		KeyHorizontalMotion(-keyForwardMotion);
+
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -424,5 +468,5 @@
 
 #pragma warning( disable : 4100 )
-void keyboard(const unsigned char c, const int x, const int y) 
+void KeyBoard(unsigned char c, int x, int y) 
 {
 	// used to avoid vertical motion with the keys
@@ -433,4 +477,5 @@
 	{
 	case 27:
+		CleanUp();
 		exit(0);
 		break;
@@ -480,6 +525,6 @@
 			break;
 		}	
-	case 'g':
-	case 'G':
+	case 'o':
+	case 'O':
 		useOptimization = !useOptimization;
 		traverser->SetUseOptimization(useOptimization);
@@ -488,9 +533,6 @@
 	case 'A':
 		{
-			Vector3 viewDir = camera->GetDirection();
-			// rotate view vector
-			Matrix4x4 rot = RotationZMatrix(keyRotation);
-			viewDir = rot * viewDir;
-			camera->SetDirection(viewDir);
+			leftKeyPressed = true;
+			KeyRotate(keyRotation);
 		}
 		break;
@@ -498,9 +540,6 @@
 	case 'D':
 	{
-			Vector3 viewDir = camera->GetDirection();
-			// rotate view vector
-			Matrix4x4 rot = RotationZMatrix(-keyRotation);
-			viewDir = rot * viewDir;
-			camera->SetDirection(viewDir);
+			rightKeyPressed = true;
+			KeyRotate(-keyRotation);
 		}
 		break;
@@ -508,7 +547,6 @@
 	case 'W':
 		{
-			Vector3 pos = camera->GetPosition();
-			pos += hvec * keyForwardMotion;
-			camera->SetPosition(pos);
+			upKeyPressed = true;
+			KeyHorizontalMotion(keyForwardMotion);
 		}
 		break;
@@ -516,7 +554,6 @@
 	case 'X':
 		{
-			Vector3 pos = camera->GetPosition();
-			pos -= hvec * keyForwardMotion;
-			camera->SetPosition(pos);
+			downKeyPressed = true;
+			KeyHorizontalMotion(-keyForwardMotion);
 		}
 		break;
@@ -535,4 +572,7 @@
 		}
 		break;
+
+
+
 	default:
 		return;
@@ -543,5 +583,55 @@
 
 
-void special(int c, int x, int y) 
+void SpecialKeyUp(int c, int x, int y) 
+{
+	switch (c) 
+	{
+	case GLUT_KEY_LEFT:
+		leftKeyPressed = false;
+		break;
+	case GLUT_KEY_RIGHT:
+		rightKeyPressed = false;
+		break;
+	case GLUT_KEY_UP:
+		upKeyPressed = false;
+		break;
+	case GLUT_KEY_DOWN:
+		downKeyPressed = false;
+		break;
+	default:
+		return;
+	}
+	//glutPostRedisplay();
+}
+
+
+void KeyUp(unsigned char c, int x, int y) 
+{
+	switch (c) 
+	{
+	case 'A':
+	case 'a':
+		leftKeyPressed = false;
+		break;
+	case 'D':
+	case 'd':
+		rightKeyPressed = false;
+		break;
+	case 'W':
+	case 'w':
+		upKeyPressed = false;
+		break;
+	case 'X':
+	case 'x':
+		downKeyPressed = false;
+		break;
+	default:
+		return;
+	}
+	//glutPostRedisplay();
+}
+
+
+void Special(int c, int x, int y) 
 {
 	// used to avoid vertical motion with the keys
@@ -568,32 +658,24 @@
 	case GLUT_KEY_LEFT:
 		{
-			Vector3 viewDir = camera->GetDirection();
-			// rotate view vector
-			Matrix4x4 rot = RotationZMatrix(keyRotation);
-			viewDir = rot * viewDir;
-			camera->SetDirection(viewDir);
+			leftKeyPressed = true;
+			KeyRotate(keyRotation);
 		}
 		break;
 	case GLUT_KEY_RIGHT:
 		{
-			Vector3 viewDir = camera->GetDirection();
-			// rotate view vector
-			Matrix4x4 rot = RotationZMatrix(-keyRotation);
-			viewDir = rot * viewDir;
-			camera->SetDirection(viewDir);
+			rightKeyPressed = true;
+			KeyRotate(-keyRotation);
 		}
 		break;
 	case GLUT_KEY_UP:
 		{
-			Vector3 pos = camera->GetPosition();
-			pos += hvec * 0.6f;
-			camera->SetPosition(pos);
+			upKeyPressed = true;
+			KeyHorizontalMotion(keyForwardMotion);
 		}
 		break;
 	case GLUT_KEY_DOWN:
 		{
-			Vector3 pos = camera->GetPosition();
-			pos -= hvec * 0.6f;
-			camera->SetPosition(pos);
+			downKeyPressed = true;
+			KeyHorizontalMotion(-keyForwardMotion);
 		}
 		break;
@@ -609,5 +691,5 @@
 
 
-void reshape(const int w, const int h) 
+void Reshape(int w, int h) 
 {
 	winAspectRatio = 1.0f;
@@ -631,5 +713,5 @@
 
 
-void mouse(int button, int state, int x, int y) 
+void Mouse(int button, int state, int x, int y) 
 {
 	if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN))
@@ -638,5 +720,5 @@
 		yMotionBegin = y;
 
-		glutMotionFunc(leftMotion);
+		glutMotionFunc(LeftMotion);
 	}
 	else if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN))
@@ -645,5 +727,5 @@
 		yMotionBegin = y;
 
-		glutMotionFunc(rightMotion);
+		glutMotionFunc(RightMotion);
 	}
 	else if ((button == GLUT_MIDDLE_BUTTON) && (state == GLUT_DOWN))
@@ -651,5 +733,5 @@
 		horizontalMotionBegin = x;
 		verticalMotionBegin = y;
-		glutMotionFunc(middleMotion);
+		glutMotionFunc(MiddleMotion);
 	}
 
@@ -661,5 +743,5 @@
 	motion for up/down mouse drag
 */
-void leftMotion(int x, int y) 
+void LeftMotion(int x, int y) 
 {
 	static float eyeXAngle = 0.0f;
@@ -694,5 +776,5 @@
 	motion for up / down mouse drag
 */
-void rightMotion(int x, int y) 
+void RightMotion(int x, int y) 
 {
 	static float eyeYAngle = 0.0f;
@@ -716,5 +798,5 @@
 
 // strafe
-void middleMotion(int x, int y) 
+void MiddleMotion(int x, int y) 
 {
 	Vector3 viewDir = camera->GetDirection();
@@ -758,5 +840,5 @@
 
 
-void begin2D(void) 
+void Begin2D(void) 
 {
 	glDisable(GL_LIGHTING);
@@ -773,5 +855,5 @@
 
 
-void end2D(void) 
+void End2D(void) 
 {
 	glPopMatrix();
@@ -803,9 +885,9 @@
 void DisplayVisualization()
 {
-	setupVisView();
+	SetupVisView();
 
 	visualization->SetFrameId(traverser->GetCurrentFrameId());
 	
-	begin2D();
+	Begin2D();
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	glEnable(GL_BLEND);
@@ -814,5 +896,5 @@
 	glRecti(winWidth, 0, winWidth - winWidth / 4, winHeight / 3);
 	glDisable(GL_BLEND);
-	end2D();
+	End2D();
 	
 	glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth, winHeight);
@@ -859,5 +941,5 @@
 /** Sets up view matrix for bird eye view
 */
-void setupVisView()
+void SetupVisView()
 {
 	Vector3 pos(-bvh->GetBox().Center());
@@ -978,7 +1060,7 @@
 
 	sprintf_s(msg7, "fps: %6.1f", fps);
-	//cout << "previously visible node queries: " << traverser->GetStats().mNumPreviouslyVisibleNodeQueries << endl;
-
-	begin2D();
+
+
+	Begin2D();
 	
 	if(showHelp)
@@ -1007,4 +1089,4 @@
 	}
 
-	end2D();
+	End2D();
 }	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp	(revision 2792)
@@ -27,5 +27,5 @@
 			{
 				BvhNode *node = query->GetNodes()[i];
-				OcclusionQuery *q = IssueOcclusionQuery(node, false);
+				OcclusionQuery *q = IssueOcclusionQuery(node);
 				mQueryQueue.push(q);
 			}
@@ -91,5 +91,5 @@
 				mVQueue.pop();
 				
-				OcclusionQuery *query = IssueOcclusionQuery(node, true);
+				OcclusionQuery *query = IssueOcclusionQuery(node);
 
 				mQueryQueue.push(query);
@@ -128,5 +128,5 @@
 					
 					// identify nodes that we cannot skip queries for
-					const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() && 
+					const bool queryFeasible = (!wasVisible || (node->IsVirtualLeaf() && 
 						(node->GetAssumedVisibleFrameId() <= mFrameId)));
 
@@ -139,5 +139,5 @@
 					
 					// skip testing previously visible interior nodes
-					if (testFeasible)
+					if (queryFeasible)
 					{
 						if (!wasVisible)
@@ -202,5 +202,5 @@
 		mVQueue.pop();
 
-		OcclusionQuery *query = IssueOcclusionQuery(node, true);
+		OcclusionQuery *query = IssueOcclusionQuery(node);
 		mQueryQueue.push(query);
 	}
@@ -264,5 +264,5 @@
 
 	//cout <<"size: " << query->GetSize() << endl;
-	IssueOcclusionQuery(*query, false);
+	IssueOcclusionQuery(*query);
 
 	return query;
@@ -284,5 +284,5 @@
 			BvhNode *node = mIQueue.front();
 			mIQueue.pop();
-			query = IssueOcclusionQuery(node, false);
+			query = IssueOcclusionQuery(node);
 		}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BinaryLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BinaryLoader.cpp	(revision 2786)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BinaryLoader.cpp	(revision 2792)
@@ -207,5 +207,4 @@
 	{
 		SceneEntity *ent = LoadSceneEntity(str);
-		ent->id = i;
 		entities[i] = ent;
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrustumCullingTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrustumCullingTraverser.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrustumCullingTraverser.cpp	(revision 2792)
@@ -37,5 +37,5 @@
 	}
 
-	// render the rest of the objects
+	// render the contents of the render queue
 	if (mUseRenderQueue)
 	{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2792)
@@ -37,5 +37,4 @@
 	int mNumIssuedQueries;
 	int mNumStateChanges;
-	int mNumPreviouslyVisibleNodeQueries;
 	
 	double mRenderTime;
@@ -130,8 +129,8 @@
 	/** Issues occlusion query for a single node
 	*/
-	OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible);
+	OcclusionQuery *IssueOcclusionQuery(BvhNode *node);
 	/** Issue multiquery.
 	*/
-	void IssueOcclusionQuery(const OcclusionQuery &query, bool wasVisible);
+	void IssueOcclusionQuery(const OcclusionQuery &query);
 	/** Retunrs true if the current bvh node intersects the near plane.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 2790)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 2792)
@@ -190,9 +190,9 @@
 	int mLast;
 
-	/// these nodes can be tested instead of the current node
+	/// the bounding boxes of these nodes are queries instead of the current node
 	int mTestNodesIdx;
-	
+	/// the number of tighter bounding volumes used for this node
 	int mNumTestNodes;
-
+	/// used for efficient element array rendering
 	int mIndicesPtr;
 
@@ -203,6 +203,4 @@
 	/// the index of this node
 	unsigned int mId;
-	/// indices used for draw array rendering
-	unsigned int *mIndices;
 	/// the bounding box
 	AxisAlignedBox3 mBox;
@@ -342,8 +340,7 @@
 	*/
 	inline BvhNode *GetFront() { return mFront; }
-	/** recursivly delete tree.
-	*/
-	virtual ~BvhInterior() { if (mBack) delete mBack; if (mFront) delete mFront;}
-
+	/** Recursivly delete hierarchy.
+	*/
+	virtual ~BvhInterior();
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/chc_revisited.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/chc_revisited.vcproj	(revision 2785)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/chc_revisited.vcproj	(revision 2792)
@@ -468,8 +468,4 @@
 				</File>
 				<File
-					RelativePath=".\Material.h"
-					>
-				</File>
-				<File
 					RelativePath=".\src\OcclusionQuery.h"
 					>
