Changeset 2801 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
- Timestamp:
- 06/27/08 13:33:46 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2800 r2801 22 22 #include "Timer/PerfTimer.h" 23 23 #include "SceneQuery.h" 24 #include "RenderQueue.h" 24 25 25 26 … … 60 61 61 62 SceneQuery *sceneQuery = NULL; 63 RenderQueue *renderQueue = NULL; 64 62 65 63 66 /// these values get scaled with the frame rate … … 66 69 /// elapsed time in seconds 67 70 double elapsedTime = 1.0f; 71 double algTime = 1.0f; 68 72 69 73 int winWidth = 1024; … … 99 103 bool useRenderQueue = true; 100 104 bool useMultiQueries = true; 101 102 105 bool flyMode = true; 103 104 /// the accumulated z axis rotation 105 float rotation = 0; 106 bool depthPass = false; 107 106 108 107 109 SceneEntityContainer skyGeometry; … … 126 128 void DrawHelpMessage(); 127 129 void RenderSky(); 130 void RenderVisibleObjects(); 128 131 129 132 void Begin2D(); … … 146 149 void KeyVerticalMotion(float shift); 147 150 151 void PlaceViewer(const Vector3 &oldPos); 152 148 153 149 154 inline float KeyRotationAngle() { return keyRotation * elapsedTime; } … … 162 167 visCamera->SetNear(0.0f); 163 168 visCamera->Yaw(.5 * M_PI); 169 170 renderQueue = new RenderQueue(&state); 164 171 165 172 glutInitWindowSize(winWidth, winHeight); … … 268 275 //glEnable(GL_ALPHA_TEST); 269 276 glDisable(GL_ALPHA_TEST); 270 glAlphaFunc(GL_GEQUAL, 0. 1f);277 glAlphaFunc(GL_GEQUAL, 0.5f); 271 278 272 279 glFrontFace(GL_CCW); … … 283 290 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); 284 291 glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); 292 293 glDepthFunc(GL_LESS); 285 294 } 286 295 … … 298 307 "'F5', - toggles between fly / walkmode", 299 308 "'F6', - shows/hides parameters", 309 "'F7', - depth pass", 300 310 "'SPACE' - cycles through occlusion culling algorithms", 301 311 "", … … 380 390 traverser->SetCamera(camera); 381 391 traverser->SetHierarchy(bvh); 392 traverser->SetRenderQueue(renderQueue); 382 393 traverser->SetRenderState(&state); 383 394 traverser->SetUseOptimization(useOptimization); … … 388 399 traverser->SetUseMultiQueries(useMultiQueries); 389 400 traverser->SetUseTightBounds(useTightBounds); 401 traverser->SetUseDepthPass(depthPass); 402 traverser->SetRenderQueue(renderQueue); 390 403 } 391 404 … … 430 443 431 444 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 432 //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);433 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);445 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 446 //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 434 447 //glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); 435 448 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT); … … 481 494 482 495 void Display() 483 { 496 { 497 PerfTimer frameTimer, algTimer; 498 frameTimer.Start(); 499 484 500 Vector3 oldPos = camera->GetPosition(); 485 486 PerfTimer frameTimer;487 frameTimer.Start();488 501 489 502 if (leftKeyPressed) … … 500 513 KeyVerticalMotion(KeyShift()); 501 514 502 Vector3 playerPos = camera->GetPosition(); 503 504 if (!flyMode) 505 { 506 Vector3 playerPos = camera->GetPosition(); 507 508 bool validIntersect = sceneQuery->CalcIntersection(playerPos); 509 510 if (validIntersect && 511 (( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f)) 512 { 513 camera->SetPosition(playerPos); 514 } 515 } 515 // place view on ground 516 if (!flyMode) PlaceViewer(oldPos); 517 518 // note: have to flush queue in order to get reliable timings 519 // for optimal performance, remove this 520 glFinish(); 521 522 algTimer.Start(); 516 523 517 524 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 525 526 glDepthFunc(GL_LESS); 527 glDisable(GL_TEXTURE_2D); 528 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 529 530 // render without shading 531 if (depthPass) 532 { 533 state.SetDepthPass(true); 534 glDisable(GL_LIGHTING); 535 } 536 else 537 { 538 state.SetDepthPass(false); 539 glEnable(GL_LIGHTING); 540 } 518 541 519 542 // bring eye modelview matrix up-to-date … … 523 546 traverser->RenderScene(); 524 547 525 548 549 ////// 550 //-- other rendering 551 552 glEnableClientState(GL_VERTEX_ARRAY); 553 glEnableClientState(GL_NORMAL_ARRAY); 554 555 556 // reset depth pass and render visible objects 557 if (depthPass) 558 { 559 RenderVisibleObjects(); 560 } 561 562 526 563 /////////////// 527 564 //-- render sky 528 565 529 566 RenderSky(); 530 567 568 state.Reset(); 569 570 glDisableClientState(GL_VERTEX_ARRAY); 571 glDisableClientState(GL_NORMAL_ARRAY); 572 573 574 575 // note: have to flush queue in order to get reliable timings 576 // for optimal performance, remove this 577 glFinish(); 578 algTime = algTimer.Elapsedms(); 579 580 /////////// 581 531 582 if (visMode) DisplayVisualization(); 532 583 … … 719 770 flyMode = !flyMode; 720 771 break; 772 case GLUT_KEY_F7: 773 depthPass = !depthPass; 774 traverser->SetUseDepthPass(depthPass); 775 break; 721 776 case GLUT_KEY_LEFT: 722 777 { … … 988 1043 DEL_PTR(camera); 989 1044 DEL_PTR(loader); 1045 DEL_PTR(renderQueue); 990 1046 } 991 1047 … … 1032 1088 1033 1089 1034 static double renderTime = traverser->GetStats().mRenderTime;1090 static double renderTime = algTime; 1035 1091 const float expFactor = 0.3f; 1036 renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 1092 1093 // if there was something fishy going on in this frame => don't count 1094 if (algTime < 1000) 1095 renderTime = algTime * expFactor + (1.0f - expFactor) * algTime; 1037 1096 1038 1097 accumulatedTime += renderTime; … … 1058 1117 assumedVisibleFrames, maxBatchSize); 1059 1118 1060 sprintf(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d",1061 useRenderQueue, useMultiQueries, useTightBounds);1119 sprintf(msg3, "render queue: %d, depth pass: %d, multiqueries: %d, tight bounds: %d", 1120 useRenderQueue, depthPass, useMultiQueries, useTightBounds); 1062 1121 1063 1122 string str; … … 1088 1147 else 1089 1148 { 1090 //glColor3f(1.0f, 1.0f, 1.0f);1091 glColor3f(1.0f, 0.0f, 0.0f);1149 glColor3f(1.0f, 1.0f, 1.0f); 1150 //glColor3f(1.0f, 0.0f, 0.0f); 1092 1151 Output(850, 30, msg[renderMode]); 1093 1152 … … 1115 1174 void RenderSky() 1116 1175 { 1117 glEnableClientState(GL_VERTEX_ARRAY);1118 glEnableClientState(GL_NORMAL_ARRAY);1119 1120 1176 SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 1121 1177 1122 1178 for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 1123 1179 (*sit)->Render(&state); 1124 1125 glDisableClientState(GL_VERTEX_ARRAY); 1126 glDisableClientState(GL_NORMAL_ARRAY); 1127 1180 } 1181 1182 1183 void RenderVisibleObjects() 1184 { 1185 state.SetDepthPass(false); 1128 1186 state.Reset(); 1129 } 1187 1188 glEnable(GL_LIGHTING); 1189 glDepthFunc(GL_LEQUAL); 1190 1191 //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 1192 1193 SceneEntityContainer::const_iterator sit, 1194 sit_end = traverser->GetVisibleObjects().end(); 1195 1196 for (sit = traverser->GetVisibleObjects().begin(); sit != sit_end; ++ sit) 1197 renderQueue->Enqueue(*sit); 1198 1199 renderQueue->Apply(); 1200 1201 glDepthFunc(GL_LESS); 1202 } 1203 1204 1205 void PlaceViewer(const Vector3 &oldPos) 1206 { 1207 Vector3 playerPos = camera->GetPosition(); 1208 1209 bool validIntersect = sceneQuery->CalcIntersection(playerPos); 1210 1211 if (validIntersect && 1212 (( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f)) 1213 { 1214 camera->SetPosition(playerPos); 1215 } 1216 }
Note: See TracChangeset
for help on using the changeset viewer.