Ignore:
Timestamp:
06/27/08 13:33:46 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2800 r2801  
    2222#include "Timer/PerfTimer.h" 
    2323#include "SceneQuery.h" 
     24#include "RenderQueue.h" 
    2425 
    2526 
     
    6061 
    6162SceneQuery *sceneQuery = NULL; 
     63RenderQueue *renderQueue = NULL; 
     64 
    6265 
    6366/// these values get scaled with the frame rate 
     
    6669/// elapsed time in seconds 
    6770double elapsedTime = 1.0f; 
     71double algTime = 1.0f; 
    6872 
    6973int winWidth = 1024; 
     
    99103bool useRenderQueue = true; 
    100104bool useMultiQueries = true; 
    101  
    102105bool flyMode = true; 
    103  
    104 /// the accumulated z axis rotation 
    105 float rotation = 0; 
     106bool depthPass = false; 
     107 
    106108 
    107109SceneEntityContainer skyGeometry; 
     
    126128void DrawHelpMessage(); 
    127129void RenderSky(); 
     130void RenderVisibleObjects(); 
    128131 
    129132void Begin2D(); 
     
    146149void KeyVerticalMotion(float shift); 
    147150 
     151void PlaceViewer(const Vector3 &oldPos); 
     152 
    148153 
    149154inline float KeyRotationAngle() { return keyRotation * elapsedTime; } 
     
    162167        visCamera->SetNear(0.0f); 
    163168        visCamera->Yaw(.5 * M_PI); 
     169 
     170        renderQueue = new RenderQueue(&state); 
    164171 
    165172        glutInitWindowSize(winWidth, winHeight); 
     
    268275        //glEnable(GL_ALPHA_TEST); 
    269276        glDisable(GL_ALPHA_TEST); 
    270         glAlphaFunc(GL_GEQUAL, 0.1f); 
     277        glAlphaFunc(GL_GEQUAL, 0.5f); 
    271278 
    272279        glFrontFace(GL_CCW); 
     
    283290        glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); 
    284291        glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); 
     292 
     293        glDepthFunc(GL_LESS); 
    285294} 
    286295 
     
    298307                "'F5',          - toggles between fly / walkmode", 
    299308                "'F6',          - shows/hides parameters", 
     309                "'F7',          - depth pass", 
    300310                "'SPACE'        - cycles through occlusion culling algorithms", 
    301311                "", 
     
    380390        traverser->SetCamera(camera); 
    381391        traverser->SetHierarchy(bvh); 
     392        traverser->SetRenderQueue(renderQueue); 
    382393        traverser->SetRenderState(&state); 
    383394        traverser->SetUseOptimization(useOptimization); 
     
    388399        traverser->SetUseMultiQueries(useMultiQueries); 
    389400        traverser->SetUseTightBounds(useTightBounds); 
     401        traverser->SetUseDepthPass(depthPass); 
     402        traverser->SetRenderQueue(renderQueue); 
    390403} 
    391404 
     
    430443 
    431444        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 
    432         //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 
    433         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 
     445        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 
     446        //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 
    434447        //glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); 
    435448        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT); 
     
    481494 
    482495void Display()  
    483 { 
     496{        
     497        PerfTimer frameTimer, algTimer; 
     498        frameTimer.Start(); 
     499 
    484500        Vector3 oldPos = camera->GetPosition(); 
    485  
    486         PerfTimer frameTimer; 
    487         frameTimer.Start(); 
    488501 
    489502        if (leftKeyPressed) 
     
    500513                KeyVerticalMotion(KeyShift()); 
    501514 
    502         Vector3 playerPos = camera->GetPosition(); 
    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                 { 
    513         camera->SetPosition(playerPos); 
    514                 } 
    515         } 
     515        // place view on ground 
     516        if (!flyMode) PlaceViewer(oldPos); 
     517 
     518        // note: have to flush queue in order to get reliable timings 
     519        // for optimal performance, remove this 
     520        glFinish(); 
     521 
     522        algTimer.Start(); 
    516523 
    517524        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     525 
     526        glDepthFunc(GL_LESS); 
     527        glDisable(GL_TEXTURE_2D); 
     528        glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
     529 
     530        // render without shading 
     531        if (depthPass)  
     532        { 
     533                state.SetDepthPass(true); 
     534                glDisable(GL_LIGHTING); 
     535        } 
     536        else 
     537        { 
     538                state.SetDepthPass(false); 
     539                glEnable(GL_LIGHTING); 
     540        } 
    518541 
    519542        // bring eye modelview matrix up-to-date 
     
    523546        traverser->RenderScene(); 
    524547 
    525          
     548 
     549        ////// 
     550        //-- other rendering 
     551 
     552        glEnableClientState(GL_VERTEX_ARRAY); 
     553        glEnableClientState(GL_NORMAL_ARRAY); 
     554 
     555 
     556        // reset depth pass and render visible objects 
     557        if (depthPass)  
     558        { 
     559                RenderVisibleObjects(); 
     560        } 
     561         
     562 
    526563        /////////////// 
    527564        //-- render sky 
    528565 
    529566        RenderSky(); 
    530          
     567 
     568        state.Reset(); 
     569 
     570        glDisableClientState(GL_VERTEX_ARRAY); 
     571        glDisableClientState(GL_NORMAL_ARRAY); 
     572 
     573 
     574         
     575        // note: have to flush queue in order to get reliable timings 
     576        // for optimal performance, remove this 
     577        glFinish(); 
     578        algTime = algTimer.Elapsedms(); 
     579 
     580        /////////// 
     581 
    531582        if (visMode) DisplayVisualization(); 
    532583         
     
    719770                flyMode = !flyMode; 
    720771                break; 
     772        case GLUT_KEY_F7: 
     773                depthPass = !depthPass; 
     774                traverser->SetUseDepthPass(depthPass); 
     775                break; 
    721776        case GLUT_KEY_LEFT: 
    722777                { 
     
    9881043        DEL_PTR(camera); 
    9891044        DEL_PTR(loader); 
     1045        DEL_PTR(renderQueue); 
    9901046} 
    9911047 
     
    10321088 
    10331089 
    1034         static double renderTime = traverser->GetStats().mRenderTime; 
     1090        static double renderTime = algTime; 
    10351091        const float expFactor = 0.3f; 
    1036         renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 
     1092 
     1093        // if there was something fishy going on in this frame => don't count 
     1094        if (algTime < 1000)  
     1095                renderTime = algTime * expFactor + (1.0f - expFactor) * algTime; 
    10371096 
    10381097        accumulatedTime += renderTime; 
     
    10581117                      assumedVisibleFrames, maxBatchSize); 
    10591118 
    1060         sprintf(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d",  
    1061                       useRenderQueue, useMultiQueries, useTightBounds); 
     1119        sprintf(msg3, "render queue: %d, depth pass: %d, multiqueries: %d, tight bounds: %d",  
     1120                      useRenderQueue, depthPass, useMultiQueries, useTightBounds); 
    10621121 
    10631122        string str; 
     
    10881147        else 
    10891148        { 
    1090         //      glColor3f(1.0f, 1.0f, 1.0f); 
    1091                 glColor3f(1.0f, 0.0f, 0.0f); 
     1149                glColor3f(1.0f, 1.0f, 1.0f); 
     1150                //glColor3f(1.0f, 0.0f, 0.0f); 
    10921151                Output(850, 30, msg[renderMode]); 
    10931152 
     
    11151174void RenderSky() 
    11161175{ 
    1117         glEnableClientState(GL_VERTEX_ARRAY); 
    1118         glEnableClientState(GL_NORMAL_ARRAY); 
    1119  
    11201176        SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 
    11211177 
    11221178        for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 
    11231179                (*sit)->Render(&state); 
    1124  
    1125         glDisableClientState(GL_VERTEX_ARRAY); 
    1126         glDisableClientState(GL_NORMAL_ARRAY); 
    1127  
     1180} 
     1181 
     1182 
     1183void RenderVisibleObjects() 
     1184{ 
     1185        state.SetDepthPass(false); 
    11281186        state.Reset(); 
    1129 } 
     1187 
     1188        glEnable(GL_LIGHTING); 
     1189        glDepthFunc(GL_LEQUAL); 
     1190 
     1191        //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 
     1192 
     1193        SceneEntityContainer::const_iterator sit,  
     1194                sit_end = traverser->GetVisibleObjects().end(); 
     1195 
     1196        for (sit = traverser->GetVisibleObjects().begin(); sit != sit_end; ++ sit) 
     1197                renderQueue->Enqueue(*sit); 
     1198                 
     1199        renderQueue->Apply(); 
     1200 
     1201        glDepthFunc(GL_LESS); 
     1202} 
     1203 
     1204 
     1205void PlaceViewer(const Vector3 &oldPos) 
     1206{ 
     1207        Vector3 playerPos = camera->GetPosition(); 
     1208 
     1209        bool validIntersect = sceneQuery->CalcIntersection(playerPos); 
     1210 
     1211        if (validIntersect && 
     1212                (( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f)) 
     1213        { 
     1214                camera->SetPosition(playerPos); 
     1215        } 
     1216} 
Note: See TracChangeset for help on using the changeset viewer.