Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::MaterialManager Class Reference

Class for managing Material settings for Ogre. More...

#include <OgreMaterialManager.h>

Inheritance diagram for Ogre::MaterialManager:

Ogre::ResourceManager Ogre::Singleton< MaterialManager > List of all members.

Public Methods

 MaterialManager ()
 Default constructor. More...

virtual ~MaterialManager ()
 Default destructor. More...

Material * add (const Material &mat)
 Adds a copy of a material created outside the MaterialManager to the master Material list. More...

Material * getByHandle (int handle)
 Gets a pointer to a Material by it's numerical handle. More...

void parseScript (DataChunk &chunk)
 Parses a Material script file passed as a chunk. More...

void parseAllSources (const String &extension=".material")
 Parses all material script files in resource folders & archives. More...

Resource * create (const String &name)
 Create implementation required by ResourceManager. More...

Material * createDeferred (const String &name)
 Create implementation that creates a deferred-load Material, ie one that does not load any resources like texture files etc, and does not register itself with SceneManagers until it is actually used. More...

virtual void setMemoryBudget (size_t bytes)
 Set a limit on the amount of memory this resource handler may use. More...

virtual void load (Resource *res, int priority)
 Load a resource. More...

virtual void unload (Resource *res)
 Unloads a Resource from the managed resources list, calling it's unload() method. More...

virtual void unloadAndDestroyAll (void)
 Unloads all Resources from memory. More...

virtual Resource * getByName (const String &name)
 Retrieves a pointer to a resource by name. More...

void addSearchPath (const String &path)
 Adds a relative path to search for resources of this type. More...

void addArchiveEx (const String &strName, const String &strDriverName)
 Adds an archive to the search path for this type of resource. More...

bool _findResourceData (const String &filename, DataChunk &refChunk)
 Internal method, used for locating resource data in the file system / archives. More...


Static Public Methods

MaterialManager & getSingleton (void)
 Override standard Singleton retrieval. More...

void addCommonSearchPath (const String &path)
 Adds a relative search path for resources of ALL types. More...

void addCommonArchiveEx (const String &strName, const String &strDriverName)
 Adds an archive to the search path for all resources. More...

std::set< String > _getAllCommonNamesLike (const String &startPath, const String &extension)
 Returns a collection of files with the given extension in the common resource paths. More...

bool _findCommonResourceData (const String &filename, DataChunk &refChunk)
 Internal method, used for locating common resource data in the file system / archives. More...

MaterialManager * getSingletonPtr (void)

Protected Types

typedef std::map< String,
MATERIAL_ATTRIB_PARSER > 
MatAttribParserList
 Keyword-mapped attribute parsers. More...

typedef std::map< String,
TEXLAYER_ATTRIB_PARSER > 
LayerAttribParserList
 Keyword-mapped attribute parsers. More...

typedef HashMap< int, Material * > MaterialHandleList
typedef HashMap< String, ArchiveEx *,
_StringHash > 
FileMap

Protected Methods

void parseNewTextureLayer (DataChunk &chunk, Material *pMat)
void parseAttrib (const String &line, Material *pMat)
void parseLayerAttrib (const String &line, Material *pMat, Material::TextureLayer *pLayer)
void checkUsage (void)
 Checks memory usage and pages out if required. More...


Protected Attributes

MatAttribParserList mMatAttribParsers
LayerAttribParserList mLayerAttribParsers
MaterialHandleList mHandles
 Materials by handle. More...

FileMap mArchiveFiles
ResourceMap mResources
size_t mMemoryBudget
size_t mMemoryUsage
std::vector< ArchiveEx * > mVFS
 Collection of searchable ArchiveEx classes (virtual file system) for this resource type. More...


Static Protected Attributes

FileMap mCommonArchiveFiles
std::vector< ArchiveEx * > mCommonVFS
 Collection of searchable ArchiveEx classes (virtual file system) for all resource types. More...

MaterialManager * ms_Singleton = 0

Detailed Description

Class for managing Material settings for Ogre.

Remarks:
Materials control the eventual surface rendering properties of geometry. This class manages the library of materials, dealing with programmatic registrations and lookups, as well as loading predefined Material settings from scripts.

When loaded from a script, a Material is in an 'unloaded' state and only stores the settings required. It does not at that stage load any textures. This is because the material settings may be loaded 'en masse' from bulk material script files, but only a subset will actually be required.

