forked from teamnwah/openmw-tes3coop
Refactored Ogre initialisation into a component
This commit is contained in:
parent
4f35fd8184
commit
636d399c7f
14 changed files with 267 additions and 261 deletions
|
@ -79,7 +79,6 @@ set(OENGINE_OGRE
|
||||||
${LIBDIR}/openengine/ogre/renderer.cpp
|
${LIBDIR}/openengine/ogre/renderer.cpp
|
||||||
${LIBDIR}/openengine/ogre/fader.cpp
|
${LIBDIR}/openengine/ogre/fader.cpp
|
||||||
${LIBDIR}/openengine/ogre/lights.cpp
|
${LIBDIR}/openengine/ogre/lights.cpp
|
||||||
${LIBDIR}/openengine/ogre/particles.cpp
|
|
||||||
${LIBDIR}/openengine/ogre/selectionbuffer.cpp
|
${LIBDIR}/openengine/ogre/selectionbuffer.cpp
|
||||||
${LIBDIR}/openengine/ogre/imagerotate.cpp
|
${LIBDIR}/openengine/ogre/imagerotate.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,12 +10,9 @@
|
||||||
#endif
|
#endif
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <boost/math/common_factor.hpp>
|
#include <boost/math/common_factor.hpp>
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#include <components/files/ogreplugin.hpp>
|
|
||||||
|
|
||||||
#include <components/fileorderlist/utils/naturalsort.hpp>
|
#include <components/fileorderlist/utils/naturalsort.hpp>
|
||||||
|
|
||||||
|
@ -54,13 +51,9 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &g
|
||||||
|
|
||||||
bool GraphicsPage::setupOgre()
|
bool GraphicsPage::setupOgre()
|
||||||
{
|
{
|
||||||
// Create a log manager so we can surpress debug text to stdout/stderr
|
|
||||||
Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager;
|
|
||||||
logMgr->createLog((mCfgMgr.getLogPath().string() + "/launcherOgre.log"), true, false, false);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mOgre = new Ogre::Root("", "", "./launcherOgre.log");
|
mOgre = mOgreInit.init(mCfgMgr.getLogPath().string() + "/launcherOgre.log");
|
||||||
}
|
}
|
||||||
catch(Ogre::Exception &ex)
|
catch(Ogre::Exception &ex)
|
||||||
{
|
{
|
||||||
|
@ -78,40 +71,6 @@ bool GraphicsPage::setupOgre()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
|
||||||
pluginDir = OGRE_PLUGIN_DIR_REL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir dir(QString::fromStdString(pluginDir));
|
|
||||||
pluginDir = dir.absolutePath().toStdString();
|
|
||||||
|
|
||||||
Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mOgre);
|
|
||||||
Files::loadOgrePlugin(pluginDir, "RenderSystem_GL3Plus", *mOgre);
|
|
||||||
Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mOgre);
|
|
||||||
|
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
|
||||||
mGLPlugin = new Ogre::GLPlugin();
|
|
||||||
mOgre->installPlugin(mGLPlugin);
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_PLUGIN_Direct3D9
|
|
||||||
mD3D9Plugin = new Ogre::D3D9Plugin();
|
|
||||||
mOgre->installPlugin(mD3D9Plugin);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Get the available renderers and put them in the combobox
|
// Get the available renderers and put them in the combobox
|
||||||
const Ogre::RenderSystemList &renderers = mOgre->getAvailableRenderers();
|
const Ogre::RenderSystemList &renderers = mOgre->getAvailableRenderers();
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,9 @@
|
||||||
|
|
||||||
#include <OgreRoot.h>
|
#include <OgreRoot.h>
|
||||||
#include <OgreRenderSystem.h>
|
#include <OgreRenderSystem.h>
|
||||||
//#include <OgreConfigFile.h>
|
|
||||||
//#include <OgreConfigDialog.h>
|
|
||||||
|
|
||||||
// Static plugin headers
|
#include <components/ogreinit/ogreinit.hpp>
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
|
||||||
# include "OgreGLPlugin.h"
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_PLUGIN_Direct3D9
|
|
||||||
# include "OgreD3D9Plugin.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ui_graphicspage.h"
|
#include "ui_graphicspage.h"
|
||||||
|
|
||||||
|
@ -41,16 +34,13 @@ private slots:
|
||||||
void slotStandardToggled(bool checked);
|
void slotStandardToggled(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
OgreInit::OgreInit mOgreInit;
|
||||||
|
|
||||||
Ogre::Root *mOgre;
|
Ogre::Root *mOgre;
|
||||||
Ogre::RenderSystem *mSelectedRenderSystem;
|
Ogre::RenderSystem *mSelectedRenderSystem;
|
||||||
Ogre::RenderSystem *mOpenGLRenderSystem;
|
Ogre::RenderSystem *mOpenGLRenderSystem;
|
||||||
Ogre::RenderSystem *mDirect3DRenderSystem;
|
Ogre::RenderSystem *mDirect3DRenderSystem;
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
|
||||||
Ogre::GLPlugin* mGLPlugin;
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_PLUGIN_Direct3D9
|
|
||||||
Ogre::D3D9Plugin* mD3D9Plugin;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
Files::ConfigurationManager &mCfgMgr;
|
||||||
GraphicsSettings &mGraphicsSettings;
|
GraphicsSettings &mGraphicsSettings;
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "maindialog.hpp"
|
#include "maindialog.hpp"
|
||||||
// SDL workaround
|
|
||||||
#include "graphicspage.hpp"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -357,8 +357,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||||
mOgre->configure(
|
mOgre->configure(
|
||||||
mCfgMgr.getLogPath().string(),
|
mCfgMgr.getLogPath().string(),
|
||||||
renderSystem,
|
renderSystem,
|
||||||
Settings::Manager::getString("opengl rtt mode", "Video"),
|
Settings::Manager::getString("opengl rtt mode", "Video"));
|
||||||
false);
|
|
||||||
|
|
||||||
// This has to be added BEFORE MyGUI is initialized, as it needs
|
// This has to be added BEFORE MyGUI is initialized, as it needs
|
||||||
// to find core.xml here.
|
// to find core.xml here.
|
||||||
|
|
|
@ -19,7 +19,7 @@ add_component_dir (nif
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (nifogre
|
add_component_dir (nifogre
|
||||||
ogrenifloader skeleton material mesh
|
ogrenifloader skeleton material mesh particles
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (nifbullet
|
add_component_dir (nifbullet
|
||||||
|
@ -48,7 +48,7 @@ add_component_dir (misc
|
||||||
|
|
||||||
add_component_dir (files
|
add_component_dir (files
|
||||||
linuxpath windowspath macospath fixedpath multidircollection collections fileops configurationmanager
|
linuxpath windowspath macospath fixedpath multidircollection collections fileops configurationmanager
|
||||||
filelibrary ogreplugin constrainedfiledatastream lowlevelfile
|
filelibrary constrainedfiledatastream lowlevelfile
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (compiler
|
add_component_dir (compiler
|
||||||
|
@ -74,6 +74,10 @@ add_component_dir (loadinglistener
|
||||||
loadinglistener
|
loadinglistener
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_component_dir (ogreinit
|
||||||
|
ogreinit ogreplugin
|
||||||
|
)
|
||||||
|
|
||||||
find_package(Qt4 COMPONENTS QtCore QtGui)
|
find_package(Qt4 COMPONENTS QtCore QtGui)
|
||||||
|
|
||||||
if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
|
if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
|
||||||
|
|
165
components/ogreinit/ogreinit.cpp
Normal file
165
components/ogreinit/ogreinit.cpp
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
#include "ogreinit.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <OgreRoot.h>
|
||||||
|
#include <OgreParticleEmitterFactory.h>
|
||||||
|
#include <OgreParticleSystemManager.h>
|
||||||
|
|
||||||
|
#include <components/nifogre/particles.hpp>
|
||||||
|
|
||||||
|
#include "ogreplugin.hpp"
|
||||||
|
|
||||||
|
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_Direct3D9
|
||||||
|
, mD3D9Plugin(NULL)
|
||||||
|
#endif
|
||||||
|
{}
|
||||||
|
|
||||||
|
Ogre::Root* OgreInit::init(const std::string &logPath)
|
||||||
|
{
|
||||||
|
// Set up logging first
|
||||||
|
new Ogre::LogManager;
|
||||||
|
Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath + std::string("Ogre.log"));
|
||||||
|
|
||||||
|
// Disable logging to cout/cerr
|
||||||
|
log->setDebugOutputEnabled(false);
|
||||||
|
|
||||||
|
mRoot = new Ogre::Root("", "", "");
|
||||||
|
|
||||||
|
#if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) || defined(ENABLE_PLUGIN_CgProgramManager) || defined(ENABLE_PLUGIN_OctreeSceneManager) || defined(ENABLE_PLUGIN_ParticleFX)
|
||||||
|
loadStaticPlugins();
|
||||||
|
#else
|
||||||
|
loadPlugins();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
loadParticleFactories();
|
||||||
|
|
||||||
|
return mRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
OgreInit::~OgreInit()
|
||||||
|
{
|
||||||
|
delete mRoot;
|
||||||
|
|
||||||
|
std::vector<Ogre::ParticleEmitterFactory*>::iterator ei;
|
||||||
|
for(ei = mEmitterFactories.begin();ei != mEmitterFactories.end();++ei)
|
||||||
|
OGRE_DELETE (*ei);
|
||||||
|
mEmitterFactories.clear();
|
||||||
|
|
||||||
|
std::vector<Ogre::ParticleAffectorFactory*>::iterator ai;
|
||||||
|
for(ai = mAffectorFactories.begin();ai != mAffectorFactories.end();++ai)
|
||||||
|
OGRE_DELETE (*ai);
|
||||||
|
mAffectorFactories.clear();
|
||||||
|
|
||||||
|
#ifdef ENABLE_PLUGIN_GL
|
||||||
|
delete mGLPlugin;
|
||||||
|
mGLPlugin = 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_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;
|
||||||
|
#endif
|
||||||
|
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||||
|
pluginDir = OGRE_PLUGIN_DIR_REL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir));
|
||||||
|
|
||||||
|
pluginDir = absPluginPath.string();
|
||||||
|
|
||||||
|
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);
|
||||||
|
Files::loadOgrePlugin(pluginDir, "Plugin_ParticleFX", *mRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OgreInit::loadParticleFactories()
|
||||||
|
{
|
||||||
|
Ogre::ParticleEmitterFactory *emitter;
|
||||||
|
emitter = OGRE_NEW NifEmitterFactory();
|
||||||
|
Ogre::ParticleSystemManager::getSingleton().addEmitterFactory(emitter);
|
||||||
|
mEmitterFactories.push_back(emitter);
|
||||||
|
|
||||||
|
Ogre::ParticleAffectorFactory *affector;
|
||||||
|
affector = OGRE_NEW GrowFadeAffectorFactory();
|
||||||
|
Ogre::ParticleSystemManager::getSingleton().addAffectorFactory(affector);
|
||||||
|
mAffectorFactories.push_back(affector);
|
||||||
|
|
||||||
|
affector = OGRE_NEW GravityAffectorFactory();
|
||||||
|
Ogre::ParticleSystemManager::getSingleton().addAffectorFactory(affector);
|
||||||
|
mAffectorFactories.push_back(affector);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
75
components/ogreinit/ogreinit.hpp
Normal file
75
components/ogreinit/ogreinit.hpp
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
#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_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:
|
||||||
|
std::vector<Ogre::ParticleEmitterFactory*> mEmitterFactories;
|
||||||
|
std::vector<Ogre::ParticleAffectorFactory*> mAffectorFactories;
|
||||||
|
Ogre::Root* mRoot;
|
||||||
|
|
||||||
|
void loadStaticPlugins();
|
||||||
|
void loadPlugins();
|
||||||
|
void loadParticleFactories();
|
||||||
|
|
||||||
|
|
||||||
|
#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_Direct3D9
|
||||||
|
Ogre::D3D9Plugin* mD3D9Plugin;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,27 +1,17 @@
|
||||||
#include "renderer.hpp"
|
#include "renderer.hpp"
|
||||||
#include "fader.hpp"
|
#include "fader.hpp"
|
||||||
#include "particles.hpp"
|
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "OgreRoot.h"
|
#include <OgreRoot.h>
|
||||||
#include "OgreRenderWindow.h"
|
#include <OgreRenderWindow.h>
|
||||||
#include "OgreLogManager.h"
|
#include <OgreTextureManager.h>
|
||||||
#include "OgreLog.h"
|
#include <OgreTexture.h>
|
||||||
#include "OgreTextureManager.h"
|
#include <OgreHardwarePixelBuffer.h>
|
||||||
#include "OgreTexture.h"
|
|
||||||
#include "OgreHardwarePixelBuffer.h"
|
|
||||||
#include <OgreParticleSystemManager.h>
|
|
||||||
#include "OgreParticleAffectorFactory.h"
|
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
#include <components/files/ogreplugin.hpp>
|
|
||||||
|
|
||||||
#include <extern/sdl4ogre/sdlwindowhelper.hpp>
|
#include <extern/sdl4ogre/sdlwindowhelper.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
@ -33,74 +23,11 @@ void OgreRenderer::cleanup()
|
||||||
delete mFader;
|
delete mFader;
|
||||||
mFader = NULL;
|
mFader = NULL;
|
||||||
|
|
||||||
delete mRoot;
|
|
||||||
mRoot = NULL;
|
|
||||||
|
|
||||||
// If we don't do this, the desktop resolution is not restored on exit
|
// If we don't do this, the desktop resolution is not restored on exit
|
||||||
SDL_SetWindowFullscreen(mSDLWindow, 0);
|
SDL_SetWindowFullscreen(mSDLWindow, 0);
|
||||||
|
|
||||||
SDL_DestroyWindow(mSDLWindow);
|
SDL_DestroyWindow(mSDLWindow);
|
||||||
mSDLWindow = NULL;
|
mSDLWindow = NULL;
|
||||||
|
|
||||||
unloadPlugins();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OgreRenderer::loadPlugins()
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
|
||||||
mGLPlugin = new Ogre::GLPlugin();
|
|
||||||
mRoot->installPlugin(mGLPlugin);
|
|
||||||
#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 OgreRenderer::unloadPlugins()
|
|
||||||
{
|
|
||||||
std::vector<Ogre::ParticleEmitterFactory*>::iterator ei;
|
|
||||||
for(ei = mEmitterFactories.begin();ei != mEmitterFactories.end();++ei)
|
|
||||||
OGRE_DELETE (*ei);
|
|
||||||
mEmitterFactories.clear();
|
|
||||||
|
|
||||||
std::vector<Ogre::ParticleAffectorFactory*>::iterator ai;
|
|
||||||
for(ai = mAffectorFactories.begin();ai != mAffectorFactories.end();++ai)
|
|
||||||
OGRE_DELETE (*ai);
|
|
||||||
mAffectorFactories.clear();
|
|
||||||
|
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
|
||||||
delete mGLPlugin;
|
|
||||||
mGLPlugin = 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 OgreRenderer::update(float dt)
|
void OgreRenderer::update(float dt)
|
||||||
|
@ -120,70 +47,10 @@ float OgreRenderer::getFPS()
|
||||||
|
|
||||||
void OgreRenderer::configure(const std::string &logPath,
|
void OgreRenderer::configure(const std::string &logPath,
|
||||||
const std::string& renderSystem,
|
const std::string& renderSystem,
|
||||||
const std::string& rttMode,
|
const std::string& rttMode
|
||||||
bool _logging)
|
)
|
||||||
{
|
{
|
||||||
// Set up logging first
|
mRoot = mOgreInit.init(logPath);
|
||||||
new LogManager;
|
|
||||||
Log *log = LogManager::getSingleton().createLog(logPath + std::string("Ogre.log"));
|
|
||||||
|
|
||||||
if(_logging)
|
|
||||||
// Full log detail
|
|
||||||
log->setLogDetail(LL_BOREME);
|
|
||||||
else
|
|
||||||
// Disable logging
|
|
||||||
log->setDebugOutputEnabled(false);
|
|
||||||
|
|
||||||
mRoot = new Root("", "", "");
|
|
||||||
|
|
||||||
#if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) || defined(ENABLE_PLUGIN_CgProgramManager) || defined(ENABLE_PLUGIN_OctreeSceneManager) || defined(ENABLE_PLUGIN_ParticleFX)
|
|
||||||
loadPlugins();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
|
||||||
pluginDir = OGRE_PLUGIN_DIR_REL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir));
|
|
||||||
|
|
||||||
pluginDir = absPluginPath.string();
|
|
||||||
|
|
||||||
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);
|
|
||||||
Files::loadOgrePlugin(pluginDir, "Plugin_ParticleFX", *mRoot);
|
|
||||||
|
|
||||||
|
|
||||||
Ogre::ParticleEmitterFactory *emitter;
|
|
||||||
emitter = OGRE_NEW NifEmitterFactory();
|
|
||||||
Ogre::ParticleSystemManager::getSingleton().addEmitterFactory(emitter);
|
|
||||||
mEmitterFactories.push_back(emitter);
|
|
||||||
|
|
||||||
|
|
||||||
Ogre::ParticleAffectorFactory *affector;
|
|
||||||
affector = OGRE_NEW GrowFadeAffectorFactory();
|
|
||||||
Ogre::ParticleSystemManager::getSingleton().addAffectorFactory(affector);
|
|
||||||
mAffectorFactories.push_back(affector);
|
|
||||||
|
|
||||||
affector = OGRE_NEW GravityAffectorFactory();
|
|
||||||
Ogre::ParticleSystemManager::getSingleton().addAffectorFactory(affector);
|
|
||||||
mAffectorFactories.push_back(affector);
|
|
||||||
|
|
||||||
|
|
||||||
RenderSystem* rs = mRoot->getRenderSystemByName(renderSystem);
|
RenderSystem* rs = mRoot->getRenderSystemByName(renderSystem);
|
||||||
if (rs == 0)
|
if (rs == 0)
|
||||||
|
|
|
@ -7,25 +7,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// Static plugin headers
|
#include <OgreTexture.h>
|
||||||
#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_Direct3D9
|
|
||||||
# include "OgreD3D9Plugin.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "OgreTexture.h"
|
#include <components/ogreinit/ogreinit.hpp>
|
||||||
#include <OgreWindowEventUtilities.h>
|
|
||||||
|
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
|
@ -72,24 +56,10 @@ namespace OEngine
|
||||||
Ogre::SceneManager *mScene;
|
Ogre::SceneManager *mScene;
|
||||||
Ogre::Camera *mCamera;
|
Ogre::Camera *mCamera;
|
||||||
Ogre::Viewport *mView;
|
Ogre::Viewport *mView;
|
||||||
#ifdef ENABLE_PLUGIN_CgProgramManager
|
|
||||||
Ogre::CgPlugin* mCgPlugin;
|
OgreInit::OgreInit mOgreInit;
|
||||||
#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_Direct3D9
|
|
||||||
Ogre::D3D9Plugin* mD3D9Plugin;
|
|
||||||
#endif
|
|
||||||
Fader* mFader;
|
Fader* mFader;
|
||||||
std::vector<Ogre::ParticleEmitterFactory*> mEmitterFactories;
|
|
||||||
std::vector<Ogre::ParticleAffectorFactory*> mAffectorFactories;
|
|
||||||
|
|
||||||
WindowSizeListener* mWindowListener;
|
WindowSizeListener* mWindowListener;
|
||||||
|
|
||||||
|
@ -102,21 +72,6 @@ namespace OEngine
|
||||||
, mCamera(NULL)
|
, mCamera(NULL)
|
||||||
, mView(NULL)
|
, mView(NULL)
|
||||||
, mWindowListener(NULL)
|
, mWindowListener(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_Direct3D9
|
|
||||||
, mD3D9Plugin(NULL)
|
|
||||||
#endif
|
|
||||||
, mFader(NULL)
|
, mFader(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -128,8 +83,7 @@ namespace OEngine
|
||||||
void configure(
|
void configure(
|
||||||
const std::string &logPath, // Path to directory where to store log files
|
const std::string &logPath, // Path to directory where to store log files
|
||||||
const std::string &renderSystem,
|
const std::string &renderSystem,
|
||||||
const std::string &rttMode,
|
const std::string &rttMode); // Enable or disable logging
|
||||||
bool _logging); // Enable or disable logging
|
|
||||||
|
|
||||||
/// Create a window with the given title
|
/// Create a window with the given title
|
||||||
void createWindow(const std::string &title, const WindowSettings& settings);
|
void createWindow(const std::string &title, const WindowSettings& settings);
|
||||||
|
@ -145,10 +99,6 @@ namespace OEngine
|
||||||
/// Kill the renderer.
|
/// Kill the renderer.
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
void loadPlugins();
|
|
||||||
|
|
||||||
void unloadPlugins();
|
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
/// Write a screenshot to file
|
/// Write a screenshot to file
|
||||||
|
|
Loading…
Reference in a new issue