Changeset 2770 for GTP/trunk/App/Demos
- Timestamp:
- 06/18/08 14:38:45 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2764 r2770 104 104 { 105 105 mIsVisible = false; 106 107 mAssumedVisibleFrames = 0; 108 106 mAssumedVisibleFrameId = 0; 109 107 mLastVisitedFrame = -1; 110 111 108 mTimesInvisible = 0; 112 109 mIsFrustumCulled = false; 113 114 110 mIsNew = true; 115 111 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2767 r2770 42 42 /// if the node is visible 43 43 bool mIsVisible; 44 /// #framesthis node is assumed to stay visible45 int mAssumedVisibleFrame s;44 /// frame id until this node is assumed to stay visible 45 int mAssumedVisibleFrameId; 46 46 /// the frame when this node was last touched during traversal 47 47 int mLastVisitedFrame; … … 96 96 */ 97 97 inline void SetVisible(bool visible); 98 /** The assumed visible time span of this node.99 */ 100 inline void SetAssumedVisibleFrame s(int t);98 /** The frame id until this node is assumed visible 99 */ 100 inline void SetAssumedVisibleFrameId(int t); 101 101 /** See set. 102 102 */ 103 inline int GetAssumedVisibleFrames() const; 104 /** The time span this node remains visible. 105 */ 106 inline void SetRemainingVisibleFrames(const int t); 107 /** Decrease the time this node is considered visible. 108 */ 109 inline void DecAssumedVisibleFrames(); 103 inline int GetAssumedVisibleFrameId() const; 110 104 /** Increases the #times this node was 111 105 successfully tested invisible. … … 318 312 319 313 320 void BvhNode::SetAssumedVisibleFrames(const int t) 321 { 322 mVisibility.mAssumedVisibleFrames = t; 323 } 324 325 326 int BvhNode::GetAssumedVisibleFrames() const 327 { 328 return mVisibility.mAssumedVisibleFrames; 329 } 330 331 void BvhNode::DecAssumedVisibleFrames() 332 { 333 -- mVisibility.mAssumedVisibleFrames; 314 void BvhNode::SetAssumedVisibleFrameId(int t) 315 { 316 mVisibility.mAssumedVisibleFrameId = t; 317 } 318 319 320 int BvhNode::GetAssumedVisibleFrameId() const 321 { 322 return mVisibility.mAssumedVisibleFrameId; 334 323 } 335 324 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp
r2767 r2770 1 1 #include "CHCPlusPlusTraverser.h" 2 #include "RenderState.h" 3 2 4 3 5 namespace CHCDemo … … 17 19 (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 18 20 { 19 OcclusionQuery *query = mQueryQueue.front(); 20 mQueryQueue.pop(); 21 22 // wait until result available 23 int visiblePixels = query->GetQueryResult(); 21 if (mQueryQueue.front()->ResultAvailable()) 22 { 23 OcclusionQuery *query = mQueryQueue.front(); 24 mQueryQueue.pop(); 24 25 25 if (visiblePixels > mVisibilityThreshold) 26 // wait until result available 27 int visiblePixels = query->GetQueryResult(); 28 29 if (visiblePixels > mVisibilityThreshold) 30 { 31 BvhNode *node = query->GetFrontNode(); 32 33 node->SetVisible(true); 34 mBvh->MakeParentsVisible(node); 35 TraverseNode(node); 36 } 37 else 38 { 39 ++ mStats.mNumQueryCulledNodes; 40 } 41 } 42 else if (!mVQueue.empty()) 26 43 { 27 BvhNode *node = query->GetFrontNode(); 44 BvhNode *node = mVQueue.front(); 45 mVQueue.pop(); 28 46 29 mBvh->MakeParentsVisible(node); 30 TraverseNode(node); 31 } 32 else 33 { 34 ++ mStats.mNumQueryCulledNodes; 47 OcclusionQuery *query = IssueOcclusionQuery(node, true); 48 mQueryQueue.push(query); 35 49 } 36 50 } … … 61 75 62 76 // identify nodes that we cannot skip queries for 63 const bool leafOrWasInvisible = 64 (node->GetLastVisitedFrame() != mFrameId) && (!wasVisible || node->IsVirtualLeaf()); 65 66 // reset node's visibility classification 67 node->SetVisible(false); 77 const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() /*&& (node->GetAssumedVisibleFrameId() <= mFrameId)*/)); 78 68 79 69 80 // update node's visited flag … … 71 82 72 83 // skip testing previously visible interior nodes 73 if ( leafOrWasInvisible)84 if (testFeasible) 74 85 { 75 OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible); 76 mQueryQueue.push(query); 86 // reset node's visibility classification 87 node->SetVisible(false); 88 89 if (!wasVisible) 90 { 91 QueryPreviouslyInvisibleNodes(node); 92 } 93 else 94 { 95 mVQueue.push(node); 96 } 77 97 } 78 98 79 // always traverse a node if it was visible99 // always traverse a node if it was previously visible 80 100 if (wasVisible) 81 101 TraverseNode(node); … … 88 108 } 89 109 } 110 111 if (mDistanceQueue.empty()) 112 { 113 // issue remaining multiqueries 114 IssueMultiQueries(); 115 } 116 } 117 118 ////////////// 119 //-- issue remaining previously visible node queries 120 121 while (!mVQueue.empty()) 122 { 123 BvhNode *node = mVQueue.front(); 124 mVQueue.pop(); 125 126 OcclusionQuery *query = IssueOcclusionQuery(node, true); 127 mQueryQueue.push(query); 128 } 129 130 while (!mQueryQueue.empty()) 131 { 132 OcclusionQuery *query = mQueryQueue.front(); 133 mQueryQueue.pop(); 134 135 // wait until result available 136 int visiblePixels = query->GetQueryResult(); 137 138 if (visiblePixels > mVisibilityThreshold) 139 { 140 BvhNode *node = query->GetFrontNode(); 141 142 node->SetVisible(true); 143 mBvh->MakeParentsVisible(node); 144 } 145 else 146 { 147 ++ mStats.mNumQueryCulledNodes; 148 } 90 149 } 91 150 } 92 151 152 153 154 void CHCPlusPlusTraverser::QueryPreviouslyInvisibleNodes(BvhNode *node) 155 { 156 mIQueue.push(node); 157 158 if (mIQueue.size() > 50) 159 { 160 IssueMultiQueries(); 161 } 93 162 } 163 164 165 void CHCPlusPlusTraverser::IssueMultiQueries() 166 { 167 if (0 && mUseRenderQueue) 168 { 169 if (mRenderState->SetState(RenderState::RENDER)) 170 ++ mStats.mNumStateChanges; 171 172 mRenderQueue.Render(); 173 mRenderQueue.Clear(); 174 } 175 176 while (!mIQueue.empty()) 177 { 178 BvhNode *node = mIQueue.front(); 179 mIQueue.pop(); 180 181 OcclusionQuery *query = IssueOcclusionQuery(node, false); 182 mQueryQueue.push(query); 183 } 184 } 185 186 187 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h
r2767 r2770 21 21 */ 22 22 virtual void Traverse(); 23 24 void QueryPreviouslyInvisibleNodes(BvhNode *node); 25 26 void IssueMultiQueries(); 27 28 ////////////// 29 30 BvhNodeQueue mIQueue; 31 BvhNodeQueue mVQueue; 23 32 }; 24 33 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.cpp
r2767 r2770 28 28 BvhNode *node = query->GetFrontNode(); 29 29 30 node->SetVisible(true); 30 31 mBvh->MakeParentsVisible(node); 31 32 TraverseNode(node); … … 62 63 63 64 // identify nodes that we cannot skip queries for 64 const bool leafOrWasInvisible = 65 (node->GetLastVisitedFrame() != mFrameId) && (!wasVisible || node->IsVirtualLeaf()); 65 const bool leafOrWasInvisible = (!wasVisible || node->IsVirtualLeaf()); 66 66 67 67 // reset node's visibility classification -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2767 r2770 36 36 } 37 37 } 38 39 mRenderQueue.Render();40 mRenderQueue.Clear();41 38 } 42 39 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2769 r2770 19 19 mNumRenderedGeometry = 0; 20 20 mNumRenderedTriangles = 0; 21 21 mNumPreviouslyVisibleNodeQueries = 0; 22 22 mNumIssuedQueries = 0; 23 23 mRenderTime = 0; 24 mNumStateChanges = 0; 24 25 } 25 26 … … 35 36 mBvh(NULL), 36 37 mIsQueryMode(false), 37 mUseOptimization( true),38 mUseOptimization(false), 38 39 mFrameId(-1), 39 mUseRenderQueue(false) 40 mUseRenderQueue(false), 41 mAssumedVisibleFrames(10) 40 42 { 41 43 } … … 61 63 if (node->IsVirtualLeaf()) 62 64 { 63 if (mUseRenderQueue) 64 { 65 int geometrySize; 66 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 67 mRenderQueue.Enqueue(geom, geometrySize); 68 mStats.mNumRenderedGeometry += geometrySize; 69 } 70 else 71 { 72 // RenderBox(node->GetBox()); 73 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 74 } 65 RenderNode(node); 75 66 } 76 67 else … … 85 76 86 77 78 void RenderTraverser::RenderNode(BvhNode *node) 79 { 80 if (mUseRenderQueue) 81 { 82 int geometrySize; 83 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 84 mRenderQueue.Enqueue(geom, geometrySize); 85 mStats.mNumRenderedGeometry += geometrySize; 86 } 87 else 88 { 89 if (mRenderState->SetState(RenderState::RENDER)) 90 ++ mStats.mNumStateChanges; 91 92 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 93 } 94 } 95 96 87 97 void RenderTraverser::SetHierarchy(Bvh *bvh) 88 98 { … … 101 111 { 102 112 ++ mStats.mNumIssuedQueries; 113 114 if (mUseRenderQueue && (mRenderState->GetMode() == RenderState::RENDER)) 115 { 116 mRenderQueue.Render(); 117 mRenderQueue.Clear(); 118 } 103 119 104 120 OcclusionQuery *query = mQueryHandler.RequestQuery(); … … 107 123 108 124 query->BeginQuery(); 109 110 // if leaf and was visible => will be rendered anyway, thus we 125 126 if (wasVisible) 127 { 128 node->SetAssumedVisibleFrameId(mFrameId + 10); 129 ++ mStats.mNumPreviouslyVisibleNodeQueries; 130 } 131 132 // if this node is a previous visible leaf => will be rendered anyway, thus we 111 133 // can also test with the real geometry 112 /*if(node->IsLeaf() &&wasVisible && mUseOptimization)113 { 114 m NumRenderedGeometry += node->Render();134 if (wasVisible && mUseOptimization) 135 { 136 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 115 137 } 116 138 else 117 {*/ 118 119 // change to query mode 120 mRenderState->SetState(RenderState::QUERY); 121 mBvh->RenderBoundingBox(node); 122 mRenderState->SetState(RenderState::RENDER); 139 { 140 // change to query mode and render box 141 if (mRenderState->SetState(RenderState::QUERY)) 142 ++ mStats.mNumStateChanges; 143 144 mBvh->RenderBoundingBox(node); 145 } 123 146 124 147 query->EndQuery(); … … 172 195 Traverse(); 173 196 197 // render the rest of the objects 198 if (mUseRenderQueue) 199 { 200 if (mRenderState->SetState(RenderState::RENDER)) 201 ++ mStats.mNumStateChanges; 202 203 mRenderQueue.Render(); 204 mRenderQueue.Clear(); 205 } 206 207 mRenderState->Reset(); 208 174 209 glDisableClientState(GL_VERTEX_ARRAY); 175 210 glDisableClientState(GL_NORMAL_ARRAY); 176 211 177 mRenderState->Reset();178 179 212 t2 = GetTime(); 180 213 mStats.mRenderTime = TimeDiff(t1, t2); -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2769 r2770 33 33 int mNumRenderedTriangles; 34 34 int mNumIssuedQueries; 35 int mNumStateChanges; 36 int mNumPreviouslyVisibleNodeQueries; 35 37 36 38 long mRenderTime; … … 99 101 */ 100 102 inline bool IntersectsNearPlane(BvhNode *node) const; 101 /** Enqueues a bvh node .103 /** Enqueues a bvh node for distance traversal 102 104 */ 103 105 void EnqueueNode(BvhNode *node); 104 106 /** Renders the bvh node. 107 */ 108 void RenderNode(BvhNode *node); 105 109 106 110 … … 134 138 135 139 bool mUseRenderQueue; 140 141 int mAssumedVisibleFrames; 136 142 }; 137 143 -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2769 r2770 57 57 float visZoomFactor = 1.5f; 58 58 59 long accumulatedTime = 1000; 60 float fps = 1e3f; 61 62 int renderedObjects = 0; 63 int issuedQueries = 0; 64 int traversedNodes = 0; 65 int frustumCulledNodes = 0; 66 int queryCulledNodes = 0; 67 int stateChanges = 0; 68 59 69 bool showHelp = false; 60 70 bool showStatistics = true; … … 69 79 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 70 80 71 bool useOptimization = true;81 bool useOptimization = false; 72 82 73 83 … … 296 306 traverser->SetHierarchy(bvh); 297 307 traverser->SetRenderState(&state); 308 traverser->SetUseOptimization(useOptimization); 309 traverser->SetUseRenderQueue(useRenderQueue); 310 traverser->SetVisibilityThreshold(threshold); 298 311 } 299 312 … … 843 856 844 857 845 sprintf_s(msg2, "traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)",846 traverser->GetStats().mNumTraversedNodes, traverser->GetStats().mNumFrustumCulledNodes,847 traverser->GetStats().mNumQueryCulledNodes, bvh->GetNumVirtualNodes());848 849 858 char *optstr[2] = {"", ", using optimization"}; 850 859 851 float fps = 1e3f;852 860 static long renderTime = traverser->GetStats().mRenderTime; 853 854 861 const float expFactor = 0.5f; 855 856 862 renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 857 863 858 if (renderTime) fps = 1e3f / (float)renderTime; 864 accumulatedTime += renderTime; 865 866 if (accumulatedTime > 200) // update every fraction of a second 867 { 868 accumulatedTime = 0; 869 if (renderTime) fps = 1e3f / (float)renderTime; 870 871 renderedObjects = traverser->GetStats().mNumRenderedGeometry; 872 traversedNodes = traverser->GetStats().mNumTraversedNodes; 873 frustumCulledNodes = traverser->GetStats().mNumFrustumCulledNodes; 874 queryCulledNodes = traverser->GetStats().mNumQueryCulledNodes; 875 issuedQueries = traverser->GetStats().mNumIssuedQueries; 876 stateChanges = traverser->GetStats().mNumStateChanges; 877 } 859 878 860 879 sprintf_s(msg2, "threshold: %4d%s", … … 869 888 870 889 sprintf_s(msg3, "rendered objects: %6d (of %6d), rendered triangles: %s (of %s)", 871 traverser->GetStats().mNumRenderedGeometry, sceneEntities.size(), str.c_str(), str2.c_str()); 872 873 sprintf_s(msg4, "issued queries: %5d", traverser->GetStats().mNumIssuedQueries); 890 renderedObjects, sceneEntities.size(), str.c_str(), str2.c_str()); 891 892 sprintf_s(msg4, "nodes: %5d, traversed: %5d, frustum culled: %5d, query culled: %5d, issued queries: %5d, state changes: %5d", 893 bvh->GetNumVirtualNodes(), traversedNodes, frustumCulledNodes, 894 queryCulledNodes, issuedQueries, stateChanges); 874 895 875 896 sprintf_s(msg5, "fps: %6.1f", fps); 876 897 898 cout << "previously visible node queries: " << traverser->GetStats().mNumPreviouslyVisibleNodeQueries << endl; 877 899 878 900 begin2D(); -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
r2763 r2770 472 472 473 473 typedef std::queue<OcclusionQuery *> QueryQueue; 474 typedef std::queue<BvhNode *> BvhNodeQueue; 474 475 475 476 static std::ofstream Debug("debug.log");
Note: See TracChangeset
for help on using the changeset viewer.