Ignore:
Timestamp:
06/27/08 01:43:45 (16 years ago)
Author:
mattausch
Message:

friendly culling debug version with timers, no materials

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
4 added
4 deleted
21 edited
2 moved

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln

    r2785 r2800  
    22Microsoft Visual Studio Solution File, Format Version 9.00 
    33# Visual Studio 2005 
    4 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chc_revisited", "chc_revisited.vcproj", "{03661866-4093-4B02-B26A-028EA91AF023}" 
     4Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chc_revisited", "FriendlyCulling.vcproj", "{03661866-4093-4B02-B26A-028EA91AF023}" 
    55EndProject 
    66Global 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2796 r2800  
    109109        mIsFrustumCulled = false; 
    110110        mIsNew = true; 
     111        mLastQueriedFrame = -1; 
    111112} 
    112113 
     
    609610                                        GL_STATIC_DRAW_ARB); 
    610611 
    611         //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
     612        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
    612613 
    613614        // data handled by graphics driver from now on 
     
    904905                } 
    905906        } 
     907 
     908        ResetNodeClassifications(); 
    906909} 
    907910 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2792 r2800  
    5252                /// if the node is newly processed with no prior history available 
    5353                bool mIsNew; 
     54                /// the frame this node was last queried 
     55                int mLastQueriedFrame; 
    5456        }; 
    5557 
     
    113115        inline void SetTurnedVisibleFrame(int turnedVisibleFrame); 
    114116 
    115         inline int GetLastTestedFrame(); 
    116         inline void SetLastTestedFrame(int lastTested); 
     117        inline int GetLastQueriedFrame() const; 
     118        inline void SetLastQueriedFrame(int lastTested); 
    117119         
    118120        inline bool IsViewFrustumCulled() const; 
     
    155157        ///////////// 
    156158         
    157         /// some flags 
    158         //int mFlags; 
    159159        /// the depth of this node 
    160160        unsigned char mDepth; 
     
    217217 
    218218 
     219 
    219220///////////////// 
    220221//-- public inline functions 
    221222 
     223 
    222224int BvhNode::GetLastVisitedFrame() const  
    223225{  
     
    268270 
    269271 
    270 void BvhNode::SetViewFrustumCulled(const bool frustumCulled)  
     272void BvhNode::SetViewFrustumCulled(bool frustumCulled)  
    271273{  
    272274        mVisibility.mIsFrustumCulled = frustumCulled;  
     
    280282 
    281283 
    282 void BvhNode::SetIsNew(const bool isNew)  
     284void BvhNode::SetIsNew(bool isNew)  
    283285{  
    284286        mVisibility.mIsNew = isNew;  
     
    320322        return mVisibility.mAssumedVisibleFrameId; 
    321323} 
     324 
     325 
     326int BvhNode::GetLastQueriedFrame() const 
     327{ 
     328        return mVisibility.mLastQueriedFrame; 
     329} 
     330 
     331 
     332void BvhNode::SetLastQueriedFrame(int lastTested) 
     333{ 
     334        mVisibility.mLastQueriedFrame = lastTested; 
     335} 
     336 
    322337 
    323338 
     
    429444        */ 
    430445        inline int GetNumLeaves() const { return mNumNodes / 2 + 1;} 
     446        /** Returns number of 'virtual' nodes in the hierarchy, i.e. 
     447                the number of nodes actually used for traversal. 
     448        */ 
     449        int GetNumVirtualNodes() const  { return mNumVirtualNodes; } 
     450        /** Returns number of bvh leaves. 
     451        */ 
     452        inline int GetNumVirtualLeaves() const { return mNumVirtualNodes / 2 + 1;} 
    431453        /** Returns root node of the bvh. 
    432454        */ 
     
    512534        */ 
    513535        void SetVirtualLeaves(int numTriangles); 
    514  
     536         
    515537 
    516538        //////// 
     
    526548        void SetAreaRatioThresholdForTestingChildren(float ratio); 
    527549 
     550 
     551        //////////////////////////// 
     552 
    528553        /** Returns stats. 
    529554        */ 
    530555        const BvhStats &GetBvhStats() const { return mBvhStats; } 
    531         /** Returns number of 'virtual' nodes in the hierarchy, i.e. 
    532                 the number of nodes actually used for traversal. 
    533         */ 
    534         int GetNumVirtualNodes() const  { return mNumVirtualNodes; } 
    535556        /** Render wireframe bvh for visualization purpose. 
    536557        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r2796 r2800  
    103103        bvh->PostProcess(); 
    104104         
    105         const int trianglesPerVirtualLeaves = 1000; 
    106105        // set virtual leaves for specified number of triangles 
    107         bvh->SetVirtualLeaves(trianglesPerVirtualLeaves); 
     106        bvh->SetVirtualLeaves(INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES); 
    108107 
    109108        bvh->UpdateNumLeaves(bvh->mRoot); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp

    r2795 r2800  
    1515void CHCPlusPlusTraverser::HandleQueryResult(OcclusionQuery *query) 
    1616{ 
     17        waitTimer.Entry(); 
     18 
    1719        // wait until result available 
    1820        const int visible = query->GetQueryResult() > mVisibilityThreshold; 
    1921 
     22        waitTimer.Exit(); 
     23 
    2024        // multiquery 
    2125        if (query->GetSize() > 1) 
     
    2731                        { 
    2832                                BvhNode *node = query->GetNodes()[i]; 
     33#if 1 
     34                                mIQueue.push_back(node); 
     35                                node->SetLastQueriedFrame(mFrameId); 
     36#else 
    2937                                OcclusionQuery *q = IssueOcclusionQuery(node); 
    3038                                mQueryQueue.push(q); 
     39#endif 
    3140                        } 
    3241                } 
     
    3847                                node->IncTimesTestedInvisible(); 
    3948                                node->SetVisible(false); 
     49                                node->SetLastQueriedFrame(mFrameId); 
    4050                        } 
    4151 
     
    4656        { 
    4757                BvhNode *node = query->GetFrontNode(); 
     58 
     59                node->SetLastQueriedFrame(mFrameId); 
    4860 
    4961                // failed query: query individual nodes 
     
    100112                        mQueryQueue.pop(); 
    101113 
     114                        // waiting for query result 
    102115                        HandleQueryResult(query); 
    103116                }        
     
    186199        if (mUseRenderQueue) ApplyRenderQueue(); 
    187200 
     201        restTimer.Entry(); 
    188202 
    189203        ////////////// 
     
    206220                HandleQueryResult(query); 
    207221        } 
    208 } 
    209  
     222 
     223        restTimer.Exit(); 
     224} 
    210225 
    211226 
    212227void CHCPlusPlusTraverser::QueryPreviouslyInvisibleNodes(BvhNode *node) 
    213228{ 
    214         mIQueue.push(node); 
     229        mIQueue.push_back(node); 
    215230 
    216231        if (mIQueue.size() > mMaxBatchSize) 
     
    221236 
    222237 
    223 OcclusionQuery * CHCPlusPlusTraverser::GetNextMultiQuery(BvhNodeQueue &iqueue) 
     238OcclusionQuery * CHCPlusPlusTraverser::GetNextMultiQuery(BvhNodeContainer &iqueue) 
    224239{ 
    225240        OcclusionQuery *query = mQueryHandler.RequestQuery(); 
     
    233248        while (!iqueue.empty()) 
    234249        { 
    235                 BvhNode *node = iqueue.front(); 
     250                BvhNode *node = iqueue.back(); 
     251 
     252                // node was already part of a mulitquery => avoid recursion 
     253                if (node->GetLastQueriedFrame() == mFrameId) 
     254                        newPBatch = 0; 
     255                else 
    236256                newPBatch *= mVisibilityPredictor.GetProbability(node); 
    237257 
    238258                if (query->GetNodes().empty()) 
    239259                { 
    240                         // single node will anever cause a wasted query 
     260                        // single node will never cause a wasted query 
    241261                        newBatchVal = 1.0f; 
    242262                } 
     
    250270                        break; 
    251271 
    252                 iqueue.pop(); 
     272                iqueue.pop_back(); 
    253273                query->AddNode(node); 
    254274 
     
    263283 
    264284 
     285static inline bool lt(BvhNode *a, BvhNode *b) 
     286{ 
     287        return a->GetTimesTestedInvisible() < b->GetTimesTestedInvisible(); 
     288} 
     289 
     290 
    265291void CHCPlusPlusTraverser::IssueMultiQueries() 
    266292{ 
    267         while (!mIQueue.empty()) 
    268         { 
    269                 OcclusionQuery *query; 
    270  
    271                 if (mUseMultiQueries) 
    272                 { 
    273                         query = GetNextMultiQuery(mIQueue); 
     293        if (mUseMultiQueries) 
     294        { 
     295                // sort queries by #times invisible 
     296                sort(mIQueue.begin(), mIQueue.end(), lt); 
     297 
     298                while (!mIQueue.empty()) 
     299                        mQueryQueue.push(GetNextMultiQuery(mIQueue)); 
    274300                } 
    275301                else 
    276302                { 
    277                         BvhNode *node = mIQueue.front(); 
    278                         mIQueue.pop(); 
    279                         query = IssueOcclusionQuery(node); 
    280                 } 
    281  
    282                 mQueryQueue.push(query); 
    283         } 
    284 } 
    285  
    286  
    287 } 
     303                BvhNodeContainer::const_iterator it, it_end = mIQueue.end(); 
     304 
     305                for (it = mIQueue.begin(); it != it_end; ++ it) 
     306                        mQueryQueue.push(IssueOcclusionQuery(*it)); 
     307 
     308                mIQueue.clear(); 
     309        } 
     310} 
     311 
     312 
     313} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.h

    r2782 r2800  
    3333         
    3434        CHCPlusPlusTraverser(); 
    35         //~CHCPlusPlusTraverser(); 
     35 
     36        virtual int GetType() const { return CHCPLUSPLUS;} 
    3637 
    3738 
     
    4546        /** Computes the next multiquery. 
    4647        */ 
    47         OcclusionQuery *GetNextMultiQuery(BvhNodeQueue &iqueue); 
     48        OcclusionQuery *GetNextMultiQuery(BvhNodeContainer &iqueue); 
    4849        /** Issues batched multiqueries. 
    4950        */ 
     
    5960        QueryQueue mQueryQueue; 
    6061 
    61         BvhNodeQueue mIQueue; 
    6262        BvhNodeQueue mVQueue; 
     63        BvhNodeContainer mIQueue; 
    6364 
    6465        VisibilityPredictor mVisibilityPredictor; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.h

    r2792 r2800  
    1414public: 
    1515        CHCTraverser(); 
    16         //~CHCTraverser(); 
     16 
     17        virtual int GetType() const { return CHC; } 
    1718 
    1819         
    1920protected: 
     21 
    2022        /** Optimized query querying the node geometry instead 
    2123                of the bounding box 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrustumCullingTraverser.h

    r2782 r2800  
    1616        FrustumCullingTraverser(); 
    1717 
     18        virtual int GetType() const { return CULL_FRUSTUM; } 
     19 
    1820protected: 
    1921        /** Traverses and renders the scene with the specified method 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/OcclusionQuery.cpp

    r2786 r2800  
    6565QueryHandler::QueryHandler(): mCurrentQueryIdx(0)  
    6666{ 
    67         Allocate(1000); 
     67        Allocate(500); 
    6868} 
    6969 
     
    9999{ 
    100100        CLEAR_CONTAINER(mOcclusionQueries); 
     101         
    101102        mCurrentQueryIdx = 0; 
    102103        mOcclusionQueries.clear(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r2795 r2800  
    2121        int tsize2 = t2 ? t2->GetByteSize() : 0; 
    2222 
    23         return tsize1 < tsize2; 
     23        return tsize1 > tsize2; 
    2424} 
    2525 
     
    8888        Debug << "\nrq size: " << GetSize() << endl; 
    8989        Debug << "texture size: " << endl; 
     90 
    9091        // show ordering by texture size 
    9192        for (sit = mEntities.begin(); sit != sit_end; ++ sit) 
     
    9394                SceneEntity *ent = *sit; 
    9495                Texture *t = ent->GetMaterial()->GetTexture(); 
     96         
    9597                int tsize = t ? t->GetByteSize() : 0; 
    9698                Debug << tsize << " "; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r2782 r2800  
    99 
    1010 
    11 /** Constructor setting render as default state. 
    12 */ 
    1311RenderState::RenderState(): 
    1412mAlphaTestEnabled(false),  
     
    2220bool RenderState::SetState(Mode mode) 
    2321{ 
     22        /////////// 
    2423        //-- just change the modewhen necessary 
     24 
    2525        if (mode == mMode) return false; 
    2626 
    2727        mMode = mode; 
    28         //++ state_changes; 
    2928 
    3029        if (mode == QUERY) 
     
    6261        { 
    6362                mTexturesEnabled = true; 
    64                 glEnable(GL_TEXTURE_2D); 
    65                 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
     63                //glEnable(GL_TEXTURE_2D); 
     64                //glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    6665        } 
    6766 
     
    7473        { 
    7574                mAlphaTestEnabled = true; 
    76                 glEnable(GL_ALPHA_TEST); 
    77                 glAlphaFunc(GL_GEQUAL, 0.5f); 
     75                //glEnable(GL_ALPHA_TEST); 
     76                //glAlphaFunc(GL_GEQUAL, 0.5f); 
    7877        } 
    7978} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r2782 r2800  
    4848        inline int GetCurrentVboId() { return mCurrentVboId; } 
    4949 
     50 
    5051protected: 
    5152 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2798 r2800  
    2727        mNumIssuedQueries = 0; 
    2828        mNumStateChanges = 0; 
     29        mNumBatches = 0; 
    2930 
    3031        mRenderTime = 0; 
     32        mWaitTime = 0; 
     33        mQueryTime = 0; 
     34        mRestTime = 0; 
    3135} 
    3236 
     
    132136        PerfTimer timer; 
    133137         
     138        glFinish(); 
     139 
    134140        timer.Start(); 
    135141 
     
    154160        // render the contents of the render queue 
    155161        if (mUseRenderQueue) ApplyRenderQueue(); 
     162         
     163        // reset the render state 
    156164        mRenderState->Reset(); 
    157165 
     
    159167        glDisableClientState(GL_NORMAL_ARRAY); 
    160168 
     169        glFinish(); 
     170 
     171 
    161172        mStats.mRenderTime = timer.Elapsedms(); 
    162173         
     174        //Debug << "type: " << GetType() << endl; 
    163175        //if (mUseRenderQueue) Debug << "rq sort: " << 1e3f * mRenderQueue.sortTimer.TotalTime() << " ms" << endl; 
     176        /* 
     177        Debug << "wait time: " << 1e3f * waitTimer.TotalTime() << " ms" << endl; 
     178        Debug << "query time: " << 1e3f * queryTimer.TotalTime() << " ms" << endl; 
     179        Debug << "rest time: " << 1e3f * restTimer.TotalTime() << " ms" << endl; 
     180        */ 
    164181} 
    165182 
     
    219236OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node) 
    220237{ 
     238        queryTimer.Entry(); 
     239 
    221240        OcclusionQuery *query = mQueryHandler.RequestQuery(); 
    222241        query->AddNode(node); 
    223242 
    224243        IssueOcclusionQuery(*query); 
     244 
     245        queryTimer.Exit(); 
    225246 
    226247        return query; 
     
    254275                ++ mStats.mNumStateChanges; 
    255276                  
     277        if (mRenderQueue.GetSize() > 0) 
     278                ++ mStats.mNumBatches; 
     279 
    256280        mRenderQueue.Apply(); 
    257281} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2795 r2800  
    77#include "Camera.h" 
    88#include "RenderQueue.h" 
     9#include "Timer/PerfTimer.h" 
    910 
    1011 
     
    3738        int mNumIssuedQueries; 
    3839        int mNumStateChanges; 
     40        int mNumBatches; 
    3941         
    4042        double mRenderTime; 
     43 
     44        double mWaitTime; 
     45        double mQueryTime; 
     46        double mRestTime; 
    4147}; 
    42  
    4348 
    4449 
     
    4954public: 
    5055         
    51         enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_RENDERMODES}; 
     56        enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_TRAVERSAL_TYPES}; 
    5257 
    5358        RenderTraverser(); 
     
    118123        void SetShowBounds(bool showBounds); 
    119124 
     125        virtual int GetType() const = 0; 
    120126         
    121127protected: 
     
    187193 
    188194        bool mShowBounds; 
     195 
     196        // timers 
     197        PerfTimer restTimer; 
     198        PerfTimer waitTimer; 
     199        PerfTimer queryTimer; 
    189200}; 
    190201 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r2795 r2800  
    8181        } 
    8282 
    83         cout << "loaded " << mTextureTable.size() << " textures" << endl; 
     83        cout << "loaded " << (int)mTextureTable.size() << " textures" << endl; 
    8484} 
    8585 
     
    102102        } 
    103103 
    104         cout << "loaded " << mGeometryTable.size() << " shapes" << endl; 
     104        cout << "loaded " << (int)mGeometryTable.size() << " shapes" << endl; 
    105105} 
    106106 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2797 r2800  
    55#include "SceneQuery.h" 
    66#include "RenderTraverser.h" 
     7#include <IL/il.h> 
     8#include <assert.h> 
    79 
    810 
    9 void startil(); 
    10 void stopil(); 
     11void startil() 
     12{ 
     13        ilInit(); 
     14        assert(ilGetError() == IL_NO_ERROR); 
     15} 
     16 
     17 
     18void stopil() 
     19{ 
     20        ilShutDown(); 
     21        assert(ilGetError() == IL_NO_ERROR); 
     22} 
    1123 
    1224 
     
    1729 
    1830 
    19 const static int viewport[4] = {0, 0, 512, 512}; 
    20 //const static int viewport[4] = {0, 0, 1024, 768}; 
     31//const static int viewport[4] = {0, 0, 512, 512}; 
     32const static int viewport[4] = {0, 0, 1024, 768}; 
     33//const static int viewport[4] = {0, 0, 2048, 2048}; 
    2134 
    2235 
     
    3447        int py = (pt.y - mSceneBox.Min(1)) * (viewport[3] - 1) / mSceneBox.Size(1); 
    3548 
    36         const float d = mDepth[px + py * viewport[1]]; 
     49        unsigned char d = mDepth[px + py * viewport[2]]; 
    3750 
    38         if (d > 0.0f) 
     51        const float offs = mSceneBox.Size(2) * 1e-1f; 
     52 
     53        static float depth = (float)d; 
     54 
     55        if (d > 0) 
    3956        { 
    40                 pt.z =  mSceneBox.Max().z - mSceneBox.Size().z * d; 
    41                 cout << "new depth " << pt.z << " (" << d << ")" << endl; 
     57                const float x = 0.1f; 
     58                depth = depth * x + d * (1.0f - x); 
     59                pt.z =  mSceneBox.Max().z - mSceneBox.Size().z * depth / 255.0f + offs; 
     60                //cout << "new depth " << pt.z << " (" << d << ")" << endl; 
    4261 
    4362                return true; 
    4463        } 
     64        //cout << "invalid depth: " << d << endl; 
    4565 
    4666        return false; 
     
    6585 
    6686        //glPixelStorei(GL_PACK_ROW_LENGTH, viewport[2]); 
     87        glPixelStorei(GL_PACK_ALIGNMENT, 1); 
     88        glReadBuffer(GL_BACK); 
    6789 
    6890        // hack: should create offscreen buffer for this 
     
    80102        glClear(GL_DEPTH_BUFFER_BIT); 
    81103 
    82         mDepth = new float[viewport[2] * viewport[3]]; 
     104        mDepth = new unsigned char[viewport[2] * viewport[3]]; 
     105        //mDepth = new float[viewport[2] * viewport[3]]; 
    83106 
    84107        //renderer->SetCamera(orthoCam); 
     
    86109        renderer->RenderScene(); 
    87110 
    88         glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 
     111        glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, mDepth); 
     112        //glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 
     113/* 
     114        startil(); 
    89115 
     116        if (!ilTexImage(viewport[2], viewport[3], 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, mDepth)) 
     117        { 
     118                cerr << "IL error " << ilGetError() << endl; 
     119                stopil(); 
     120                return; 
     121        } 
     122 
     123        ILstring writename = ILstring("out.tga"); 
     124 
     125        ilSetInteger(IL_TGA_RLE, 1); 
     126        if (!ilSaveImage(writename)) 
     127        { 
     128                cerr << "TGA write error " << ilGetError() << endl; 
     129        } 
     130 
     131        stopil(); 
     132*/ 
    90133        DEL_PTR(orthoCam); 
    91134} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h

    r2796 r2800  
    44#include "common.h" 
    55#include "AxisAlignedBox3.h" 
     6 
    67 
    78namespace CHCDemoEngine 
     
    2223        bool CalcIntersection(Vector3 &pt); 
    2324 
    24  
    2525protected: 
    2626 
     
    3232        AxisAlignedBox3 mSceneBox; 
    3333 
    34         float *mDepth; 
     34        unsigned char *mDepth; 
    3535}; 
    3636 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp

    r2795 r2800  
    3333                                OcclusionQuery *query = IssueOcclusionQuery(node); 
    3434 
     35                                waitTimer.Entry(); 
    3536                                bool visible = query->GetQueryResult() > mVisibilityThreshold; 
     37                                waitTimer.Exit(); 
    3638 
    3739                                if (visible) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.h

    r2782 r2800  
    1616        StopAndWaitTraverser(); 
    1717 
    18         //~StopAndWaitTraverser(); 
     18        int GetType() const { return STOP_AND_WAIT; } 
     19 
    1920 
    2021protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp

    r2782 r2800  
    22#include "glInterface.h" 
    33#include "common.h" 
    4  
    54 
    65#include <IL/il.h> 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2797 r2800  
    5757int maxBatchSize = 50; 
    5858 
    59 int trianglesPerVirtualLeaf = 1000; 
     59int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 
    6060 
    6161SceneQuery *sceneQuery = NULL; 
     
    8383int queryCulledNodes = 0; 
    8484int stateChanges = 0; 
     85int numBatches = 0; 
    8586 
    8687bool showHelp = false; 
     
    9899bool useRenderQueue = true; 
    99100bool useMultiQueries = true; 
     101 
     102bool flyMode = true; 
    100103 
    101104/// the accumulated z axis rotation 
     
    233236        visualization = new Visualization(bvh, camera, NULL, &state); 
    234237 
    235         //sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
     238        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
     239 
    236240 
    237241        glutMainLoop(); 
     
    270274        glEnable(GL_CULL_FACE); 
    271275        //glDisable(GL_CULL_FACE); 
    272          
     276        glDisable(GL_TEXTURE_2D); 
    273277 
    274278        GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0}; 
     
    292296                "'F3'           - shows/hides bounds (boxes or tight bounds)", 
    293297                "'F4'           - shows/hides statistics", 
    294                 "'F5',          - shows/hides parameters", 
     298                "'F5',          - toggles between fly / walkmode", 
     299                "'F6',          - shows/hides parameters", 
    295300                "'SPACE'        - cycles through occlusion culling algorithms", 
    296301                "", 
     
    390395        glEnable(GL_LIGHTING); 
    391396        glEnable(GL_LIGHT0); 
    392         glEnable(GL_LIGHT1); 
     397        //glEnable(GL_LIGHT1); 
     398        glDisable(GL_LIGHT1); 
    393399 
    394400        //GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 
     
    424430 
    425431        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 
    426         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 
    427         //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 
     432        //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 
     433        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 
    428434        //glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); 
    429435        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT); 
    430  
    431 } 
     436} 
     437 
    432438 
    433439void SetupEyeView() 
     
    476482void Display()  
    477483{ 
     484        Vector3 oldPos = camera->GetPosition(); 
     485 
    478486        PerfTimer frameTimer; 
    479  
    480487        frameTimer.Start(); 
    481488 
     
    493500                KeyVerticalMotion(KeyShift()); 
    494501 
    495          
    496502        Vector3 playerPos = camera->GetPosition(); 
    497         //sceneQuery->CalcIntersection(playerPos); 
     503         
     504        if (!flyMode) 
     505        { 
     506        Vector3 playerPos = camera->GetPosition(); 
     507 
     508                bool validIntersect = sceneQuery->CalcIntersection(playerPos); 
     509 
     510                if (validIntersect && 
     511                        (( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f)) 
     512                { 
    498513        camera->SetPosition(playerPos); 
     514                } 
     515        } 
    499516 
    500517        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    532549                break; 
    533550        case 32: //space 
    534                 renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 
     551                renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES; 
    535552                ResetTraverser(); 
    536553                break; 
     
    563580                break; 
    564581        case '8': 
    565                 { 
    566582                        eightKeyPressed = true; 
    567                         KeyVerticalMotion(-KeyShift()); 
    568583                        break; 
    569                 } 
    570584        case '9': 
    571                 { 
    572585                        nineKeyPressed = true; 
    573                         KeyVerticalMotion(+KeyShift()); 
    574586                        break; 
    575                 }        
    576587        case 'o': 
    577588        case 'O': 
     
    581592        case 'a': 
    582593        case 'A': 
    583                 { 
    584594                        leftKeyPressed = true; 
    585                         camera->Pitch(KeyRotationAngle()); 
    586                 } 
    587595                break; 
    588596        case 'd': 
    589597        case 'D': 
    590         { 
    591598                        rightKeyPressed = true; 
    592                         camera->Pitch(-KeyRotationAngle()); 
    593                 } 
    594599                break; 
    595600        case 'w': 
    596601        case 'W': 
    597                 { 
    598602                        upKeyPressed = true; 
    599                         KeyHorizontalMotion(KeyShift()); 
    600                 } 
    601603                break; 
    602604        case 'x': 
    603605        case 'X': 
    604                 { 
    605606                        downKeyPressed = true; 
    606                         KeyHorizontalMotion(-KeyShift()); 
    607                 } 
    608607                break; 
    609608        case 'r': 
     
    716715        case GLUT_KEY_F5: 
    717716                showOptions = !showOptions; 
     717                break; 
     718        case GLUT_KEY_F6: 
     719                flyMode = !flyMode; 
    718720                break; 
    719721        case GLUT_KEY_LEFT: 
     
    10041006        if (numbers.size() > 0) 
    10051007        { 
    1006                 sprintf_s(hstr, "%d", numbers.back()); 
     1008                sprintf(hstr, "%d", numbers.back()); 
    10071009                str.append(hstr); 
    10081010        } 
     
    10101012        for (int i = (int)numbers.size() - 2; i >= 0; i--) 
    10111013        { 
    1012                 sprintf_s(hstr, ",%03d", numbers[i]); 
     1014                sprintf(hstr, ",%03d", numbers[i]); 
    10131015                str.append(hstr); 
    10141016        } 
     
    10501052                issuedQueries = traverser->GetStats().mNumIssuedQueries; 
    10511053                stateChanges = traverser->GetStats().mNumStateChanges; 
    1052         } 
    1053  
    1054         sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d",  
     1054                numBatches = traverser->GetStats().mNumBatches; 
     1055        } 
     1056 
     1057        sprintf(msg2, "assumed visible frames: %4d, max batch size: %4d",  
    10551058                      assumedVisibleFrames, maxBatchSize); 
    10561059 
    1057         sprintf_s(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d",  
     1060        sprintf(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d",  
    10581061                      useRenderQueue, useMultiQueries, useTightBounds); 
    10591062 
     
    10641067        CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 
    10651068 
    1066         sprintf_s(msg4, "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)",  
     1069        sprintf(msg4, "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)",  
    10671070                          renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str());  
    10681071 
    1069         sprintf_s(msg5, "traversed: %5d, frustum culled: %5d, query culled: %5d", 
     1072        sprintf(msg5, "traversed: %5d, frustum culled: %5d, query culled: %5d", 
    10701073                          traversedNodes, frustumCulledNodes, queryCulledNodes); 
    10711074 
    1072         sprintf_s(msg6, "issued queries: %5d, state changes: %5d", issuedQueries, stateChanges); 
    1073  
    1074         sprintf_s(msg8, "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 
    1075  
    1076         sprintf_s(msg7, "fps: %6.1f", fps); 
     1075        sprintf(msg6, "issued queries: %5d, state changes: %5d, render batches: %5d", issuedQueries, stateChanges, numBatches); 
     1076 
     1077        sprintf(msg8, "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 
     1078 
     1079        sprintf(msg7, "fps: %6.1f", fps); 
    10771080 
    10781081 
     
    10851088        else 
    10861089        { 
    1087                 glColor3f(1.0f, 1.0f, 1.0f); 
     1090        //      glColor3f(1.0f, 1.0f, 1.0f); 
     1091                glColor3f(1.0f, 0.0f, 0.0f); 
    10881092                Output(850, 30, msg[renderMode]); 
    10891093 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h

    r2795 r2800  
    476476static std::string model_path("data/city/model/"); 
    477477 
     478 
    478479/////////// 
    479480//-- typedefs 
     
    490491static std::ofstream Debug("debug.log"); 
    491492 
    492 } 
    493  
    494 #endif 
    495  
    496  
    497  
    498  
    499  
    500  
    501  
    502  
     493 
     494#define INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES 1000 
     495 
     496} 
     497 
     498#endif 
     499 
     500 
     501 
     502 
     503 
     504 
     505 
     506 
Note: See TracChangeset for help on using the changeset viewer.