Changeset 724
- Timestamp:
- 04/04/06 23:47:05 (19 years ago)
- Location:
- GTP/trunk/App/Demos/Vis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp
r723 r724 195 195 //mMyStatsAlgorithmInfo->setTop(top); 196 196 197 mMyStatsOverlay->show();197 //mMyStatsOverlay->show(); 198 198 199 199 if (1) … … 204 204 205 205 // show stats overlays 206 showStats( false);206 showStats(true); 207 207 } 208 208 -
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 { -
GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.h
r643 r724 58 58 void SetUseOptimization(bool useOptimization); 59 59 60 //! if arb queries should be used instead of nv 61 void SetUseArbQueries(const bool useArbQueries); 62 //! see set 63 bool GetUseArbQueries() const; 64 60 65 protected: 61 66 … … 70 75 71 76 //! returns occlusion query result for specified node 72 int GetOcclusionQueryResult(HierarchyNode *node);77 unsigned int GetOcclusionQueryResult(HierarchyNode *node) const; 73 78 //! the node is traversed as usual 74 79 void TraverseNode(HierarchyNode *node); … … 76 81 void PullUpVisibility(HierarchyNode *node); 77 82 //! is result available from query queue? 78 bool ResultAvailable(HierarchyNode *node) ;83 bool ResultAvailable(HierarchyNode *node) const; 79 84 //! issues occlusion query for specified node 80 85 void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible); 81 86 //! resets occlusion queries after a traversal 82 void ResetQueries();87 void DelQueries(); 83 88 //! does view frustum culling. returns intersect (if intersects view plane) 84 89 bool InsideViewFrustum(HierarchyNode *node, bool &intersects); … … 88 93 void Switch2GLQueryState(); 89 94 95 90 96 protected: 97 98 /// if arb queries should be instead of nv 99 bool mUseArbQueries; 91 100 92 101 // the current clip planes of the view frustum … … 95 104 int mNPVertexIndices[12]; 96 105 106 // the current view point 97 107 Vector3 mViewpoint; 98 108 Matrix4x4 mProjViewMatrix; 109 // the root of the scene hierarchy 99 110 HierarchyNode *mHierarchyRoot; 100 111 //TraversalStack mTraversalStack; … … 105 116 int mVisibilityThreshold; 106 117 unsigned int *mOcclusionQueries; 107 int mCurrent TestIdx;118 int mCurrentQueryIdx; 108 119 bool mIsQueryMode; 109 120 -
GTP/trunk/App/Demos/Vis/Teapots/occquery.cpp
r643 r724 14 14 #include <math.h> 15 15 #include <time.h> 16 17 bool arbQuerySupport = false; 18 bool nvQuerySupport = false; 16 19 17 20 double nearDist = 0.1; // eye near plane distance … … 68 71 69 72 bool useOptimization = true; 73 bool useArbQueries = false; 70 74 71 75 Vector3 amb[2]; … … 213 217 "'C' - recreates the scene hierarchy", 214 218 "'G' - enables/disables optimization to take geometry as occluder", 219 "'N' - triggers NV / ARB queries", 215 220 "", 216 221 "'R' - shows/hides recreation parameters", … … 357 362 358 363 char *optstr[2] = {"", ", using optimization"}; 359 364 char *querystr[2] = {"NV", "ARB"}; 365 360 366 float fps = 1000.0; 361 367 long renderTime = calcRenderTime(); 362 368 if(renderTime) fps = 1000000.0f / (float)calcRenderTime(); 363 369 364 sprintf(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps) %s",365 traverser.GetVisibilityThreshold(), renderTime / 1000, fps, optstr[useOptimization]);370 sprintf(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps), queries: %s%s", 371 traverser.GetVisibilityThreshold(), renderTime / 1000, fps, querystr[useArbQueries], optstr[useOptimization]); 366 372 367 373 string str; … … 494 500 traverser.SetUseOptimization(useOptimization); 495 501 break; 502 case 'n': 503 case 'N': 504 useArbQueries = !useArbQueries; 505 traverser.SetUseArbQueries(useArbQueries); 506 break; 496 507 case 'c': 497 508 case 'C': … … 658 669 { 659 670 GLenum err = glewInit(); 660 if(GLEW_OK != err) { 671 if (GLEW_OK != err) 672 { 661 673 // problem: glewInit failed, something is seriously wrong 662 fprintf(stderr,"Error: %s\n", glewGetErrorString(err));674 fprintf(stderr,"Error: %s\n", glewGetErrorString(err)); 663 675 exit(1); 664 676 } 665 677 666 if(!GLEW_ARB_occlusion_query) { 667 printf("I require the GL_ARB_occlusion_query OpenGL extension to work.\n"); 678 if (GLEW_ARB_occlusion_query) 679 arbQuerySupport = true; 680 681 if (GLEW_NV_occlusion_query) 682 nvQuerySupport = true; 683 684 685 if (!arbQuerySupport && !nvQuerySupport) 686 { 687 printf("I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n"); 668 688 exit(1); 669 689 }
Note: See TracChangeset
for help on using the changeset viewer.