Changeset 3074 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
- Timestamp:
- 10/27/08 03:26:48 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3073 r3074 207 207 Bvh::~Bvh() 208 208 { 209 if (mVertices) delete [] mVertices;210 if (mIndices) delete [] mIndices;211 if (mTestIndices) delete [] mTestIndices;212 if (mGeometry) delete [] mGeometry;209 DEL_ARRAY_PTR(mVertices); 210 DEL_ARRAY_PTR(mIndices); 211 DEL_ARRAY_PTR(mTestIndices); 212 DEL_ARRAY_PTR(mGeometry); 213 213 214 214 if (mRoot) delete mRoot; … … 220 220 void Bvh::Init() 221 221 { 222 //mStaticRoot = NULL;222 mStaticRoot = NULL; 223 223 mDynamicRoot = NULL; 224 224 mRoot = NULL; … … 435 435 436 436 437 void Bvh::InitFrame(Camera *cam )437 void Bvh::InitFrame(Camera *cam, RenderState *state) 438 438 { 439 439 // = 0011 1111 which means that at the beginning, all six planes have to frustum culled … … 452 452 { 453 453 UpdateDynamicBranch(mDynamicRoot); 454 UpdateDynamicBounds(state); 454 455 } 455 456 } … … 532 533 /////////////////// 533 534 //-- for the first time we come here => create vbo and indices 534 /* 535 535 536 if (!mIndices) 536 537 { … … 544 545 PrepareVertices(); 545 546 } 546 */ 547 547 548 /////////////// 548 549 549 550 int numNodes = 0; 550 /* 551 551 552 BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 552 553 … … 563 564 numNodes += node->mNumTestNodes; 564 565 } 565 */ 566 566 567 return numNodes; 567 568 } … … 660 661 // collect all nodes 661 662 BvhNodeContainer nodes; 662 CollectNodes(mRoot, nodes); 663 664 // assign ids to all nodes of the "regular" hierarchy 663 //CollectNodes(mRoot, nodes); 664 // first collect dynamic nodes so we make sure that they are in the beginning 665 CollectNodes(mDynamicRoot, nodes); 666 // then collect static nodes 667 CollectNodes(mStaticRoot, nodes); 668 // also add root 669 nodes.push_back(mRoot); 670 671 // assign ids to all nodes of the hierarchy 665 672 int i = 0; 666 673 BvhNodeContainer::const_iterator lit, lit_end = nodes.end(); … … 679 686 680 687 nodes.reserve(GetNumNodes()); 681 CollectNodes(mRoot, nodes); 688 // first collect dynamic nodes so we make sure that they are in the beginning 689 CollectNodes(mDynamicRoot, nodes); 690 // then collect static nodes 691 CollectNodes(mStaticRoot, nodes); 692 // also add root 693 nodes.push_back(mRoot); 682 694 683 695 const unsigned int bufferSize = 8 * (int)nodes.size(); … … 704 716 bufferSize * sizeof(Vector3), 705 717 mVertices, 706 GL_STATIC_DRAW_ARB); 718 //GL_STATIC_DRAW_ARB); 719 GL_DYNAMIC_DRAW_ARB); 707 720 708 721 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 709 722 710 723 // data handled by graphics driver from now on 711 DEL_ PTR(mVertices);724 DEL_ARRAY_PTR(mVertices); 712 725 713 726 cout << "******** created vbos for tighter bounds *********" << endl; 727 } 728 729 730 void Bvh::UpdateDynamicBounds(RenderState *state) 731 { 732 // vbos not created yet 733 if (mVboId == -1) return; 734 735 // collect all nodes 736 static BvhNodeContainer nodes; 737 nodes.clear(); 738 //nodes.reserve(GetNumNodes()); 739 CollectNodes(mDynamicRoot, nodes); 740 741 const unsigned int bufferSize = 8 * (int)nodes.size(); 742 743 if (!mVertices) mVertices = new Vector3[bufferSize]; 744 745 int i = 0; 746 747 // store bounding box vertices 748 BvhNodeContainer::const_iterator lit, lit_end = nodes.end(); 749 750 for (lit = nodes.begin(); lit != lit_end; ++ lit, i += 8) 751 { 752 BvhNode *node = *lit; 753 754 for (int j = 0; j < 8; ++ j) 755 (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = node->GetBox().GetVertex(j); 756 } 757 758 if (state->GetCurrentVboId() != mVboId) 759 { 760 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 761 // set the vertex pointer to the vertex buffer 762 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 763 764 state->SetCurrentVboId(mVboId); 765 } 766 767 glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, 768 bufferSize * sizeof(Vector3), 769 mVertices); 770 771 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 714 772 } 715 773 … … 1061 1119 CreateRoot(); 1062 1120 1063 ComputeIds();1064 1121 ComputeMaxDepthForVirtualLeaves(); 1065 1122 // set virtual leaves for specified number of triangles … … 1067 1124 /// for each node compute the number of leaves under this node 1068 1125 UpdateNumLeaves(mRoot); 1126 // compute new ids 1127 ComputeIds(); 1069 1128 // specify bounds for occlusion tests 1070 1129 RecomputeBounds(); 1130 1131 mBox = mRoot->GetBox(); 1071 1132 1072 1133 // compute and print stats … … 1267 1328 if (TerminationCriteriaMet(leaf)) 1268 1329 { 1269 leaf->mIsVirtualLeaf = true;1270 leaf->mIsMaxDepthForVirtualLeaf = true;1271 1330 //cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 1272 1331 return leaf; … … 1412 1471 // create new root 1413 1472 mRoot = new BvhInterior(NULL); 1414 1473 1415 1474 // the separation is a purely logical one 1416 1475 // the bounding boxes of the child nodes are
Note: See TracChangeset
for help on using the changeset viewer.