mirror of https://github.com/OpenMW/openmw.git
Remove OgreInit
parent
d9d84bd7b2
commit
cac288d5be
@ -1,210 +0,0 @@
|
||||
#include "ogreinit.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreParticleEmitterFactory.h>
|
||||
#include <OgreParticleSystemManager.h>
|
||||
#include <OgreLogManager.h>
|
||||
#include <OgreLog.h>
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
#include <OSX/macUtils.h>
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#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!");
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
#ifndef OPENMW_COMPONENTS_OGREINIT_H
|
||||
#define OPENMW_COMPONENTS_OGREINIT_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// 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
|
@ -1,45 +0,0 @@
|
||||
#include "ogreplugin.hpp"
|
||||
|
||||
#include <OgrePrerequisites.h>
|
||||
#include <OgreRoot.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#ifndef COMPONENTS_FILES_OGREPLUGIN_H
|
||||
#define COMPONENTS_FILES_OGREPLUGIN_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
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 */
|
Loading…
Reference in New Issue