Changeset 3074
- Timestamp:
- 10/27/08 03:26:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 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 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r3073 r3074 586 586 /** Sets frame dependent values 587 587 */ 588 void InitFrame(Camera *camera );588 void InitFrame(Camera *camera, RenderState *state); 589 589 /** Stores the orthogonal distance from the viewpoint to a point on the node. 590 590 We choose the the nearest bounding box vertex . … … 738 738 739 739 void CreateRoot(); 740 741 void UpdateDynamicBounds(RenderState *state); 740 742 741 743 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r3072 r3074 78 78 79 79 bvh->mStaticRoot = root; 80 // we have at least the root, the static and the dynamic branch 80 81 bvh->mNumNodes = 3; 81 82 … … 107 108 } 108 109 109 110 //////////// 110 /////////// 111 111 //-- create dynamic part of the hierarchy 112 112 113 113 bvh->CreateDynamicBranch(); 114 114 115 116 115 /////////// 117 116 //-- post process nodes 118 117 119 /// this function must be called once after creation120 118 bvh->PostProcess(); 121 122 119 123 120 cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3073 r3074 311 311 } 312 312 } 313 ShaderManager::GetSingleton()->DisableFragmentProfile();314 ShaderManager::GetSingleton()->DisableVertexProfile();315 316 313 } 317 314 … … 341 338 342 339 343 } 340 341 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r3072 r3074 150 150 ++ mFrameId; 151 151 152 mBvh->InitFrame(mCamera );152 mBvh->InitFrame(mCamera, mRenderState); 153 153 154 154 mStats.Reset(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
r3073 r3074 26 26 void Shape::Render(RenderState *state) 27 27 { 28 //if (mMaterial) mMaterial->Render(state); 29 //mDepthWriteEnabled = true; 30 glDepthMask(GL_TRUE); glDepthFunc(GL_LESS); 31 glEnable(GL_DEPTH_TEST); 28 if (mMaterial) mMaterial->Render(state); 29 32 30 mGeometry->Render(state); 33 31 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r3071 r3074 40 40 mIsIdentity = false; 41 41 mMatrix = mMatrix * trafo; 42 //mMatrix = trafo * mMatrix; 42 43 } 43 44 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3072 r3074 53 53 #include "SkyPreetham.h" 54 54 #include "Texture.h" 55 //#include "EntityMerger.h"56 55 #include "ShaderManager.h" 57 56 … … 184 183 185 184 bool useOptimization = false; 186 //bool useTightBounds = true; 187 bool useTightBounds = false; 185 bool useTightBounds = true; 188 186 bool useRenderQueue = true; 189 187 bool useMultiQueries = true; … … 453 451 LoadModel("city.dem", sceneEntities); 454 452 455 /* 453 456 454 ////////// 457 455 //-- load some dynamic stuff … … 464 462 buddha->GetTransform()->SetMatrix(transl); 465 463 466 for (int i = 0; i < 10; ++ i)464 /*for (int i = 0; i < 10; ++ i) 467 465 { 468 466 SceneEntity *ent = new SceneEntity(*buddha); … … 471 469 Vector3 offs = Vector3::ZERO(); 472 470 473 offs.x = RandomValue(.0f, 150.0f);474 offs.y = RandomValue(.0f, 150.0f);471 offs.x = RandomValue(.0f, 50.0f); 472 offs.y = RandomValue(.0f, 50.0f); 475 473 476 474 transl = TranslationMatrix(sceneCenter + offs); … … 479 477 ent->SetTransform(transform); 480 478 dynamicObjects.push_back(ent); 481 } 482 483 */ 479 }*/ 480 481 484 482 /////////// 485 483 //-- load the associated static bvh … … 870 868 void MainLoop() 871 869 { 870 Vector3 offs = Vector3::ZERO(); 871 //offs.x = RandomValue(-.1f, .1f); 872 //offs.y = RandomValue(-.1f, .1f); 873 offs.x = RandomValue(.0f, .01f); 874 offs.y = RandomValue(.0f, .01f); 875 876 Matrix4x4 mat = TranslationMatrix(offs); 877 878 buddha->GetTransform()->MultMatrix(mat); 879 872 880 Vector3 oldPos = camera->GetPosition(); 873 881
Note: See TracChangeset
for help on using the changeset viewer.