2015-03-26 17:02:51 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_RESOURCE_SCENEMANAGER_H
|
|
|
|
#define OPENMW_COMPONENTS_RESOURCE_SCENEMANAGER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Node>
|
2016-02-05 17:51:51 +00:00
|
|
|
#include <osg/Texture>
|
2015-03-26 17:02:51 +00:00
|
|
|
|
2015-03-28 01:20:20 +00:00
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
class TextureManager;
|
2015-12-01 22:04:02 +00:00
|
|
|
class NifFileManager;
|
2015-03-28 01:20:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
class Manager;
|
|
|
|
}
|
|
|
|
|
2015-05-26 18:20:18 +00:00
|
|
|
namespace osgUtil
|
|
|
|
{
|
|
|
|
class IncrementalCompileOperation;
|
|
|
|
}
|
|
|
|
|
2016-02-05 17:51:51 +00:00
|
|
|
namespace osgViewer
|
|
|
|
{
|
|
|
|
class Viewer;
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
|
|
|
|
/// @brief Handles loading and caching of scenes, e.g. NIF files
|
|
|
|
class SceneManager
|
|
|
|
{
|
|
|
|
public:
|
2015-12-01 22:04:02 +00:00
|
|
|
SceneManager(const VFS::Manager* vfs, Resource::TextureManager* textureManager, Resource::NifFileManager* nifFileManager);
|
2015-05-08 15:52:35 +00:00
|
|
|
~SceneManager();
|
2015-03-26 17:02:51 +00:00
|
|
|
|
|
|
|
/// Get a read-only copy of this scene "template"
|
2015-07-27 20:59:20 +00:00
|
|
|
/// @note If the given filename does not exist or fails to load, an error marker mesh will be used instead.
|
|
|
|
/// If even the error marker mesh can not be found, an exception is thrown.
|
2015-03-26 17:02:51 +00:00
|
|
|
osg::ref_ptr<const osg::Node> getTemplate(const std::string& name);
|
|
|
|
|
|
|
|
/// Create an instance of the given scene template
|
2015-07-27 20:59:20 +00:00
|
|
|
/// @see getTemplate
|
2015-03-27 23:30:49 +00:00
|
|
|
osg::ref_ptr<osg::Node> createInstance(const std::string& name);
|
|
|
|
|
|
|
|
/// Create an instance of the given scene template and immediately attach it to a parent node
|
2015-07-27 20:59:20 +00:00
|
|
|
/// @see getTemplate
|
2015-03-27 23:30:49 +00:00
|
|
|
osg::ref_ptr<osg::Node> createInstance(const std::string& name, osg::Group* parentNode);
|
|
|
|
|
|
|
|
/// Attach the given scene instance to the given parent node
|
|
|
|
/// @note You should have the parentNode in its intended position before calling this method,
|
|
|
|
/// so that world space particles of the \a instance get transformed correctly.
|
|
|
|
/// @note Assumes the given instance was not attached to any parents before.
|
|
|
|
void attachTo(osg::Node* instance, osg::Group* parentNode) const;
|
2015-03-26 17:02:51 +00:00
|
|
|
|
2015-04-02 15:34:44 +00:00
|
|
|
/// Manually release created OpenGL objects for the given graphics context. This may be required
|
|
|
|
/// in cases where multiple contexts are used over the lifetime of the application.
|
2015-03-28 19:15:17 +00:00
|
|
|
void releaseGLObjects(osg::State* state);
|
|
|
|
|
2015-05-26 18:20:18 +00:00
|
|
|
/// Set up an IncrementalCompileOperation for background compiling of loaded scenes.
|
|
|
|
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico);
|
|
|
|
|
2015-12-01 22:04:02 +00:00
|
|
|
/// @note SceneManager::attachTo calls this method automatically, only needs to be called by users if manually attaching
|
2015-06-01 14:25:15 +00:00
|
|
|
void notifyAttached(osg::Node* node) const;
|
|
|
|
|
2015-04-14 13:55:56 +00:00
|
|
|
const VFS::Manager* getVFS() const;
|
|
|
|
|
|
|
|
Resource::TextureManager* getTextureManager();
|
|
|
|
|
2015-11-10 16:00:33 +00:00
|
|
|
/// @param mask The node mask to apply to loaded particle system nodes.
|
|
|
|
void setParticleSystemMask(unsigned int mask);
|
|
|
|
|
2016-02-05 17:51:51 +00:00
|
|
|
void setFilterSettings(const std::string &magfilter, const std::string &minfilter,
|
|
|
|
const std::string &mipmap, int maxAnisotropy,
|
|
|
|
osgViewer::Viewer *viewer);
|
|
|
|
|
|
|
|
/// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e. calling getTemplate / createInstance)
|
|
|
|
/// the filter settings are applied automatically. This method is provided for textures that were created outside of the SceneManager.
|
|
|
|
void applyFilterSettings (osg::Texture* tex);
|
|
|
|
|
|
|
|
/// Keep a copy of the texture data around in system memory? This is needed when using multiple graphics contexts,
|
|
|
|
/// otherwise should be disabled to reduce memory usage.
|
|
|
|
void setUnRefImageDataAfterApply(bool unref);
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
private:
|
|
|
|
const VFS::Manager* mVFS;
|
2015-03-28 01:20:20 +00:00
|
|
|
Resource::TextureManager* mTextureManager;
|
2015-12-01 22:04:02 +00:00
|
|
|
Resource::NifFileManager* mNifFileManager;
|
2015-03-26 17:02:51 +00:00
|
|
|
|
2016-02-05 17:51:51 +00:00
|
|
|
osg::Texture::FilterMode mMinFilter;
|
|
|
|
osg::Texture::FilterMode mMagFilter;
|
|
|
|
int mMaxAnisotropy;
|
|
|
|
bool mUnRefImageDataAfterApply;
|
|
|
|
|
2015-05-26 18:20:18 +00:00
|
|
|
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
|
|
|
|
|
2015-11-10 16:00:33 +00:00
|
|
|
unsigned int mParticleSystemMask;
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
// observer_ptr?
|
2016-02-05 18:28:52 +00:00
|
|
|
typedef std::map<std::string, osg::ref_ptr<osg::Node> > Index;
|
2015-03-26 17:02:51 +00:00
|
|
|
Index mIndex;
|
2015-04-02 15:34:44 +00:00
|
|
|
|
2015-05-08 15:52:35 +00:00
|
|
|
SceneManager(const SceneManager&);
|
|
|
|
void operator = (const SceneManager&);
|
2016-02-05 17:51:51 +00:00
|
|
|
|
|
|
|
/// @warning It is unsafe to call this function when a draw thread is using the textures. Call stopThreading() first!
|
|
|
|
void setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode maxFilter, int maxAnisotropy);
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|