#ifndef _TerrainFrameListener_H__ #define _TerrainFrameListener_H__ #include "CEGUIForwardRefs.h" #include #include #include #include #include #include "VisibilityEnvironment.h" #include "VisibilityManager.h" #include "OgreTerrainContentGenerator.h" #include "OgrePlatformQueryManager.h" class TestCullingTerrainApplication; using namespace Ogre; /** Struct storing walktrough statistics */ struct WalkthroughStats { public: unsigned long mAccFps; unsigned long mBestFps; unsigned long mWorstFps; unsigned long mAccTris; unsigned long mAccQueryCulledNodes; unsigned long mAccFrustumCulledNodes; unsigned long mFrameCount; unsigned long mAccRenderedNodes; WalkthroughStats(): mAccFps(0), mBestFps(0), mWorstFps(0), mAccTris(0), mAccQueryCulledNodes(0), mAccFrustumCulledNodes(0), mFrameCount(0), mAccRenderedNodes(0) {} void Reset() { mAccFps = 0; mBestFps = 0; mWorstFps = 0; mAccTris = 0; mAccQueryCulledNodes = 0; mAccFrustumCulledNodes = 0; mFrameCount = mAccRenderedNodes = 0; } void UpdateFrame(int currentFps, int bestFps, int worstFps, int renderedTris, int renderedNodes, int queryCulledNodes, int frustumCulledNodes) { mAccFps += currentFps; mBestFps = bestFps; mWorstFps = worstFps; // accumulated #triangles (M) mAccTris += renderedTris / 1000; mAccRenderedNodes += renderedNodes; mAccQueryCulledNodes += queryCulledNodes; mAccFrustumCulledNodes += frustumCulledNodes; ++ mFrameCount; } void Print(std::ostream &d, const std::string &algorithmName) const { // compuate average fps and triangle count float avgFps = (float)mAccFps / (float)mFrameCount; float avgTris = (float)mAccTris / (float)mFrameCount; float avgFrustumCulledNodes = 0; float avgRenderedNodes = 0; float avgQueryCulledNodes = 0; if (mFrameCount != 0) { avgFrustumCulledNodes = (float)mAccFrustumCulledNodes / (float)mFrameCount; avgQueryCulledNodes = (float)mAccQueryCulledNodes / (float)mFrameCount; avgRenderedNodes = (float)mAccRenderedNodes / (float) mFrameCount; } //-- write out stats for recorded walkthrough d << "Algorithm: " << algorithmName << "\n" << "avg. FPS: " << avgFps << "\n" << "best FPS: " << mBestFps << "\n" << "worst FPS: " << mWorstFps << "\n" << "#frames: " << mFrameCount << "\n" << "avg. #triangles: " << avgTris << " M\n" << "avg. #query culled nodes: " << avgFrustumCulledNodes << "\n" << "avg. #frustum culled nodes: " << avgQueryCulledNodes << "\n" << "avg. #rendered nodes: " << avgRenderedNodes << "\n"; } }; /** Frame listener specialised for terrains. */ class TerrainFrameListener: public FrameListener, public MouseListener, public MouseMotionListener, public KeyListener { public: TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera, SceneNode *camNode, Light *sunLight, TestCullingTerrainApplication *app); ~TerrainFrameListener(); bool frameStarted(const FrameEvent& evt); bool frameEnded(const FrameEvent& evt); /* MouseListener callbacks. */ virtual void mouseClicked(MouseEvent* e) { } virtual void mouseEntered(MouseEvent* e) { } virtual void mouseExited(MouseEvent* e) { } // This is when the mouse button goes DOWN. void mousePressed(MouseEvent* e); // This is when the mouse button is let UP. void mouseReleased(MouseEvent* e); /* MouseMotionListener callbacks */ void mouseMoved(MouseEvent *e); // This is when the mouse is clicked, held and dragged. void mouseDragged(MouseEvent *e); void mouseDragDropped(MouseEvent *e); void keyPressed(KeyEvent* e); void keyReleased(KeyEvent* e); void keyClicked(KeyEvent* e); /** The information about camera position and orienation per frame. */ typedef struct { Vector3 position; Quaternion orientation; Real timeElapsed; Real fps; } frame_info; typedef std::vector FrameInfoContainer; enum {WALKTHROUGH, REPLAY, STATE_NUM}; // visualization modes for scene nodes enum { NODEVIZ_NONE, NODEVIZ_RENDER_NODES, NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_RENDER_PVS, NODEVIZ_MODES_NUM}; //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM}; void zoomVizCamera(int zoom); void addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed); void setCurrentFrameInfo(Real timeElapsed); void applyCurrentAlgorithm(); void moveCamera(); void writeFrames(const std::string filename, const FrameInfoContainer &frameInfo) const; void loadFrames(const std::string filename, FrameInfoContainer &frameInfo); bool processUnbufferedKeyInput(const FrameEvent& evt); bool processUnbufferedMouseInput(const FrameEvent& evt); void switchMouseMode(); /** Shows the frame / algorithm statistics. */ void showStats(bool show); /** Updates frame statistics and the frame statistics display. */ void updateStats(); /** Toggles whether help screen is shown or not. */ void toggleShowHelp(); /** Toggles whether shadows are shown or not. */ void toggleShowShadows(); /** if camera stats (e.g, location, orientation, ...) should be displayed- */ void toggleDisplayCameraDetails(); /** Takes screenshot of the current scene. */ void takeScreenshot(); /** Takes one video frame. */ void showBoundingBoxes(); void takeVideoFrame(std::ofstream &ofstr); void nextSceneDetailLevel(); void nextFilter(); void nextAlgorithm(); void nextNodeVizMode(); void nextAppState(); void changeThreshold(int incr); void changeAssumedVisibility(int incr); void changeVizScale(const int incr); void setTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves); /** Shows visualization of octree hierarchy nodes. */ void toggleShowOctree(); /** Shows visualization of the view cells. */ void toggleShowViewCells(); /** Toggles between view cells / no view cells. */ void toggleUseViewCells(); void toggleUseVisibilityFilter(); /** Toggles whether we use the initial depth pass. */ void toggleUseDepthPass(); void toggleFlushQueue(); /** Toggles whether the visualization is shown. */ void toggleShowViz(); /** Toggles whether the frames are recorded. */ void toggleRecord(); void changeFloorDist(const float incr); /** Applies visibility query. Collects the visible objects and their visibility information. @param fromPoint if query should be from point or from camera @param relativeVisibility if query should return number of visible pixels or the ratio visible / projected pixels. @param useItemBuffer if item buffer should be used or occlusion queries */ void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer); /** Shows result from visibility queries. */ void toggleShowQueryStats(); /** Sets the type of the objects generated in the scene. */ void applyObjectType(); void setAlgorithm(const int algorithm); static String msAlgorithmCaptions[]; static String msApprevAlgorithmCaptions[]; static String msQueryTypeCaptions[]; static String msQueryRelativeVisCaptions[]; static String msQueryMethodCaptions[]; static Real msObjectTerrainOffsets[]; static Real msObjectScales[]; static String msObjectCaptions[]; protected: void initHelpOverlayElement(String name, int top); void initOverlayElement(OverlayElement **elInfo, String ext, String name, int top, String caption); //-- initialise overlays void initHelpOverlay(); void initVisStatsOverlay(); void initQueryOverlay(); SceneManager *mSceneMgr; // A pointer to the scene manager CEGUI::Renderer *mGUIRenderer; // cegui renderer int mCurrentAlgorithm; int mVisibilityThreshold; int mAssumedVisibility; /// the current frame number int mCurrentFrame; /// the current application state int mAppState; /// The number of objects on the screen int mObjectCount; /// visualization mode int mNodeVizMode; /// number of video frames int mNumVideoFrames; /// the newly created object int m_iShowBoundingBoxes; int m_iBoundingBoxLevel; SceneNode *mCurrentObject; WalkthroughStats mWalkthroughStats; /// visualization scale float mVizScale; //////////////////////////////////////////////////////////////////////// /** HACK for recording demo: 1) the walkthrough must be recorded. 2) the walktrough must be replayed using the different options, e.g., CHC with the mSavePrecomputedFps (key "E") option. This saves the frame rates for the different methods. 3) the walkthrough must then be replayed with the mRecordDemo (KEY "M") options turned on. for the video recording we are using FRAPS. */ /// the currently interpolated FPS float mPrecomputedFps; /// saves the precomputed fps for the different methods. bool mSavePrecomputedFps; /// displayes the precomputed fps bool mRecordDemo; //////////////////////////////////////////////////////////////////////////// OverlayElement *mAlgorithmInfo; OverlayElement *mThresholdInfo; OverlayElement *mAssumedVisibilityInfo; OverlayElement *mFrustumCulledNodesInfo; OverlayElement *mQueryCulledNodesInfo; OverlayElement *mTraversedNodesInfo; OverlayElement *mHierarchyNodesInfo; OverlayElement *mTestGeometryForVisibleLeavesInfo; OverlayElement *mUseDepthPassInfo; OverlayElement *mRenderedNodesInfo; OverlayElement *mObjectsCountInfo; OverlayElement *mQueriesIssuedInfo; OverlayElement *mDelayedQueriesIssuedInfo; OverlayElement *mDelayedTraversedNodesInfo; OverlayElement *mCurrentObjectTypeInfo; OverlayElement *mViewCellsInfo; OverlayElement *mMyStatsAlgorithmInfo; OverlayElement *mMyStatsFpsInfo; OverlayElement *mMyLoadingInfo; OverlayElement *mQueryTypeInfo; OverlayElement *mQueryVisibleNodesInfo; OverlayElement *mQueryVisibleGeometryInfo; OverlayElement *mQueryVisiblePatchInfo; OverlayElement *mQueryVisiblityInfo; OverlayElement *mQueryNodeVisibilityInfo; OverlayElement *mQueryGeometryVisibilityInfo; OverlayElement *mQueryPatchVisibilityInfo; //OverlayElement *mHelpInfo; RayQueryExecutor *mRayQueryExecutor; TerrainContentGenerator *mTerrainContentGenerator; bool mTestGeometryForVisibleLeaves; bool mShowOctree; bool mShowViewCells; bool mUseDepthPass; bool mFlushQueue; bool mShowVisualization; bool mCullCamera; bool mRecordFrames; bool mShowShadows; bool mVisualizeCulledNodes; bool mShowHelp; bool mStatsOn; bool mLMouseDown; // True if the mouse buttons are down bool mRMouseDown; bool mShutdownRequested; bool mDisplayCameraDetails; bool mUseItemBuffer; bool mUseAnimation; int mItemBufferMode; Real mVizCameraHeight; Camera *mVizCamera; SceneNode *mCamNode; /// Per frame data stored for a walkthrough FrameInfoContainer mFrameInfo; /// HACK for demo FrameInfoContainer mPrecomputedFpsFrameInfo; Real mReplayTimeElapsed; //EventProcessor* mEventProcessor; InputReader* mInputDevice; Camera* mCamera; Vector3 mTranslateVector; RenderWindow* mWindow; unsigned int mNumScreenShots; int mSceneDetailIndex; int mAniso; float mMoveScale; Degree mRotScale; // just to stop toggles flipping too fast Real mTimeDelay; Radian mRotX, mRotY; TextureFilterOptions mFiltering; Real mMoveSpeed; Degree mRotateSpeed; Overlay* mDebugOverlay; Overlay* mHelpOverlay; Overlay* mCullStatsOverlay; Overlay* mQueryOverlay; Overlay* mMyStatsOverlay; Overlay *mLoadingOverlay; Light *mSunLight; GtpVisibility::VisibilityManager *mVisibilityManager; EventProcessor* mEventProcessor; bool mShiftPressed; bool mShowQueryStats; //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; PlatformQueryManager *mQueryManager; float mDelayedQueriesIssued; float mDelayedTraversedNodes; int mCurrentObjectType; bool mDeleteObjects; bool mRecordVideo; Timer *mTimer; long mTimeFrameEnded; long mTimeFrameStarted; float mPureRenderTimeFps; TestCullingTerrainApplication *mApplication; bool mUseBufferedInputMouse; bool mUseViewCells; bool mViewCellsLoaded; bool mUseVisibilityFilter; float mFloorDist; }; #endif //_TerrainFrameListener_H__