Changeset 3074 for GTP


Ignore:
Timestamp:
10/27/08 03:26:48 (16 years ago)
Author:
mattausch
Message:

included vbo support for dynamic objects

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited

Legend:

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

    r3073 r3074  
    207207Bvh::~Bvh()  
    208208{ 
    209         if (mVertices) delete [] mVertices;  
    210         if (mIndices) delete [] mIndices; 
    211         if (mTestIndices) delete [] mTestIndices; 
    212         if (mGeometry) delete [] mGeometry; 
     209        DEL_ARRAY_PTR(mVertices); 
     210        DEL_ARRAY_PTR(mIndices); 
     211        DEL_ARRAY_PTR(mTestIndices); 
     212        DEL_ARRAY_PTR(mGeometry); 
    213213 
    214214        if (mRoot) delete mRoot; 
     
    220220void Bvh::Init() 
    221221{ 
    222         //mStaticRoot = NULL; 
     222        mStaticRoot = NULL; 
    223223        mDynamicRoot = NULL; 
    224224        mRoot = NULL; 
     
    435435 
    436436 
    437 void Bvh::InitFrame(Camera *cam) 
     437void Bvh::InitFrame(Camera *cam, RenderState *state) 
    438438{ 
    439439        // = 0011 1111 which means that at the beginning, all six planes have to frustum culled 
     
    452452        { 
    453453                UpdateDynamicBranch(mDynamicRoot); 
     454                UpdateDynamicBounds(state); 
    454455        } 
    455456} 
     
    532533        /////////////////// 
    533534        //-- for the first time we come here => create vbo and indices 
    534 /* 
     535 
    535536        if (!mIndices) 
    536537        {        
     
    544545                PrepareVertices(); 
    545546        } 
    546 */ 
     547 
    547548        /////////////// 
    548549 
    549550        int numNodes = 0; 
    550 /* 
     551 
    551552        BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 
    552553 
     
    563564                numNodes += node->mNumTestNodes; 
    564565        } 
    565 */ 
     566 
    566567        return numNodes; 
    567568} 
     
    660661        // collect all nodes 
    661662        BvhNodeContainer nodes; 
    662         CollectNodes(mRoot, nodes); 
    663  
    664         // assign ids to all nodes of the "regular" hierarchy 
     663        //CollectNodes(mRoot, nodes); 
     664        // first collect dynamic nodes so we make sure that they are in the beginning 
     665        CollectNodes(mDynamicRoot, nodes); 
     666        // then collect static nodes 
     667        CollectNodes(mStaticRoot, nodes); 
     668        // also add root 
     669        nodes.push_back(mRoot); 
     670 
     671        // assign ids to all nodes of the hierarchy 
    665672        int i = 0; 
    666673        BvhNodeContainer::const_iterator lit, lit_end = nodes.end(); 
     
    679686 
    680687        nodes.reserve(GetNumNodes()); 
    681         CollectNodes(mRoot, nodes); 
     688        // first collect dynamic nodes so we make sure that they are in the beginning 
     689        CollectNodes(mDynamicRoot, nodes); 
     690        // then collect static nodes 
     691        CollectNodes(mStaticRoot, nodes); 
     692        // also add root 
     693        nodes.push_back(mRoot); 
    682694 
    683695        const unsigned int bufferSize = 8 * (int)nodes.size(); 
     
    704716                            bufferSize * sizeof(Vector3),  
    705717                            mVertices,  
    706                                         GL_STATIC_DRAW_ARB); 
     718                                        //GL_STATIC_DRAW_ARB); 
     719                                        GL_DYNAMIC_DRAW_ARB); 
    707720 
    708721        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
    709722 
    710723        // data handled by graphics driver from now on 
    711         DEL_PTR(mVertices); 
     724        DEL_ARRAY_PTR(mVertices); 
    712725 
    713726        cout << "******** created vbos for tighter bounds *********" << endl; 
     727} 
     728 
     729 
     730void Bvh::UpdateDynamicBounds(RenderState *state) 
     731{ 
     732        // vbos not created yet 
     733        if (mVboId == -1) return; 
     734 
     735        // collect all nodes 
     736        static BvhNodeContainer nodes; 
     737        nodes.clear(); 
     738        //nodes.reserve(GetNumNodes()); 
     739        CollectNodes(mDynamicRoot, nodes); 
     740 
     741        const unsigned int bufferSize = 8 * (int)nodes.size(); 
     742         
     743        if (!mVertices) mVertices = new Vector3[bufferSize]; 
     744         
     745        int i = 0; 
     746         
     747        // store bounding box vertices 
     748        BvhNodeContainer::const_iterator lit, lit_end = nodes.end(); 
     749 
     750        for (lit = nodes.begin(); lit != lit_end; ++ lit, i += 8) 
     751        { 
     752                BvhNode *node = *lit; 
     753 
     754                for (int j = 0; j < 8; ++ j) 
     755                        (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = node->GetBox().GetVertex(j); 
     756        } 
     757         
     758        if (state->GetCurrentVboId() != mVboId) 
     759        { 
     760                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 
     761                // set the vertex pointer to the vertex buffer 
     762                glVertexPointer(3, GL_FLOAT, 0, (char *)NULL);   
     763 
     764                state->SetCurrentVboId(mVboId); 
     765        } 
     766 
     767        glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, 
     768                                           bufferSize * sizeof(Vector3),  
     769                                           mVertices); 
     770 
     771        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
    714772} 
    715773 
     
    10611119        CreateRoot(); 
    10621120 
    1063         ComputeIds(); 
    10641121        ComputeMaxDepthForVirtualLeaves(); 
    10651122        // set virtual leaves for specified number of triangles 
     
    10671124        /// for each node compute the number of leaves under this node 
    10681125        UpdateNumLeaves(mRoot); 
     1126        // compute new ids 
     1127        ComputeIds(); 
    10691128        // specify bounds for occlusion tests 
    10701129        RecomputeBounds(); 
     1130 
     1131        mBox = mRoot->GetBox(); 
    10711132 
    10721133        // compute and print stats 
     
    12671328        if (TerminationCriteriaMet(leaf)) 
    12681329        { 
    1269                 leaf->mIsVirtualLeaf = true; 
    1270                 leaf->mIsMaxDepthForVirtualLeaf = true; 
    12711330                //cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
    12721331                return leaf; 
     
    14121471        // create new root 
    14131472        mRoot = new BvhInterior(NULL); 
    1414          
     1473 
    14151474        // the separation is a purely logical one 
    14161475        // the bounding boxes of the child nodes are  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r3073 r3074  
    586586        /** Sets frame dependent values 
    587587        */ 
    588         void InitFrame(Camera *camera); 
     588        void InitFrame(Camera *camera, RenderState *state); 
    589589        /** Stores the orthogonal distance from the viewpoint to a point on the node. 
    590590                We choose the the nearest bounding box vertex .  
     
    738738 
    739739        void CreateRoot(); 
     740 
     741        void UpdateDynamicBounds(RenderState *state); 
    740742 
    741743 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3072 r3074  
    7878 
    7979        bvh->mStaticRoot = root; 
     80        // we have at least the root, the static and the dynamic branch 
    8081        bvh->mNumNodes = 3; 
    8182 
     
    107108        } 
    108109 
    109  
    110         //////////// 
     110        /////////// 
    111111        //-- create dynamic part of the hierarchy 
    112112 
    113113        bvh->CreateDynamicBranch(); 
    114114 
    115          
    116115        /////////// 
    117116        //-- post process nodes 
    118117 
    119         /// this function must be called once after creation 
    120118        bvh->PostProcess(); 
    121  
    122119 
    123120        cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3073 r3074  
    311311                } 
    312312        } 
    313                         ShaderManager::GetSingleton()->DisableFragmentProfile(); 
    314                         ShaderManager::GetSingleton()->DisableVertexProfile(); 
    315  
    316313} 
    317314 
     
    341338 
    342339 
    343 } 
     340 
     341} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r3072 r3074  
    150150        ++ mFrameId; 
    151151 
    152         mBvh->InitFrame(mCamera); 
     152        mBvh->InitFrame(mCamera, mRenderState); 
    153153 
    154154        mStats.Reset(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r3073 r3074  
    2626void Shape::Render(RenderState *state) 
    2727{ 
    28         //if (mMaterial) mMaterial->Render(state); 
    29         //mDepthWriteEnabled = true; 
    30 glDepthMask(GL_TRUE);   glDepthFunc(GL_LESS); 
    31 glEnable(GL_DEPTH_TEST); 
     28        if (mMaterial) mMaterial->Render(state); 
     29         
    3230        mGeometry->Render(state); 
    3331} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r3071 r3074  
    4040        mIsIdentity = false; 
    4141        mMatrix = mMatrix * trafo; 
     42        //mMatrix = trafo * mMatrix; 
    4243} 
    4344 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3072 r3074  
    5353#include "SkyPreetham.h" 
    5454#include "Texture.h" 
    55 //#include "EntityMerger.h" 
    5655#include "ShaderManager.h" 
    5756 
     
    184183 
    185184bool useOptimization = false; 
    186 //bool useTightBounds = true; 
    187 bool useTightBounds = false; 
     185bool useTightBounds = true; 
    188186bool useRenderQueue = true; 
    189187bool useMultiQueries = true; 
     
    453451        LoadModel("city.dem", sceneEntities); 
    454452 
    455 /* 
     453 
    456454        ////////// 
    457455        //-- load some dynamic stuff 
     
    464462        buddha->GetTransform()->SetMatrix(transl); 
    465463 
    466         for (int i = 0; i < 10; ++ i) 
     464        /*for (int i = 0; i < 10; ++ i) 
    467465        { 
    468466                SceneEntity *ent = new SceneEntity(*buddha); 
     
    471469                Vector3 offs = Vector3::ZERO(); 
    472470 
    473                 offs.x = RandomValue(.0f, 150.0f); 
    474                 offs.y = RandomValue(.0f, 150.0f); 
     471                offs.x = RandomValue(.0f, 50.0f); 
     472                offs.y = RandomValue(.0f, 50.0f); 
    475473 
    476474                transl = TranslationMatrix(sceneCenter + offs); 
     
    479477                ent->SetTransform(transform); 
    480478                dynamicObjects.push_back(ent); 
    481         } 
    482  
    483 */ 
     479        }*/ 
     480 
     481 
    484482        /////////// 
    485483        //-- load the associated static bvh 
     
    870868void MainLoop()  
    871869{        
     870        Vector3 offs = Vector3::ZERO(); 
     871        //offs.x = RandomValue(-.1f, .1f); 
     872        //offs.y = RandomValue(-.1f, .1f); 
     873        offs.x = RandomValue(.0f, .01f); 
     874        offs.y = RandomValue(.0f, .01f); 
     875 
     876        Matrix4x4 mat = TranslationMatrix(offs); 
     877                 
     878        buddha->GetTransform()->MultMatrix(mat); 
     879 
    872880        Vector3 oldPos = camera->GetPosition(); 
    873881 
Note: See TracChangeset for help on using the changeset viewer.