[612] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1293] | 3 | * > www.orxonox.net < |
---|
[612] | 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 |
---|
[1349] | 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
[612] | 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: |
---|
[1535] | 23 | * Reto Grieder |
---|
[1755] | 24 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
[612] | 25 | * Co-authors: |
---|
[1755] | 26 | * Felix Schulthess |
---|
[612] | 27 | * |
---|
| 28 | */ |
---|
[1035] | 29 | |
---|
[2801] | 30 | #include "GraphicsManager.h" |
---|
[612] | 31 | |
---|
[8351] | 32 | #include <cstdlib> |
---|
[2801] | 33 | #include <fstream> |
---|
[5695] | 34 | #include <sstream> |
---|
[2801] | 35 | #include <boost/filesystem.hpp> |
---|
[5695] | 36 | #include <boost/shared_array.hpp> |
---|
[2801] | 37 | |
---|
| 38 | #include <OgreFrameListener.h> |
---|
| 39 | #include <OgreRoot.h> |
---|
| 40 | #include <OgreLogManager.h> |
---|
[1755] | 41 | #include <OgreRenderWindow.h> |
---|
[2801] | 42 | #include <OgreRenderSystem.h> |
---|
[5695] | 43 | #include <OgreResourceGroupManager.h> |
---|
[2801] | 44 | #include <OgreTextureManager.h> |
---|
| 45 | #include <OgreViewport.h> |
---|
| 46 | #include <OgreWindowEventUtilities.h> |
---|
[1538] | 47 | |
---|
[2801] | 48 | #include "SpecialConfig.h" |
---|
[5929] | 49 | #include "util/Clock.h" |
---|
[8079] | 50 | #include "util/Convert.h" |
---|
[2801] | 51 | #include "util/Exception.h" |
---|
[3280] | 52 | #include "util/StringUtils.h" |
---|
[2801] | 53 | #include "util/SubString.h" |
---|
[3346] | 54 | #include "ConfigValueIncludes.h" |
---|
| 55 | #include "CoreIncludes.h" |
---|
[7870] | 56 | #include "Core.h" |
---|
[3346] | 57 | #include "Game.h" |
---|
| 58 | #include "GameMode.h" |
---|
[8079] | 59 | #include "GUIManager.h" |
---|
[5695] | 60 | #include "Loader.h" |
---|
[5929] | 61 | #include "PathConfig.h" |
---|
[8079] | 62 | #include "ViewportEventListener.h" |
---|
[3346] | 63 | #include "WindowEventListener.h" |
---|
[5695] | 64 | #include "XMLFile.h" |
---|
[7284] | 65 | #include "command/ConsoleCommand.h" |
---|
[8079] | 66 | #include "input/InputManager.h" |
---|
[1032] | 67 | |
---|
[1625] | 68 | namespace orxonox |
---|
| 69 | { |
---|
[8079] | 70 | static const std::string __CC_GraphicsManager_group = "GraphicsManager"; |
---|
| 71 | static const std::string __CC_setScreenResolution_name = "setScreenResolution"; |
---|
| 72 | static const std::string __CC_setFSAA_name = "setFSAA"; |
---|
| 73 | static const std::string __CC_setVSync_name = "setVSync"; |
---|
| 74 | DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name, &prototype::string__uint_uint_bool); |
---|
| 75 | DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name, &prototype::string__string); |
---|
| 76 | DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name, &prototype::string__bool); |
---|
| 77 | |
---|
[7284] | 78 | static const std::string __CC_printScreen_name = "printScreen"; |
---|
| 79 | DeclareConsoleCommand(__CC_printScreen_name, &prototype::void__void); |
---|
| 80 | |
---|
[3327] | 81 | class OgreWindowEventListener : public Ogre::WindowEventListener |
---|
[2801] | 82 | { |
---|
[3327] | 83 | public: |
---|
| 84 | void windowResized (Ogre::RenderWindow* rw) |
---|
| 85 | { orxonox::WindowEventListener::resizeWindow(rw->getWidth(), rw->getHeight()); } |
---|
| 86 | void windowFocusChange (Ogre::RenderWindow* rw) |
---|
[7874] | 87 | { orxonox::WindowEventListener::changeWindowFocus(rw->isActive()); } |
---|
[3327] | 88 | void windowClosed (Ogre::RenderWindow* rw) |
---|
| 89 | { orxonox::Game::getInstance().stop(); } |
---|
| 90 | void windowMoved (Ogre::RenderWindow* rw) |
---|
| 91 | { orxonox::WindowEventListener::moveWindow(); } |
---|
[2801] | 92 | }; |
---|
[1032] | 93 | |
---|
[3366] | 94 | GraphicsManager* GraphicsManager::singletonPtr_s = 0; |
---|
[1293] | 95 | |
---|
[5695] | 96 | GraphicsManager::GraphicsManager(bool bLoadRenderer) |
---|
| 97 | : ogreWindowEventListener_(new OgreWindowEventListener()) |
---|
[2801] | 98 | , renderWindow_(0) |
---|
| 99 | , viewport_(0) |
---|
[8079] | 100 | , lastFrameStartTime_(0.0f) |
---|
| 101 | , lastFrameEndTime_(0.0f) |
---|
[8423] | 102 | , destructionHelper_(this) |
---|
[1024] | 103 | { |
---|
[2801] | 104 | RegisterObject(GraphicsManager); |
---|
| 105 | |
---|
[8858] | 106 | orxout(internal_status) << "initializing GraphicsManager..." << endl; |
---|
[2801] | 107 | this->setConfigValues(); |
---|
[612] | 108 | |
---|
[5695] | 109 | // Ogre setup procedure (creating Ogre::Root) |
---|
| 110 | this->loadOgreRoot(); |
---|
[2801] | 111 | |
---|
[5695] | 112 | // At first, add the root paths of the data directories as resource locations |
---|
[6417] | 113 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem"); |
---|
[5695] | 114 | // Load resources |
---|
[6417] | 115 | resources_.reset(new XMLFile("DefaultResources.oxr")); |
---|
[5695] | 116 | resources_->setLuaSupport(false); |
---|
[8858] | 117 | Loader::open(resources_.get(), ClassTreeMask(), false); |
---|
[5695] | 118 | |
---|
[8366] | 119 | // Only for runs in the build directory (not installed) |
---|
| 120 | if (PathConfig::buildDirectoryRun()) |
---|
[6417] | 121 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem"); |
---|
[2801] | 122 | |
---|
[8351] | 123 | extResources_.reset(new XMLFile("resources.oxr")); |
---|
| 124 | extResources_->setLuaSupport(false); |
---|
[8858] | 125 | Loader::open(extResources_.get(), ClassTreeMask(), false); |
---|
[8351] | 126 | |
---|
[5695] | 127 | if (bLoadRenderer) |
---|
[3280] | 128 | { |
---|
[5695] | 129 | // Reads the ogre config and creates the render window |
---|
| 130 | this->upgradeToGraphics(); |
---|
[3280] | 131 | } |
---|
[8858] | 132 | |
---|
| 133 | orxout(internal_status) << "finished initializing GraphicsManager" << endl; |
---|
[2801] | 134 | } |
---|
| 135 | |
---|
[8423] | 136 | void GraphicsManager::destroy() |
---|
[1535] | 137 | { |
---|
[8858] | 138 | orxout(internal_status) << "destroying GraphicsManager..." << endl; |
---|
| 139 | |
---|
[5929] | 140 | Loader::unload(debugOverlay_.get()); |
---|
| 141 | |
---|
[8423] | 142 | Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_); |
---|
[7284] | 143 | ModifyConsoleCommand(__CC_printScreen_name).resetFunction(); |
---|
[8079] | 144 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction(); |
---|
| 145 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).resetFunction(); |
---|
| 146 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).resetFunction(); |
---|
[5929] | 147 | |
---|
| 148 | // Undeclare the resources |
---|
| 149 | Loader::unload(resources_.get()); |
---|
[8351] | 150 | Loader::unload(extResources_.get()); |
---|
[8423] | 151 | |
---|
| 152 | safeObjectDelete(&ogreRoot_); |
---|
| 153 | safeObjectDelete(&ogreLogger_); |
---|
| 154 | safeObjectDelete(&ogreWindowEventListener_); |
---|
[8858] | 155 | |
---|
| 156 | orxout(internal_status) << "finished destroying GraphicsManager" << endl; |
---|
[1535] | 157 | } |
---|
| 158 | |
---|
[2801] | 159 | void GraphicsManager::setConfigValues() |
---|
[1535] | 160 | { |
---|
[2801] | 161 | SetConfigValue(ogreConfigFile_, "ogre.cfg") |
---|
| 162 | .description("Location of the Ogre config file"); |
---|
[5695] | 163 | SetConfigValue(ogrePlugins_, specialConfig::ogrePlugins) |
---|
[2801] | 164 | .description("Comma separated list of all plugins to load."); |
---|
| 165 | SetConfigValue(ogreLogFile_, "ogre.log") |
---|
| 166 | .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); |
---|
[1535] | 167 | } |
---|
[612] | 168 | |
---|
[5695] | 169 | /** |
---|
| 170 | @brief |
---|
| 171 | Loads the renderer and creates the render window if not yet done so. |
---|
| 172 | @remarks |
---|
| 173 | This operation is irreversible without recreating the GraphicsManager! |
---|
| 174 | So if it throws you HAVE to recreate the GraphicsManager!!! |
---|
| 175 | It therefore offers almost no exception safety. |
---|
| 176 | */ |
---|
| 177 | void GraphicsManager::upgradeToGraphics() |
---|
[2801] | 178 | { |
---|
[5695] | 179 | if (renderWindow_ != NULL) |
---|
| 180 | return; |
---|
[2801] | 181 | |
---|
[8858] | 182 | orxout(internal_info) << "GraphicsManager upgrade to graphics" << endl; |
---|
| 183 | |
---|
[6075] | 184 | // load all the required plugins for Ogre |
---|
[8861] | 185 | orxout(user_info) << "Loading Ogre plugins..." << endl; |
---|
[6075] | 186 | this->loadOgrePlugins(); |
---|
| 187 | |
---|
[8861] | 188 | orxout(user_info) << "Creating render window..." << endl; |
---|
[5695] | 189 | this->loadRenderer(); |
---|
[2801] | 190 | |
---|
[5695] | 191 | // Initialise all resources (do this AFTER the renderer has been loaded!) |
---|
| 192 | // Note: You can only do this once! Ogre will check whether a resource group has |
---|
| 193 | // already been initialised. If you need to load resources later, you will have to |
---|
| 194 | // choose another resource group. |
---|
[8861] | 195 | orxout(user_info) << "Initializing all resource groups..." << endl; |
---|
[5695] | 196 | Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
[8858] | 197 | |
---|
| 198 | orxout(internal_info) << "GraphicsManager finished upgrade to graphics" << endl; |
---|
[2801] | 199 | } |
---|
| 200 | |
---|
[1755] | 201 | /** |
---|
| 202 | @brief |
---|
[2801] | 203 | Creates the Ogre Root object and sets up the ogre log. |
---|
[1755] | 204 | */ |
---|
[5695] | 205 | void GraphicsManager::loadOgreRoot() |
---|
[1538] | 206 | { |
---|
[8858] | 207 | orxout(internal_info) << "Setting up Ogre..." << endl; |
---|
[2801] | 208 | |
---|
[6417] | 209 | if (ogreConfigFile_.empty()) |
---|
[2801] | 210 | { |
---|
[8858] | 211 | orxout(internal_warning) << "Ogre config file set to \"\". Defaulting to config.cfg" << endl; |
---|
[2801] | 212 | ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); |
---|
| 213 | } |
---|
[6417] | 214 | if (ogreLogFile_.empty()) |
---|
[2801] | 215 | { |
---|
[8858] | 216 | orxout(internal_warning) << "Ogre log file set to \"\". Defaulting to ogre.log" << endl; |
---|
[2801] | 217 | ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); |
---|
| 218 | } |
---|
| 219 | |
---|
[5929] | 220 | boost::filesystem::path ogreConfigFilepath(PathConfig::getConfigPath() / this->ogreConfigFile_); |
---|
| 221 | boost::filesystem::path ogreLogFilepath(PathConfig::getLogPath() / this->ogreLogFile_); |
---|
[2801] | 222 | |
---|
| 223 | // create a new logManager |
---|
| 224 | // Ogre::Root will detect that we've already created a Log |
---|
[8423] | 225 | ogreLogger_ = new Ogre::LogManager(); |
---|
[8858] | 226 | orxout(internal_info) << "Ogre LogManager created" << endl; |
---|
[2801] | 227 | |
---|
| 228 | // create our own log that we can listen to |
---|
| 229 | Ogre::Log *myLog; |
---|
[5695] | 230 | myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false); |
---|
[8858] | 231 | orxout(internal_info) << "Ogre Log created" << endl; |
---|
[2801] | 232 | |
---|
| 233 | myLog->setLogDetail(Ogre::LL_BOREME); |
---|
| 234 | myLog->addListener(this); |
---|
| 235 | |
---|
[8858] | 236 | orxout(internal_info) << "Creating Ogre Root..." << endl; |
---|
[2801] | 237 | |
---|
| 238 | // check for config file existence because Ogre displays (caught) exceptions if not |
---|
| 239 | if (!boost::filesystem::exists(ogreConfigFilepath)) |
---|
| 240 | { |
---|
| 241 | // create a zero sized file |
---|
| 242 | std::ofstream creator; |
---|
| 243 | creator.open(ogreConfigFilepath.string().c_str()); |
---|
| 244 | creator.close(); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | // Leave plugins file empty. We're going to do that part manually later |
---|
[8423] | 248 | ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()); |
---|
[2801] | 249 | |
---|
[8858] | 250 | orxout(internal_info) << "Ogre set up done." << endl; |
---|
[1538] | 251 | } |
---|
[2801] | 252 | |
---|
| 253 | void GraphicsManager::loadOgrePlugins() |
---|
| 254 | { |
---|
[8858] | 255 | orxout(internal_info) << "loading ogre plugins" << endl; |
---|
| 256 | |
---|
[8351] | 257 | // Plugin path can have many different locations... |
---|
| 258 | std::string pluginPath = specialConfig::ogrePluginsDirectory; |
---|
| 259 | #ifdef DEPENDENCY_PACKAGE_ENABLE |
---|
[8366] | 260 | if (!PathConfig::buildDirectoryRun()) |
---|
[8351] | 261 | { |
---|
| 262 | # if defined(ORXONOX_PLATFORM_WINDOWS) |
---|
| 263 | pluginPath = PathConfig::getExecutablePathString(); |
---|
| 264 | # elif defined(ORXONOX_PLATFORM_APPLE) |
---|
| 265 | // TODO: Where are the plugins being installed to? |
---|
| 266 | pluginPath = PathConfig::getExecutablePathString(); |
---|
| 267 | # endif |
---|
| 268 | } |
---|
| 269 | #endif |
---|
[2801] | 270 | |
---|
[8351] | 271 | #ifdef ORXONOX_PLATFORM_WINDOWS |
---|
| 272 | // Add OGRE plugin path to the environment. That way one plugin could |
---|
| 273 | // also depend on another without problems on Windows |
---|
| 274 | const char* currentPATH = getenv("PATH"); |
---|
| 275 | std::string newPATH = pluginPath; |
---|
| 276 | if (currentPATH != NULL) |
---|
| 277 | newPATH = std::string(currentPATH) + ';' + newPATH; |
---|
| 278 | putenv(const_cast<char*>(("PATH=" + newPATH).c_str())); |
---|
| 279 | #endif |
---|
| 280 | |
---|
[2801] | 281 | // Do some SubString magic to get the comma separated list of plugins |
---|
[7284] | 282 | SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '{', '}', false, '\0'); |
---|
[2801] | 283 | for (unsigned int i = 0; i < plugins.size(); ++i) |
---|
[8351] | 284 | ogreRoot_->loadPlugin(pluginPath + '/' + plugins[i]); |
---|
[2801] | 285 | } |
---|
| 286 | |
---|
| 287 | void GraphicsManager::loadRenderer() |
---|
| 288 | { |
---|
[8858] | 289 | orxout(internal_info) << "GraphicsManager: Configuring Renderer" << endl; |
---|
[2801] | 290 | |
---|
[8079] | 291 | bool updatedConfig = Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp(); |
---|
| 292 | if (updatedConfig) |
---|
[8858] | 293 | orxout(user_info)<< "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << endl; |
---|
[8079] | 294 | |
---|
| 295 | if (!ogreRoot_->restoreConfig() || updatedConfig) |
---|
[7870] | 296 | { |
---|
[2801] | 297 | if (!ogreRoot_->showConfigDialog()) |
---|
[7868] | 298 | ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue canceled."); |
---|
[7870] | 299 | else |
---|
| 300 | Core::getInstance().updateOgreConfigTimestamp(); |
---|
| 301 | } |
---|
[2801] | 302 | |
---|
[8858] | 303 | orxout(internal_info) << "Creating render window" << endl; |
---|
[2801] | 304 | |
---|
| 305 | this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox"); |
---|
[5695] | 306 | // Propagate the size of the new winodw |
---|
[3327] | 307 | this->ogreWindowEventListener_->windowResized(renderWindow_); |
---|
[2801] | 308 | |
---|
[8423] | 309 | Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_); |
---|
[2801] | 310 | |
---|
[5695] | 311 | // create a full screen default viewport |
---|
| 312 | // Note: This may throw when adding a viewport with an existing z-order! |
---|
| 313 | // But in our case we only have one viewport for now anyway, therefore |
---|
| 314 | // no ScopeGuards or anything to handle exceptions. |
---|
| 315 | this->viewport_ = this->renderWindow_->addViewport(0, 0); |
---|
| 316 | |
---|
[6524] | 317 | Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(Ogre::MIP_UNLIMITED); |
---|
[2801] | 318 | |
---|
[5695] | 319 | // add console commands |
---|
[7284] | 320 | ModifyConsoleCommand(__CC_printScreen_name).setFunction(&GraphicsManager::printScreen, this); |
---|
[8079] | 321 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).setFunction(&GraphicsManager::setScreenResolution, this); |
---|
| 322 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).setFunction(&GraphicsManager::setFSAA, this); |
---|
| 323 | ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).setFunction(&GraphicsManager::setVSync, this); |
---|
[2801] | 324 | } |
---|
| 325 | |
---|
[5929] | 326 | void GraphicsManager::loadDebugOverlay() |
---|
| 327 | { |
---|
| 328 | // Load debug overlay to show info about fps and tick time |
---|
[8858] | 329 | orxout(internal_info) << "Loading Debug Overlay..." << endl; |
---|
[5929] | 330 | debugOverlay_.reset(new XMLFile("debug.oxo")); |
---|
[8858] | 331 | Loader::open(debugOverlay_.get(), ClassTreeMask(), false); |
---|
[5929] | 332 | } |
---|
| 333 | |
---|
| 334 | /** |
---|
| 335 | @note |
---|
| 336 | A note about the Ogre::FrameListener: Even though we don't use them, |
---|
[8079] | 337 | they still get called. |
---|
[5929] | 338 | */ |
---|
[6417] | 339 | void GraphicsManager::postUpdate(const Clock& time) |
---|
[2801] | 340 | { |
---|
[8079] | 341 | // Time before rendering |
---|
| 342 | uint64_t timeBeforeTick = time.getRealMicroseconds(); |
---|
| 343 | |
---|
| 344 | // Ogre's time keeping object |
---|
[5695] | 345 | Ogre::FrameEvent evt; |
---|
| 346 | |
---|
[8079] | 347 | // Translate to Ogre float times before the update |
---|
| 348 | float temp = lastFrameStartTime_; |
---|
| 349 | lastFrameStartTime_ = (float)timeBeforeTick * 0.000001f; |
---|
| 350 | evt.timeSinceLastFrame = lastFrameStartTime_ - temp; |
---|
| 351 | evt.timeSinceLastEvent = lastFrameStartTime_ - lastFrameEndTime_; |
---|
| 352 | |
---|
| 353 | // Ogre requires the time too |
---|
[5695] | 354 | ogreRoot_->_fireFrameStarted(evt); |
---|
| 355 | |
---|
| 356 | // Pump messages in all registered RenderWindows |
---|
| 357 | // This calls the WindowEventListener objects. |
---|
| 358 | Ogre::WindowEventUtilities::messagePump(); |
---|
[8079] | 359 | // Make sure the window stays active even when not focused |
---|
[5695] | 360 | // (probably only necessary on windows) |
---|
| 361 | this->renderWindow_->setActive(true); |
---|
| 362 | |
---|
| 363 | // Render frame |
---|
| 364 | ogreRoot_->_updateAllRenderTargets(); |
---|
| 365 | |
---|
| 366 | uint64_t timeAfterTick = time.getRealMicroseconds(); |
---|
| 367 | // Subtract the time used for rendering from the tick time counter |
---|
[6502] | 368 | Game::getInstance().subtractTickTime((int32_t)(timeAfterTick - timeBeforeTick)); |
---|
[5695] | 369 | |
---|
[8079] | 370 | // Translate to Ogre float times after the update |
---|
| 371 | temp = lastFrameEndTime_; |
---|
| 372 | lastFrameEndTime_ = (float)timeBeforeTick * 0.000001f; |
---|
| 373 | evt.timeSinceLastFrame = lastFrameEndTime_ - temp; |
---|
| 374 | evt.timeSinceLastEvent = lastFrameEndTime_ - lastFrameStartTime_; |
---|
| 375 | |
---|
| 376 | // Ogre also needs the time after the frame finished |
---|
| 377 | ogreRoot_->_fireFrameEnded(evt); |
---|
[2801] | 378 | } |
---|
| 379 | |
---|
[5695] | 380 | void GraphicsManager::setCamera(Ogre::Camera* camera) |
---|
| 381 | { |
---|
[8079] | 382 | Ogre::Camera* oldCamera = this->viewport_->getCamera(); |
---|
| 383 | |
---|
[5695] | 384 | this->viewport_->setCamera(camera); |
---|
[8079] | 385 | GUIManager::getInstance().setCamera(camera); |
---|
| 386 | |
---|
| 387 | for (ObjectList<ViewportEventListener>::iterator it = ObjectList<ViewportEventListener>::begin(); it != ObjectList<ViewportEventListener>::end(); ++it) |
---|
| 388 | it->cameraChanged(this->viewport_, oldCamera); |
---|
[5695] | 389 | } |
---|
| 390 | |
---|
[2801] | 391 | /** |
---|
| 392 | @brief |
---|
| 393 | Method called by the LogListener interface from Ogre. |
---|
| 394 | We use it to capture Ogre log messages and handle it ourselves. |
---|
| 395 | @param message |
---|
| 396 | The message to be logged |
---|
| 397 | @param lml |
---|
| 398 | The message level the log is using |
---|
| 399 | @param maskDebug |
---|
| 400 | If we are printing to the console or not |
---|
| 401 | @param logName |
---|
| 402 | The name of this log (so you can have several listeners |
---|
| 403 | for different logs, and identify them) |
---|
| 404 | */ |
---|
| 405 | void GraphicsManager::messageLogged(const std::string& message, |
---|
| 406 | Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName) |
---|
| 407 | { |
---|
[8858] | 408 | OutputLevel orxonoxLevel; |
---|
[6417] | 409 | std::string introduction; |
---|
| 410 | // Do not show caught OGRE exceptions in front |
---|
| 411 | if (message.find("EXCEPTION") != std::string::npos) |
---|
[2801] | 412 | { |
---|
[8858] | 413 | orxonoxLevel = level::internal_error; |
---|
[6417] | 414 | introduction = "Ogre, caught exception: "; |
---|
[2801] | 415 | } |
---|
[6417] | 416 | else |
---|
| 417 | { |
---|
| 418 | switch (lml) |
---|
| 419 | { |
---|
| 420 | case Ogre::LML_TRIVIAL: |
---|
[8858] | 421 | orxonoxLevel = level::verbose_more; |
---|
[6417] | 422 | break; |
---|
| 423 | case Ogre::LML_NORMAL: |
---|
[8858] | 424 | orxonoxLevel = level::verbose; |
---|
[6417] | 425 | break; |
---|
| 426 | case Ogre::LML_CRITICAL: |
---|
[8858] | 427 | orxonoxLevel = level::internal_warning; |
---|
[6417] | 428 | break; |
---|
| 429 | default: |
---|
[8858] | 430 | orxonoxLevel = level::debug_output; |
---|
[6417] | 431 | } |
---|
| 432 | introduction = "Ogre: "; |
---|
| 433 | } |
---|
[8858] | 434 | |
---|
| 435 | orxout(orxonoxLevel, context::ogre) << introduction << message << endl; |
---|
[2801] | 436 | } |
---|
| 437 | |
---|
[5695] | 438 | size_t GraphicsManager::getRenderWindowHandle() |
---|
| 439 | { |
---|
| 440 | size_t windowHnd = 0; |
---|
| 441 | renderWindow_->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 442 | return windowHnd; |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | bool GraphicsManager::isFullScreen() const |
---|
| 446 | { |
---|
[8079] | 447 | return this->renderWindow_->isFullScreen(); |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | unsigned int GraphicsManager::getWindowWidth() const |
---|
| 451 | { |
---|
| 452 | return this->renderWindow_->getWidth(); |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | unsigned int GraphicsManager::getWindowHeight() const |
---|
| 456 | { |
---|
| 457 | return this->renderWindow_->getHeight(); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | bool GraphicsManager::hasVSyncEnabled() const |
---|
| 461 | { |
---|
[5695] | 462 | Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); |
---|
[8079] | 463 | Ogre::ConfigOptionMap::iterator it = options.find("VSync"); |
---|
| 464 | if (it != options.end()) |
---|
| 465 | return (it->second.currentValue == "Yes"); |
---|
| 466 | else |
---|
| 467 | return false; |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | std::string GraphicsManager::getFSAAMode() const |
---|
| 471 | { |
---|
| 472 | Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); |
---|
| 473 | Ogre::ConfigOptionMap::iterator it = options.find("FSAA"); |
---|
| 474 | if (it != options.end()) |
---|
| 475 | return it->second.currentValue; |
---|
| 476 | else |
---|
| 477 | return ""; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | std::string GraphicsManager::setScreenResolution(unsigned int width, unsigned int height, bool fullscreen) |
---|
| 481 | { |
---|
| 482 | // workaround to detect if the colour depth should be written to the config file |
---|
| 483 | bool bWriteColourDepth = false; |
---|
| 484 | Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); |
---|
| 485 | Ogre::ConfigOptionMap::iterator it = options.find("Video Mode"); |
---|
| 486 | if (it != options.end()) |
---|
| 487 | bWriteColourDepth = (it->second.currentValue.find('@') != std::string::npos); |
---|
| 488 | |
---|
| 489 | if (bWriteColourDepth) |
---|
[5695] | 490 | { |
---|
[8079] | 491 | this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width) |
---|
| 492 | + " x " + multi_cast<std::string>(height) |
---|
| 493 | + " @ " + multi_cast<std::string>(this->getRenderWindow()->getColourDepth()) + "-bit colour"); |
---|
[5695] | 494 | } |
---|
| 495 | else |
---|
| 496 | { |
---|
[8079] | 497 | this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width) |
---|
| 498 | + " x " + multi_cast<std::string>(height)); |
---|
[5695] | 499 | } |
---|
[8079] | 500 | |
---|
| 501 | this->ogreRoot_->getRenderSystem()->setConfigOption("Full Screen", fullscreen ? "Yes" : "No"); |
---|
| 502 | |
---|
| 503 | std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); |
---|
| 504 | |
---|
| 505 | if (validate == "") |
---|
| 506 | { |
---|
| 507 | GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height); |
---|
| 508 | this->ogreRoot_->saveConfig(); |
---|
| 509 | Core::getInstance().updateOgreConfigTimestamp(); |
---|
| 510 | // Also reload the input devices |
---|
| 511 | InputManager::getInstance().reload(); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | return validate; |
---|
[5695] | 515 | } |
---|
| 516 | |
---|
[8079] | 517 | std::string GraphicsManager::setFSAA(const std::string& mode) |
---|
| 518 | { |
---|
| 519 | this->ogreRoot_->getRenderSystem()->setConfigOption("FSAA", mode); |
---|
| 520 | |
---|
| 521 | std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); |
---|
| 522 | |
---|
| 523 | if (validate == "") |
---|
| 524 | { |
---|
| 525 | //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ |
---|
| 526 | this->ogreRoot_->saveConfig(); |
---|
| 527 | Core::getInstance().updateOgreConfigTimestamp(); |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | return validate; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | std::string GraphicsManager::setVSync(bool vsync) |
---|
| 534 | { |
---|
| 535 | this->ogreRoot_->getRenderSystem()->setConfigOption("VSync", vsync ? "Yes" : "No"); |
---|
| 536 | |
---|
| 537 | std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); |
---|
| 538 | |
---|
| 539 | if (validate == "") |
---|
| 540 | { |
---|
| 541 | //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ |
---|
| 542 | this->ogreRoot_->saveConfig(); |
---|
| 543 | Core::getInstance().updateOgreConfigTimestamp(); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | return validate; |
---|
| 547 | } |
---|
| 548 | |
---|
[2801] | 549 | void GraphicsManager::printScreen() |
---|
| 550 | { |
---|
| 551 | assert(this->renderWindow_); |
---|
[6417] | 552 | this->renderWindow_->writeContentsToTimestampedFile(PathConfig::getLogPathString() + "screenShot_", ".png"); |
---|
[2801] | 553 | } |
---|
[612] | 554 | } |
---|