| 1 | /* | 
|---|
| 2 | *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| 3 | *                    > www.orxonox.net < | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | *   License notice: | 
|---|
| 7 | * | 
|---|
| 8 | *   This program is free software; you can redistribute it and/or | 
|---|
| 9 | *   modify it under the terms of the GNU General Public License | 
|---|
| 10 | *   as published by the Free Software Foundation; either version 2 | 
|---|
| 11 | *   of the License, or (at your option) any later version. | 
|---|
| 12 | * | 
|---|
| 13 | *   This program is distributed in the hope that it will be useful, | 
|---|
| 14 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | *   GNU General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | *   You should have received a copy of the GNU General Public License | 
|---|
| 19 | *   along with this program; if not, write to the Free Software | 
|---|
| 20 | *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
| 21 | * | 
|---|
| 22 | *   Author: | 
|---|
| 23 | *      Reto Grieder | 
|---|
| 24 | *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 | 
|---|
| 25 | *   Co-authors: | 
|---|
| 26 | *      Felix Schulthess | 
|---|
| 27 | * | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | /** | 
|---|
| 31 | @defgroup Graphics Graphics and GUI | 
|---|
| 32 | @ingroup Core | 
|---|
| 33 | */ | 
|---|
| 34 |  | 
|---|
| 35 | /** | 
|---|
| 36 | @file | 
|---|
| 37 | @ingroup Graphics | 
|---|
| 38 | @brief | 
|---|
| 39 | Declaration of GraphicsManager Singleton. | 
|---|
| 40 | */ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef _GraphicsManager_H__ | 
|---|
| 43 | #define _GraphicsManager_H__ | 
|---|
| 44 |  | 
|---|
| 45 | #include "CorePrereqs.h" | 
|---|
| 46 |  | 
|---|
| 47 | #include <cassert> | 
|---|
| 48 | #include <string> | 
|---|
| 49 | #include <OgreLog.h> | 
|---|
| 50 | #include <boost/shared_ptr.hpp> | 
|---|
| 51 |  | 
|---|
| 52 | #include "util/DestructionHelper.h" | 
|---|
| 53 | #include "util/Singleton.h" | 
|---|
| 54 | #include "config/Configurable.h" | 
|---|
| 55 |  | 
|---|
| 56 | // tolua_begin | 
|---|
| 57 | namespace orxonox | 
|---|
| 58 | { | 
|---|
| 59 | /** | 
|---|
| 60 | @brief | 
|---|
| 61 | Graphics engine manager class | 
|---|
| 62 | */ | 
|---|
| 63 | class _CoreExport GraphicsManager | 
|---|
| 64 | // tolua_end | 
|---|
| 65 | : public Singleton<GraphicsManager>, public Configurable, public Ogre::LogListener | 
|---|
| 66 | { // tolua_export | 
|---|
| 67 | friend class Singleton<GraphicsManager>; | 
|---|
| 68 | public: | 
|---|
| 69 | GraphicsManager(bool bLoadRenderer = true); | 
|---|
| 70 |  | 
|---|
| 71 | //! Leave empty and use cleanup() instead | 
|---|
| 72 | ~GraphicsManager() {} | 
|---|
| 73 | /// Destructor that also executes when object fails to construct | 
|---|
| 74 | void destroy(); | 
|---|
| 75 |  | 
|---|
| 76 | void setConfigValues(); | 
|---|
| 77 |  | 
|---|
| 78 | void postUpdate(const Clock& time); | 
|---|
| 79 |  | 
|---|
| 80 | Ogre::Viewport* getViewport()         { return this->viewport_; } | 
|---|
| 81 | Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } | 
|---|
| 82 | size_t getRenderWindowHandle(); | 
|---|
| 83 |  | 
|---|
| 84 | // tolua_begin | 
|---|
| 85 | static GraphicsManager& getInstance() { return Singleton<GraphicsManager>::getInstance(); } // tolua_export | 
|---|
| 86 |  | 
|---|
| 87 | bool isFullScreen() const; | 
|---|
| 88 | unsigned int getWindowWidth() const; | 
|---|
| 89 | unsigned int getWindowHeight() const; | 
|---|
| 90 |  | 
|---|
| 91 | bool hasVSyncEnabled() const; | 
|---|
| 92 | std::string getFSAAMode() const; | 
|---|
| 93 | // tolua_end | 
|---|
| 94 |  | 
|---|
| 95 | void upgradeToGraphics(); | 
|---|
| 96 | void loadDebugOverlay(); | 
|---|
| 97 | void unloadDebugOverlay(); | 
|---|
| 98 | bool rendererLoaded() const { return renderWindow_ != NULL; } | 
|---|
| 99 |  | 
|---|
| 100 | void setCamera(Ogre::Camera* camera); | 
|---|
| 101 |  | 
|---|
| 102 | private: | 
|---|
| 103 | GraphicsManager(GraphicsManager&); // don't mess with singletons | 
|---|
| 104 |  | 
|---|
| 105 | // OGRE initialisation | 
|---|
| 106 | void loadOgreRoot(); | 
|---|
| 107 | void loadOgrePlugins(); | 
|---|
| 108 | void loadRenderer(); | 
|---|
| 109 |  | 
|---|
| 110 | // event from Ogre::LogListener | 
|---|
| 111 | #if OGRE_VERSION >= 0x010800 | 
|---|
| 112 | void messageLogged(const std::string& message, Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName, bool& skipThisMessage); | 
|---|
| 113 | #else | 
|---|
| 114 | void messageLogged(const std::string& message, Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName); | 
|---|
| 115 | #endif | 
|---|
| 116 |  | 
|---|
| 117 | // console commands | 
|---|
| 118 | void printScreen(); | 
|---|
| 119 | std::string setScreenResolution(unsigned int width, unsigned int height, bool fullscreen); | 
|---|
| 120 | std::string setFSAA(const std::string& mode); | 
|---|
| 121 | std::string setVSync(bool vsync); | 
|---|
| 122 |  | 
|---|
| 123 | OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h | 
|---|
| 124 | Ogre::LogManager*        ogreLogger_; | 
|---|
| 125 | Ogre::Root*              ogreRoot_;                //!< Ogre's root | 
|---|
| 126 | Ogre::RenderWindow* renderWindow_;             //!< the one and only render window | 
|---|
| 127 | Ogre::Viewport*     viewport_;                 //!< default full size viewport | 
|---|
| 128 | float               lastFrameStartTime_;       //!< Time stamp of the beginning of the last frame | 
|---|
| 129 | float               lastFrameEndTime_;         //!< Time stamp of the end of the last frame | 
|---|
| 130 |  | 
|---|
| 131 | // XML files for the resources and the debug overlay | 
|---|
| 132 | shared_ptr<XMLFile> resources_;                //!< XML with resource locations | 
|---|
| 133 | shared_ptr<XMLFile> extResources_;             //!< XML with resource locations in the external path (only for dev runs) | 
|---|
| 134 | shared_ptr<XMLFile> debugOverlay_;             //!< XML with various debug overlays | 
|---|
| 135 |  | 
|---|
| 136 | // config values | 
|---|
| 137 | std::string         ogreConfigFile_;           //!< ogre config filename | 
|---|
| 138 | std::string         ogrePlugins_;              //!< Comma separated list of all plugins to load | 
|---|
| 139 | std::string         ogreLogFile_;              //!< log filename for Ogre log messages | 
|---|
| 140 |  | 
|---|
| 141 | /// Helper object that executes the surrogate destructor destroy() | 
|---|
| 142 | DestructionHelper<GraphicsManager> destructionHelper_; | 
|---|
| 143 |  | 
|---|
| 144 | static GraphicsManager* singletonPtr_s;        //!< Pointer to the Singleton | 
|---|
| 145 | // tolua_begin | 
|---|
| 146 | }; | 
|---|
| 147 | } | 
|---|
| 148 | // tolua_end | 
|---|
| 149 |  | 
|---|
| 150 | #endif /* _GraphicsManager_H__ */ | 
|---|