[5] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | You may use this sample code for anything you like, it is not covered by the |
---|
| 11 | LGPL like the rest of the engine. |
---|
| 12 | ----------------------------------------------------------------------------- |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifndef _CompositorDemo_FrameListener_H_ |
---|
| 16 | #define _CompositorDemo_FrameListener_H_ |
---|
| 17 | |
---|
| 18 | #include <OgreFrameListener.h> |
---|
| 19 | #include <OIS/OIS.h> |
---|
| 20 | |
---|
| 21 | #include "ItemSelectorViewManager.h" |
---|
| 22 | |
---|
| 23 | //--------------------------------------------------------------------------- |
---|
| 24 | class HeatVisionListener: public Ogre::CompositorInstance::Listener |
---|
| 25 | { |
---|
| 26 | public: |
---|
| 27 | HeatVisionListener(); |
---|
| 28 | virtual ~HeatVisionListener(); |
---|
| 29 | virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 30 | virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 31 | protected: |
---|
| 32 | Ogre::GpuProgramParametersSharedPtr fpParams; |
---|
| 33 | float start, end, curr; |
---|
| 34 | Ogre::Timer *timer; |
---|
| 35 | }; |
---|
| 36 | //--------------------------------------------------------------------------- |
---|
| 37 | class HDRListener: public Ogre::CompositorInstance::Listener |
---|
| 38 | { |
---|
| 39 | protected: |
---|
| 40 | int mVpWidth, mVpHeight; |
---|
| 41 | int mBloomSize; |
---|
| 42 | // Array params - have to pack in groups of 4 since this is how Cg generates them |
---|
| 43 | // also prevents dependent texture read problems if ops don't require swizzle |
---|
| 44 | float mBloomTexWeights[15][4]; |
---|
| 45 | float mBloomTexOffsetsHorz[15][4]; |
---|
| 46 | float mBloomTexOffsetsVert[15][4]; |
---|
| 47 | public: |
---|
| 48 | HDRListener(); |
---|
| 49 | virtual ~HDRListener(); |
---|
| 50 | void notifyViewportSize(int width, int height); |
---|
| 51 | void notifyCompositor(Ogre::CompositorInstance* instance); |
---|
| 52 | virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 53 | virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 54 | }; |
---|
| 55 | //--------------------------------------------------------------------------- |
---|
| 56 | class GaussianListener: public Ogre::CompositorInstance::Listener |
---|
| 57 | { |
---|
| 58 | protected: |
---|
| 59 | int mVpWidth, mVpHeight; |
---|
| 60 | // Array params - have to pack in groups of 4 since this is how Cg generates them |
---|
| 61 | // also prevents dependent texture read problems if ops don't require swizzle |
---|
| 62 | float mBloomTexWeights[15][4]; |
---|
| 63 | float mBloomTexOffsetsHorz[15][4]; |
---|
| 64 | float mBloomTexOffsetsVert[15][4]; |
---|
| 65 | public: |
---|
| 66 | GaussianListener(); |
---|
| 67 | virtual ~GaussianListener(); |
---|
| 68 | void notifyViewportSize(int width, int height); |
---|
| 69 | virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 70 | virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat); |
---|
| 71 | }; |
---|
| 72 | //--------------------------------------------------------------------------- |
---|
| 73 | class CompositorDemo; |
---|
| 74 | |
---|
| 75 | class CompositorDemo_FrameListener : Ogre::FrameListener, OIS::KeyListener, |
---|
| 76 | OIS::MouseListener, ItemSelectorInterface |
---|
| 77 | { |
---|
| 78 | #define MINSPEED .150f |
---|
| 79 | #define MOVESPEED 30 |
---|
| 80 | #define MAXSPEED 1.800f |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | protected: |
---|
| 84 | std::string mDebugText; |
---|
| 85 | |
---|
| 86 | CompositorDemo* mMain; |
---|
| 87 | HeatVisionListener *hvListener; |
---|
| 88 | HDRListener *hdrListener; |
---|
| 89 | GaussianListener *gaussianListener; |
---|
| 90 | Ogre::Vector3 mTranslateVector; |
---|
| 91 | bool mStatsOn; |
---|
| 92 | unsigned int mNumScreenShots; |
---|
| 93 | bool mWriteToFile; |
---|
| 94 | float mSkipCount; |
---|
| 95 | float mUpdateFreq; |
---|
| 96 | int mSceneDetailIndex; |
---|
| 97 | Ogre::TextureFilterOptions mFiltering; |
---|
| 98 | int mAniso; |
---|
| 99 | bool mQuit; |
---|
| 100 | |
---|
| 101 | float mMoveScale; |
---|
| 102 | float mRotScale; |
---|
| 103 | float mSpeed; |
---|
| 104 | float mAvgFrameTime; |
---|
| 105 | Ogre::Real mMoveSpeed; |
---|
| 106 | Ogre::Real mRotateSpeed; |
---|
| 107 | CEGUI::Point mLastMousePosition; |
---|
| 108 | bool mLastMousePositionSet; |
---|
| 109 | // just to stop toggles flipping too fast |
---|
| 110 | Ogre::Real mTimeUntilNextToggle ; |
---|
| 111 | float mRotX, mRotY; |
---|
| 112 | bool mProcessMovement; |
---|
| 113 | bool mUpdateMovement; |
---|
| 114 | bool mLMBDown; |
---|
| 115 | bool mRMBDown; |
---|
| 116 | bool mMoveFwd; |
---|
| 117 | bool mMoveBck; |
---|
| 118 | bool mMoveLeft; |
---|
| 119 | bool mMoveRight; |
---|
| 120 | Ogre::SceneNode* mSpinny; |
---|
| 121 | |
---|
| 122 | ItemSelectorViewManager* mCompositorSelectorViewManager; |
---|
| 123 | |
---|
| 124 | OIS::Mouse *mMouse; |
---|
| 125 | OIS::Keyboard *mKeyboard; |
---|
| 126 | OIS::InputManager* mInputManager; |
---|
| 127 | |
---|
| 128 | CEGUI::Renderer* mGuiRenderer; |
---|
| 129 | CEGUI::Window* mGuiAvg; |
---|
| 130 | CEGUI::Window* mGuiCurr; |
---|
| 131 | CEGUI::Window* mGuiBest; |
---|
| 132 | CEGUI::Window* mGuiWorst; |
---|
| 133 | CEGUI::Window* mGuiTris; |
---|
| 134 | CEGUI::Window* mGuiDbg; |
---|
| 135 | CEGUI::Window* mRoot; |
---|
| 136 | CEGUI::Listbox* mDebugRTTListbox; |
---|
| 137 | CEGUI::Window* mDebugRTTStaticImage; |
---|
| 138 | typedef std::vector<CEGUI::Imageset*> ImageSetList; |
---|
| 139 | ImageSetList mDebugRTTImageSets; |
---|
| 140 | |
---|
| 141 | CEGUI::MouseButton convertOISButtonToCegui(int ois_button_id); |
---|
| 142 | void CheckMovementKeys( CEGUI::Key::Scan keycode, bool state ); |
---|
| 143 | void updateStats(void); |
---|
| 144 | void registerCompositors(void); |
---|
| 145 | void initDebugRTTWindow(void); |
---|
| 146 | void updateDebugRTTWindow(void); |
---|
| 147 | |
---|
| 148 | public: |
---|
| 149 | CompositorDemo_FrameListener(CompositorDemo* main); |
---|
| 150 | virtual ~CompositorDemo_FrameListener(); |
---|
| 151 | void setSpinningNode(Ogre::SceneNode* node) { mSpinny = node; } |
---|
| 152 | |
---|
| 153 | private: |
---|
| 154 | void connectEventHandlers(void); |
---|
| 155 | |
---|
| 156 | virtual bool mouseMoved(const OIS::MouseEvent &e); |
---|
| 157 | virtual bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id); |
---|
| 158 | virtual bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id); |
---|
| 159 | |
---|
| 160 | virtual bool keyPressed(const OIS::KeyEvent &e); |
---|
| 161 | virtual bool keyReleased(const OIS::KeyEvent &e); |
---|
| 162 | |
---|
| 163 | // Event handlers |
---|
| 164 | bool frameStarted(const Ogre::FrameEvent& evt); |
---|
| 165 | bool handleMouseMove(const CEGUI::EventArgs& e); |
---|
| 166 | bool handleMouseButtonUp(const CEGUI::EventArgs& e); |
---|
| 167 | bool handleMouseButtonDown(const CEGUI::EventArgs& e); |
---|
| 168 | bool handleMouseWheelEvent(const CEGUI::EventArgs& e); |
---|
| 169 | bool handleKeyDownEvent(const CEGUI::EventArgs& e); |
---|
| 170 | bool handleKeyUpEvent(const CEGUI::EventArgs& e); |
---|
| 171 | bool handleRttSelection(const CEGUI::EventArgs& e); |
---|
| 172 | void itemStateChanged(const size_t index, const bool state); |
---|
| 173 | }; |
---|
| 174 | |
---|
| 175 | #endif |
---|