Ignore:
Timestamp:
06/20/08 02:26:30 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BinaryLoader.cpp

    r2784 r2786  
    193193                texcoords = NULL; 
    194194 
    195         return new Geometry(vertices, normals, texcoords, vertexCount, false); 
     195        return new Geometry(vertices, normals, texcoords, vertexCount, true); 
    196196} 
    197197 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2782 r2786  
    366366 
    367367 
    368 void Bvh::RenderBoundingBox(BvhNode *node, RenderState *state) 
    369 { 
    370         //RenderBoundingBoxImmediate(node->GetBox()); 
    371         static BvhNodeContainer dummy(1); 
    372         dummy[0] = node; 
    373         RenderBoundingBoxes(dummy, state); 
    374 } 
    375  
    376  
    377  
    378 int Bvh::RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state) 
    379 { 
    380         int renderedBoxes = PrepareBoundingBoxesWithDrawArrays(nodes); 
    381         RenderBoundingBoxesWithDrawArrays(renderedBoxes, state); 
     368void Bvh::RenderBounds(BvhNode *node, RenderState *state, bool useTightBounds) 
     369{ 
     370        // if not using tight bounds, rendering boxes in immediate mode 
     371        // is preferable to vertex arrays (less setup time) 
     372        if (!useTightBounds) 
     373        { 
     374                RenderBoundingBoxImmediate(node->GetBox()); 
     375        } 
     376        else 
     377        { 
     378                static BvhNodeContainer dummy(1); 
     379                dummy[0] = node; 
     380                RenderBounds(dummy, state, useTightBounds); 
     381        } 
     382} 
     383 
     384 
     385int Bvh::RenderBounds(const BvhNodeContainer &nodes,  
     386                                          RenderState *state,  
     387                                          bool useTightBounds) 
     388{ 
     389        // if not using tight bounds, rendering boxes in immediate mode 
     390        // is preferable to vertex arrays (less setup time) 
     391 
     392        int renderedBoxes; 
     393 
     394        if (!useTightBounds) 
     395        { 
     396                BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 
     397                         
     398                for (nit = nodes.begin(); nit != nit_end; ++ nit) 
     399                { 
     400                        RenderBoundingBoxImmediate((*nit)->GetBox()); 
     401                } 
     402 
     403                renderedBoxes = (int)nodes.size(); 
     404        } 
     405        else 
     406        { 
     407                renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
     408                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     409        } 
    382410 
    383411        return renderedBoxes; 
     
    385413 
    386414 
    387 int Bvh::PrepareBoundingBoxesWithDrawArrays(const BvhNodeContainer &nodes) 
     415int Bvh::PrepareBoundsWithDrawArrays(const BvhNodeContainer &nodes) 
    388416{ 
    389417        ////// 
     
    428456 
    429457 
    430 void Bvh::RenderBoundingBoxesWithDrawArrays(int numNodes, RenderState *state) 
     458void Bvh::RenderBoundsWithDrawArrays(int numNodes, RenderState *state) 
    431459{ 
    432460        ////// 
     
    706734        nodeStack.push(mRoot); 
    707735 
     736        int numVirtualLeaves = 0; 
     737 
    708738        while (!nodeStack.empty())  
    709739        { 
     
    713743                if (node->IsVirtualLeaf())  
    714744                { 
     745                        ++ numVirtualLeaves; 
     746 
    715747                        BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 
    716748 
     
    731763        } 
    732764 
    733         mBvhStats.mGeometryRatio = mGeometrySize / (float)GetNumLeaves(); 
    734         mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float)GetNumLeaves(); 
     765        mBvhStats.mGeometryRatio = mGeometrySize / (float)numVirtualLeaves; 
     766        mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float)numVirtualLeaves; 
    735767} 
    736768 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2782 r2786  
    460460        //-- Rendering related options 
    461461 
    462         /** Renders the bounding box of this node (Or the tigher bounding boxes of some subnodes). 
    463         */ 
    464         void RenderBoundingBox(BvhNode *node, RenderState *state); 
     462        /** Renders the bounds of this node  
     463            (the box of the node or the tigher bounds of some subnodes). 
     464        */ 
     465        void RenderBounds(BvhNode *node, RenderState *state, bool useTightBounds); 
    465466        /** Renders bounding boxes of the collection of nodes. 
    466467                @returns #rendered boxes 
    467468        */ 
    468         int RenderBoundingBoxes(const BvhNodeContainer &nodes, RenderState *state); 
    469  
     469        int RenderBounds(const BvhNodeContainer &nodes, RenderState *state, bool useTightBounds); 
    470470        /** Returns the bounding box of this bvh. 
    471471        */ 
     
    516516        void SetVirtualLeaves(int numTriangles); 
    517517 
     518 
    518519        //////// 
    519520        //-- functions influencing tighter bounds 
     
    562563        void PrepareVertices(); 
    563564 
    564         int PrepareBoundingBoxesWithDrawArrays(const BvhNodeContainer &nodes); 
    565         void RenderBoundingBoxesWithDrawArrays(int numNodes, RenderState *state); 
     565        int PrepareBoundsWithDrawArrays(const BvhNodeContainer &nodes); 
     566        void RenderBoundsWithDrawArrays(int numNodes, RenderState *state); 
    566567 
    567568        /** Create the indices that each node needs to use vbo rendering. 
     
    590591        */ 
    591592        inline bool TestPlane(BvhNode *node, int i, bool &bIntersect); 
    592  
     593        /** Renders a bounding box in immediate mode. 
     594        */ 
    593595        void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box); 
    594596 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r2782 r2786  
    9898 
    9999        bvh->PostProcess(); 
    100         // set virtual leaves for 500 triangles 
    101         bvh->SetVirtualLeaves(0); 
     100        const int n = 1000; 
     101        // set virtual leaves for n triangles 
     102        bvh->SetVirtualLeaves(n); 
    102103 
    103104        bvh->UpdateNumLeaves(bvh->mRoot); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp

    r2782 r2786  
    2525                delete [] mVertices; mVertices = NULL; 
    2626                delete [] mNormals;  mNormals = NULL; 
    27                 if (!mTexCoords) delete [] mTexCoords; mTexCoords = NULL; 
     27                //if (mTexCoords) delete [] mTexCoords; mTexCoords = NULL; 
    2828        } 
    2929} 
    3030 
     31 
    3132Geometry::~Geometry() 
    3233{ 
    33         if (!mVertices) delete [] mVertices;     
    34         if (!mNormals) delete [] mNormals; 
    35         if (!mTexCoords) delete [] mTexCoords; 
     34        if (mVertices) delete [] mVertices;      
     35        if (mNormals) delete [] mNormals; 
     36        if (mTexCoords) delete [] mTexCoords; 
    3637 
    3738        // delete vbo 
     
    7475                glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 
    7576        } 
     77 
    7678        glBufferDataARB(GL_ARRAY_BUFFER_ARB,  
    7779                            dataSize * sizeof(float),  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/OcclusionQuery.cpp

    r2782 r2786  
    1313        glGenQueriesARB(1, &mQueryId); 
    1414 
    15         // reverse for multiequeries with 32 nodes 
     15        // reverse for multiqueries with 20 nodes 
    1616        mNodes.reserve(32); 
    1717} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2784 r2786  
    4646mUseRenderQueue(false), 
    4747mAssumedVisibleFrames(10), 
    48 mMaxBatchSize(50) 
     48mMaxBatchSize(50), 
     49mUseTightBounds(false) 
    4950{ 
    5051} 
     
    127128void RenderTraverser::RenderScene() 
    128129{ 
     130        //glFinish(); 
    129131        PerfTimer timer; 
    130  
    131132        timer.Start(); 
    132  
    133         //InitTiming(); 
    134         //long t1, t2; 
    135         //t1 = GetTime(); 
    136133 
    137134        glEnableClientState(GL_VERTEX_ARRAY); 
     
    158155        glDisableClientState(GL_NORMAL_ARRAY); 
    159156 
    160         //t2 = GetTime(); 
    161         //mStats.mRenderTime = TimeDiff(t1, t2); 
     157        //glFinish(); 
    162158        mStats.mRenderTime = timer.Elapsedms(); 
    163159} 
     
    198194{ 
    199195        mUseMultiQueries = useMultiQueries; 
    200         std::cout << "using multiqueries: " << mUseMultiQueries << std::endl; 
    201 } 
    202  
     196        //cout << "using multiqueries: " << mUseMultiQueries << endl; 
     197} 
     198 
     199 
     200void RenderTraverser::SetUseTightBounds(bool useTightBounds) 
     201{ 
     202        mUseTightBounds = useTightBounds; 
     203        cout << "using tight bounds: " << useTightBounds << endl; 
     204} 
    203205 
    204206 
     
    243245                        ++ mStats.mNumStateChanges; 
    244246 
    245                 mBvh->RenderBoundingBoxes(query.GetNodes(), mRenderState); 
     247                mBvh->RenderBounds(query.GetNodes(), mRenderState, mUseTightBounds); 
    246248        } 
    247249 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2782 r2786  
    109109        */ 
    110110        void SetUseMultiQueries(bool useMultiQueries); 
     111        /** If thight bounds should be used or the bounding boxes should be tested. 
     112        */ 
     113        void SetUseTightBounds(bool useTightBounds); 
    111114 
    112115protected: 
     
    171174 
    172175        bool mUseMultiQueries; 
     176 
     177        bool mUseTightBounds; 
    173178}; 
    174179 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2784 r2786  
    4949int assumedVisibleFrames = 10; 
    5050int maxBatchSize = 50; 
    51 bool useMultiQueries = true; 
    5251 
    5352const float keyForwardMotion = 1.0f; 
    5453const float keyRotation = 0.2f; 
    55  
    56 bool useRenderQueue = false; 
    5754 
    5855int winWidth = 1024; 
     
    8481 
    8582bool useOptimization = false; 
     83bool useTightBounds = true; 
     84bool useRenderQueue = false; 
     85bool useMultiQueries = true; 
    8686 
    8787 
     
    9595void DisplayStats(); 
    9696void Output(int x, int y, const char *string); 
     97void DrawHelpMessage(); 
    9798 
    9899void begin2D(); 
    99100void end2D(); 
    100101void keyboard(unsigned char c, int x, int y); 
    101 void drawHelpMessage(); 
    102102void drawStatistics(); 
    103103void display(void); 
     
    233233 
    234234 
    235 void drawHelpMessage(void)  
     235void DrawHelpMessage(void)  
    236236{ 
    237237        const char *message[] =  
     
    257257                "'9'            - downward motion", 
    258258                "", 
    259                 "'G'            - enables/disables optimization to take geometry as occluder", 
     259                "'R'            - use render queue", 
    260260                "", 
    261261                "'S'            - shows/hides statistics", 
     
    269269         
    270270         
    271         int x = 40, y = 42; 
     271        int x = 40, y = 60; 
    272272 
    273273        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
     
    286286                if(message[i][0] == '\0')  
    287287                { 
    288                         y += 7; 
     288                        y += 15; 
    289289                }  
    290290                else  
    291291                { 
    292292                        Output(x, y, message[i]); 
    293                         y += 14; 
     293                        y += 20; 
    294294                } 
    295295        } 
     
    332332        traverser->SetMaxBatchSize(maxBatchSize); 
    333333        traverser->SetUseMultiQueries(useMultiQueries); 
     334        traverser->SetUseTightBounds(useTightBounds); 
    334335} 
    335336 
     
    546547                        traverser->SetUseRenderQueue(useRenderQueue); 
    547548                } 
     549        case 'b': 
     550        case 'B': 
     551                { 
     552                        useTightBounds = !useTightBounds; 
     553                        traverser->SetUseTightBounds(useTightBounds); 
     554                } 
    548555        default: 
    549556                return; 
     
    718725        // the 90 degree rotated view vector  
    719726        // y zero so we don't move in the vertical 
    720         //Vector3 rVec(viewDir[0], 0, viewDir[2]); 
    721727        Vector3 rVec(viewDir[0], viewDir[1], 0); 
    722728         
    723         //Matrix4x4 rot = RotationYMatrix(M_PI * 0.5f); 
    724729        Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f); 
    725730        rVec = rot * rVec; 
    726731         
    727732        pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 
    728         //pos[1] += (verticalMotionBegin - y) * 0.1f; 
    729733        pos[2] += (verticalMotionBegin - y) * 0.1f; 
    730734 
     
    914918        } 
    915919 
    916         sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d, using multiqueries: %d, using render queue: %d", assumedVisibleFrames, maxBatchSize, useMultiQueries, useRenderQueue); 
     920        sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d, using render queue: %d",  
     921                      assumedVisibleFrames, maxBatchSize, useRenderQueue); 
    917922 
    918923        string str; 
     
    935940        if(showHelp) 
    936941        {        
    937                 drawHelpMessage(); 
     942                DrawHelpMessage(); 
    938943        } 
    939944        else 
     
    942947                Output(850, 30, msg[renderMode]); 
    943948 
    944                 if(showStatistics) 
     949                if (showStatistics) 
    945950                { 
    946951                        Output(20, 30, msg2); 
Note: See TracChangeset for help on using the changeset viewer.