Changeset 8079 for code/trunk/src/libraries/core/GraphicsManager.cc
- Timestamp:
- Mar 15, 2011, 9:47:11 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/GraphicsManager.cc
r7874 r8079 49 49 #include "SpecialConfig.h" 50 50 #include "util/Clock.h" 51 #include "util/Convert.h" 51 52 #include "util/Exception.h" 52 53 #include "util/StringUtils.h" … … 57 58 #include "Game.h" 58 59 #include "GameMode.h" 60 #include "GUIManager.h" 59 61 #include "Loader.h" 60 62 #include "MemoryArchive.h" 61 63 #include "PathConfig.h" 64 #include "ViewportEventListener.h" 62 65 #include "WindowEventListener.h" 63 66 #include "XMLFile.h" 64 67 #include "command/ConsoleCommand.h" 68 #include "input/InputManager.h" 65 69 66 70 namespace orxonox 67 71 { 72 static const std::string __CC_GraphicsManager_group = "GraphicsManager"; 73 static const std::string __CC_setScreenResolution_name = "setScreenResolution"; 74 static const std::string __CC_setFSAA_name = "setFSAA"; 75 static const std::string __CC_setVSync_name = "setVSync"; 76 DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name, &prototype::string__uint_uint_bool); 77 DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name, &prototype::string__string); 78 DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name, &prototype::string__bool); 79 68 80 static const std::string __CC_printScreen_name = "printScreen"; 69 81 DeclareConsoleCommand(__CC_printScreen_name, &prototype::void__void); … … 95 107 , renderWindow_(0) 96 108 , viewport_(0) 109 , lastFrameStartTime_(0.0f) 110 , lastFrameEndTime_(0.0f) 97 111 { 98 112 RegisterObject(GraphicsManager); … … 136 150 Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get()); 137 151 ModifyConsoleCommand(__CC_printScreen_name).resetFunction(); 152 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction(); 153 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).resetFunction(); 154 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).resetFunction(); 138 155 139 156 // Undeclare the resources … … 304 321 CCOUT(4) << "Configuring Renderer" << std::endl; 305 322 306 if (!ogreRoot_->restoreConfig() || Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp()) 323 bool updatedConfig = Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp(); 324 if (updatedConfig) 325 COUT(2) << "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << std::endl; 326 327 if (!ogreRoot_->restoreConfig() || updatedConfig) 307 328 { 308 329 if (!ogreRoot_->showConfigDialog()) … … 330 351 // add console commands 331 352 ModifyConsoleCommand(__CC_printScreen_name).setFunction(&GraphicsManager::printScreen, this); 353 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).setFunction(&GraphicsManager::setScreenResolution, this); 354 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).setFunction(&GraphicsManager::setFSAA, this); 355 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).setFunction(&GraphicsManager::setVSync, this); 332 356 } 333 357 … … 343 367 @note 344 368 A note about the Ogre::FrameListener: Even though we don't use them, 345 they still get called. However, the delta times are not correct (except 346 for timeSinceLastFrame, which is the most important). A little research 347 as shown that there is probably only one FrameListener that doesn't even 348 need the time. So we shouldn't run into problems. 369 they still get called. 349 370 */ 350 371 void GraphicsManager::postUpdate(const Clock& time) 351 372 { 373 // Time before rendering 374 uint64_t timeBeforeTick = time.getRealMicroseconds(); 375 376 // Ogre's time keeping object 352 377 Ogre::FrameEvent evt; 353 evt.timeSinceLastFrame = time.getDeltaTime(); 354 evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway 355 356 // don't forget to call _fireFrameStarted to OGRE to make sure 357 // everything goes smoothly 378 379 // Translate to Ogre float times before the update 380 float temp = lastFrameStartTime_; 381 lastFrameStartTime_ = (float)timeBeforeTick * 0.000001f; 382 evt.timeSinceLastFrame = lastFrameStartTime_ - temp; 383 evt.timeSinceLastEvent = lastFrameStartTime_ - lastFrameEndTime_; 384 385 // Ogre requires the time too 358 386 ogreRoot_->_fireFrameStarted(evt); 359 387 … … 361 389 // This calls the WindowEventListener objects. 362 390 Ogre::WindowEventUtilities::messagePump(); 363 // make sure the window stays active even when not focused391 // Make sure the window stays active even when not focused 364 392 // (probably only necessary on windows) 365 393 this->renderWindow_->setActive(true); 366 367 // Time before rendering368 uint64_t timeBeforeTick = time.getRealMicroseconds();369 394 370 395 // Render frame … … 375 400 Game::getInstance().subtractTickTime((int32_t)(timeAfterTick - timeBeforeTick)); 376 401 377 // again, just to be sure OGRE works fine 378 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 402 // Translate to Ogre float times after the update 403 temp = lastFrameEndTime_; 404 lastFrameEndTime_ = (float)timeBeforeTick * 0.000001f; 405 evt.timeSinceLastFrame = lastFrameEndTime_ - temp; 406 evt.timeSinceLastEvent = lastFrameEndTime_ - lastFrameStartTime_; 407 408 // Ogre also needs the time after the frame finished 409 ogreRoot_->_fireFrameEnded(evt); 379 410 } 380 411 381 412 void GraphicsManager::setCamera(Ogre::Camera* camera) 382 413 { 414 Ogre::Camera* oldCamera = this->viewport_->getCamera(); 415 383 416 this->viewport_->setCamera(camera); 417 GUIManager::getInstance().setCamera(camera); 418 419 for (ObjectList<ViewportEventListener>::iterator it = ObjectList<ViewportEventListener>::begin(); it != ObjectList<ViewportEventListener>::end(); ++it) 420 it->cameraChanged(this->viewport_, oldCamera); 384 421 } 385 422 … … 440 477 bool GraphicsManager::isFullScreen() const 441 478 { 479 return this->renderWindow_->isFullScreen(); 480 } 481 482 unsigned int GraphicsManager::getWindowWidth() const 483 { 484 return this->renderWindow_->getWidth(); 485 } 486 487 unsigned int GraphicsManager::getWindowHeight() const 488 { 489 return this->renderWindow_->getHeight(); 490 } 491 492 bool GraphicsManager::hasVSyncEnabled() const 493 { 442 494 Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); 443 if (options.find("Full Screen") != options.end()) 444 { 445 if (options["Full Screen"].currentValue == "Yes") 446 return true; 447 else 448 return false; 449 } 495 Ogre::ConfigOptionMap::iterator it = options.find("VSync"); 496 if (it != options.end()) 497 return (it->second.currentValue == "Yes"); 450 498 else 451 {452 COUT(0) << "Could not find 'Full Screen' render system option. Fix This!!!" << std::endl;453 499 return false; 454 } 500 } 501 502 std::string GraphicsManager::getFSAAMode() const 503 { 504 Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); 505 Ogre::ConfigOptionMap::iterator it = options.find("FSAA"); 506 if (it != options.end()) 507 return it->second.currentValue; 508 else 509 return ""; 510 } 511 512 std::string GraphicsManager::setScreenResolution(unsigned int width, unsigned int height, bool fullscreen) 513 { 514 // workaround to detect if the colour depth should be written to the config file 515 bool bWriteColourDepth = false; 516 Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions(); 517 Ogre::ConfigOptionMap::iterator it = options.find("Video Mode"); 518 if (it != options.end()) 519 bWriteColourDepth = (it->second.currentValue.find('@') != std::string::npos); 520 521 if (bWriteColourDepth) 522 { 523 this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width) 524 + " x " + multi_cast<std::string>(height) 525 + " @ " + multi_cast<std::string>(this->getRenderWindow()->getColourDepth()) + "-bit colour"); 526 } 527 else 528 { 529 this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width) 530 + " x " + multi_cast<std::string>(height)); 531 } 532 533 this->ogreRoot_->getRenderSystem()->setConfigOption("Full Screen", fullscreen ? "Yes" : "No"); 534 535 std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); 536 537 if (validate == "") 538 { 539 GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height); 540 this->ogreRoot_->saveConfig(); 541 Core::getInstance().updateOgreConfigTimestamp(); 542 // Also reload the input devices 543 InputManager::getInstance().reload(); 544 } 545 546 return validate; 547 } 548 549 std::string GraphicsManager::setFSAA(const std::string& mode) 550 { 551 this->ogreRoot_->getRenderSystem()->setConfigOption("FSAA", mode); 552 553 std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); 554 555 if (validate == "") 556 { 557 //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ 558 this->ogreRoot_->saveConfig(); 559 Core::getInstance().updateOgreConfigTimestamp(); 560 } 561 562 return validate; 563 } 564 565 std::string GraphicsManager::setVSync(bool vsync) 566 { 567 this->ogreRoot_->getRenderSystem()->setConfigOption("VSync", vsync ? "Yes" : "No"); 568 569 std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions(); 570 571 if (validate == "") 572 { 573 //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ 574 this->ogreRoot_->saveConfig(); 575 Core::getInstance().updateOgreConfigTimestamp(); 576 } 577 578 return validate; 455 579 } 456 580
Note: See TracChangeset
for help on using the changeset viewer.