From cac288d5be337758005ca9b2583821e8f5f3665f Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 1 May 2015 21:49:36 +0200 Subject: [PATCH] Remove OgreInit --- apps/launcher/graphicspage.cpp | 121 +---------------- apps/launcher/graphicspage.hpp | 13 -- components/CMakeLists.txt | 4 - components/ogreinit/ogreinit.cpp | 210 ----------------------------- components/ogreinit/ogreinit.hpp | 78 ----------- components/ogreinit/ogreplugin.cpp | 45 ------- components/ogreinit/ogreplugin.hpp | 42 ------ files/settings-default.cfg | 7 - 8 files changed, 1 insertion(+), 519 deletions(-) delete mode 100644 components/ogreinit/ogreinit.cpp delete mode 100644 components/ogreinit/ogreinit.hpp delete mode 100644 components/ogreinit/ogreplugin.cpp delete mode 100644 components/ogreinit/ogreplugin.hpp diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index cdb51348c..cb3a3e7cb 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -12,9 +12,6 @@ #include -#include -#include - #include #include @@ -36,11 +33,7 @@ QString getAspect(int x, int y) } Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSetting, QWidget *parent) - : mOgre(NULL) - , mSelectedRenderSystem(NULL) - , mOpenGLRenderSystem(NULL) - , mDirect3DRenderSystem(NULL) - , mCfgMgr(cfg) + : mCfgMgr(cfg) , mGraphicsSettings(graphicsSetting) , QWidget(parent) { @@ -52,79 +45,12 @@ Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsS customWidthSpinBox->setMaximum(res.width()); customHeightSpinBox->setMaximum(res.height()); - connect(rendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int))); connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); connect(screenComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(screenChanged(int))); } -bool Launcher::GraphicsPage::setupOgre() -{ - try - { - mOgre = mOgreInit.init(mCfgMgr.getLogPath().string() + "/launcherOgre.log"); - } - catch(Ogre::Exception &ex) - { - QString ogreError = QString::fromUtf8(ex.getFullDescription().c_str()); - QMessageBox msgBox; - msgBox.setWindowTitle("Error creating Ogre::Root"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Failed to create the Ogre::Root object

\ - Press \"Show Details...\" for more information.
")); - msgBox.setDetailedText(ogreError); - msgBox.exec(); - - qCritical("Error creating Ogre::Root, the error reported was:\n %s", qPrintable(ogreError)); - return false; - } - - // Get the available renderers and put them in the combobox - const Ogre::RenderSystemList &renderers = mOgre->getAvailableRenderers(); - - for (Ogre::RenderSystemList::const_iterator r = renderers.begin(); r != renderers.end(); ++r) { - mSelectedRenderSystem = *r; - rendererComboBox->addItem((*r)->getName().c_str()); - } - - QString openGLName = QString("OpenGL Rendering Subsystem"); - QString direct3DName = QString("Direct3D9 Rendering Subsystem"); - - // Create separate rendersystems - mOpenGLRenderSystem = mOgre->getRenderSystemByName(openGLName.toStdString()); - mDirect3DRenderSystem = mOgre->getRenderSystemByName(direct3DName.toStdString()); - - if (!mOpenGLRenderSystem && !mDirect3DRenderSystem) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error creating renderer")); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not select a valid render system

