Index: GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp	(revision 643)
+++ GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp	(revision 724)
@@ -10,7 +10,8 @@
 
 RenderTraverser::RenderTraverser(): mFrameID(1), mVisibilityThreshold(0),
-mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrentTestIdx(0), mIsQueryMode(false),
+mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrentQueryIdx(0), mIsQueryMode(false),
 mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0),
-mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true)
+mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true),
+mUseArbQueries(false)
 {
 }
@@ -18,6 +19,5 @@
 RenderTraverser::~RenderTraverser()
 {
-	if(mOcclusionQueries) 
-		delete [] mOcclusionQueries;
+	DelQueries();
 }
 
@@ -47,5 +47,5 @@
 
 	mFrameID ++;
-	ResetQueries();
+	
 
 	long endTime = getTime();
@@ -267,11 +267,20 @@
 }
 
-bool RenderTraverser::ResultAvailable(HierarchyNode *node)
-{
-	int result;
-
-	glGetQueryivARB(node->GetOcclusionQuery(),
-					GL_QUERY_RESULT_AVAILABLE_ARB, &result);
-
+bool RenderTraverser::ResultAvailable(HierarchyNode *node) const
+{
+	unsigned int result;
+	if (mUseArbQueries)
+	{
+		glGetQueryObjectuivARB(node->GetOcclusionQuery(),
+							   GL_QUERY_RESULT_AVAILABLE_ARB, &result);
+	}
+	else
+	{
+		
+		glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), 
+								 GL_PIXEL_COUNT_AVAILABLE_NV, &result);
+
+	}
+	
 	return (result == GL_TRUE);
 }
@@ -281,7 +290,5 @@
 	mHierarchyRoot = sceneRoot;
 
-	// not valid anymore for new hierarchy => delete
-	delete [] mOcclusionQueries;
-	mOcclusionQueries = NULL;
+	DelQueries();
 }
 
@@ -291,11 +298,18 @@
 }
 
-int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node)
+unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const
 {
 	unsigned int result;
-	
-	glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result);
-
-	return (int)result;
+
+	if (mUseArbQueries)
+	{
+		glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result);
+	}
+	else
+	{
+		glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), GL_PIXEL_COUNT_NV, &result);
+	}
+
+	return result;
 }
 
@@ -330,9 +344,17 @@
 {
 	// get next available test id
-	unsigned int occlusionQuery = mOcclusionQueries[mCurrentTestIdx++];
+	unsigned int occlusionQuery = mOcclusionQueries[mCurrentQueryIdx ++];
 	
 	node->SetOcclusionQuery(occlusionQuery);
+
 	// do the actual occlusion query for this node
-	glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery);
+	if (mUseArbQueries)
+	{
+		glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery);
+	}
+	else
+	{
+		glBeginOcclusionQueryNV(occlusionQuery);
+	}
 	
 	// if leaf and was visible => will be rendered anyway, thus we
@@ -350,12 +372,29 @@
 	}
 
-	glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+	if (mUseArbQueries)
+	{
+		glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+	}
+	else
+	{
+		glEndOcclusionQueryNV();
+	}
 }
 
 void RenderTraverser::Preprocess()
 {
-	if(!mOcclusionQueries)
+	if (!mOcclusionQueries)
 	{
 		mOcclusionQueries = new unsigned int[mHierarchyRoot->GetNumHierarchyNodes()];
+
+		// generate ids for occlusion test
+		if (mUseArbQueries)
+		{
+			glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
+		}
+		else
+		{
+			glGenOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
+		}
 	}
 
@@ -363,7 +402,6 @@
 	calcViewFrustumPlanes(&mClipPlanes, mProjViewMatrix);
 	calcAABNPVertexIndices(mNPVertexIndices, mClipPlanes);
-	// generate ids for occlusion test
-	glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
-	mCurrentTestIdx = 0;
+
+	mCurrentQueryIdx = 0;
 
 	// reset statistics
@@ -375,8 +413,22 @@
 
 
-void RenderTraverser::ResetQueries()
-{
+void RenderTraverser::DelQueries()
+{
+	if (!mOcclusionQueries)
+		return;
+
 	// tell the driver that the occlusion queries won't be needed any more
-	glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
+	if (mUseArbQueries)
+	{
+		glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
+	}
+	else
+	{
+		glDeleteOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries);
+	}
+
+	delete [] mOcclusionQueries;
+
+	mOcclusionQueries = NULL;
 }
 
@@ -435,4 +487,15 @@
 }
 
+void RenderTraverser::SetUseArbQueries(const bool useArbQueries)
+{
+	DelQueries();
+	mUseArbQueries = useArbQueries;
+}
+
+bool RenderTraverser::GetUseArbQueries() const
+{
+	return mUseArbQueries;
+}
+
 long RenderTraverser::GetRenderTime()
 {
