Changeset 2754 for GTP


Ignore:
Timestamp:
06/11/08 00:18:07 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2746 r2754  
    44 
    55 
    6 #if TOIMPLEMENT 
     6namespace CHCDemo 
     7{ 
    78 
    89RenderTraverser::RenderTraverser():  
    910mFrameID(1),  
    1011mVisibilityThreshold(0), 
    11 mHierarchyRoot(NULL),  
    12 mOcclusionQueries(NULL),  
    13 mCurrentQueryIdx(0),  
     12mBvh(NULL),  
    1413mIsQueryMode(false), 
    15 mNumTraversedNodes(0),  
    16 mNumQueryCulledNodes(0),  
    17 mNumFrustumCulledNodes(0), 
    18 mRenderTime(0),  
    19 mNumRenderedGeometry(0),  
    2014mUseOptimization(true), 
    21 mUseArbQueries(false) 
     15mCurrentQueryIdx(0) 
    2216{ 
    2317} 
     
    2620RenderTraverser::~RenderTraverser() 
    2721{ 
    28         DelQueries(); 
    29 } 
    30  
    31  
    32 void RenderTraverser::Render(int mode) 
     22        //DelQueries(); 
     23} 
     24 
     25 
     26/*void RenderTraverser::Render(int mode) 
    3327{ 
    3428        mDistanceQueue.push(mHierarchyRoot); 
     
    6155 
    6256        finishTiming(); 
    63 } 
    64  
    65 /** 
    66         This is the standard render traversal algorithm doing only frustum culling 
    67 */ 
    68 void RenderTraverser::RenderCullFrustum() 
    69 { 
    70         while(!mDistanceQueue.empty()) 
    71         { 
    72                 HierarchyNode *node = mDistanceQueue.top(); 
    73                 mDistanceQueue.pop(); 
    74          
    75                 // interesting for the visualization, so rest and set 
    76                 node->SetVisible(false); 
    77                 mNumTraversedNodes ++; 
    78  
    79                 bool intersects; 
    80          
    81                 if(InsideViewFrustum(node, intersects)) 
    82                 { 
    83                         // update node's visited flag => needed for rendering 
    84                         // so set it also here 
    85                         node->SetLastVisited(mFrameID); 
    86                         node->SetVisible(true); 
    87                         TraverseNode(node); 
    88                 } 
    89                 else 
    90                 { 
    91                         mNumFrustumCulledNodes ++; 
    92                 } 
    93         } 
    94 } 
    95  
    96 void RenderTraverser::RenderStopAndWait() 
    97 { 
    98         while(! mDistanceQueue.empty()) 
    99         { 
    100                 HierarchyNode *node = mDistanceQueue.top(); 
    101                 mDistanceQueue.pop(); 
    102                 mNumTraversedNodes ++; 
    103                 // interesting for the visualization, so rest and set 
    104                 node->SetVisible(false); 
    105  
    106                 bool intersects; 
    107                  
    108                 if(InsideViewFrustum(node, intersects)) 
    109                 { 
    110                         // update node's visited flag 
    111                         node->SetLastVisited(mFrameID); 
    112  
    113                         // for near plane intersecting abbs possible  
    114                         // wrong results => skip occlusion query 
    115                         if(intersects) 
    116                         { 
    117                                 node->SetVisible(true); 
    118                                 TraverseNode(node); 
    119                         } 
    120                         else 
    121                         { 
    122                                 IssueOcclusionQuery(node, false); 
    123                                  
    124                                 // wait if result not available 
    125                                 int visiblePixels = GetOcclusionQueryResult(node); 
    126                                  
    127                                 // node visible 
    128                                 if(visiblePixels > mVisibilityThreshold) 
    129                                 { 
    130                                         node->SetVisible(true); 
    131                                         TraverseNode(node); 
    132                                 } 
    133                                 else 
    134                                 { 
    135                                         mNumQueryCulledNodes ++; 
    136                                 } 
    137                         }                                        
    138                 } 
    139                 else 
    140                 { 
    141                         mNumFrustumCulledNodes ++; 
    142                 } 
    143         } 
    144 } 
    145  
    146 void RenderTraverser::RenderCoherentWithQueue() 
    147 { 
    148         QueryQueue queryQueue; 
    149  
    150         //-- PART 1: process finished occlusion queries 
    151         while (!mDistanceQueue.empty() || !queryQueue.empty()) 
    152         { 
    153                 while (!queryQueue.empty() &&  
    154                            (ResultAvailable(queryQueue.front()) || mDistanceQueue.empty())) 
    155                 { 
    156                         HierarchyNode *node = queryQueue.front(); 
    157                         queryQueue.pop(); 
    158                          
    159                         // wait until result available 
    160                         int visiblePixels = GetOcclusionQueryResult(node); 
    161  
    162                         if(visiblePixels > mVisibilityThreshold) 
    163                         { 
    164                                 PullUpVisibility(node); 
    165                                 TraverseNode(node); 
    166                         } 
    167                         else 
    168                         { 
    169                                 mNumQueryCulledNodes ++; 
    170                         } 
    171                 }        
    172  
    173                 //-- PART 2: hierarchical traversal 
    174                 if (!mDistanceQueue.empty()) 
    175                 { 
    176                         HierarchyNode *node = mDistanceQueue.top(); 
    177  
    178                         mDistanceQueue.pop(); 
    179          
    180                         mNumTraversedNodes ++; 
    181  
    182                         bool intersects; 
    183                          
    184                         if (InsideViewFrustum(node, intersects)) 
    185                         { 
    186                                 // for near plane intersecting bounding box possible  
    187                                 // wrong results => skip occlusion query 
    188                                 if(intersects) 
    189                                 { 
    190                                         // update node's visited flag 
    191                                         node->SetLastVisited(mFrameID); 
    192                                         node->SetVisible(true); 
    193                                         PullUpVisibility(node); 
    194                                         TraverseNode(node); 
    195                                 } 
    196                                 else 
    197                                 {                
    198                                         // identify previously visible nodes 
    199                                         bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1); 
    200                                          
    201                                         // identify nodes that we cannot skip queries for 
    202                                         bool leafOrWasInvisible = (node->LastVisited() != mFrameID) && (!wasVisible || node->IsLeaf()); 
    203  
    204                                         // reset node's visibility classification  
    205                                         node->SetVisible(false); 
    206  
    207                                         // update node's visited flag 
    208                                         node->SetLastVisited(mFrameID); 
    209                                          
    210                                         // skip testing previously visible interior nodes 
    211                                         if(leafOrWasInvisible) 
    212                                         { 
    213                                                 IssueOcclusionQuery(node, wasVisible); 
    214                                                 queryQueue.push(node); 
    215                                         } 
    216                                          
    217                                         // always traverse a node if it was visible 
    218                                         if(wasVisible) 
    219                                                 TraverseNode(node); 
    220                                 } 
    221                         } 
    222                         else 
    223                         { 
    224                                 // for stats 
    225                                 mNumFrustumCulledNodes ++; 
    226                         } 
    227                 } 
    228         } 
    229 } 
    230          
     57}*/ 
     58 
     59#if 0 
    23160void RenderTraverser::TraverseNode(HierarchyNode *node) 
    23261{ 
     
    533362 
    534363 
    535 int RenderTraverser::GetVisibilityThreshold() 
    536 { 
    537         return mVisibilityThreshold; 
    538 } 
     364#endif 
     365 
    539366 
    540367void RenderTraverser::SetUseOptimization(bool useOptimization) 
     
    544371} 
    545372 
    546  
    547 #endif 
     373} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h

    r2753 r2754  
    1 #ifndef RENDERTRAVERSER_H 
    2 #define RENDERTRAVERSER_H 
    3  
    4  
    5  
    6 #if TOIMPLEMENT 
    7  
    8 #include "glInterface.h" 
    9 #include "HierarchyNode.h" 
     1#ifndef __RENDERTRAVERSER_H 
     2#define __RENDERTRAVERSER_H 
    103 
    114#include <queue> 
    125#include <stack> 
     6#include "glInterface.h" 
     7 
    138 
    149namespace CHCDemo 
    1510{ 
    1611 
     12class BvhNode; 
     13class Bvh; 
     14class Camera; 
     15class Matrix4x4; 
     16 
     17 
     18struct TraversalStatistics 
     19{ 
     20        friend class RenderTraverser; 
     21 
     22public: 
     23 
     24        ////////// 
     25        //-- several statistics for a rendering pass 
     26 
     27        long GetRenderTime(); 
     28        int GetNumTraversedNodes(); 
     29        int GetNumQueryCulledNodes(); 
     30        int GetNumFrustumCulledNodes(); 
     31        int GetNumRenderedGeometry(); 
     32         
     33protected: 
     34 
     35        // statistics 
     36        int mNumTraversedNodes; 
     37        int mNumQueryCulledNodes; 
     38        int mNumFrustumCulledNodes; 
     39        int mNumRenderedGeometry; 
     40 
     41        long mRenderTime; 
     42}; 
     43 
     44 
     45//typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue; 
     46 
     47/** Abstract class implementing a scene traversal for rendering. 
     48*/ 
    1749class RenderTraverser 
    1850{ 
    1951public: 
    20         enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; 
     52        //enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; 
    2153 
    2254        RenderTraverser(); 
     
    3062                RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm 
    3163        */ 
    32         void Render(int mode=RENDER_CULL_FRUSTUM); 
    33         //! sets the scene hierarchy. 
    34         void SetHierarchy(HierarchyNode *sceneRoot); 
    35         //! sets viewpoint 
    36         void SetViewpoint(Vector3 const &viewpoint); 
    37         //! sets view projection matrix 
    38         void SetProjViewMatrix(Matrix4x4 const &projViewMatrix); 
    39         //! returns root of hierarchy 
    40         HierarchyNode *GetHierarchy(); 
    41         //! sets visible pixels threshold for visibility classification 
     64        virtual void Render() = 0; 
     65        /** Sets the scene hierarchy. 
     66        */ 
     67        void SetHierarchy(Bvh *bvh); 
     68        /** Sets the camera. 
     69        */ 
     70        void SetCamera(Camera *camera); 
     71        /** sets view projection matrix 
     72        */ 
     73        //void SetProjViewMatrix(Matrix4x4 const &projViewMatrix); 
     74        /** Sets visible pixels threshold for visibility classification 
     75        */ 
    4276        void SetVisibilityThreshold(int threshold); 
    43         //! returns visibility threshold 
    44         int GetVisibilityThreshold(); 
    45  
    46         // several statistics for a rendering pass 
    47         long GetRenderTime(); 
    48         int GetNumTraversedNodes(); 
    49         int GetNumQueryCulledNodes(); 
    50         int GetNumFrustumCulledNodes(); 
    51         int GetNumRenderedGeometry(); 
    52  
    53         //! renders a visualization of the hierarchy 
     77        /** Returns visibility threshold 
     78        */ 
     79        int GetVisibilityThreshold() const; 
     80        /** renders a visualization of the hierarchy 
     81        */ 
    5482        void RenderVisualization(); 
    55  
    56         //! use optimization to take leaf nodes instead of bounding box for occlusion queries    
     83        /** use optimization to take leaf nodes instead of bounding box for occlusion queries    
     84        */ 
    5785        void SetUseOptimization(bool useOptimization); 
    58  
    59         //! if arb queries should be used instead of nv 
    60         void SetUseArbQueries(const bool useArbQueries); 
    61         //!     see set 
    62         bool GetUseArbQueries() const; 
    6386 
    6487protected: 
    6588 
    66         //! renders the scene with view frustum culling only 
    67         void RenderCullFrustum(); 
    68         //! renders the scene with the hierarchical stop and wait algorithm 
    69         void RenderStopAndWait(); 
    70         //! renders the scene with the coherent hierarchical algorithm and the query queye 
    71         void RenderCoherentWithQueue(); 
    72         //! does some importand initialisations 
     89        /** does some important initializations 
     90        */ 
    7391        void Preprocess(); 
    74          
    75         //! returns occlusion query result for specified node 
    76         unsigned int GetOcclusionQueryResult(HierarchyNode *node) const; 
    77         //! the node is traversed as usual 
    78         void TraverseNode(HierarchyNode *node); 
    79         //! visibility is pulled up from visibility of children  
    80         void PullUpVisibility(HierarchyNode *node); 
    81         //! is result available from query queue? 
    82         bool ResultAvailable(HierarchyNode *node) const; 
    83         //! issues occlusion query for specified node 
    84         void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible); 
    85         //! resets occlusion queries after a traversal 
     92        /** Hierarchy traversal 
     93        */ 
     94        void TraverseNode(BvhNode *node); 
     95        /** Visibility is pulled up from visibility of children  
     96        */ 
     97        void PullUpVisibility(BvhNode *node); 
     98        /** Issues occlusion query for specified node 
     99        */ 
     100        void IssueOcclusionQuery(BvhNode *node, bool wasVisible); 
     101        /** Resets occlusion queries after a traversal 
     102        */ 
    86103        void DelQueries(); 
    87         //! does view frustum culling. returns intersect (if intersects view plane) 
    88         bool InsideViewFrustum(HierarchyNode *node, bool &intersects); 
    89         //! switches to normal render mode 
     104        /** Does view frustum culling. returns intersect (if intersects view plane) 
     105        */ 
     106        bool InsideViewFrustum(BvhNode *node, bool &intersects); 
     107        /** switches to normal render mode 
     108        */ 
    90109        void Switch2GLRenderState(); 
    91         //! switches to occlusion query mode (geometry not rendered on the screen) 
     110        /** switches to occlusion query mode (geometry not rendered on the screen) 
     111        */ 
    92112        void Switch2GLQueryState(); 
    93113 
     
    95115protected: 
    96116 
    97         /// if arb queries should be instead of nv 
    98         bool mUseArbQueries; 
     117        // /the current clip planes of the view frustum 
     118        //VecPlane mClipPlanes; 
     119        /// the indices of the np-vertices of the bounding box for view frustum culling 
     120        //int mNPVertexIndices[12]; 
    99121 
    100         // the current clip planes of the view frustum 
    101         VecPlane mClipPlanes; 
    102         // the indices of the np-vertices of the bounding box for view frustum culling 
    103         int mNPVertexIndices[12]; 
    104  
    105         // the current view point 
    106         Vector3 mViewpoint; 
    107         Matrix4x4 mProjViewMatrix; 
    108         // the root of the scene hierarchy 
    109         HierarchyNode *mHierarchyRoot; 
    110         //TraversalStack mTraversalStack; 
    111         PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack 
     122        /// the current camera 
     123        Camera *mCamera; 
     124        //Matrix4x4 mProjViewMatrix; 
     125        /// the root of the scene hierarchy 
     126        Bvh *mBvh; 
     127        /// use a priority queue rather than a renderstack 
     128        //PriorityQueue mDistanceQueue;  
    112129         
    113         //priority_queue<vector<HierarchyNode *>, HierarchyNode *> mPriorityQueue; 
    114130        int mFrameID; 
    115131        int mVisibilityThreshold; 
    116         unsigned int *mOcclusionQueries; 
     132         
     133        //unsigned int *mOcclusionQueries; 
    117134        int mCurrentQueryIdx; 
    118135        bool mIsQueryMode; 
    119136         
    120         bool mIntersects; 
    121  
    122         // statistics 
    123         int mNumTraversedNodes; 
    124         int mNumQueryCulledNodes; 
    125         int mNumFrustumCulledNodes; 
    126         int mNumRenderedGeometry; 
    127  
    128         long mRenderTime; 
    129  
     137        //bool mIntersects; 
    130138        bool mUseOptimization; 
    131139}; 
     
    133141} 
    134142 
    135 #endif 
    136143 
    137144 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj

    r2753 r2754  
    307307                        > 
    308308                        <File 
     309                                RelativePath=".\CHCPlusPlusTraverser.cpp" 
     310                                > 
     311                        </File> 
     312                        <File 
     313                                RelativePath=".\CHCPlusPlusTraverser.h" 
     314                                > 
     315                        </File> 
     316                        <File 
     317                                RelativePath=".\CHCTraverser.cpp" 
     318                                > 
     319                        </File> 
     320                        <File 
     321                                RelativePath=".\CHCTraverser.h" 
     322                                > 
     323                        </File> 
     324                        <File 
     325                                RelativePath=".\FrustumCullingTraverser.cpp" 
     326                                > 
     327                        </File> 
     328                        <File 
     329                                RelativePath=".\FrustumCullingTraverser.h" 
     330                                > 
     331                        </File> 
     332                        <File 
    309333                                RelativePath=".\RenderTraverser.cpp" 
    310334                                > 
     
    312336                        <File 
    313337                                RelativePath=".\RenderTraverser.h" 
     338                                > 
     339                        </File> 
     340                        <File 
     341                                RelativePath=".\StopAndWaitTraverser.cpp" 
     342                                > 
     343                        </File> 
     344                        <File 
     345                                RelativePath=".\StopAndWaitTraverser.h" 
    314346                                > 
    315347                        </File> 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/common.h

    r2753 r2754  
    469469 
    470470typedef std::queue<OcclusionQuery *> QueryQueue; 
    471 //typedef std::priority_queue<BvhNode *, vector<BvhNode *>, myless<vector<BvhNode *>::value_type> > TraversalQueue; 
    472  
    473 } 
    474  
    475 #endif 
    476  
    477  
    478  
    479  
    480  
    481  
    482  
    483  
     471 
     472} 
     473 
     474#endif 
     475 
     476 
     477 
     478 
     479 
     480 
     481 
     482 
Note: See TracChangeset for help on using the changeset viewer.