Ignore:
Timestamp:
10/21/08 12:47:27 (16 years ago)
Author:
mattausch
Message:

debug render queue

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

Legend:

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

    r3052 r3053  
    204204 
    205205        mVboId = -1; 
     206 
     207        mMaxDepthForDynamicBranch = 10; 
    206208} 
    207209 
     
    397399        // store near plane 
    398400        sNearPlane = Plane3(cam->GetDirection(), cam->GetPosition()); 
     401 
     402        // rebuild dynamic part of the hierarchy 
     403        if (!mDynamicEntities.empty()) 
     404        { 
     405                UpdateDynamicBranch(); 
     406        } 
    399407} 
    400408 
     
    11101118 
    11111119 
    1112 } 
     1120//////////////////////// 
     1121// construction of the dynamic hierarchy 
     1122 
     1123int Bvh::SortTriangles(BvhLeaf *leaf,  
     1124                                           int axis,  
     1125                                           float position, 
     1126                                           SceneEntityContainer &entities) 
     1127{ 
     1128        int i = leaf->mFirst; 
     1129        int j = leaf->mLast; 
     1130 
     1131    while (1)  
     1132        { 
     1133                while (entities[i]->GetCenter()[axis] < position)  
     1134                        ++ i; 
     1135         
     1136                while (position < entities[j]->GetCenter()[axis]) 
     1137                        -- j; 
     1138 
     1139                if (i < j)  
     1140                { 
     1141                        swap(entities[i], entities[j]); 
     1142                         
     1143                        ++ i; 
     1144                        -- j; 
     1145                } 
     1146                else 
     1147                { 
     1148                        break; 
     1149                } 
     1150        } 
     1151 
     1152        return j; 
     1153} 
     1154 
     1155 
     1156int Bvh::SortTrianglesSpatialMedian(BvhLeaf *leaf,  
     1157                                                                        int axis, 
     1158                                                                        SceneEntityContainer &entities) 
     1159{ 
     1160        // spatial median 
     1161        float m = leaf->mBox.Center()[axis]; 
     1162        return SortTriangles(leaf, axis, m, entities); 
     1163} 
     1164 
     1165 
     1166BvhNode *Bvh::SubdivideLeaf(BvhLeaf *leaf,  
     1167                                                        int parentAxis,  
     1168                                                        SceneEntityContainer &entities) 
     1169{ 
     1170        if (TerminationCriteriaMet(leaf)) 
     1171                return leaf; 
     1172         
     1173        //int axis = leaf->mBox.MajorAxis(); 
     1174        int axis = (parentAxis + 1) % 3; 
     1175 
     1176        // position of the split in the partailly sorted array of triangles 
     1177        // corresponding to this leaf 
     1178        int split = -1; 
     1179        const int scale = 20; 
     1180 
     1181        float pos = -1.0f; 
     1182 
     1183        // Spatial median subdivision 
     1184        split = SortTrianglesSpatialMedian(leaf, axis, entities); 
     1185        pos = leaf->mBox.Center()[axis]; 
     1186         
     1187        if (split == leaf->mLast) 
     1188        { 
     1189                // no split could be achieved => just halve number of objects 
     1190                split = (leaf->mLast - leaf->mFirst) / 2; 
     1191                cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << split << " " << leaf->mLast << endl; 
     1192        } 
     1193 
     1194        // create two more nodes 
     1195        mNumNodes += 2; 
     1196        BvhInterior *parent = new BvhInterior(leaf->GetParent()); 
     1197        BvhLeaf *front = new BvhLeaf(parent); 
     1198         
     1199        parent->mAxis = axis; 
     1200        parent->mBox = leaf->mBox; 
     1201        parent->mDepth = leaf->mDepth; 
     1202 
     1203        parent->mBack = leaf; 
     1204        parent->mFront = front; 
     1205        //parent->mPosition = pos; 
     1206         
     1207        // now assign the triangles to the subnodes 
     1208        front->mFirst = split + 1; 
     1209        front->mLast = leaf->mLast; 
     1210        front->mDepth = leaf->mDepth + 1; 
     1211        leaf->mLast = split; 
     1212        leaf->mDepth = front->mDepth; 
     1213        leaf->mParent = parent; 
     1214         
     1215        // reset box 
     1216        leaf->mBox.Initialize(); 
     1217 
     1218        // recursively continue subdivision 
     1219        parent->mBack = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mBack), axis, entities); 
     1220        parent->mFront = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mFront), axis, entities); 
     1221         
     1222        return parent; 
     1223} 
     1224 
     1225 
     1226bool Bvh::TerminationCriteriaMet(BvhLeaf *leaf) const 
     1227{ 
     1228        const bool criteriaMet =  
     1229                (leaf->mDepth > mMaxDepthForDynamicBranch) || 
     1230                (leaf->CountPrimitives() == 1); 
     1231 
     1232        return criteriaMet; 
     1233} 
     1234 
     1235 
     1236void Bvh::UpdateDynamicBranch() 
     1237{ 
     1238        BvhNode *dynamicRoot = static_cast<BvhInterior *>(mRoot)->mBack; 
     1239 
     1240        cout << "updating dynamic branch" << endl; 
     1241 
     1242        // delete old branch 
     1243        if (!dynamicRoot->IsLeaf()) 
     1244        { 
     1245                cout << "deleting old branch" << endl; 
     1246 
     1247                DEL_PTR(dynamicRoot); 
     1248 
     1249                dynamicRoot = new BvhLeaf(mRoot); 
     1250                dynamicRoot->mBox = mRoot->mBox; 
     1251        } 
     1252 
     1253        dynamicRoot = SubdivideLeaf(static_cast<BvhLeaf *>(dynamicRoot), 0, mDynamicEntities); 
     1254} 
     1255 
     1256} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2954 r3053  
    77#include "Vector3.h" 
    88#include "AxisAlignedBox3.h" 
    9 //#include "SceneEntity.h" 
     9 
    1010 
    1111 
     
    343343bool BvhNode::Empty() const  
    344344{  
    345         return mFirst == -1;  
     345        return (mFirst == -1);  
    346346} 
    347347 
     
    637637 
    638638 
     639        ///////////////////////////// 
     640 
     641        int SortTriangles(BvhLeaf *leaf,  
     642                              int axis,  
     643                                          float position, 
     644                                          SceneEntityContainer &entities); 
     645 
     646        int SortTrianglesSpatialMedian(BvhLeaf *leaf,  
     647                                           int axis, 
     648                                                                   SceneEntityContainer &entities); 
     649 
     650        BvhNode *SubdivideLeaf(BvhLeaf *leaf,  
     651                                   int parentAxis,  
     652                                                   SceneEntityContainer &entities); 
     653 
     654        /** Recompute the dynamic branch of the hierarchy. 
     655        */ 
     656        void UpdateDynamicBranch(); 
     657 
     658        inline bool TerminationCriteriaMet(BvhLeaf *leaf) const; 
     659 
    639660 
    640661        //////////////////////// 
     
    686707        /// indices used for draw array rendering 
    687708        unsigned int *mIndices; 
     709 
     710 
     711        /////////// 
     712        //-- termination criteria for dynamic branch 
     713 
     714        int mMaxDepthForDynamicBranch; 
     715 
     716        SceneEntityContainer mDynamicEntities; 
    688717}; 
    689718 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r3051 r3053  
    5555        // test if entity belongs to this bucket 
    5656        // note: rather slows down the application for some reason!! 
    57         if (tech->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) return false; 
    58         if (tech->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled) return false; 
    59         if (tech->IsColorWriteEnabled() != mBuckets[idx]->mColorWriteEnabled) return false; 
    60         if (tech->IsLightingEnabled() != mBuckets[idx]->mLightingEnabled) return false; 
    61         if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) return false; 
     57        if (tech->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) { cout << "a"; return false; } 
     58        if (tech->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled) { cout << "b"; return false; } 
     59        if (tech->IsColorWriteEnabled() != mBuckets[idx]->mColorWriteEnabled) { cout << "c"; return false; } 
     60        if (tech->IsLightingEnabled() != mBuckets[idx]->mLightingEnabled) { cout << "d"; return false; } 
     61        if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { cout << "e"; return false; } 
    6262 
    6363        const bool hasTexture = (tech->GetTexture() != NULL); 
    6464 
    65         if (hasTexture != mBuckets[idx]->mHasTexture) 
    66                 return false; 
     65        if (hasTexture != mBuckets[idx]->mHasTexture) { cout << "f"; return false; } 
    6766 
    6867        if (hasTexture) 
    6968        { 
    70                 if (tech->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth) return false; 
    71                 if (tech->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight) return false; 
    72                 if (tech->GetTexture()->GetFormat() != mBuckets[idx]->mTexFormat) return false; 
    73         } 
    74  
    75         if ((tech->GetFragmentProgram() != NULL) && mBuckets[idx]->mHasFragmentProgram) return false; 
    76         if ((tech->GetVertexProgram() != NULL) && mBuckets[idx]->mHasVertexProgram) return false; 
     69                if (tech->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth) { cout << "g"; return false; } 
     70                if (tech->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight) { cout << "h"; return false; } 
     71                if (tech->GetTexture()->GetFormat() != mBuckets[idx]->mTexFormat) { cout << "i"; return false; } 
     72        } 
     73 
     74        if (!tech->GetFragmentProgram() && mBuckets[idx]->mHasFragmentProgram) { cout << "j"; return false; } 
     75        if (!tech->GetVertexProgram() && mBuckets[idx]->mHasVertexProgram) { cout << "h"; return false; } 
    7776 
    7877 
     
    156155                        mBuckets.push_back(bucket); 
    157156 
    158                         //cout << "num buckets: " << (int)mBuckets.size() << endl; 
     157                        cout << "num buckets: " << (int)mBuckets.size() << endl; 
    159158                } 
    160159 
Note: See TracChangeset for help on using the changeset viewer.