Because this is a subclass of ResourceManager, any files loaded will be searched for in any path or archive added to the resource paths/archives. See ResourceManager for details.

For a definition of the material script format, see the Tutorials/MaterialScript.html file.


Member Typedef Documentation

typedef HashMap< String, ArchiveEx *, _StringHash > Ogre::ResourceManager::FileMap [protected, inherited]
 

typedef std::map<String, TEXLAYER_ATTRIB_PARSER> Ogre::MaterialManager::LayerAttribParserList [protected]
 

Keyword-mapped attribute parsers.

typedef std::map<String, MATERIAL_ATTRIB_PARSER> Ogre::MaterialManager::MatAttribParserList [protected]
 

Keyword-mapped attribute parsers.

typedef HashMap<int, Material*> Ogre::MaterialManager::MaterialHandleList [protected]
 


Constructor & Destructor Documentation

Ogre::MaterialManager::MaterialManager (    ) 
 

Default constructor.

Ogre::MaterialManager::~MaterialManager (    )  [virtual]
 

Default destructor.


Member Function Documentation

bool Ogre::ResourceManager::_findCommonResourceData (  const String &    filename,
DataChunk &    refChunk
)  [static, inherited]
 

Internal method, used for locating common resource data in the file system / archives.

Remarks:
This is a static version of _findResourceData specifically designed to only search in the common resource archives, and is therefore usable from non-ResourceManager subclasses.
Parameters:
filename  File to find
refChunk  Reference to a DataChunk object to fill with the data from the file
Returns:
On success, true is returned

On failiure, false is returned

bool Ogre::ResourceManager::_findResourceData (  const String &    filename,
DataChunk &    refChunk
)  [inherited]
 

Internal method, used for locating resource data in the file system / archives.

Parameters:
filename  File to find
refChunk  Reference to a DataChunk object to fill with the data from the file
Returns:
On success, true is returned

On failiure, false is returnec

std::set< String > Ogre::ResourceManager::_getAllCommonNamesLike (  const String &    startPath,
const String &    extension
)  [static, inherited]
 

Returns a collection of files with the given extension in the common resource paths.

Remarks:
This is a convenience method to allow non-subclasses to search for files in the common paths.
Parameters:
startPath  The path, relative to each common resource start, to search in (use "./" for the root)
extension  The extension of file to search for.
Returns:
A set of String filenames (it is a set because duplicates will be ignored)

Material * Ogre::MaterialManager::add (  const Material &    mat ) 
 

Adds a copy of a material created outside the MaterialManager to the master Material list.

Note:
MaterialManager copies the Material so there are no memory management issues. However note that the Material's internal handle will be regenerated to ensure uniqueness.

Note it is usually better to just use the create() method instead.

Parameters:
mat  A reference to a manually created Material
Returns:
A pointer to the newly created Material based on the one passed in

void Ogre::ResourceManager::addArchiveEx (  const String &    strName,
const String &    strDriverName
)  [inherited]
 

Adds an archive to the search path for this type of resource.

Remarks:
Ogre can load resources from archives. This method adds the named archive to the search path for the type of resource managed by the specific resource manager. Archives are not searched for themselves so a complete path must be specified here (or relative to the current path). Archives take precedence over files in the filesystem.

void Ogre::ResourceManager::addCommonArchiveEx (  const String &    strName,
const String &    strDriverName
)  [static, inherited]
 

Adds an archive to the search path for all resources.

Remarks:
As ResourceManager::addArchive, except this archive is used for all types of resources, not just the type managed by the resource manager in question.

void Ogre::ResourceManager::addCommonSearchPath (  const String &    path )  [static, inherited]
 

Adds a relative search path for resources of ALL types.

This method has the same effect as ResourceManager::addSearchPath, except that the path added applies to ALL resources, not just the one managed by the subclass in question.

void Ogre::ResourceManager::addSearchPath (  const String &    path )  [inherited]
 

Adds a relative path to search for resources of this type.

Remarks:
This method adds the supplied path to the list of relative locations that that will be searched for a single type of resource only. Each subclass of ResourceManager will maintain it's own list of specific subpaths, which it will append to the current path as it searches for matching files.

void Ogre::ResourceManager::checkUsage (  void    )  [protected, inherited]
 

Checks memory usage and pages out if required.

Resource * Ogre::MaterialManager::create (  const String &    name )  [virtual]
 

Create implementation required by ResourceManager.

Implements Ogre::ResourceManager.