\ - Please make sure Ogre plugins were installed correctly.
")); - msgBox.exec(); - return false; - } - - // Now fill the GUI elements - int index = rendererComboBox->findText(mGraphicsSettings.value(QString("Video/render system"))); - if ( index != -1) { - rendererComboBox->setCurrentIndex(index); - } else { -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - rendererComboBox->setCurrentIndex(rendererComboBox->findText(direct3DName)); -#else - rendererComboBox->setCurrentIndex(rendererComboBox->findText(openGLName)); -#endif - } - - antiAliasingComboBox->clear(); - antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); - - return true; -} - bool Launcher::GraphicsPage::setupSDL() { int displays = SDL_GetNumVideoDisplays(); @@ -153,8 +79,6 @@ bool Launcher::GraphicsPage::loadSettings() { if (!setupSDL()) return false; - if (!mOgre && !setupOgre()) - return false; if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true")) vSyncCheckBox->setCheckState(Qt::Checked); @@ -203,7 +127,6 @@ void Launcher::GraphicsPage::saveSettings() : mGraphicsSettings.setValue(QString("Video/window border"), QString("false")); mGraphicsSettings.setValue(QString("Video/antialiasing"), antiAliasingComboBox->currentText()); - mGraphicsSettings.setValue(QString("Video/render system"), rendererComboBox->currentText()); if (standardRadioButton->isChecked()) { @@ -221,39 +144,6 @@ void Launcher::GraphicsPage::saveSettings() mGraphicsSettings.setValue(QString("Video/screen"), QString::number(screenComboBox->currentIndex())); } -QStringList Launcher::GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer) -{ - QStringList result; - - uint row = 0; - Ogre::ConfigOptionMap options = renderer->getConfigOptions(); - - for (Ogre::ConfigOptionMap::iterator i = options.begin (); i != options.end (); ++i, ++row) - { - Ogre::StringVector::iterator opt_it; - uint idx = 0; - - for (opt_it = i->second.possibleValues.begin(); - opt_it != i->second.possibleValues.end(); ++opt_it, ++idx) - { - if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) { - result << ((key == "FSAA") ? QString("MSAA ") : QString("")) + QString::fromUtf8((*opt_it).c_str()).simplified(); - } - } - } - - // Sort ascending - qSort(result.begin(), result.end(), naturalSortLessThanCI); - - // Replace the zero option with Off - int index = result.indexOf("MSAA 0"); - - if (index != -1) - result.replace(index, tr("Off")); - - return result; -} - QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) { QStringList result; @@ -316,15 +206,6 @@ QRect Launcher::GraphicsPage::getMaximumResolution() return max; } -void Launcher::GraphicsPage::rendererChanged(const QString &renderer) -{ - mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); - - antiAliasingComboBox->clear(); - - antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); -} - void Launcher::GraphicsPage::screenChanged(int screen) { if (screen >= 0) { diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 213b6bccb..fb96c39d7 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -3,12 +3,8 @@ #include -#include - #include "ui_graphicspage.h" -namespace Ogre { class Root; class RenderSystem; } - namespace Files { struct ConfigurationManager; } namespace Launcher @@ -26,7 +22,6 @@ namespace Launcher bool loadSettings(); public slots: - void rendererChanged(const QString &renderer); void screenChanged(int screen); private slots: @@ -34,20 +29,12 @@ namespace Launcher void slotStandardToggled(bool checked); private: - OgreInit::OgreInit mOgreInit; - Ogre::Root *mOgre; - Ogre::RenderSystem *mSelectedRenderSystem; - Ogre::RenderSystem *mOpenGLRenderSystem; - Ogre::RenderSystem *mDirect3DRenderSystem; - Files::ConfigurationManager &mCfgMgr; GraphicsSettings &mGraphicsSettings; - QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); QStringList getAvailableResolutions(int screen); QRect getMaximumResolution(); - bool setupOgre(); bool setupSDL(); }; } diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 9ec648381..1f9bd337b 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -114,10 +114,6 @@ add_component_dir (loadinglistener loadinglistener ) -add_component_dir (ogreinit - ogreinit ogreplugin - ) - add_component_dir (myguiplatform myguirendermanager myguidatamanager myguiplatform myguitexture myguiloglistener ) diff --git a/components/ogreinit/ogreinit.cpp b/components/ogreinit/ogreinit.cpp deleted file mode 100644 index e8ca2e8bd..000000000 --- a/components/ogreinit/ogreinit.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "ogreinit.hpp" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE -#include -#endif - -#include -#include - -#include "ogreplugin.hpp" - - -namespace bfs = boost::filesystem; - -namespace -{ - /** \brief Custom Ogre::LogListener interface implementation being - able to portably handle UTF-8 encoded path. - - Effectively this is used in conjunction with default listener, - but since on every message messageLogged() set 'skip' flag to - true, there should be no troubles sharing same file. - */ - class LogListener : public Ogre::LogListener - { - bfs::ofstream file; - char buffer[16]; - - - public: - - LogListener(const std::string &path) - : file((bfs::path(path))) - { - memset(buffer, 0, sizeof(buffer)); - } - - void timestamp() - { - int local = time(0) % 86400; - int sec = local % 60; - int min = (local / 60) % 60; - int hrs = local / 3600; - sprintf(buffer, "%02d:%02d:%02d: ", hrs, min, sec); - } - - virtual void messageLogged(const std::string &msg, Ogre::LogMessageLevel lvl, bool mask, const std::string &logName, bool &skip) - { - timestamp(); - file << buffer << msg << std::endl; - skip = true; - } - }; -} - -namespace OgreInit -{ - - OgreInit::OgreInit() - : mRoot(NULL) - #ifdef ENABLE_PLUGIN_CgProgramManager - , mCgPlugin(NULL) - #endif - #ifdef ENABLE_PLUGIN_OctreeSceneManager - , mOctreePlugin(NULL) - #endif - #ifdef ENABLE_PLUGIN_ParticleFX - , mParticleFXPlugin(NULL) - #endif - #ifdef ENABLE_PLUGIN_GL - , mGLPlugin(NULL) - #endif - #ifdef ENABLE_PLUGIN_GLES2 - , mGLES2Plugin(NULL) - #endif - - #ifdef ENABLE_PLUGIN_Direct3D9 - , mD3D9Plugin(NULL) - #endif - {} - - Ogre::Root* OgreInit::init(const std::string &logPath) - { - if (mRoot) - throw std::runtime_error("OgreInit was already initialised"); - - #ifndef ANDROID - // Set up logging first - new Ogre::LogManager; - Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath); - - #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - // Use custom listener only on Windows - log->addListener(new LogListener(logPath)); - #endif - - // Disable logging to cout/cerr - log->setDebugOutputEnabled(false); - #endif - mRoot = new Ogre::Root("", "", ""); - - #if defined(ENABLE_PLUGIN_GL) || (ENABLE_PLUGIN_GLES2) || defined(ENABLE_PLUGIN_Direct3D9) || defined(ENABLE_PLUGIN_CgProgramManager) || defined(ENABLE_PLUGIN_OctreeSceneManager) || defined(ENABLE_PLUGIN_ParticleFX) - loadStaticPlugins(); - #else - loadPlugins(); - #endif - - return mRoot; - } - - OgreInit::~OgreInit() - { - delete mRoot; - delete Ogre::LogManager::getSingletonPtr(); - - #ifdef ENABLE_PLUGIN_GL - delete mGLPlugin; - mGLPlugin = NULL; - #endif - #ifdef ENABLE_PLUGIN_GLES2 - delete mGLES2Plugin; - mGLES2Plugin = NULL; - #endif - #ifdef ENABLE_PLUGIN_Direct3D9 - delete mD3D9Plugin; - mD3D9Plugin = NULL; - #endif - #ifdef ENABLE_PLUGIN_CgProgramManager - delete mCgPlugin; - mCgPlugin = NULL; - #endif - #ifdef ENABLE_PLUGIN_OctreeSceneManager - delete mOctreePlugin; - mOctreePlugin = NULL; - #endif - #ifdef ENABLE_PLUGIN_ParticleFX - delete mParticleFXPlugin; - mParticleFXPlugin = NULL; - #endif - } - - void OgreInit::loadStaticPlugins() - { - #ifdef ENABLE_PLUGIN_GL - mGLPlugin = new Ogre::GLPlugin(); - mRoot->installPlugin(mGLPlugin); - #endif - #ifdef ENABLE_PLUGIN_GLES2 - mGLES2Plugin = new Ogre::GLES2Plugin(); - mRoot->installPlugin(mGLES2Plugin); - #endif - #ifdef ENABLE_PLUGIN_Direct3D9 - mD3D9Plugin = new Ogre::D3D9Plugin(); - mRoot->installPlugin(mD3D9Plugin); - #endif - #ifdef ENABLE_PLUGIN_CgProgramManager - mCgPlugin = new Ogre::CgPlugin(); - mRoot->installPlugin(mCgPlugin); - #endif - #ifdef ENABLE_PLUGIN_OctreeSceneManager - mOctreePlugin = new Ogre::OctreePlugin(); - mRoot->installPlugin(mOctreePlugin); - #endif - #ifdef ENABLE_PLUGIN_ParticleFX - mParticleFXPlugin = new Ogre::ParticleFXPlugin(); - mRoot->installPlugin(mParticleFXPlugin); - #endif - } - - void OgreInit::loadPlugins() - { - std::string pluginDir; - const char* pluginEnv = getenv("OPENMW_OGRE_PLUGIN_DIR"); - if (pluginEnv) - pluginDir = pluginEnv; - else - { - #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - pluginDir = ".\\"; - #endif - #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE - pluginDir = OGRE_PLUGIN_DIR; - // if path is not specified try to find plugins inside the app bundle - if (pluginDir.empty()) - pluginDir = Ogre::macFrameworksPath(); - #endif - #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX - pluginDir = OGRE_PLUGIN_DIR; - #endif - } - Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mRoot); - Files::loadOgrePlugin(pluginDir, "RenderSystem_GLES2", *mRoot); - Files::loadOgrePlugin(pluginDir, "RenderSystem_GL3Plus", *mRoot); - Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mRoot); - Files::loadOgrePlugin(pluginDir, "Plugin_CgProgramManager", *mRoot); - if (!Files::loadOgrePlugin(pluginDir, "Plugin_ParticleFX", *mRoot)) - throw std::runtime_error("Required Plugin_ParticleFX for Ogre not found!"); - } -} diff --git a/components/ogreinit/ogreinit.hpp b/components/ogreinit/ogreinit.hpp deleted file mode 100644 index d1743950f..000000000 --- a/components/ogreinit/ogreinit.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef OPENMW_COMPONENTS_OGREINIT_H -#define OPENMW_COMPONENTS_OGREINIT_H - -#include -#include - -// Static plugin headers -#ifdef ENABLE_PLUGIN_CgProgramManager -# include "OgreCgPlugin.h" -#endif -#ifdef ENABLE_PLUGIN_OctreeSceneManager -# include "OgreOctreePlugin.h" -#endif -#ifdef ENABLE_PLUGIN_ParticleFX -# include "OgreParticleFXPlugin.h" -#endif -#ifdef ENABLE_PLUGIN_GL -# include "OgreGLPlugin.h" -#endif -#ifdef ENABLE_PLUGIN_GLES2 -# include "OgreGLES2Plugin.h" -#endif - -#ifdef ENABLE_PLUGIN_Direct3D9 -# include "OgreD3D9Plugin.h" -#endif - -namespace Ogre -{ - class ParticleEmitterFactory; - class ParticleAffectorFactory; - class Root; -} - -namespace OgreInit -{ - /** - * @brief Starts Ogre::Root and loads required plugins and NIF particle factories - */ - class OgreInit - { - public: - OgreInit(); - - Ogre::Root* init(const std::string &logPath // Path to directory where to store log files - ); - - ~OgreInit(); - - private: - Ogre::Root* mRoot; - - void loadStaticPlugins(); - void loadPlugins(); - - #ifdef ENABLE_PLUGIN_CgProgramManager - Ogre::CgPlugin* mCgPlugin; - #endif - #ifdef ENABLE_PLUGIN_OctreeSceneManager - Ogre::OctreePlugin* mOctreePlugin; - #endif - #ifdef ENABLE_PLUGIN_ParticleFX - Ogre::ParticleFXPlugin* mParticleFXPlugin; - #endif - #ifdef ENABLE_PLUGIN_GL - Ogre::GLPlugin* mGLPlugin; - #endif - #ifdef ENABLE_PLUGIN_GLES2 - Ogre::GLES2Plugin* mGLES2Plugin; - #endif - #ifdef ENABLE_PLUGIN_Direct3D9 - Ogre::D3D9Plugin* mD3D9Plugin; - #endif - - }; -} - -#endif diff --git a/components/ogreinit/ogreplugin.cpp b/components/ogreinit/ogreplugin.cpp deleted file mode 100644 index 069b25e7b..000000000 --- a/components/ogreinit/ogreplugin.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "ogreplugin.hpp" - -#include -#include - -namespace Files { - -bool loadOgrePlugin(const std::string &pluginDir, std::string pluginName, Ogre::Root &ogreRoot) { - std::string pluginExt; -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - pluginExt = ".dll"; -#endif -#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE - pluginExt = ".framework"; -#endif -#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX - pluginExt = ".so"; -#endif - - // Append plugin suffix if debugging. - std::string pluginPath; -#if defined(DEBUG) - pluginPath = pluginDir + "/" + pluginName + OGRE_PLUGIN_DEBUG_SUFFIX + pluginExt; - if (boost::filesystem::exists(pluginPath)) { - ogreRoot.loadPlugin(pluginPath); - return true; - } - else { -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - return false; -#endif //OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - } -#endif //defined(DEBUG) - - pluginPath = pluginDir + "/" + pluginName + pluginExt; - if (boost::filesystem::exists(pluginPath)) { - ogreRoot.loadPlugin(pluginPath); - return true; - } - else { - return false; - } -} - -} diff --git a/components/ogreinit/ogreplugin.hpp b/components/ogreinit/ogreplugin.hpp deleted file mode 100644 index 6fcf61376..000000000 --- a/components/ogreinit/ogreplugin.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef COMPONENTS_FILES_OGREPLUGIN_H -#define COMPONENTS_FILES_OGREPLUGIN_H - -#include - -#include -#include - -namespace Ogre { - class Root; -} - -#if (BOOST_VERSION <= 104500) -namespace boost { -namespace filesystem { -inline path absolute(const path& p, const path& base=current_path()) { - // call obsolete version of this function on older boost - return complete(p, base); -} -} -} -#endif /* (BOOST_VERSION <= 104300) */ - -/** - * \namespace Files - */ -namespace Files { - -/** - * \brief Loads Ogre plugin with given name. - * - * \param pluginDir absolute path to plugins - * \param pluginName plugin name, for example "RenderSystem_GL" - * \param ogreRoot Ogre::Root instance - * - * \return whether plugin was located or not - */ -bool loadOgrePlugin(const std::string &pluginDir, std::string pluginName, Ogre::Root &ogreRoot); - -} - -#endif /* COMPONENTS_FILES_OGREPLUGIN_H */ diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 32c3861c0..f1af8b654 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -12,13 +12,6 @@ screen = 0 # Minimize the window if it loses key focus? minimize on focus loss = true -# Render system -# blank means default -# Valid values: -# OpenGL Rendering Subsystem -# Direct3D9 Rendering Subsystem -render system = - # Valid values: # none # MSAA 2