Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/GraphicsManager.cc @ 11772

Last change on this file since 11772 was 11115, checked in by landauf, 9 years ago

fixed code to compile in 64bit mode

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