From c27ff546e4c5ae4975dfda6f7f13dbaddea65843 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 2 Sep 2012 19:40:26 +0200 Subject: [PATCH] shader cache --- apps/openmw/engine.cpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 12 ++++++++++-- apps/openmw/mwrender/renderingmanager.hpp | 3 ++- apps/openmw/mwworld/worldimp.cpp | 4 ++-- apps/openmw/mwworld/worldimp.hpp | 2 +- components/files/configurationmanager.cpp | 5 +++++ components/files/configurationmanager.hpp | 2 ++ components/files/fixedpath.hpp | 9 +++++++++ components/files/linuxpath.cpp | 23 +++++++++++++++++++++++ components/files/linuxpath.hpp | 7 +++++++ components/files/macospath.cpp | 21 +++++++++++++++++++++ components/files/macospath.hpp | 7 +++++++ components/files/windowspath.cpp | 5 +++++ components/files/windowspath.hpp | 7 +++++++ extern/shiny | 2 +- 15 files changed, 103 insertions(+), 8 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3de4ba8ac..171fcde7c 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -325,7 +325,7 @@ void OMW::Engine::go() // Create the world mEnvironment.setWorld (new MWWorld::World (*mOgre, mFileCollections, mMaster, - mResDir, mNewGame, mEncoding, mFallbackMap)); + mResDir, mCfgMgr.getCachePath(), mNewGame, mEncoding, mFallbackMap)); // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index edeb0fe12..e983353cb 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -40,7 +40,8 @@ using namespace Ogre; namespace MWRender { -RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, + const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine) :mRendering(_rend), mObjects(mRendering), mActors(mRendering), mAmbientMode(0), mSunEnabled(0), mPhysicsEngine(engine) { // select best shader mode @@ -63,7 +64,9 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const // material system sh::OgrePlatform* platform = new sh::OgrePlatform("General", (resDir / "materials").string()); - platform->setCacheFolder ("./"); + if (!boost::filesystem::exists (cacheDir)) + boost::filesystem::create_directory (cacheDir); + platform->setCacheFolder (cacheDir.string()); mFactory = new sh::Factory(platform); sh::Language lang; @@ -75,6 +78,11 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const else lang = sh::Language_CG; mFactory->setCurrentLanguage (lang); + mFactory->setWriteSourceCache (true); + mFactory->setReadSourceCache (true); + mFactory->setReadMicrocodeCache (true); + mFactory->setWriteMicrocodeCache (true); + mFactory->loadAllFiles(); // Set default mipmap level (NB some APIs ignore this) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index de2449150..e5be238bd 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -53,7 +53,8 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList virtual MWRender::Actors& getActors(); public: - RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, + const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine); virtual ~RenderingManager(); void togglePOV() { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 968aa8cee..869ce94d1 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -164,7 +164,7 @@ namespace MWWorld World::World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, - const std::string& master, const boost::filesystem::path& resDir, bool newGame, + const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame, const std::string& encoding, std::map fallbackMap) : mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (true), mNextDynamicRecord (0), mCells (mStore, mEsm), @@ -173,7 +173,7 @@ namespace MWWorld mPhysics = new PhysicsSystem(renderer); mPhysEngine = mPhysics->getEngine(); - mRendering = new MWRender::RenderingManager(renderer, resDir, mPhysEngine); + mRendering = new MWRender::RenderingManager(renderer, resDir, cacheDir, mPhysEngine); mWeatherManager = new MWWorld::WeatherManager(mRendering); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 1d932bce2..6279343d4 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -96,7 +96,7 @@ namespace MWWorld World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, - const std::string& master, const boost::filesystem::path& resDir, bool newGame, + const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame, const std::string& encoding, std::map fallbackMap); virtual ~World(); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index ef810fb06..56e55a98d 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -147,6 +147,11 @@ const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const return mFixedPath.getGlobalDataPath(); } +const boost::filesystem::path& ConfigurationManager::getCachePath() const +{ + return mFixedPath.getCachePath(); +} + const boost::filesystem::path& ConfigurationManager::getInstallPath() const { return mFixedPath.getInstallPath(); diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index ecbfac664..9056e792d 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -40,6 +40,8 @@ struct ConfigurationManager const boost::filesystem::path& getLocalDataPath() const; const boost::filesystem::path& getInstallPath() const; + const boost::filesystem::path& getCachePath() const; + const boost::filesystem::path& getLogPath() const; private: diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 9e5c4f8f2..3c1f6d801 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -75,6 +75,7 @@ struct FixedPath , mLocalPath(mPath.getLocalPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) , mInstallPath(mPath.getInstallPath()) + , mCachePath(mPath.getCachePath()) { if (!application_name.empty()) { @@ -83,6 +84,7 @@ struct FixedPath mUserPath /= suffix; mGlobalPath /= suffix; mGlobalDataPath /= suffix; + mCachePath /= suffix; } } @@ -126,6 +128,11 @@ struct FixedPath return mGlobalDataPath; } + const boost::filesystem::path& getCachePath() const + { + return mCachePath; + } + private: PathType mPath; @@ -135,6 +142,8 @@ struct FixedPath boost::filesystem::path mGlobalDataPath; /**< Global application data path */ + boost::filesystem::path mCachePath; + boost::filesystem::path mInstallPath; }; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 92e4dce33..8009fd3e8 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -62,6 +62,29 @@ boost::filesystem::path LinuxPath::getUserPath() const return userPath; } +boost::filesystem::path LinuxPath::getCachePath() const +{ + boost::filesystem::path userPath("."); + + const char* theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + + if (theDir != NULL) + { + userPath = boost::filesystem::path(theDir); + } + userPath /= "/.cache/"; + + return userPath; +} + boost::filesystem::path LinuxPath::getGlobalPath() const { boost::filesystem::path globalPath("/etc/"); diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 48fdbb2ff..ce339a5bf 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -67,6 +67,13 @@ struct LinuxPath */ boost::filesystem::path getGlobalDataPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getCachePath() const; + /** * \brief Gets the path of the installed Morrowind version if there is one. * diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 94dafe794..bbd1dbcdd 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -69,6 +69,27 @@ boost::filesystem::path MacOsPath::getGlobalPath() const return globalPath; } +boost::filesystem::path MacOsPath::getCachePath() const +{ + boost::filesystem::path userPath("."); + + const char* theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + if (theDir != NULL) + { + userPath = boost::filesystem::path(theDir) / "Library/Caches/"; + } + + return userPath; +} + boost::filesystem::path MacOsPath::getLocalPath() const { return boost::filesystem::path("./"); diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 0e9b3402e..0e9136078 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -60,6 +60,13 @@ struct MacOsPath */ boost::filesystem::path getLocalPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getCachePath() const; + /** * \brief * diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index dfa8f20cc..744ad8ce8 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -67,6 +67,11 @@ boost::filesystem::path WindowsPath::getGlobalDataPath() const return getGlobalPath(); } +boost::filesystem::path WindowsPath::getCachePath() const +{ + return getUserPath() / "/cache"; +} + boost::filesystem::path WindowsPath::getInstallPath() const { boost::filesystem::path installPath(""); diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index d4c716c50..fa010730e 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -61,6 +61,13 @@ struct WindowsPath */ boost::filesystem::path getLocalPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getCachePath() const; + /** * \brief Return same path like getGlobalPath * diff --git a/extern/shiny b/extern/shiny index 164bc8d3b..278c6952b 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 164bc8d3bfe860bd16ad89c0bd1b59f465c9bb24 +Subproject commit 278c6952b5c38e4b2a10205953e379598fad71a0