Changeset 2773 for GTP/trunk/App/Demos
- Timestamp:
- 06/18/08 20:42:06 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2771 r2773 12 12 #include "SceneEntity.h" 13 13 #include "Geometry.h" 14 #include "RenderState.h" 15 14 16 15 17 namespace CHCDemo … … 17 19 18 20 #define INVALID_TEST ((unsigned int)-1) 19 20 const static bool useVbos = true;21 unsigned int Bvh::sCurrentVboId = -1;22 21 23 22 using namespace std; … … 122 121 123 122 124 Bvh::Bvh(): 125 mCamera(NULL), 126 mRoot(NULL), 127 mVertices(NULL), 128 mIndices(NULL), 129 mTestIndices(NULL), 130 mCurrentIndicesPtr(0), 131 mNumNodes(0), 132 mMaxDepthForTestingChildren(4), 133 mAreaRatioThreshold(1.4f) 134 {} 135 136 137 Bvh::Bvh(const SceneEntityContainer &entities): 138 mCamera(NULL), 139 mRoot(NULL), 140 mVertices(NULL), 141 mIndices(NULL), 142 mTestIndices(NULL), 143 mCurrentIndicesPtr(0), 144 mNumNodes(0), 145 mMaxDepthForTestingChildren(4), 146 mAreaRatioThreshold(1.4f) 147 { 123 Bvh::Bvh() 124 { 125 Init(); 126 } 127 128 129 Bvh::Bvh(const SceneEntityContainer &entities) 130 { 131 Init(); 132 148 133 mGeometrySize = entities.size(); 149 134 mGeometry = new SceneEntity*[mGeometrySize]; … … 172 157 173 158 if (mRoot) delete mRoot; 159 } 160 161 162 void Bvh::Init() 163 { 164 mCamera = NULL; 165 mRoot = NULL; 166 mVertices = NULL; 167 mIndices = NULL; 168 mTestIndices = NULL; 169 mCurrentIndicesPtr = 0; 170 mNumNodes = 0; 171 mMaxDepthForTestingChildren = 4; 172 mAreaRatioThreshold = 1.4f; 173 mVboId = -1; 174 174 } 175 175 … … 366 366 367 367 368 void Bvh::RenderBoundingBox(BvhNode *node )369 { 370 RenderBoundingBoxImmediate(node->GetBox());371 /**static BvhNodeContainer dummy(1);368 void Bvh::RenderBoundingBox(BvhNode *node, RenderState *state) 369 { 370 //RenderBoundingBoxImmediate(node->GetBox()); 371 static BvhNodeContainer dummy(1); 372 372 dummy[0] = node; 373 RenderBoundingBoxes(dummy );*/374 } 375 376 377 378 int Bvh::RenderBoundingBoxes(const BvhNodeContainer &nodes )373 RenderBoundingBoxes(dummy, state); 374 } 375 376 377 378 int Bvh::RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state) 379 379 { 380 380 int renderedBoxes = PrepareBoundingBoxesWithDrawArrays(nodes); 381 RenderBoundingBoxesWithDrawArrays(renderedBoxes );381 RenderBoundingBoxesWithDrawArrays(renderedBoxes, state); 382 382 383 383 return renderedBoxes; … … 395 395 } 396 396 397 if ( sCurrentVboId == -1)397 if (mVboId == -1) 398 398 { 399 399 // prepare the vbo … … 428 428 429 429 430 void Bvh::RenderBoundingBoxesWithDrawArrays(int numNodes )430 void Bvh::RenderBoundingBoxesWithDrawArrays(int numNodes, RenderState *state) 431 431 { 432 432 ////// 433 433 //-- Rendering the vbo 434 if (useVbos) 434 435 if (state->GetCurrentVboId() != mVboId) 436 { 437 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 435 438 // set the vertex pointer to the vertex buffer 436 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 437 else 438 glVertexPointer(3, GL_FLOAT, 0, mVertices); 439 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 440 441 state->SetCurrentVboId(mVboId); 442 } 439 443 440 444 // we do use the last or the first index (they are generate and only used to connect strips) 441 const int numElements = numNodes * sNumIndicesPerBox - 1; 442 445 int numElements = numNodes * sNumIndicesPerBox - 1; 443 446 // don't render first degenerate index 444 447 glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, mIndices + 1); … … 559 562 } 560 563 561 if (useVbos) 562 { 563 glGenBuffersARB(1, &sCurrentVboId); 564 glBindBufferARB(GL_ARRAY_BUFFER_ARB, sCurrentVboId); 565 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 566 567 glBufferDataARB(GL_ARRAY_BUFFER_ARB, 568 bufferSize * sizeof(Vector3), 569 mVertices, 570 GL_STATIC_DRAW_ARB); 571 572 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 573 574 // data handled by graphics driver from now on 575 DEL_PTR(mVertices); 576 577 cout << "***** created vbos *********" << endl; 578 } 579 else 580 { 581 sCurrentVboId = 0; 582 glVertexPointer(3, GL_FLOAT, 0, mVertices); 583 584 cout << "******* created vertex arrays ********" << endl; 585 } 564 glGenBuffersARB(1, &mVboId); 565 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 566 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 567 568 glBufferDataARB(GL_ARRAY_BUFFER_ARB, 569 bufferSize * sizeof(Vector3), 570 mVertices, 571 GL_STATIC_DRAW_ARB); 572 573 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 574 575 // data handled by graphics driver from now on 576 DEL_PTR(mVertices); 577 578 cout << "***** created vbos for tighter bounds *********" << endl; 586 579 } 587 580 … … 713 706 714 707 for (int i = leaf->mFirst; i <= leaf->mLast; ++ i) 715 triangleCount += mGeometry[i]->GetGeometry()-> CountTriangles();708 triangleCount += mGeometry[i]->GetGeometry()->GetNumTriangles(); 716 709 717 710 return triangleCount; … … 729 722 nodeStack.pop(); 730 723 731 if (node->Is Leaf())724 if (node->IsVirtualLeaf()) 732 725 { 733 726 BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 734 727 728 mBvhStats.mTriangles += CountTriangles(leaf); 735 729 mBvhStats.mLeafSA += leaf->mBox.SurfaceArea(); 736 730 mBvhStats.mLeafVol += leaf->mBox.GetVolume(); … … 771 765 772 766 for (int i = node->mFirst; i <= node->mLast; ++ i) 773 numTriangles += mGeometry[i]->GetGeometry()-> CountTriangles();767 numTriangles += mGeometry[i]->GetGeometry()->GetNumTriangles(); 774 768 775 769 return numTriangles; … … 799 793 node->mNumLeaves = f->mNumLeaves + b->mNumLeaves; 800 794 } 801 }802 803 804 int Bvh::Render(BvhNode *node, RenderState *state)805 {806 int renderedTriangles = 0;807 808 for (int i = node->mFirst; i <= node->mLast; ++ i)809 {810 renderedTriangles += mGeometry[i]->GetGeometry()->CountTriangles();811 mGeometry[i]->Render(state);812 }813 814 return renderedTriangles;815 795 } 816 796 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2772 r2773 105 105 successfully tested invisible. 106 106 */ 107 inline void IncTimes Invisible();108 109 inline int GetTimes Invisible() const;110 inline void SetTimes Invisible(int t);107 inline void IncTimesTestedInvisible(); 108 109 inline int GetTimesTestedInvisible() const; 110 inline void SetTimesTestedInvisible(int t); 111 111 112 112 inline int GetTurnedVisibleFrame() const; … … 246 246 247 247 248 void BvhNode::IncTimes Invisible()248 void BvhNode::IncTimesTestedInvisible() 249 249 { 250 250 ++ mVisibility.mTimesInvisible; … … 252 252 253 253 254 int BvhNode::GetTimes Invisible() const254 int BvhNode::GetTimesTestedInvisible() const 255 255 { 256 256 return mVisibility.mTimesInvisible; … … 258 258 259 259 260 void BvhNode::SetTimes Invisible(const int t)260 void BvhNode::SetTimesTestedInvisible(const int t) 261 261 { 262 262 mVisibility.mTimesInvisible = t; … … 465 465 /** Renders the bounding box of this node (Or the tigher bounding boxes of some subnodes). 466 466 */ 467 void RenderBoundingBox(BvhNode *node );467 void RenderBoundingBox(BvhNode *node, RenderState *state); 468 468 /** Renders bounding boxes of the collection of nodes. 469 469 @returns #rendered boxes 470 470 */ 471 int RenderBoundingBoxes(const BvhNodeContainer &nodes );471 int RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state); 472 472 473 473 /** Returns the bounding box of this bvh. … … 533 533 /** Returns stats. 534 534 */ 535 const BvhStats &GetBvhStats() const {return mBvhStats;} 536 /** Renders the geometry contained in this node. 537 */ 538 int Render(BvhNode *node, RenderState *state); 535 const BvhStats &GetBvhStats() const { return mBvhStats; } 539 536 /** Returns number of 'virtual' nodes in the hierarchy, i.e. 540 537 the number of nodes actually used for traversal. … … 550 547 */ 551 548 Bvh(); 552 553 549 /** Protected constructor taking scene geometry into account 554 550 */ 555 551 const Bvh(const SceneEntityContainer &entities); 556 552 /** Called by the constructor. Initializes important members. 553 */ 554 void Init(); 557 555 558 556 ///////////// … … 568 566 569 567 int PrepareBoundingBoxesWithDrawArrays(const BvhNodeContainer &nodes); 570 void RenderBoundingBoxesWithDrawArrays(int numNodes );568 void RenderBoundingBoxesWithDrawArrays(int numNodes, RenderState *state); 571 569 572 570 /** Create the indices that each node needs to use vbo rendering. … … 644 642 ////////////// 645 643 646 static unsigned int sCurrentVboId;644 unsigned int mVboId; 647 645 }; 648 646 -
GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp
r2763 r2773 105 105 bvh->ComputeIds(); 106 106 // specify bounds for occlusion tests 107 //bvh->RecomputeBounds();107 bvh->RecomputeBounds(); 108 108 // compute and print stats 109 109 bvh->ComputeBvhStats(); -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp
r2772 r2773 16 16 { 17 17 // wait until result available 18 int visiblePixels = query->GetQueryResult(); 19 20 int visible = visiblePixels > mVisibilityThreshold; 18 const int visible = query->GetQueryResult() > mVisibilityThreshold; 21 19 22 20 BvhNode *node = query->GetFrontNode(); … … 26 24 // node was previously invisible 27 25 if (!node->IsVisible()) 26 { 27 // reset flag 28 node->SetTimesTestedInvisible(0); 28 29 node->SetAssumedVisibleFrameId(mFrameId + mAssumedVisibleFrames); 30 } 29 31 else 30 32 // randomize first invokation … … 36 38 else 37 39 { 40 node->IncTimesTestedInvisible(); 38 41 ++ mStats.mNumQueryCulledNodes; 39 42 } … … 58 61 59 62 OcclusionQuery *query = IssueOcclusionQuery(node, true); 63 60 64 mQueryQueue.push(query); 61 65 resultAvailable = mQueryQueue.front()->ResultAvailable(); … … 94 98 // identify nodes that we cannot skip queries for 95 99 const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() && (node->GetAssumedVisibleFrameId() <= mFrameId))); 100 101 // node was not recently tested => reset flag 102 if (node->GetLastVisitedFrame() != mFrameId - 1) 103 node->SetTimesTestedInvisible(0); 96 104 97 105 // update node's visited flag … … 176 184 177 185 186 OcclusionQuery * CHCPlusPlusTraverser::GetNextMultiQuery(BvhNodeQueue &iqueue) 187 { 188 OcclusionQuery *query = mQueryHandler.RequestQuery(); 189 190 float pFail = 1.0f; 191 float maxBatchVal = 0.0f; 192 float newPBatch = 1.0f; 193 float newBatchVal; 194 195 // issue next query 196 while (!iqueue.empty()) 197 { 198 BvhNode *node = iqueue.front(); 199 newPBatch *= mVisibilityPredictor.GetProbability(node); 200 201 if (query->GetNodes().empty()) 202 newBatchVal = 1.0f; 203 else 204 { 205 int newSize = query->GetSize() + 1; 206 newBatchVal = newSize / (1.0f + (1.0f - newPBatch) * newSize); 207 } 208 209 if (newBatchVal <= maxBatchVal) 210 break; 211 212 iqueue.pop(); 213 query->AddNode(node); 214 215 maxBatchVal = newBatchVal; 216 } 217 218 IssueOcclusionQuery(*query, false); 219 220 return query; 221 } 222 223 178 224 void CHCPlusPlusTraverser::IssueMultiQueries() 179 225 { … … 191 237 BvhNode *node = mIQueue.front(); 192 238 mIQueue.pop(); 193 194 OcclusionQuery *query = IssueOcclusionQuery(node, false); 239 OcclusionQuery *query = GetNextMultiQuery(mIQueue); 240 //OcclusionQuery *query = IssueOcclusionQuery(node); 241 195 242 mQueryQueue.push(query); 196 243 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h
r2772 r2773 7 7 namespace CHCDemo 8 8 { 9 10 class OcclusionQuery; 11 12 13 /** Class predicting the visiblity of nodes. 14 */ 15 class VisibilityPredictor 16 { 17 public: 18 /** Predicts the probability of a node to stay visible / invisible. 19 The probability could be taken from a measured or analytic function. 20 */ 21 float GetProbability(BvhNode *node) const 22 { 23 return 0.98f - 0.68f * exp(-(float)node->GetTimesTestedInvisible()); 24 } 25 }; 26 9 27 10 28 /** Class implementing traversal using the CHC++ algorithm. … … 22 40 */ 23 41 virtual void Traverse(); 24 42 /** Queries nodes nodes tested invisible in previous frames. 43 */ 25 44 void QueryPreviouslyInvisibleNodes(BvhNode *node); 26 45 /** Computes the next multiquery. 46 */ 47 OcclusionQuery *GetNextMultiQuery(BvhNodeQueue &iqueue); 48 /** Issues batched multiqueries. 49 */ 27 50 void IssueMultiQueries(); 28 51 /** Handles the result of an occlusion query. … … 38 61 BvhNodeQueue mIQueue; 39 62 BvhNodeQueue mVQueue; 63 64 VisibilityPredictor mVisibilityPredictor; 40 65 }; 41 66 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp
r2756 r2773 2 2 #include "Triangle3.h" 3 3 #include "glInterface.h" 4 #include "RenderState.h" 4 5 5 6 … … 67 68 68 69 69 void Geometry::Render( )70 void Geometry::Render(RenderState *state) 70 71 { 71 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 72 if (state->GetCurrentVboId() != mVboId) 73 { 74 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 75 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 76 glNormalPointer(GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 72 77 73 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL);74 glNormalPointer(GL_FLOAT, 0, (char *)NULL +mNumVertices * sizeof(Vector3));78 if (mTexCoords) 79 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 75 80 76 if (mTexCoords)77 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3));81 state->SetCurrentVboId(mVboId); 82 } 78 83 79 84 // don't render first degenerate index -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h
r2756 r2773 10 10 { 11 11 12 class RenderState; 13 12 14 /** Represents drawable geometry consisting of triangles 13 15 */ … … 20 22 /** Render the geometry 21 23 */ 22 void Render( );24 void Render(RenderState *state); 23 25 24 int CountTriangles() const { return mNumVertices / 3; }26 int GetNumTriangles() const { return mNumVertices / 3; } 25 27 26 28 inline bool HasTexture() const { return mTexCoords != NULL; } -
GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.cpp
r2764 r2773 18 18 19 19 20 OcclusionQuery::OcclusionQuery(unsigned int idx):21 mQueryId(idx)22 {23 // reverse for multiequeries with 32 nodes24 mNodes.reserve(32);25 }26 27 28 20 OcclusionQuery::~OcclusionQuery() 29 21 { … … 32 24 33 25 34 void OcclusionQuery::BeginQuery() 26 void OcclusionQuery::BeginQuery() const 35 27 { 36 28 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryId); … … 38 30 39 31 40 void OcclusionQuery::EndQuery() 32 void OcclusionQuery::EndQuery() const 41 33 { 42 34 glEndQueryARB(GL_SAMPLES_PASSED_ARB); … … 87 79 { 88 80 query = mOcclusionQueries[mCurrentQueryIdx]; 81 query->Reset(); 89 82 } 90 83 -
GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.h
r2772 r2773 17 17 { 18 18 public: 19 19 /** constructor requesting an opengl occlusion query. 20 */ 20 21 OcclusionQuery(); 21 22 … … 26 27 unsigned int GetQueryResult() const; 27 28 28 void BeginQuery() ;29 void BeginQuery() const; 29 30 30 void EndQuery() ;31 void EndQuery() const; 31 32 32 33 unsigned int GetQueryId() const; … … 34 35 */ 35 36 inline BvhNode *GetFrontNode() const { return mNodes[0]; } 36 /** Reset the contents of this query. 37 inline const BvhNodeContainer &GetNodes() const { return mNodes; } 38 39 /** Reset the list of nodes associated with this query. 37 40 */ 38 41 inline void Reset() { mNodes.clear(); } … … 40 43 */ 41 44 inline void AddNode(BvhNode *node) { mNodes.push_back(node); } 42 /** Convenience method that sets up a single nodequery.45 /** Returns the size of the multiquery. 43 46 */ 44 inline void SetNode(BvhNode *node) { Reset(); AddNode(node);}47 inline int GetSize() const { return (int)mNodes.size();} 45 48 46 47 49 protected: 48 50 49 OcclusionQuery(unsigned int id);50 51 51 52 52 /////// 53 53 //-- members 54 54 55 //float mPFail;56 55 /// all nodes that are tested with the same query 57 56 BvhNodeContainer mNodes; -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp
r2771 r2773 39 39 40 40 41 void RenderQueue::Enqueue(SceneEntity * *entities, int size)41 void RenderQueue::Enqueue(SceneEntity *entity) 42 42 { 43 for (int i = 0; i < size; ++ i) 44 mEntities.push_back(entities[i]); 43 mEntities.push_back(entity); 45 44 } 46 45 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.h
r2771 r2773 23 23 */ 24 24 RenderQueue(RenderState *state); 25 /** Enqueues a number of entities25 /** Enqueues an entity 26 26 */ 27 void Enqueue(SceneEntity * *entities, int size);27 void Enqueue(SceneEntity *entity); 28 28 /** Renders the contents of the render queue. 29 29 */ -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderState.cpp
r2769 r2773 12 12 */ 13 13 RenderState::RenderState(): 14 mAlphaTestEnabled(false), mTexturesEnabled(false), mMode(RENDER) 14 mAlphaTestEnabled(false), 15 mTexturesEnabled(false), 16 mMode(RENDER) 15 17 { 16 18 Reset(); … … 32 34 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 33 35 glDepthMask(GL_FALSE); 34 35 36 /////////37 //-- handle vbo38 39 /*glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);40 41 if (Bvh::sCurrentVboId != -1)42 glBindBufferARB(GL_ARRAY_BUFFER_ARB, Bvh::sCurrentVboId);43 else44 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);45 */46 36 47 37 SetState(false, false); … … 92 82 void RenderState::Reset() 93 83 { 84 mCurrentVboId = -1; 94 85 SetState(false, false); 95 86 SetState(RENDER); -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderState.h
r2769 r2773 41 41 */ 42 42 void Reset(); 43 /** Stores the current vbo id. 44 */ 45 inline void SetCurrentVboId(int id) { mCurrentVboId = id; } 46 /** Returns the current vbo id. 47 */ 48 inline int GetCurrentVboId() { return mCurrentVboId; } 43 49 44 50 protected: … … 48 54 49 55 Mode mMode; 56 57 int mCurrentVboId; 50 58 }; 51 59 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2772 r2773 5 5 #include "SceneEntity.h" 6 6 #include "RenderState.h" 7 #include "Geometry.h" 7 8 8 9 … … 16 17 void TraversalStatistics::Reset() 17 18 { 18 // reset statistics19 19 mNumTraversedNodes = 0; 20 20 mNumQueryCulledNodes = 0; 21 21 mNumFrustumCulledNodes = 0; 22 22 23 mNumRenderedGeometry = 0; 23 24 mNumRenderedTriangles = 0; 25 mNumRenderedNodes = 0; 26 24 27 mNumPreviouslyVisibleNodeQueries = 0; 25 28 mNumIssuedQueries = 0; 29 mNumStateChanges = 0; 30 26 31 mRenderTime = 0; 27 mNumStateChanges = 0;28 32 } 29 33 … … 83 87 if (node->GetLastRenderedFrame() != mFrameId) 84 88 { 85 //cout << "big error!!" << endl; 89 if (mUseRenderQueue && mRenderState->SetState(RenderState::RENDER)) 90 ++ mStats.mNumStateChanges; 91 86 92 node->SetLastRenderedFrame(mFrameId); 87 93 88 if (mUseRenderQueue) 94 int geometrySize; 95 SceneEntity **entities = mBvh->GetGeometry(node, geometrySize); 96 97 mStats.mNumRenderedGeometry += geometrySize; 98 ++ mStats.mNumRenderedNodes; 99 100 for (int i = 0; i < geometrySize; ++ i) 89 101 { 90 int geometrySize; 91 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 92 mRenderQueue.Enqueue(geom, geometrySize); 93 mStats.mNumRenderedGeometry += geometrySize; 94 } 95 else 96 { 97 if (mRenderState->SetState(RenderState::RENDER)) 98 ++ mStats.mNumStateChanges; 99 100 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 102 SceneEntity *ent = entities[i]; 103 mStats.mNumRenderedTriangles += ent->GetGeometry()->GetNumTriangles(); 104 105 if (mUseRenderQueue) 106 mRenderQueue.Enqueue(ent); 107 else 108 ent->Render(mRenderState); 101 109 } 102 110 } … … 114 122 mRenderState = state; 115 123 mRenderQueue.SetRenderState(state); 116 }117 118 119 OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible)120 {121 ++ mStats.mNumIssuedQueries;122 123 if (mUseRenderQueue && (mRenderState->GetMode() == RenderState::RENDER))124 {125 mRenderQueue.Render();126 mRenderQueue.Clear();127 }128 129 OcclusionQuery *query = mQueryHandler.RequestQuery();130 131 query->SetNode(node);132 133 query->BeginQuery();134 135 if (wasVisible)136 ++ mStats.mNumPreviouslyVisibleNodeQueries;137 138 // if this node is a previous visible leaf:139 // leaves will be rendered anyway => we can also test with the real geometry140 if (wasVisible && mUseOptimization)141 {142 RenderNode(node);143 }144 else145 {146 // change to query mode and render box147 if (mRenderState->SetState(RenderState::QUERY))148 ++ mStats.mNumStateChanges;149 150 mBvh->RenderBoundingBox(node);151 }152 153 query->EndQuery();154 155 return query;156 124 } 157 125 … … 213 181 214 182 215 } 183 184 185 OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible) 186 { 187 OcclusionQuery *query = mQueryHandler.RequestQuery(); 188 query->AddNode(node); 189 190 IssueOcclusionQuery(*query, wasVisible); 191 192 return query; 193 } 194 195 196 void RenderTraverser::IssueOcclusionQuery(const OcclusionQuery &query, bool wasVisible) 197 { 198 ++ mStats.mNumIssuedQueries; 199 200 if (mUseRenderQueue && (mRenderState->GetMode() == RenderState::RENDER)) 201 { 202 mRenderQueue.Render(); 203 mRenderQueue.Clear(); 204 } 205 206 query.BeginQuery(); 207 208 if (wasVisible) 209 ++ mStats.mNumPreviouslyVisibleNodeQueries; 210 211 // if this node is a previous visible leaf: 212 // leaves will be rendered anyway => we can also test with the real geometry 213 if (wasVisible && mUseOptimization) 214 { 215 for (size_t i = 0; i < query.GetNodes().size(); ++ i) 216 RenderNode(query.GetNodes()[i]); 217 } 218 else 219 { 220 // change to query mode and render box 221 if (mRenderState->SetState(RenderState::QUERY)) 222 ++ mStats.mNumStateChanges; 223 224 mBvh->RenderBoundingBoxes(query.GetNodes(), mRenderState); 225 } 226 227 query.EndQuery(); 228 } 229 230 231 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2771 r2773 30 30 int mNumQueryCulledNodes; 31 31 int mNumFrustumCulledNodes; 32 32 33 int mNumRenderedGeometry; 33 34 int mNumRenderedTriangles; 35 int mNumRenderedNodes; 36 34 37 int mNumIssuedQueries; 35 38 int mNumStateChanges; 36 39 int mNumPreviouslyVisibleNodeQueries; 37 40 38 41 long mRenderTime; 39 42 }; … … 114 117 */ 115 118 void TraverseNode(BvhNode *node); 116 /** Issues occlusion query for specifiednode119 /** Issues occlusion query for a single node 117 120 */ 118 121 OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 122 /** Issue multiquery. 123 */ 124 void IssueOcclusionQuery(const OcclusionQuery &query, bool wasVisible); 119 125 /** Retunrs true if the current bvh node intersects the near plane. 120 126 */ -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.cpp
r2769 r2773 26 26 glPushMatrix(); 27 27 glMultMatrixf((float *)mTransform->x); 28 mGeometry->Render( );28 mGeometry->Render(state); 29 29 30 30 glPopMatrix(); … … 32 32 else 33 33 { 34 mGeometry->Render( );34 mGeometry->Render(state); 35 35 } 36 36 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2771 r2773 62 62 63 63 int renderedObjects = 0; 64 int renderedNodes = 0; 65 int renderedTriangles = 0; 66 64 67 int issuedQueries = 0; 65 68 int traversedNodes = 0; … … 869 872 870 873 renderedObjects = traverser->GetStats().mNumRenderedGeometry; 874 renderedNodes = traverser->GetStats().mNumRenderedNodes; 875 renderedTriangles = traverser->GetStats().mNumRenderedTriangles; 876 871 877 traversedNodes = traverser->GetStats().mNumTraversedNodes; 872 878 frustumCulledNodes = traverser->GetStats().mNumFrustumCulledNodes; … … 881 887 string str2; 882 888 883 int dummy = 0; 884 CalcDecimalPoint(str, dummy); 885 CalcDecimalPoint(str2, traverser->GetStats().mNumRenderedTriangles); 886 887 sprintf_s(msg3, "rendered objects: %6d (of %6d), rendered triangles: %s (of %s)", 888 renderedObjects, sceneEntities.size(), str.c_str(), str2.c_str()); 889 890 sprintf_s(msg4, "nodes: %5d, traversed: %5d, frustum culled: %5d, query culled: %5d, issued queries: %5d, state changes: %5d", 891 bvh->GetNumVirtualNodes(), traversedNodes, frustumCulledNodes, 892 queryCulledNodes, issuedQueries, stateChanges); 889 CalcDecimalPoint(str, renderedTriangles); 890 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 891 892 sprintf_s(msg3, "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)", 893 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 894 895 sprintf_s(msg4, "traversed: %5d, frustum culled: %5d, query culled: %5d, issued queries: %5d, state changes: %5d", 896 traversedNodes, frustumCulledNodes, queryCulledNodes, issuedQueries, stateChanges); 893 897 894 898 sprintf_s(msg5, "fps: %6.1f", fps); 895 899 896 cout << "previously visible node queries: " << traverser->GetStats().mNumPreviouslyVisibleNodeQueries << endl;900 //cout << "previously visible node queries: " << traverser->GetStats().mNumPreviouslyVisibleNodeQueries << endl; 897 901 898 902 begin2D(); … … 906 910 glColor3f(1.0f, 1.0f, 1.0f); 907 911 908 Output(8 00, 30, msg[renderMode]);912 Output(850, 30, msg[renderMode]); 909 913 910 914 if(showStatistics)
Note: See TracChangeset
for help on using the changeset viewer.