Changeset 724 for GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp
- Timestamp:
- 04/04/06 23:47:05 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp
r643 r724 10 10 11 11 RenderTraverser::RenderTraverser(): mFrameID(1), mVisibilityThreshold(0), 12 mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrent TestIdx(0), mIsQueryMode(false),12 mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrentQueryIdx(0), mIsQueryMode(false), 13 13 mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 14 mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true) 14 mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true), 15 mUseArbQueries(false) 15 16 { 16 17 } … … 18 19 RenderTraverser::~RenderTraverser() 19 20 { 20 if(mOcclusionQueries) 21 delete [] mOcclusionQueries; 21 DelQueries(); 22 22 } 23 23 … … 47 47 48 48 mFrameID ++; 49 ResetQueries();49 50 50 51 51 long endTime = getTime(); … … 267 267 } 268 268 269 bool RenderTraverser::ResultAvailable(HierarchyNode *node) 270 { 271 int result; 272 273 glGetQueryivARB(node->GetOcclusionQuery(), 274 GL_QUERY_RESULT_AVAILABLE_ARB, &result); 275 269 bool RenderTraverser::ResultAvailable(HierarchyNode *node) const 270 { 271 unsigned int result; 272 if (mUseArbQueries) 273 { 274 glGetQueryObjectuivARB(node->GetOcclusionQuery(), 275 GL_QUERY_RESULT_AVAILABLE_ARB, &result); 276 } 277 else 278 { 279 280 glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), 281 GL_PIXEL_COUNT_AVAILABLE_NV, &result); 282 283 } 284 276 285 return (result == GL_TRUE); 277 286 } … … 281 290 mHierarchyRoot = sceneRoot; 282 291 283 // not valid anymore for new hierarchy => delete 284 delete [] mOcclusionQueries; 285 mOcclusionQueries = NULL; 292 DelQueries(); 286 293 } 287 294 … … 291 298 } 292 299 293 int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) 300 unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const 294 301 { 295 302 unsigned int result; 296 297 glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result); 298 299 return (int)result; 303 304 if (mUseArbQueries) 305 { 306 glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result); 307 } 308 else 309 { 310 glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), GL_PIXEL_COUNT_NV, &result); 311 } 312 313 return result; 300 314 } 301 315 … … 330 344 { 331 345 // get next available test id 332 unsigned int occlusionQuery = mOcclusionQueries[mCurrent TestIdx++];346 unsigned int occlusionQuery = mOcclusionQueries[mCurrentQueryIdx ++]; 333 347 334 348 node->SetOcclusionQuery(occlusionQuery); 349 335 350 // do the actual occlusion query for this node 336 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery); 351 if (mUseArbQueries) 352 { 353 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery); 354 } 355 else 356 { 357 glBeginOcclusionQueryNV(occlusionQuery); 358 } 337 359 338 360 // if leaf and was visible => will be rendered anyway, thus we … … 350 372 } 351 373 352 glEndQueryARB(GL_SAMPLES_PASSED_ARB); 374 if (mUseArbQueries) 375 { 376 glEndQueryARB(GL_SAMPLES_PASSED_ARB); 377 } 378 else 379 { 380 glEndOcclusionQueryNV(); 381 } 353 382 } 354 383 355 384 void RenderTraverser::Preprocess() 356 385 { 357 if (!mOcclusionQueries)386 if (!mOcclusionQueries) 358 387 { 359 388 mOcclusionQueries = new unsigned int[mHierarchyRoot->GetNumHierarchyNodes()]; 389 390 // generate ids for occlusion test 391 if (mUseArbQueries) 392 { 393 glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 394 } 395 else 396 { 397 glGenOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 398 } 360 399 } 361 400 … … 363 402 calcViewFrustumPlanes(&mClipPlanes, mProjViewMatrix); 364 403 calcAABNPVertexIndices(mNPVertexIndices, mClipPlanes); 365 // generate ids for occlusion test 366 glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 367 mCurrentTestIdx = 0; 404 405 mCurrentQueryIdx = 0; 368 406 369 407 // reset statistics … … 375 413 376 414 377 void RenderTraverser::ResetQueries() 378 { 415 void RenderTraverser::DelQueries() 416 { 417 if (!mOcclusionQueries) 418 return; 419 379 420 // tell the driver that the occlusion queries won't be needed any more 380 glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 421 if (mUseArbQueries) 422 { 423 glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 424 } 425 else 426 { 427 glDeleteOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 428 } 429 430 delete [] mOcclusionQueries; 431 432 mOcclusionQueries = NULL; 381 433 } 382 434 … … 435 487 } 436 488 489 void RenderTraverser::SetUseArbQueries(const bool useArbQueries) 490 { 491 DelQueries(); 492 mUseArbQueries = useArbQueries; 493 } 494 495 bool RenderTraverser::GetUseArbQueries() const 496 { 497 return mUseArbQueries; 498 } 499 437 500 long RenderTraverser::GetRenderTime() 438 501 {
Note: See TracChangeset
for help on using the changeset viewer.