Changeset 2786 for GTP/trunk/App/Demos
- Timestamp:
- 06/20/08 02:26:30 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BinaryLoader.cpp
r2784 r2786 193 193 texcoords = NULL; 194 194 195 return new Geometry(vertices, normals, texcoords, vertexCount, false);195 return new Geometry(vertices, normals, texcoords, vertexCount, true); 196 196 } 197 197 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2782 r2786 366 366 367 367 368 void Bvh::RenderBoundingBox(BvhNode *node, RenderState *state) 369 { 370 //RenderBoundingBoxImmediate(node->GetBox()); 371 static BvhNodeContainer dummy(1); 372 dummy[0] = node; 373 RenderBoundingBoxes(dummy, state); 374 } 375 376 377 378 int Bvh::RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state) 379 { 380 int renderedBoxes = PrepareBoundingBoxesWithDrawArrays(nodes); 381 RenderBoundingBoxesWithDrawArrays(renderedBoxes, state); 368 void Bvh::RenderBounds(BvhNode *node, RenderState *state, bool useTightBounds) 369 { 370 // if not using tight bounds, rendering boxes in immediate mode 371 // is preferable to vertex arrays (less setup time) 372 if (!useTightBounds) 373 { 374 RenderBoundingBoxImmediate(node->GetBox()); 375 } 376 else 377 { 378 static BvhNodeContainer dummy(1); 379 dummy[0] = node; 380 RenderBounds(dummy, state, useTightBounds); 381 } 382 } 383 384 385 int Bvh::RenderBounds(const BvhNodeContainer &nodes, 386 RenderState *state, 387 bool useTightBounds) 388 { 389 // if not using tight bounds, rendering boxes in immediate mode 390 // is preferable to vertex arrays (less setup time) 391 392 int renderedBoxes; 393 394 if (!useTightBounds) 395 { 396 BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 397 398 for (nit = nodes.begin(); nit != nit_end; ++ nit) 399 { 400 RenderBoundingBoxImmediate((*nit)->GetBox()); 401 } 402 403 renderedBoxes = (int)nodes.size(); 404 } 405 else 406 { 407 renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 408 RenderBoundsWithDrawArrays(renderedBoxes, state); 409 } 382 410 383 411 return renderedBoxes; … … 385 413 386 414 387 int Bvh::PrepareBound ingBoxesWithDrawArrays(const BvhNodeContainer &nodes)415 int Bvh::PrepareBoundsWithDrawArrays(const BvhNodeContainer &nodes) 388 416 { 389 417 ////// … … 428 456 429 457 430 void Bvh::RenderBound ingBoxesWithDrawArrays(int numNodes, RenderState *state)458 void Bvh::RenderBoundsWithDrawArrays(int numNodes, RenderState *state) 431 459 { 432 460 ////// … … 706 734 nodeStack.push(mRoot); 707 735 736 int numVirtualLeaves = 0; 737 708 738 while (!nodeStack.empty()) 709 739 { … … 713 743 if (node->IsVirtualLeaf()) 714 744 { 745 ++ numVirtualLeaves; 746 715 747 BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 716 748 … … 731 763 } 732 764 733 mBvhStats.mGeometryRatio = mGeometrySize / (float) GetNumLeaves();734 mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float) GetNumLeaves();765 mBvhStats.mGeometryRatio = mGeometrySize / (float)numVirtualLeaves; 766 mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float)numVirtualLeaves; 735 767 } 736 768 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r2782 r2786 460 460 //-- Rendering related options 461 461 462 /** Renders the bounding box of this node (Or the tigher bounding boxes of some subnodes). 463 */ 464 void RenderBoundingBox(BvhNode *node, RenderState *state); 462 /** Renders the bounds of this node 463 (the box of the node or the tigher bounds of some subnodes). 464 */ 465 void RenderBounds(BvhNode *node, RenderState *state, bool useTightBounds); 465 466 /** Renders bounding boxes of the collection of nodes. 466 467 @returns #rendered boxes 467 468 */ 468 int RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state); 469 469 int RenderBounds(const BvhNodeContainer &nodes, RenderState *state, bool useTightBounds); 470 470 /** Returns the bounding box of this bvh. 471 471 */ … … 516 516 void SetVirtualLeaves(int numTriangles); 517 517 518 518 519 //////// 519 520 //-- functions influencing tighter bounds … … 562 563 void PrepareVertices(); 563 564 564 int PrepareBound ingBoxesWithDrawArrays(const BvhNodeContainer &nodes);565 void RenderBound ingBoxesWithDrawArrays(int numNodes, RenderState *state);565 int PrepareBoundsWithDrawArrays(const BvhNodeContainer &nodes); 566 void RenderBoundsWithDrawArrays(int numNodes, RenderState *state); 566 567 567 568 /** Create the indices that each node needs to use vbo rendering. … … 590 591 */ 591 592 inline bool TestPlane(BvhNode *node, int i, bool &bIntersect); 592 593 /** Renders a bounding box in immediate mode. 594 */ 593 595 void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box); 594 596 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r2782 r2786 98 98 99 99 bvh->PostProcess(); 100 // set virtual leaves for 500 triangles 101 bvh->SetVirtualLeaves(0); 100 const int n = 1000; 101 // set virtual leaves for n triangles 102 bvh->SetVirtualLeaves(n); 102 103 103 104 bvh->UpdateNumLeaves(bvh->mRoot); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
r2782 r2786 25 25 delete [] mVertices; mVertices = NULL; 26 26 delete [] mNormals; mNormals = NULL; 27 if (!mTexCoords) delete [] mTexCoords; mTexCoords = NULL;27 //if (mTexCoords) delete [] mTexCoords; mTexCoords = NULL; 28 28 } 29 29 } 30 30 31 31 32 Geometry::~Geometry() 32 33 { 33 if ( !mVertices) delete [] mVertices;34 if ( !mNormals) delete [] mNormals;35 if ( !mTexCoords) delete [] mTexCoords;34 if (mVertices) delete [] mVertices; 35 if (mNormals) delete [] mNormals; 36 if (mTexCoords) delete [] mTexCoords; 36 37 37 38 // delete vbo … … 74 75 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 75 76 } 77 76 78 glBufferDataARB(GL_ARRAY_BUFFER_ARB, 77 79 dataSize * sizeof(float), -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/OcclusionQuery.cpp
r2782 r2786 13 13 glGenQueriesARB(1, &mQueryId); 14 14 15 // reverse for multi equeries with 32nodes15 // reverse for multiqueries with 20 nodes 16 16 mNodes.reserve(32); 17 17 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2784 r2786 46 46 mUseRenderQueue(false), 47 47 mAssumedVisibleFrames(10), 48 mMaxBatchSize(50) 48 mMaxBatchSize(50), 49 mUseTightBounds(false) 49 50 { 50 51 } … … 127 128 void RenderTraverser::RenderScene() 128 129 { 130 //glFinish(); 129 131 PerfTimer timer; 130 131 132 timer.Start(); 132 133 //InitTiming();134 //long t1, t2;135 //t1 = GetTime();136 133 137 134 glEnableClientState(GL_VERTEX_ARRAY); … … 158 155 glDisableClientState(GL_NORMAL_ARRAY); 159 156 160 //t2 = GetTime(); 161 //mStats.mRenderTime = TimeDiff(t1, t2); 157 //glFinish(); 162 158 mStats.mRenderTime = timer.Elapsedms(); 163 159 } … … 198 194 { 199 195 mUseMultiQueries = useMultiQueries; 200 std::cout << "using multiqueries: " << mUseMultiQueries << std::endl; 201 } 202 196 //cout << "using multiqueries: " << mUseMultiQueries << endl; 197 } 198 199 200 void RenderTraverser::SetUseTightBounds(bool useTightBounds) 201 { 202 mUseTightBounds = useTightBounds; 203 cout << "using tight bounds: " << useTightBounds << endl; 204 } 203 205 204 206 … … 243 245 ++ mStats.mNumStateChanges; 244 246 245 mBvh->RenderBound ingBoxes(query.GetNodes(), mRenderState);247 mBvh->RenderBounds(query.GetNodes(), mRenderState, mUseTightBounds); 246 248 } 247 249 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
r2782 r2786 109 109 */ 110 110 void SetUseMultiQueries(bool useMultiQueries); 111 /** If thight bounds should be used or the bounding boxes should be tested. 112 */ 113 void SetUseTightBounds(bool useTightBounds); 111 114 112 115 protected: … … 171 174 172 175 bool mUseMultiQueries; 176 177 bool mUseTightBounds; 173 178 }; 174 179 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2784 r2786 49 49 int assumedVisibleFrames = 10; 50 50 int maxBatchSize = 50; 51 bool useMultiQueries = true;52 51 53 52 const float keyForwardMotion = 1.0f; 54 53 const float keyRotation = 0.2f; 55 56 bool useRenderQueue = false;57 54 58 55 int winWidth = 1024; … … 84 81 85 82 bool useOptimization = false; 83 bool useTightBounds = true; 84 bool useRenderQueue = false; 85 bool useMultiQueries = true; 86 86 87 87 … … 95 95 void DisplayStats(); 96 96 void Output(int x, int y, const char *string); 97 void DrawHelpMessage(); 97 98 98 99 void begin2D(); 99 100 void end2D(); 100 101 void keyboard(unsigned char c, int x, int y); 101 void drawHelpMessage();102 102 void drawStatistics(); 103 103 void display(void); … … 233 233 234 234 235 void drawHelpMessage(void)235 void DrawHelpMessage(void) 236 236 { 237 237 const char *message[] = … … 257 257 "'9' - downward motion", 258 258 "", 259 "' G' - enables/disables optimization to take geometry as occluder",259 "'R' - use render queue", 260 260 "", 261 261 "'S' - shows/hides statistics", … … 269 269 270 270 271 int x = 40, y = 42;271 int x = 40, y = 60; 272 272 273 273 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); … … 286 286 if(message[i][0] == '\0') 287 287 { 288 y += 7;288 y += 15; 289 289 } 290 290 else 291 291 { 292 292 Output(x, y, message[i]); 293 y += 14;293 y += 20; 294 294 } 295 295 } … … 332 332 traverser->SetMaxBatchSize(maxBatchSize); 333 333 traverser->SetUseMultiQueries(useMultiQueries); 334 traverser->SetUseTightBounds(useTightBounds); 334 335 } 335 336 … … 546 547 traverser->SetUseRenderQueue(useRenderQueue); 547 548 } 549 case 'b': 550 case 'B': 551 { 552 useTightBounds = !useTightBounds; 553 traverser->SetUseTightBounds(useTightBounds); 554 } 548 555 default: 549 556 return; … … 718 725 // the 90 degree rotated view vector 719 726 // y zero so we don't move in the vertical 720 //Vector3 rVec(viewDir[0], 0, viewDir[2]);721 727 Vector3 rVec(viewDir[0], viewDir[1], 0); 722 728 723 //Matrix4x4 rot = RotationYMatrix(M_PI * 0.5f);724 729 Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f); 725 730 rVec = rot * rVec; 726 731 727 732 pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 728 //pos[1] += (verticalMotionBegin - y) * 0.1f;729 733 pos[2] += (verticalMotionBegin - y) * 0.1f; 730 734 … … 914 918 } 915 919 916 sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d, using multiqueries: %d, using render queue: %d", assumedVisibleFrames, maxBatchSize, useMultiQueries, useRenderQueue); 920 sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d, using render queue: %d", 921 assumedVisibleFrames, maxBatchSize, useRenderQueue); 917 922 918 923 string str; … … 935 940 if(showHelp) 936 941 { 937 drawHelpMessage();942 DrawHelpMessage(); 938 943 } 939 944 else … … 942 947 Output(850, 30, msg[renderMode]); 943 948 944 if (showStatistics)949 if (showStatistics) 945 950 { 946 951 Output(20, 30, msg2);
Note: See TracChangeset
for help on using the changeset viewer.