Material * Ogre::MaterialManager::createDeferred (  const String &    name ) 
 

Create implementation that creates a deferred-load Material, ie one that does not load any resources like texture files etc, and does not register itself with SceneManagers until it is actually used.

Material * Ogre::MaterialManager::getByHandle (  int    handle ) 
 

Gets a pointer to a Material by it's numerical handle.

Remarks:
Numerical handles are assigned on creation of a material, or when a copy is registered with the MaterialManager using the add method. Retreiving materials by handle is more efficient than doing so by name.

Resource * Ogre::ResourceManager::getByName (  const String &    name )  [virtual, inherited]
 

Retrieves a pointer to a resource by name.

MaterialManager & Ogre::MaterialManager::getSingleton (  void    )  [static]
 

Override standard Singleton retrieval.

Remarks:
Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.
Precondition:
This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< MaterialManager >.

MaterialManager* Ogre::Singleton< MaterialManager >::getSingletonPtr (  void    )  [inline, static, inherited]
 

void Ogre::ResourceManager::load (  Resource *    res,
int    priority
)  [virtual, inherited]
 

Load a resource.

Resources will be subclasses.

Reimplemented in Ogre::TextureManager.

void Ogre::MaterialManager::parseAllSources (  const String &    extension = ".material" ) 
 

Parses all material script files in resource folders & archives.

void Ogre::MaterialManager::parseAttrib (  const String &    line,
Material *    pMat
)  [protected]
 

void Ogre::MaterialManager::parseLayerAttrib (  const String &    line,
Material *    pMat,
Material::TextureLayer *    pLayer
)  [protected]
 

void Ogre::MaterialManager::parseNewTextureLayer (  DataChunk &    chunk,
Material *    pMat
)  [protected]
 

void Ogre::MaterialManager::parseScript (  DataChunk &    chunk ) 
 

Parses a Material script file passed as a chunk.

void Ogre::ResourceManager::setMemoryBudget (  size_t    bytes )  [virtual, inherited]
 

Set a limit on the amount of memory this resource handler may use.

Remarks:
If, when asked to load a new resource, the manager believes it will exceed this memory budget, it will temporarily unload a resource to make room for the new one. This unloading is not permanent and the Resource is not destroyed; it simply needs to be reloaded when next used.

void Ogre::ResourceManager::unload (  Resource *    res )  [virtual, inherited]
 

Unloads a Resource from the managed resources list, calling it's unload() method.

Remarks:
This method removes a resource from the list maintained by this manager, and unloads it from memory. It does NOT destroy the resource itself, although the memory used by it will be largely freed up. This would allow you to reload the resource again if you wished.

Permanently destroying the resource is, as mentioned in ResourceManager::create, the library user's responsibility.

void Ogre::ResourceManager::unloadAndDestroyAll (  void    )  [virtual, inherited]
 

Unloads all Resources from memory.

Remarks:
Note that unlike ResourceManager::unload, Resource objects are DESTROYED as well as unloaded. This is because you are unlikely to be managing the deletion of the objects individually in this case.

Reimplemented in Ogre::D3D8TextureManager.


Member Data Documentation

FileMap Ogre::ResourceManager::mArchiveFiles [protected, inherited]
 

ResourceManager::FileMap Ogre::ResourceManager::mCommonArchiveFiles [static, protected, inherited]
 

std::vector< ArchiveEx * > Ogre::ResourceManager::mCommonVFS [static, protected, inherited]
 

Collection of searchable ArchiveEx classes (virtual file system) for all resource types.

MaterialHandleList Ogre::MaterialManager::mHandles [protected]
 

Materials by handle.

LayerAttribParserList Ogre::MaterialManager::mLayerAttribParsers [protected]
 

MatAttribParserList Ogre::MaterialManager::mMatAttribParsers [protected]
 

size_t Ogre::ResourceManager::mMemoryBudget [protected, inherited]
 

size_t Ogre::ResourceManager::mMemoryUsage [protected, inherited]
 

ResourceMap Ogre::ResourceManager::mResources [protected, inherited]
 

MaterialManager * Ogre::Singleton< MaterialManager >::ms_Singleton = 0 [static, protected, inherited]
 

std::vector<ArchiveEx*> Ogre::ResourceManager::mVFS [protected, inherited]
 

Collection of searchable ArchiveEx classes (virtual file system) for this resource type.

Copyright © 2002 by The OGRE Team