Changeset 724


Ignore:
Timestamp:
04/04/06 23:47:05 (18 years ago)
Author:
mattausch
Message:

fixed bug in teapot demo

Location:
GTP/trunk/App/Demos/Vis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp

    r723 r724  
    195195        //mMyStatsAlgorithmInfo->setTop(top); 
    196196 
    197         mMyStatsOverlay->show(); 
     197        //mMyStatsOverlay->show(); 
    198198 
    199199        if (1) 
     
    204204         
    205205                // show stats overlays 
    206                 showStats(false); 
     206                showStats(true); 
    207207        } 
    208208 
  • GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp

    r643 r724  
    1010 
    1111RenderTraverser::RenderTraverser(): mFrameID(1), mVisibilityThreshold(0), 
    12 mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrentTestIdx(0), mIsQueryMode(false), 
     12mHierarchyRoot(NULL), mOcclusionQueries(NULL), mCurrentQueryIdx(0), mIsQueryMode(false), 
    1313mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 
    14 mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true) 
     14mRenderTime(0), mNumRenderedGeometry(0), mUseOptimization(true), 
     15mUseArbQueries(false) 
    1516{ 
    1617} 
     
    1819RenderTraverser::~RenderTraverser() 
    1920{ 
    20         if(mOcclusionQueries)  
    21                 delete [] mOcclusionQueries; 
     21        DelQueries(); 
    2222} 
    2323 
     
    4747 
    4848        mFrameID ++; 
    49         ResetQueries(); 
     49         
    5050 
    5151        long endTime = getTime(); 
     
    267267} 
    268268 
    269 bool RenderTraverser::ResultAvailable(HierarchyNode *node) 
    270 { 
    271         int result; 
    272  
    273         glGetQueryivARB(node->GetOcclusionQuery(), 
    274                                         GL_QUERY_RESULT_AVAILABLE_ARB, &result); 
    275  
     269bool RenderTraverser::ResultAvailable(HierarchyNode *node) const 
     270{ 
     271        unsigned int result; 
     272        if (mUseArbQueries) 
     273        { 
     274                glGetQueryObjectuivARB(node->GetOcclusionQuery(), 
     275                                                           GL_QUERY_RESULT_AVAILABLE_ARB, &result); 
     276        } 
     277        else 
     278        { 
     279                 
     280                glGetOcclusionQueryuivNV(node->GetOcclusionQuery(),  
     281                                                                 GL_PIXEL_COUNT_AVAILABLE_NV, &result); 
     282 
     283        } 
     284         
    276285        return (result == GL_TRUE); 
    277286} 
     
    281290        mHierarchyRoot = sceneRoot; 
    282291 
    283         // not valid anymore for new hierarchy => delete 
    284         delete [] mOcclusionQueries; 
    285         mOcclusionQueries = NULL; 
     292        DelQueries(); 
    286293} 
    287294 
     
    291298} 
    292299 
    293 int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) 
     300unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const 
    294301{ 
    295302        unsigned int result; 
    296          
    297         glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result); 
    298  
    299         return (int)result; 
     303 
     304        if (mUseArbQueries) 
     305        { 
     306                glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result); 
     307        } 
     308        else 
     309        { 
     310                glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), GL_PIXEL_COUNT_NV, &result); 
     311        } 
     312 
     313        return result; 
    300314} 
    301315 
     
    330344{ 
    331345        // get next available test id 
    332         unsigned int occlusionQuery = mOcclusionQueries[mCurrentTestIdx++]; 
     346        unsigned int occlusionQuery = mOcclusionQueries[mCurrentQueryIdx ++]; 
    333347         
    334348        node->SetOcclusionQuery(occlusionQuery); 
     349 
    335350        // do the actual occlusion query for this node 
    336         glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery); 
     351        if (mUseArbQueries) 
     352        { 
     353                glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery); 
     354        } 
     355        else 
     356        { 
     357                glBeginOcclusionQueryNV(occlusionQuery); 
     358        } 
    337359         
    338360        // if leaf and was visible => will be rendered anyway, thus we 
     
    350372        } 
    351373 
    352         glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
     374        if (mUseArbQueries) 
     375        { 
     376                glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
     377        } 
     378        else 
     379        { 
     380                glEndOcclusionQueryNV(); 
     381        } 
    353382} 
    354383 
    355384void RenderTraverser::Preprocess() 
    356385{ 
    357         if(!mOcclusionQueries) 
     386        if (!mOcclusionQueries) 
    358387        { 
    359388                mOcclusionQueries = new unsigned int[mHierarchyRoot->GetNumHierarchyNodes()]; 
     389 
     390                // generate ids for occlusion test 
     391                if (mUseArbQueries) 
     392                { 
     393                        glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
     394                } 
     395                else 
     396                { 
     397                        glGenOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
     398                } 
    360399        } 
    361400 
     
    363402        calcViewFrustumPlanes(&mClipPlanes, mProjViewMatrix); 
    364403        calcAABNPVertexIndices(mNPVertexIndices, mClipPlanes); 
    365         // generate ids for occlusion test 
    366         glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
    367         mCurrentTestIdx = 0; 
     404 
     405        mCurrentQueryIdx = 0; 
    368406 
    369407        // reset statistics 
     
    375413 
    376414 
    377 void RenderTraverser::ResetQueries() 
    378 { 
     415void RenderTraverser::DelQueries() 
     416{ 
     417        if (!mOcclusionQueries) 
     418                return; 
     419 
    379420        // tell the driver that the occlusion queries won't be needed any more 
    380         glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
     421        if (mUseArbQueries) 
     422        { 
     423                glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
     424        } 
     425        else 
     426        { 
     427                glDeleteOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 
     428        } 
     429 
     430        delete [] mOcclusionQueries; 
     431 
     432        mOcclusionQueries = NULL; 
    381433} 
    382434 
     
    435487} 
    436488 
     489void RenderTraverser::SetUseArbQueries(const bool useArbQueries) 
     490{ 
     491        DelQueries(); 
     492        mUseArbQueries = useArbQueries; 
     493} 
     494 
     495bool RenderTraverser::GetUseArbQueries() const 
     496{ 
     497        return mUseArbQueries; 
     498} 
     499 
    437500long RenderTraverser::GetRenderTime() 
    438501{ 
  • GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.h

    r643 r724  
    5858        void SetUseOptimization(bool useOptimization); 
    5959 
     60        //! if arb queries should be used instead of nv 
     61        void SetUseArbQueries(const bool useArbQueries); 
     62        //!     see set 
     63        bool GetUseArbQueries() const; 
     64 
    6065protected: 
    6166 
     
    7075         
    7176        //! returns occlusion query result for specified node 
    72         int GetOcclusionQueryResult(HierarchyNode *node); 
     77        unsigned int GetOcclusionQueryResult(HierarchyNode *node) const; 
    7378        //! the node is traversed as usual 
    7479        void TraverseNode(HierarchyNode *node); 
     
    7681        void PullUpVisibility(HierarchyNode *node); 
    7782        //! is result available from query queue? 
    78         bool ResultAvailable(HierarchyNode *node); 
     83        bool ResultAvailable(HierarchyNode *node) const; 
    7984        //! issues occlusion query for specified node 
    8085        void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible); 
    8186        //! resets occlusion queries after a traversal 
    82         void ResetQueries(); 
     87        void DelQueries(); 
    8388        //! does view frustum culling. returns intersect (if intersects view plane) 
    8489        bool InsideViewFrustum(HierarchyNode *node, bool &intersects); 
     
    8893        void Switch2GLQueryState(); 
    8994 
     95 
    9096protected: 
     97 
     98        /// if arb queries should be instead of nv 
     99        bool mUseArbQueries; 
    91100 
    92101        // the current clip planes of the view frustum 
     
    95104        int mNPVertexIndices[12]; 
    96105 
     106        // the current view point 
    97107        Vector3 mViewpoint; 
    98108        Matrix4x4 mProjViewMatrix; 
     109        // the root of the scene hierarchy 
    99110        HierarchyNode *mHierarchyRoot; 
    100111        //TraversalStack mTraversalStack; 
     
    105116        int mVisibilityThreshold; 
    106117        unsigned int *mOcclusionQueries; 
    107         int mCurrentTestIdx; 
     118        int mCurrentQueryIdx; 
    108119        bool mIsQueryMode; 
    109120         
  • GTP/trunk/App/Demos/Vis/Teapots/occquery.cpp

    r643 r724  
    1414#include <math.h> 
    1515#include <time.h> 
     16 
     17bool arbQuerySupport = false; 
     18bool nvQuerySupport = false; 
    1619 
    1720double nearDist = 0.1; // eye near plane distance 
     
    6871 
    6972bool useOptimization = true; 
     73bool useArbQueries = false; 
    7074 
    7175Vector3 amb[2]; 
     
    213217                "'C'            - recreates the scene hierarchy", 
    214218                "'G'            - enables/disables optimization to take geometry as occluder", 
     219                "'N'            - triggers NV / ARB queries", 
    215220                "", 
    216221                "'R'            - shows/hides recreation parameters", 
     
    357362         
    358363        char *optstr[2] = {"", ", using optimization"}; 
    359          
     364        char *querystr[2] = {"NV", "ARB"}; 
     365 
    360366        float fps = 1000.0; 
    361367        long renderTime = calcRenderTime(); 
    362368        if(renderTime) fps = 1000000.0f / (float)calcRenderTime(); 
    363369 
    364         sprintf(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps)%s",  
    365                         traverser.GetVisibilityThreshold(), renderTime / 1000, fps, optstr[useOptimization]); 
     370        sprintf(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps), queries: %s%s",  
     371                traverser.GetVisibilityThreshold(), renderTime / 1000, fps, querystr[useArbQueries], optstr[useOptimization]); 
    366372 
    367373        string str; 
     
    494500                traverser.SetUseOptimization(useOptimization); 
    495501                break; 
     502        case 'n': 
     503        case 'N': 
     504                useArbQueries = !useArbQueries; 
     505                traverser.SetUseArbQueries(useArbQueries); 
     506                break; 
    496507        case 'c': 
    497508        case 'C':        
     
    658669{ 
    659670        GLenum err = glewInit(); 
    660         if(GLEW_OK != err) { 
     671        if (GLEW_OK != err)  
     672        { 
    661673                // problem: glewInit failed, something is seriously wrong 
    662                 fprintf(stderr,"Error: %s\n",glewGetErrorString(err)); 
     674                fprintf(stderr,"Error: %s\n", glewGetErrorString(err)); 
    663675                exit(1); 
    664676        } 
    665677 
    666         if(!GLEW_ARB_occlusion_query) { 
    667                 printf("I require the GL_ARB_occlusion_query OpenGL extension to work.\n"); 
     678        if (GLEW_ARB_occlusion_query)  
     679                arbQuerySupport = true; 
     680         
     681        if (GLEW_NV_occlusion_query)  
     682                nvQuerySupport = true; 
     683         
     684 
     685        if  (!arbQuerySupport && !nvQuerySupport) 
     686        { 
     687                printf("I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n"); 
    668688                exit(1); 
    669689        } 
Note: See TracChangeset for help on using the changeset viewer.