Changeset 254 for trunk/VUT


Ignore:
Timestamp:
08/26/05 23:24:31 (19 years ago)
Author:
mattausch
Message:

added some hack for video recording

Location:
trunk/VUT
Files:
1 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibility/include/VisibilityEnvironment.h

    r175 r254  
    1313        /** Different types of occlusion culling algorithms  
    1414        */ 
    15         enum CullingManagerType { 
    16                                                          COHERENT_HIERARCHICAL_CULLING,  
     15        enum CullingManagerType {COHERENT_HIERARCHICAL_CULLING,  
    1716                                                         FRUSTUM_CULLING,  
    1817                                                         STOP_AND_WAIT_CULLING,  
  • trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp

    r187 r254  
    2525        unsigned int visiblePixels = 0; 
    2626        bool isAvailable = false; 
    27         //Ogre::LogManager::getSingleton().logMessage("Coherent Hierarchical Culling"); 
     27        Ogre::LogManager::getSingleton().logMessage("Coherent Hierarchical Culling"); 
    2828 
    2929        //-- PART 1: process finished occlusion queries 
  • trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp

    r175 r254  
    77void FrustumCullingManager::RenderScene() 
    88{ 
    9         //Ogre::LogManager::getSingleton().logMessage("Frustum Culling"); 
     9        Ogre::LogManager::getSingleton().logMessage("Frustum Culling"); 
    1010        while (!mHierarchyInterface->GetQueue()->empty()) 
    1111        { 
  • trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp

    r175 r254  
    77void StopAndWaitCullingManager::RenderScene() 
    88{ 
    9         //Ogre::LogManager::getSingleton().logMessage("Stop and Wait Culling"); 
     9        Ogre::LogManager::getSingleton().logMessage("Stop and Wait Culling"); 
    1010        while (!mHierarchyInterface->GetQueue()->empty()) 
    1111        { 
  • trunk/VUT/GtpVisibility/src/VisibilityManager.cpp

    r155 r254  
    6161                } 
    6262 
    63                 // -- set threshold 
     63                //-- set threshold 
    6464                mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);           
    6565        } 
  • trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h

    r202 r254  
    8686        void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup); 
    8787 
     88        void loadVisibilityConfig(const String& filename); 
     89 
    8890protected: 
    8991         
     
    123125        bool mUseDepthPass; 
    124126        /// flag indicating if we currently render the depth pass 
    125         bool mRenderDepthPass; 
     127        bool mIsDepthPassPhase; 
    126128 
    127129        /// if we use an item buffer for rendering (i.e., object ids as color codes 
    128130        bool mUseItemBuffer; 
    129131        /// if we currently render the item buffer  
    130         bool mRenderItemBuffer; 
     132        bool mIsItemBufferPhase; 
    131133 
    132134        /// if depth write should be enabled 
  • trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h

    r202 r254  
    128128        /// if we use a depth pass (i.e., fill only the depth buffer in the first pass) 
    129129        bool mUseDepthPass; 
    130         /// if we currently render the depth pass 
    131         bool mRenderDepthPass; 
     130        /// if we currently rendering the depth pass 
     131        bool mIsDepthPassPhase; 
    132132         
    133133        /// if we use an item buffer for rendering (i.e., object ids as color codes 
    134134        bool mUseItemBuffer; 
    135135        /// if we currently render the item buffer  
    136         bool mRenderItemBuffer; 
     136        bool mIsItemBufferPhase; 
    137137 
    138138        /// if depth write should be enabled 
  • trunk/VUT/Ogre/resources/materials/scripts/natFX_Tree1_LOD3.material

    r183 r254  
    204204                        texture_unit 
    205205                        { 
    206                                 texture D:\Profiles\giegl\My Documents\maya\projects\default\sourceimages\_12bb041f_1121354365.png 
     206                                texture _12bb041f_1121354365.png 
    207207                                tex_coord_set 0 
    208208                                colour_op modulate 
     
    228228                        texture_unit 
    229229                        { 
    230                                 texture D:\Profiles\giegl\My Documents\maya\projects\default\sourceimages\_12bb041l_1121354365.png 
     230                                texture _12bb041l_1121354365.png 
    231231                                tex_coord_set 0 
    232232                                colour_op modulate 
     
    252252                        texture_unit 
    253253                        { 
    254                                 texture D:\Profiles\giegl\My Documents\maya\projects\default\sourceimages\_12bb049f_1121354365.png 
     254                                texture _12bb049f_1121354365.png 
    255255                                tex_coord_set 0 
    256256                                colour_op modulate 
     
    276276                        texture_unit 
    277277                        { 
    278                                 texture D:\Profiles\giegl\My Documents\maya\projects\default\sourceimages\_12bb049l_1121354365.png 
    279                                 tex_coord_set 0 
    280                                 colour_op modulate 
    281                         } 
    282                 } 
    283         } 
    284 } 
    285  
     278                                texture _12bb049l_1121354365.png 
     279                                tex_coord_set 0 
     280                                colour_op modulate 
     281                        } 
     282                } 
     283        } 
     284} 
     285 
  • trunk/VUT/Ogre/resources/overlays/VisibilityDemo.overlay

    r183 r254  
    333333                        caption [F9] Start / End animation 
    334334                } 
     335                element TextArea(Example/Visibility/Help/Video): Example/Visibility/Templates/BasicText 
     336                { 
     337                        left 5 
     338                        width 180 
     339                        height 30 
     340                        caption [F10] Write out video (i.e., one image per frame) 
     341                } 
    335342                element TextArea(Example/Visibility/Help/Screenshots): Example/Visibility/Templates/BasicText 
    336343                { 
  • trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp

    r202 r254  
    99#include <OgreEntity.h> 
    1010#include <OgreSubEntity.h> 
    11  
     11#include <OgreConfigFile.h> 
    1212 
    1313namespace Ogre { 
     
    2424mLeavePassesInQueue(0), 
    2525mDelayRenderTransparents(true), 
     26//mDelayRenderTransparents(false), 
     27//mUseDepthPass(true), 
    2628mUseDepthPass(false), 
    27 mRenderDepthPass(false), 
     29mIsDepthPassPhase(false), 
    2830mUseItemBuffer(false), 
    2931//mUseItemBuffer(true), 
    30 mRenderItemBuffer(false), 
     32mIsItemBufferPhase(false), 
    3133mCurrentEntityId(1), 
    3234mEnableDepthWrite(true), 
     
    4446        // TODO: set maxdepth to reasonable value 
    4547        mMaxDepth = 50; 
     48 
     49        //loadVisibilityConfig("GtpVisibility.cfg"); 
    4650} 
    4751//----------------------------------------------------------------------- 
     
    145149{ 
    146150        // set depth fill pass if we currently do not make an aabb occlusion query 
    147         Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?  
     151        Pass *usedPass = (mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery() ?  
    148152                                          mDepthPass : pass); 
    149153 
     
    152156        // set illumination stage to NONE so no shadow material is used  
    153157        // for depth pass or for occlusion query 
    154         if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 
     158        if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery()) 
    155159        { 
    156160                mIlluminationStage = IRS_NONE; 
     
    158162 
    159163        //-- set vertex program of current pass in order to set correct depth 
    160         if (mRenderDepthPass && mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 
     164        if (mIsDepthPassPhase && mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 
    161165    { 
    162166                // add vertex program of current pass to depth pass 
     
    311315 
    312316                //-- reset parameters 
    313                 mRenderDepthPass = false; 
    314                 mRenderItemBuffer = false; 
     317                mIsDepthPassPhase = false; 
     318                mIsItemBufferPhase = false; 
    315319                mSkipTransparents = false; 
    316320                mIsHierarchicalCulling = false; 
     
    498502{ 
    499503        // skip all but first pass if we are doing the depth pass 
    500         if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0) 
     504        if ((mIsDepthPassPhase || mIsItemBufferPhase) && pass->getIndex() > 0) 
    501505        { 
    502506                return false; 
     
    507511void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup) 
    508512{ 
    509         if (!mRenderItemBuffer) 
     513        if (!mIsItemBufferPhase) 
    510514        { 
    511515                OctreeSceneManager::renderQueueGroupObjects(pGroup); 
     
    513517        } 
    514518 
    515         // --- item buffer 
     519        //-- renders item buffer 
    516520 
    517521    // Iterate through priorities 
     
    559563        } 
    560564 
    561         // -- TRANSPARENT LOOP: must be handled differently  
     565        //-- TRANSPARENT LOOP: must be handled differently  
    562566 
    563567        // transparents are treated either as solids or completely discarded 
     
    637641 
    638642        // set depth pass flag before rendering 
    639         mRenderDepthPass = mUseDepthPass; 
     643        mIsDepthPassPhase = mUseDepthPass; 
    640644 
    641645        mIsHierarchicalCulling = true; // during hierarchical culling 
     
    644648        if (mUseItemBuffer)  
    645649        { 
    646                 mRenderItemBuffer = true; 
     650                mIsItemBufferPhase = true; 
    647651                setAmbientLight(ColourValue(1,1,1,1)); 
    648652        } 
     
    739743                } 
    740744        } 
    741         else 
     745        else // render the rest of the passes 
    742746        { 
    743747                OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup); 
    744  
    745                 /*RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 
    746             LightList lightList; 
    747                  
    748                 while (groupIt.hasMoreElements()) 
    749                 { 
    750                  
    751                         RenderPriorityGroup* pPriorityGrp = groupIt.getNext(); 
    752  
    753                         // Sort the queue first 
    754                         pPriorityGrp->sort(mCameraInProgress); 
    755  
    756                         // Clear light list 
    757                         lightList.clear(); 
    758  
    759                         // Now iterate per light 
    760                         mIlluminationStage = IRS_PER_LIGHT; 
    761          
    762                     // Iterate over lights, render all volumes to stencil 
    763                 LightList::const_iterator li, liend; 
    764                     liend = mLightsAffectingFrustum.end(); 
    765          
    766                     for (li = mLightsAffectingFrustum.begin(); li != liend; ++li) 
    767                         { 
    768                                 LogManager::getSingleton().logMessage("iterating over lights"); 
    769                                 Light* l = *li; 
    770                                 // Set light state 
    771  
    772                                 if (l->getCastShadows()) 
    773                                 { 
    774                                         // Clear stencil 
    775                                         mDestRenderSystem->clearFrameBuffer(FBT_STENCIL); 
    776                                         renderShadowVolumesToStencil(l, mCameraInProgress); 
    777                                         // turn stencil check on 
    778                                         mDestRenderSystem->setStencilCheckEnabled(true); 
    779                                         // NB we render where the stencil is equal to zero to render lit areas 
    780                                         mDestRenderSystem->setStencilBufferParams(CMPF_EQUAL, 0); 
    781                                 } 
    782  
    783                                 // render lighting passes for this light 
    784                                 if (lightList.empty()) 
    785                                         lightList.push_back(l); 
    786                                 else 
    787                                         lightList[0] = l; 
    788                                 OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesDiffuseSpecular(), false, &lightList); 
    789  
    790                                 // Reset stencil params 
    791                                 mDestRenderSystem->setStencilBufferParams(); 
    792                                 mDestRenderSystem->setStencilCheckEnabled(false); 
    793                                 mDestRenderSystem->_setDepthBufferParams(); 
    794  
    795                         }// for each light 
    796  
    797                         // Now render decal passes, no need to set lights as lighting will be disabled 
    798                         mIlluminationStage = IRS_DECAL; 
    799                         OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesDecal(), false); 
    800             }// for each priority 
    801          
    802                 // reset lighting stage 
    803             mIlluminationStage = IRS_NONE;*/ 
    804748        } 
    805749} 
     
    828772   } 
    829773} 
    830 }   // namespace Ogre 
     774//------------------------------------------------------------------------- 
     775void VisibilityOctreeSceneManager::loadVisibilityConfig(const String& filename) 
     776{ 
     777        /// Set up the options 
     778        ConfigFile config; 
     779        String val; 
     780 
     781        config.load(filename); 
     782 
     783        val = config.getSetting("Algorithm"); 
     784 
     785    if (!val.empty()) 
     786        { 
     787                 VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).setOption("Algorithm", val.c_str()); 
     788        } 
     789 
     790        val = config.getSetting("UseDepthPass"); 
     791 
     792        if (!val.empty()) 
     793        { 
     794                 setOption("UseDepthPass", val.c_str()); 
     795        } 
     796} 
     797}  // namespace Ogre 
  • trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp

    r187 r254  
    1515        if (key == "Algorithm") 
    1616        { 
     17                // delete old queries (not needed for e.g., view frustum culling) 
    1718                mHierarchyInterface->DeleteQueries(); 
    1819                mVisibilityManager->SetCullingManager(*static_cast<const  
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r202 r254  
    2424mDelayRenderTransparents(true), 
    2525mUseDepthPass(false), 
    26 mRenderDepthPass(false), 
     26mIsDepthPassPhase(false), 
    2727mUseItemBuffer(false), 
    2828//mUseItemBuffer(true), 
    29 mRenderItemBuffer(false), 
     29mIsItemBufferPhase(false), 
    3030mCurrentEntityId(1), 
    3131mEnableDepthWrite(true), 
     
    147147{ 
    148148        // TODO: setting vertex program is not efficient 
    149         //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);  
     149        //Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass);  
    150150         
    151151        // set depth fill pass if we currently do not make an aabb occlusion query 
    152         Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ?  
     152        Pass *usedPass = (mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery() ?  
    153153                                          mDepthPass : pass); 
    154154                 
     
    157157        // set illumination stage to NONE so no shadow material is used  
    158158        // for depth pass or for occlusion query 
    159         if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 
     159        if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery()) 
    160160        { 
    161161                mIlluminationStage = IRS_NONE; 
     
    163163         
    164164        // --- set vertex program of current pass in order to set correct depth 
    165         if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram()) 
     165        if (mExecuteVertexProgramForAllPasses && mIsDepthPassPhase && pass->hasVertexProgram()) 
    166166        { 
    167167                // add vertex program of current pass to depth pass 
     
    315315 
    316316                //-- reset parameters 
    317                 mRenderDepthPass = false; 
    318                 mRenderItemBuffer = false; 
     317                mIsDepthPassPhase = false; 
     318                mIsItemBufferPhase = false; 
    319319                mSkipTransparents = false; 
    320320                mLeavePassesInQueue = 0; 
     
    501501{ 
    502502        // skip all but first pass if we are doing the depth pass 
    503         if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0) 
     503        if ((mIsDepthPassPhase || mIsItemBufferPhase) && pass->getIndex() > 0) 
    504504        { 
    505505                return false; 
     
    510510void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup) 
    511511{ 
    512         if (!mRenderItemBuffer) 
     512        if (!mIsItemBufferPhase) 
    513513        { 
    514514                TerrainSceneManager::renderQueueGroupObjects(pGroup); 
     
    640640 
    641641        // set depth pass flag before rendering 
    642         mRenderDepthPass = mUseDepthPass; 
     642        mIsDepthPassPhase = mUseDepthPass; 
    643643 
    644644        // item buffer needs full ambient lighting to use item colors as unique id 
    645645        if (mUseItemBuffer)  
    646646        { 
    647                 mRenderItemBuffer = true; 
     647                mIsItemBufferPhase = true; 
    648648                setAmbientLight(ColourValue(1,1,1,1)); 
    649649        } 
  • trunk/VUT/work/TestCulling/TestCullingApplication.cpp

    r160 r254  
    2020 
    2121 
    22 /***********************************************/ 
    23 /* TestCullingApplication implementation       */ 
    24 /***********************************************/ 
     22/***************************************************/ 
     23/*     TestCullingApplication implementation       */ 
     24/***************************************************/ 
    2525 
    2626//----------------------------------------------------------------------- 
  • trunk/VUT/work/TestCulling/TestCullingApplication.h

    r160 r254  
    1717} 
    1818 
    19 String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] =  
     19String mCurrentAlgorithmCaptions[] =  
    2020{ 
    2121    "View Frustum Culling",  
  • trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp

    r187 r254  
    7070// output file for object positions / orientations 
    7171const char* objects_out_filename = "objects.out"; 
    72  
     72         
     73std::ofstream video_out("video.lst"); 
    7374 
    7475//----------------------------------------------------------------------- 
     
    117118mShowVisualization(false), 
    118119mCullCamera(false), 
    119 mRecord(false), 
     120mRecordFrames(false), 
    120121mShowShadows(false), 
    121122mShowHelp(false), 
     
    134135mDeleteObjects(false), 
    135136mUseItemBuffer(false), 
    136 mItemBufferMode(GtpVisibility::QueryManager::PATCH_VISIBILITY) 
     137mItemBufferMode(GtpVisibility::QueryManager::PATCH_VISIBILITY), 
     138mRecordVideo(false), 
     139mPureRenderTimeFps(0.0), 
     140mNumVideoFrames(0), 
     141mDemoFps(0), 
     142mUseDemoFps(false) 
    137143{ 
    138144        //mInputDevice = PlatformManager::getSingleton().createInputReader(); 
     
    159165 
    160166        initVisStatsOverlay(); // visibility stats overlay 
    161         initHelpOverlay(); // help overlay 
    162         initQueryOverlay(); // visibility query stats overlay 
     167        initHelpOverlay();     // help overlay 
     168        initQueryOverlay();    // visibility query stats overlay 
    163169 
    164170        // show stats overlays 
     
    179185        setObjectType(mCurrentObjectType); 
    180186 
     187        // initialise timer 
     188        mTimer = Root::getSingleton().getTimer(); 
     189        mTimeFrameEnded = mTimeFrameStarted = mTimer->getMilliseconds(); 
     190         
    181191        // reset statistics 
    182192        resetStats(); 
     
    356366        {       return false;   }*/ 
    357367 
    358         // --- set parameters for visualization 
     368        //-- set parameters for visualization 
    359369        if (mShowVisualization) 
    360370        { 
     
    362372                mSceneMgr->setOption("ShowOctree", &mShowVisualization); 
    363373                 
    364                 // ---- setup visualization camera 
     374                //-- setup visualization camera 
    365375 
    366376                mVizCamera->setPosition(0, 0, 0); 
     
    380390                mVizCamera->moveRelative(Vector3(0, 800, 0)); 
    381391        } 
     392        else 
     393        { 
     394                // frame start time 
     395                mTimeFrameStarted = mTimer->getMilliseconds(); 
     396                //Ogre::LogManager::getSingleton().logMessage("Frame started"); 
     397        } 
    382398 
    383399        //-- set application state 
     
    385401        { 
    386402        case REPLAY: 
     403                /// set the current camera data to loaded frame information  
    387404                setCurrentFrameInfo(evt.timeSinceLastFrame); 
     405                // HACK to produce demo 
     406                addFrameInfo(mSavedFrameInfo, mCamNode, evt.timeSinceLastFrame); 
    388407                break; 
    389408        case WALKTHROUGH: 
    390                 //-- if we are recording camera status per frame 
    391                 if (mRecord) 
     409                //-- recording the camera settings per frame 
     410                if (mRecordFrames) 
    392411                { 
    393                         addFrameInfo(mCamNode, evt.timeSinceLastFrame); 
     412                        addFrameInfo(mFrameInfo, mCamNode, evt.timeSinceLastFrame); 
    394413                        // print recording message 
    395414                        mWindow->setDebugText("Recording frame " +  
     
    573592                return false; 
    574593 
     594        // timer end time 
     595        if (!mShowVisualization) 
     596        { 
     597                mTimeFrameEnded = mTimer->getMilliseconds(); 
     598                //Ogre::LogManager::getSingleton().logMessage("Frame ended"); 
     599        } 
     600 
    575601    updateStats(); 
    576602 
     603        if (mRecordVideo) // record current frame 
     604        { 
     605                //Ogre::LogManager::getSingleton().logMessage("taking video frame"); 
     606                takeVideoFrame(video_out); 
     607                //Ogre::LogManager::getSingleton().logMessage("finished"); 
     608        } 
    577609        //-- IMPORTANT: must be set, otherwise terrain is not rendered correctly 
    578610        mSceneMgr->endFrame(); 
    579611 
    580         if (mTimeDelay <= 0) // approx. one second 
     612        if (mTimeDelay <= 0) // simulates approx. one second 
    581613                mTimeDelay = 1.0; 
    582614 
     
    603635                ofstr << StringConverter::toString((*it).position) << " "  
    604636                          << StringConverter::toString((*it).orientation) << " " 
    605                           << StringConverter::toString((*it).timeElapsed) << "\n"; 
     637                          << StringConverter::toString((*it).timeElapsed) << " " 
     638                          << StringConverter::toString((*it).fps) << "\n"; 
     639        } 
     640        ofstr.close(); 
     641} 
     642// quick hack 
     643void TerrainFrameListener::writeNewFrameInfo() 
     644{ 
     645        std::ofstream ofstr("newframe.out"); 
     646         
     647        std::vector<frame_info>::const_iterator it, it_end; 
     648 
     649        it_end = mSavedFrameInfo.end(); 
     650        for (it = mSavedFrameInfo.begin(); it < it_end; ++it) 
     651        { 
     652                ofstr << StringConverter::toString((*it).position) << " "  
     653                          << StringConverter::toString((*it).orientation) << " " 
     654                          << StringConverter::toString((*it).timeElapsed) << " " 
     655                          << StringConverter::toString((*it).fps) << "\n"; 
    606656        } 
    607657        ofstr.close(); 
     
    621671        { 
    622672                ifstr.getline(line, 256); 
    623                 sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z, 
     673                sscanf(line, "%f %f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z, 
    624674                           &info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z, 
    625                            &info.timeElapsed); 
     675                           &info.timeElapsed, &info.fps); 
    626676                 
    627677                mFrameInfo.push_back(info); 
     
    636686{ 
    637687        mCurrentFrame = 0; 
     688        int lastState = mAppState; 
     689 
     690        // transition to the next state 
     691        mAppState = (mAppState + 1) % STATE_NUM; 
    638692 
    639693        // if last state was replay state 
    640         if (mAppState == REPLAY) 
    641         { 
    642                 // reset debug text and write frame info to file 
     694        if (lastState == REPLAY) 
     695        { 
     696        // reset debug text 
    643697                mWindow->setDebugText(""); 
    644                 writeFrames(); 
    645                  
     698                                 
     699                // hack for producing demo 
     700                writeNewFrameInfo(); 
     701                mSavedFrameInfo.clear(); 
     702 
    646703                float avgFps = (float)mAvgFps / (float)mFrameCount; 
    647704 
     
    659716        } 
    660717         
    661         //-- set the next státe 
    662         mAppState = (mAppState + 1) % STATE_NUM; 
    663  
    664718        // replay recorded walkthrough 
    665719        if (mAppState == REPLAY) 
    666720        { 
    667721                // no recording during replay 
    668                 mRecord = false; 
    669  
    670                 // load recorded walkthrough 
     722                mRecordFrames = false; mWindow->setDebugText(""); 
     723 
     724                // load recorded walkthrough from disk 
    671725                if (mFrameInfo.size() == 0) 
    672726                { 
    673727                        loadFrames(); 
    674728                } 
    675  
     729                 
    676730                // if there are no recorded frames => set next state 
    677731                if (mFrameInfo.size() == 0)  
     
    679733                        nextAppState(); 
    680734                } 
    681                 else 
     735                else // replay 
    682736                { 
    683737                        mWindow->setDebugText("Replay"); 
     
    699753void TerrainFrameListener::toggleRecord() 
    700754{ 
    701         mRecord = !mRecord; 
    702  
    703         // clear previous camera path 
    704         if (mRecord) 
     755        mRecordFrames = !mRecordFrames; 
     756 
     757        if (mRecordFrames)  
     758        { 
     759                // starting new recording => clear old frame info 
    705760                mFrameInfo.clear(); 
     761        } 
    706762        else 
     763        { 
     764                writeFrames(); // write frame info to file 
    707765                mWindow->setDebugText(""); 
     766        } 
    708767} 
    709768//----------------------------------------------------------------------- 
     
    711770{ 
    712771        mVisibilityThreshold += incr;  
    713         if(mVisibilityThreshold < 0) mVisibilityThreshold = 0; 
    714          
     772 
     773        if (mVisibilityThreshold < 0) 
     774        { 
     775                mVisibilityThreshold = 0; 
     776        } 
     777 
    715778        char str[100]; sprintf(str,": %d", mVisibilityThreshold); 
    716779 
     
    722785{ 
    723786        mAssumedVisibility += incr;  
    724         if(mAssumedVisibility < 0) mAssumedVisibility = 0; 
    725          
     787 
     788        if (mAssumedVisibility < 0)  
     789        {        
     790                mAssumedVisibility = 0; 
     791        } 
     792 
    726793        char str[100]; sprintf(str,": %d", mAssumedVisibility); 
    727794 
     
    739806{ 
    740807        mCurrentAlgorithm = (mCurrentAlgorithm + 1) %  
    741                 (GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS - 1); 
     808                GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS; 
    742809        setAlgorithm(mCurrentAlgorithm); 
    743810} 
     
    745812void TerrainFrameListener::setObjectType(int objectType) 
    746813{ 
    747         if (mCurrentObjectType >= 3) 
     814        if (mCurrentObjectType >= 3) // TODO: define a constant 
    748815                mCurrentObjectType = 0; 
    749816 
     
    779846        static String trisString = "Triangle Count: "; 
    780847 
     848        int currentFps = mWindow->getStatistics().lastFPS; 
     849         
     850        if (mUseDemoFps) 
     851                currentFps = mDemoFps; 
     852#if 0 
     853        // HACK: take pure rendering time, only measures the render call 
     854        long pureRenderTime = mTimeFrameEnded - mTimeFrameStarted; 
     855 
     856        if (pureRenderTime) 
     857        { 
     858                mPureRenderTimeFps = 1000.0 / (float) pureRenderTime; 
     859        } 
     860        currentFps = mPureRenderRenderTimeFps; 
     861        //std::stringstream d; d << "Pure render time fps: " << mPureRenderTimeFps << "\n"; 
     862        //Ogre::LogManager::getSingleton().logMessage(d.str()); 
     863#endif 
     864         
    781865        // HACK: compute average fps ourselfs, because ogre avg. fps is wrong 
    782866        // TODO: update only once per second 
    783         mAvgFps += mWindow->getStatistics().lastFPS; 
    784         ++ mFrameCount; 
    785          
    786         float avgFps = (float)mAvgFps / (float)mFrameCount; 
    787      
     867        mAvgFps += currentFps; 
     868        float avgFps = (float)mAvgFps / (float)(mFrameCount++); 
     869    
    788870        // update stats when necessary 
    789871    try  
     
    796878                const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 
    797879 
    798                 //guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 
    799                 if (mTimeDelay < 0) // only update once per second 
     880                // HACK: take newly computed avg. fps instead of Ogre avg fps and update only once per second 
     881                if (mTimeDelay < 0)  
    800882                {                
    801883                        guiAvg->setCaption(avgFpsString + StringConverter::toString(avgFps) + " ms"); 
     884                        //guiCurr->setCaption(currFpsString + StringConverter::toString(currentFps)); 
    802885                } 
    803  
    804                 guiCurr->setCaption(currFpsString + StringConverter::toString(stats.lastFPS)); 
     886                //guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 
     887                guiCurr->setCaption(currFpsString + StringConverter::toString(currentFps)); 
     888                 
     889 
    805890                guiBest->setCaption(bestFpsString + StringConverter::toString(stats.bestFPS) 
    806891                        +" "+StringConverter::toString(stats.bestFrameTime) + " ms"); 
     
    10391124                break; 
    10401125        case KC_F2: 
    1041                 toggleShowStats(); 
     1126                mStatsOn = !mStatsOn; 
     1127                showStats(mStatsOn); 
    10421128                break; 
    10431129        case KC_F3: 
     
    10631149                mUseAnimation = !mUseAnimation; 
    10641150                break; 
     1151 
     1152        case KC_F10: 
     1153                mRecordVideo = !mRecordVideo; 
     1154                         
    10651155        case KC_F11: 
    10661156                takeScreenshot(); 
     
    10811171        case KC_DELETE: 
    10821172                mDeleteObjects = true; 
     1173                break; 
     1174        case KC_M: // hack 
     1175                mUseDemoFps = !mUseDemoFps; 
    10831176                break; 
    10841177        //KEY_PRESSED(KC_F3, 0.3, writeFrames()); 
     
    11101203} 
    11111204//----------------------------------------------------------------------- 
    1112 void TerrainFrameListener::addFrameInfo(SceneNode *camNode, Real timeElapsed) 
     1205void TerrainFrameListener::addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed) 
    11131206{ 
    11141207        frame_info info; 
     1208 
    11151209        info.orientation = mCamNode->getOrientation(); 
    11161210        info.position = mCamNode->getPosition(); 
    11171211        info.timeElapsed = timeElapsed; 
    1118  
    1119         mFrameInfo.push_back(info); 
     1212        info.fps = mWindow->getStatistics().lastFPS; 
     1213 
     1214        frameInfos.push_back(info); 
    11201215} 
    11211216//----------------------------------------------------------------------- 
     
    11241219        //-- find current frame relative to elapsed frame time           
    11251220        mReplayTimeElapsed -= timeElapsed; 
    1126  
     1221         
    11271222        while ((mReplayTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1)) 
    11281223        { 
     
    11301225        } 
    11311226 
    1132         frame_info new_frame = mFrameInfo[mCurrentFrame]; 
     1227 
     1228        // TODO: crashes here if recording / replaying on the same time!! 
     1229        frame_info new_frame = mFrameInfo[mCurrentFrame];  
    11331230        frame_info old_frame = mFrameInfo[mCurrentFrame - 1]; 
    11341231                 
     
    11431240        Vector3 camPos = old_frame.position + factor  
    11441241                * (new_frame.position - old_frame.position); 
     1242 
     1243        // interpolate the orientation 
    11451244        Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation,  
    11461245                new_frame.orientation, true); 
    11471246 
     1247        // HACK: interpolate fps 
     1248        mDemoFps = old_frame.fps + factor * (new_frame.fps -old_frame.fps); 
     1249 
    11481250        mCamNode->setPosition(camPos); 
    11491251        mCamNode->setOrientation(camOrienation); 
    11501252         
    1151         // stop replay after a full walkthrough 
     1253        // stop replaying after one full walkthrough 
    11521254        if (mCurrentFrame == (int)mFrameInfo.size() - 1) 
    11531255        { 
     
    12491351} 
    12501352//----------------------------------------------------------------------- 
     1353void TerrainFrameListener::takeVideoFrame(std::ofstream &ofstr) 
     1354{ 
     1355        char name[50]; 
     1356 
     1357        sprintf(name, "frame_%05d.tga", ++mNumVideoFrames); 
     1358    mWindow->writeContentsToFile(name); 
     1359    //mWindow->setDebugText(String("Wrote ") + name); 
     1360 
     1361        ofstr << name << "\n"; 
     1362} 
     1363//----------------------------------------------------------------------- 
    12511364void TerrainFrameListener::takeScreenshot() 
    12521365{ 
    1253         char tmp[20]; 
    1254         sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); 
    1255     mWindow->writeContentsToFile(tmp); 
    1256     mWindow->setDebugText(String("Wrote ") + tmp); 
     1366        char name[50]; 
     1367 
     1368        sprintf(name, "screenshot_%05d.png", ++mNumScreenShots); 
     1369    mWindow->writeContentsToFile(name); 
     1370    //mWindow->setDebugText(String("Wrote ") + name); 
    12571371} 
    12581372//----------------------------------------------------------------------- 
     
    12831397        } 
    12841398} 
    1285 //----------------------------------------------------------------------- 
    1286 void TerrainFrameListener::toggleShowStats() 
    1287 { 
    1288         mStatsOn = !mStatsOn; 
    1289  
    1290         showStats(mStatsOn); 
    1291 } 
     1399 
    12921400//----------------------------------------------------------------------- 
    12931401void TerrainFrameListener::toggleShowHelp() 
     
    13361444        initHelpOverlayElement("Recorded", top); top += vert_space; 
    13371445        initHelpOverlayElement("Animation", top); top += vert_space; 
     1446        initHelpOverlayElement("Video", top); top += vert_space; 
    13381447        initHelpOverlayElement("Screenshots", top); top += vert_space; 
    13391448        initHelpOverlayElement("WriteOut", top); top += vert_space; 
     1449 
    13401450 
    13411451        top +=vert_space; 
  • trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h

    r187 r254  
    2020 
    2121 
     22 
    2223/** Frame listener specialised for terrains. 
    2324*/ 
     
    7576           Quaternion orientation; 
    7677           Real timeElapsed; 
     78           Real fps; 
    7779   } frame_info; 
     80 
     81   typedef std::vector<frame_info> FrameInfoContainer; 
    7882 
    7983   enum  {WALKTHROUGH, REPLAY, STATE_NUM}; 
     
    8589   void zoomVizCamera(int zoom); 
    8690         
    87    void addFrameInfo(SceneNode *camNode, Real timeElapsed); 
     91   void addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed); 
    8892   void setCurrentFrameInfo(Real timeElapsed); 
    8993 
     
    9599   void loadFrames(); 
    96100 
    97    
    98     // Constructor takes a RenderWindow because it uses that to determine input context 
    99     //ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false) 
     101        // quick hack 
     102        void writeNewFrameInfo(); 
    100103     
    101104    bool processUnbufferedKeyInput(const FrameEvent& evt); 
    102105    bool processUnbufferedMouseInput(const FrameEvent& evt); 
    103106 
     107        /** Shows the frame / algorithm statistics. 
     108        */  
    104109    void showStats(bool show); 
    105110 
     111        /** Updates frame statistics and the frame statistics display. 
     112        */ 
    106113        void updateStats(); 
    107114 
     115        /** Toggles wether help screen is shown or not. 
     116        */ 
    108117        void toggleShowHelp(); 
    109         void toggleShowStats(); 
    110  
     118         
     119        /** Toggles wether shadows are shown or not. 
     120        */ 
    111121        void toggleShowShadows(); 
    112122        void toggleDisplayCameraDetails(); 
     123        /** Takes screenshot of the current scene. 
     124        */ 
    113125        void takeScreenshot(); 
     126        /** Takes one video frame. 
     127        */ 
     128        void takeVideoFrame(std::ofstream &ofstr); 
     129 
    114130        void nextSceneDetailLevel(); 
    115131        void nextFilter(); 
     
    120136        void changeAssumedVisibility(int incr); 
    121137        void setTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves); 
     138        /** Shows octree hierarchy of the scene. 
     139        */ 
    122140        void toggleShowOctree(); 
     141        /** Toggles wether we use the initial depth pass. 
     142        */ 
    123143        void toggleUseDepthPass(); 
     144        /** Toggles wether the visualization is shown. 
     145        */ 
    124146        void toggleShowViz(); 
     147        /** Toggles wether the frames are recorded. 
     148        */ 
    125149        void toggleRecord(); 
    126150 
     
    134158        void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer); 
    135159 
     160        /** Shows result from visibility queries. 
     161        */ 
    136162        void toggleShowQueryStats(); 
    137163 
     
    168194        int mVisibilityThreshold; 
    169195        int mAssumedVisibility; 
    170         // the current frame number 
     196        /// the current frame number 
    171197        int mCurrentFrame; 
    172         // the current application state 
     198        /// the current application state 
    173199        int mAppState; 
    174         // The number of objects on the screen 
     200        /// The number of objects on the screen 
    175201        int mObjectCount;             
    176         // visualization mode 
     202        /// visualization mode 
    177203        int mNodeVizMode; 
    178  
    179         SceneNode *mCurrentObject;    // the newly created object 
    180  
     204        /// number of video frames 
     205        int mNumVideoFrames; 
     206        /// the newly created object 
     207        SceneNode *mCurrentObject;     
     208/// HACK 
     209float mDemoFps; 
     210bool mUseDemoFps; 
    181211        OverlayElement *mAlgorithmInfo; 
    182212        OverlayElement *mThresholdInfo; 
     
    214244        bool mShowVisualization; 
    215245        bool mCullCamera; 
    216         bool mRecord; 
     246        bool mRecordFrames; 
    217247        bool mShowShadows; 
    218248        bool mVisualizeCulledNodes; 
     
    232262        SceneNode *mCamNode; 
    233263         
    234         //std::deque<Vector3> mWalkList;   // The list of points we are walking to 
    235         std::vector<frame_info> mFrameInfo; 
    236                  
     264        /// Per frame data stored for a walkthrough 
     265        FrameInfoContainer mFrameInfo; 
     266        /// HACK: for demo 
     267        FrameInfoContainer mSavedFrameInfo; 
     268         
    237269        Real mReplayTimeElapsed; 
    238270        //EventProcessor* mEventProcessor; 
     
    282314 
    283315        bool mDeleteObjects; 
    284  
     316        bool mRecordVideo; 
     317 
     318        Timer *mTimer; 
     319        long mTimeFrameEnded; 
     320        long mTimeFrameStarted; 
     321        float mPureRenderTimeFps; 
    285322        TestCullingTerrainApplication *mApplication; 
    286323}; 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp

    r187 r254  
    305305        { 
    306306                // the objects are generated randomly distributed over the terrain 
    307                 generateScene(900, 0); 
     307                generateScene(900, 0); // create soldiers, trees, ninjas 
    308308                generateScene(500, 1); 
    309309                generateScene(100, 2); 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h

    r183 r254  
    157157        Vector3 mTerrainMaxPos; 
    158158 
    159  
    160159private: 
    161160        void chooseSceneManager(void); 
  • trunk/VUT/work/iv/IVFrameListener.cpp

    r187 r254  
    6666mShowVisualization(false), 
    6767mCullCamera(false), 
    68 mRecord(false), 
     68mRecordFrames(false), 
    6969mShowShadows(false), 
    7070mShowHelp(false), 
     
    288288        case WALKTHROUGH: 
    289289                //-- if we are recording camera status per frame 
    290                 if (mRecord) 
     290                if (mRecordFrames) 
    291291                { 
    292292                        addFrameInfo(mCamNode, evt.timeSinceLastFrame); 
     
    442442        { 
    443443                // no recording during replay 
    444                 mRecord = false; 
     444                mRecordFrames = false; 
    445445 
    446446                // load recorded walkthrough 
     
    475475void IVFrameListener::toggleRecord() 
    476476{ 
    477         mRecord = !mRecord; 
     477        mRecordFrames = !mRecordFrames; 
    478478 
    479479        // clear previous camera path 
    480         if (mRecord) 
     480        if (mRecordFrames) 
    481481                mFrameInfo.clear(); 
    482482        else 
     
    834834        info.position = mCamNode->getPosition(); 
    835835        info.timeElapsed = timeElapsed; 
    836  
     836         
    837837        mFrameInfo.push_back(info); 
    838838} 
  • trunk/VUT/work/iv/IVFrameListener.h

    r187 r254  
    182182        bool mShowVisualization; 
    183183        bool mCullCamera; 
    184         bool mRecord; 
     184        bool mRecordFrames; 
    185185        bool mShowShadows; 
    186186        bool mVisualizeCulledNodes; 
Note: See TracChangeset for help on using the changeset viewer.