Polymorph package
polymorph::PMaterial Class Reference

#include <PMaterial.h>

Public Member Functions

 PMaterial ()
 
 PMaterial (const PMaterial &src, std::string name="")
 
virtual ~PMaterial ()
 
bool create (const std::string &groupname, const std::string &materialname)
 
bool load (const std::string &groupname, const std::string &materialname)
 
bool load (Ogre::MaterialPtr ptr)
 
void diffuse (Ogre::Real r, Ogre::Real g, Ogre::Real b, Ogre::Real a=1, ushort technique=0, ushort pass=0)
 
void diffuse (const Ogre::ColourValue &colour, ushort technique=0, ushort pass=0)
 
void specular (Ogre::Real r, Ogre::Real g, Ogre::Real b, Ogre::Real a=1, ushort technique=0, ushort pass=0)
 
void specular (const Ogre::ColourValue &colour, ushort technique=0, ushort pass=0)
 
void ambient (Ogre::Real r, Ogre::Real g, Ogre::Real b, ushort technique=0, ushort pass=0)
 
void ambient (const Ogre::ColourValue &colour, ushort technique=0, ushort pass=0)
 
void emissive (Ogre::Real r, Ogre::Real g, Ogre::Real b, ushort technique=0, ushort pass=0)
 
void emissive (const Ogre::ColourValue &colour, ushort technique=0, ushort pass=0)
 
void fogColor (Ogre::Real r, Ogre::Real g, Ogre::Real b, ushort technique=0, ushort pass=0)
 
void fogColor (const Ogre::ColourValue &colour, ushort technique=0, ushort pass=0)
 
void fogMode (const Ogre::FogMode &mode, ushort technique=0, ushort pass=0)
 
void fogDistance (const Ogre::Real &start, const Ogre::Real &end, ushort technique=0, ushort pass=0)
 
void fogDensity (const Ogre::Real &density, ushort technique=0, ushort pass=0)
 
void fog (bool overwrite, const Ogre::FogMode &mode, const Ogre::ColourValue &colour, const Ogre::Real &density, const Ogre::Real &start, const Ogre::Real &end, ushort technique=0, ushort pass=0)
 
bool addTexture (std::string groupname="", std::string imagename="", ushort technique=0, ushort pass=0)
 
bool addTexture (const Ogre::TexturePtr &ptr, ushort technique=0, ushort pass=0)
 
bool setTexture (std::string groupname, std::string imagename, ushort technique=0, ushort pass=0, ushort textureunit=0)
 
bool setTexture (const Ogre::TexturePtr &ptr, ushort technique=0, ushort pass=0, ushort textureunit=0)
 
bool exists (ushort technique)
 
bool exists (ushort technique, ushort pass)
 
bool exists (ushort technique, ushort pass, ushort texunit)
 
Ogre::MaterialPtr & getMaterial ()
 
const std::string & getGroup ()
 
const std::string & getName ()
 
Ogre::Technique * getTechnique (ushort technique)
 
Ogre::Pass * getPass (ushort technique, ushort pass)
 
Ogre::TextureUnitState * getTextureUnit (ushort technique, ushort pass, ushort textureunit)
 
uint getTextureUnitCount (ushort technique=0, ushort pass=0)
 
void print (bool full=false)
 

Private Attributes

Ogre::MaterialPtr _mat
 
std::string _group
 
std::string _name
 

Detailed Description

Definition at line 60 of file PMaterial.h.

Constructor & Destructor Documentation

PMaterial::PMaterial ( )

default constructor of PMaterial all private params stays at default values, no material pointer set by default

Definition at line 56 of file PMaterial.cpp.

PMaterial::PMaterial ( const PMaterial src,
std::string  name = "" 
)

clone an existing PMaterial, if source is correctly set otherwise, equivalent to PMaterial()

Parameters
PMaterial: object to clone
std::string,nameof the new material
Remarks
if no name is given, a new name is generated by appending the pointer of the current object to the source material name
if a name is given and it already exists in resources, creation fails

Definition at line 59 of file PMaterial.cpp.

References _group, _mat, _name, and polymorph::PUtil::materialLoaded().

Here is the call graph for this function:

PMaterial::~PMaterial ( )
virtual

destructor

Remarks
destruction of the PMaterial does not implies destruction of the Ogre::MaterialPtr stored inside

Definition at line 98 of file PMaterial.cpp.

Member Function Documentation

bool PMaterial::addTexture ( std::string  groupname = "",
std::string  imagename = "",
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to add a texture unit and load a texture in it

Parameters
std::string,nameof the resource group, empty by default
std::string,nameof the new material, empty by default
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Returns
bool : true if success
Remarks
this method checks existence of texture unit, technique and pass before loading the texture

Definition at line 363 of file PMaterial.cpp.

References _mat, exists(), getPass(), and polymorph::PUtil::getTexture().

Referenced by fogColor().

Here is the call graph for this function:

bool PMaterial::addTexture ( const Ogre::TexturePtr &  ptr,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to add a texture unit and load a texture pointer in it

Parameters
Ogre::TexturePtr: pointer to texture
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Returns
bool : true if success
Remarks
this method checks existence of texture unit, technique and pass before loading the texture

Definition at line 382 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

void polymorph::PMaterial::ambient ( Ogre::Real  r,
Ogre::Real  g,
Ogre::Real  b,
ushort  technique = 0,
ushort  pass = 0 
)
inline

shortcut to set ambient color

Parameters
Ogre::Real: red channel, in range [0,1]
Ogre::Real: green channel, in range [0,1]
Ogre::Real: blue channel, in range [0,1]
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this is a helper method, use ambient( Ogre::ColourValue ) for better performance

Definition at line 194 of file PMaterial.h.

void PMaterial::ambient ( const Ogre::ColourValue &  colour,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set ambient color

Parameters
Ogre::ColourValue: color value
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 253 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

bool PMaterial::create ( const std::string &  groupname,
const std::string &  materialname 
)

creation of a new Ogre::Material

Parameters
std::string,nameof the resource group
std::string,nameof the nw material
Returns
bool : true if the material has been successfully created
Remarks
once successfully created, a PMaterial can not be created again

Definition at line 101 of file PMaterial.cpp.

References _group, _mat, _name, polymorph::PUtil::groupExists(), polymorph::PUtil::materialExists(), and polymorph::PUtil::materialLoaded().

Here is the call graph for this function:

void polymorph::PMaterial::diffuse ( Ogre::Real  r,
Ogre::Real  g,
Ogre::Real  b,
Ogre::Real  a = 1,
ushort  technique = 0,
ushort  pass = 0 
)
inline

shortcut to set diffuse color

Parameters
Ogre::Real: red channel, in range [0,1]
Ogre::Real: green channel, in range [0,1]
Ogre::Real: blue channel, in range [0,1]
Ogre::Real: alpha channel, in range [0,1], 1 by default
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this is a helper method, use diffuse( Ogre::ColourValue ) for better performance

Definition at line 129 of file PMaterial.h.

void PMaterial::diffuse ( const Ogre::ColourValue &  colour,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set diffuse color

Parameters
Ogre::ColourValue: color value
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 231 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

void polymorph::PMaterial::emissive ( Ogre::Real  r,
Ogre::Real  g,
Ogre::Real  b,
ushort  technique = 0,
ushort  pass = 0 
)
inline

shortcut to set emissive color

Parameters
Ogre::Real: red channel, in range [0,1]
Ogre::Real: green channel, in range [0,1]
Ogre::Real: blue channel, in range [0,1]
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this is a helper method, use emissive( Ogre::ColourValue ) for better performance

Definition at line 225 of file PMaterial.h.

void PMaterial::emissive ( const Ogre::ColourValue &  colour,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set emissive color

Parameters
Ogre::ColourValue: color value
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 264 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

bool PMaterial::exists ( ushort  technique)

test the existence of specified pass in specified technique

Parameters
ushort: technique ID
Returns
bool true if the technique exists

Definition at line 459 of file PMaterial.cpp.

References _mat.

Referenced by addTexture(), ambient(), diffuse(), emissive(), fog(), fogColor(), fogDensity(), fogDistance(), fogMode(), getTextureUnitCount(), setTexture(), and specular().

bool PMaterial::exists ( ushort  technique,
ushort  pass 
)

test the existence of specified pass in specified technique

Parameters
ushort: technique ID
ushort: pass ID
Returns
bool true if the pass exists

Definition at line 467 of file PMaterial.cpp.

References _mat.

bool PMaterial::exists ( ushort  technique,
ushort  pass,
ushort  texunit 
)

test the existence of specified texture unit in specified technique and specified pass

Parameters
ushort: technique ID
ushort: pass ID
ushort: texture unit ID
Returns
bool true if the pass exists

Definition at line 477 of file PMaterial.cpp.

References getTextureUnitCount().

Here is the call graph for this function:

void PMaterial::fog ( bool  overwrite,
const Ogre::FogMode &  mode,
const Ogre::ColourValue &  colour,
const Ogre::Real &  density,
const Ogre::Real &  start,
const Ogre::Real &  end,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set all fog params at once

Parameters
bool: allow material to overwrite scene fog params, false by default
Ogre::FogMode: FOG_NONE, FOG_EXP, FOG_EXP2 or FOG_LINEAR, FOG_NONE by default
Ogre::ColourValue: color value, white by default
Ogre::Real: density, 0.001 by default
Ogre::Real: start distance, 0 by default
Ogre::Real: end distance, 1 by default
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 347 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Referenced by fogColor().

Here is the call graph for this function:

void polymorph::PMaterial::fogColor ( Ogre::Real  r,
Ogre::Real  g,
Ogre::Real  b,
ushort  technique = 0,
ushort  pass = 0 
)
inline

shortcut to set fog color

Parameters
Ogre::Real: red channel, in range [0,1]
Ogre::Real: green channel, in range [0,1]
Ogre::Real: blue channel, in range [0,1]
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this is a helper method, use fogColor( Ogre::ColourValue ) for better performance

Definition at line 256 of file PMaterial.h.

References addTexture(), exists(), fog(), fogDensity(), fogDistance(), fogMode(), and setTexture().

Here is the call graph for this function:

void PMaterial::fogColor ( const Ogre::ColourValue &  colour,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set fog color

Parameters
Ogre::ColourValue: color value
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 275 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

void PMaterial::fogDensity ( const Ogre::Real &  density,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set fog density

Parameters
Ogre::Real: density
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 329 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Referenced by fogColor().

Here is the call graph for this function:

void PMaterial::fogDistance ( const Ogre::Real &  start,
const Ogre::Real &  end,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set fog start and end distance

Parameters
Ogre::Real: start distance
Ogre::Real: end distance
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 311 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Referenced by fogColor().

Here is the call graph for this function:

void PMaterial::fogMode ( const Ogre::FogMode &  mode,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set fog mode

Parameters
FOG_NONE,FOG_EXP,FOG_EXP2or FOG_LINEAR
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 293 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Referenced by fogColor().

Here is the call graph for this function:

const std::string& polymorph::PMaterial::getGroup ( )
inline

getter for group name

Returns
std::string

Definition at line 435 of file PMaterial.h.

References _group.

Ogre::MaterialPtr& polymorph::PMaterial::getMaterial ( )
inline

getter for inner Ogre::MaterialPtr

Returns
Ogre::MaterialPtr

Definition at line 428 of file PMaterial.h.

References _mat.

const std::string& polymorph::PMaterial::getName ( )
inline

getter for material name

Returns
std::string

Definition at line 442 of file PMaterial.h.

References _name.

Ogre::Pass* polymorph::PMaterial::getPass ( ushort  technique,
ushort  pass 
)
inline

getter for Ogre::Pass*

Parameters
ushort: technique ID
ushort: pass ID
Returns
Ogre::Pass pointer
Remarks
use this carefully: there is no safety check when accessing the pass or the technique, use exists(ushort,ushort) to validate

Definition at line 465 of file PMaterial.h.

References _mat, and getTechnique().

Referenced by addTexture(), ambient(), diffuse(), emissive(), fog(), fogColor(), fogDensity(), fogDistance(), fogMode(), getTextureUnit(), getTextureUnitCount(), and specular().

Here is the call graph for this function:

Ogre::Technique* polymorph::PMaterial::getTechnique ( ushort  technique)
inline

getter for Ogre::Technique*

Parameters
ushort: technique ID
Returns
Ogre::Technique pointer
Remarks
use this carefully: there is no safety check when accessing the technique, use exists(ushort) to validate

Definition at line 452 of file PMaterial.h.

References _mat.

Referenced by getPass(), and getTextureUnit().

Ogre::TextureUnitState* polymorph::PMaterial::getTextureUnit ( ushort  technique,
ushort  pass,
ushort  textureunit 
)
inline

getter for Ogre::TextureUnitState*

Parameters
ushort: technique ID
ushort: pass ID
ushort: texture unit ID
Returns
Ogre::TextureUnitState : pointer
Remarks
use this carefully: there is no safety check when accessing the texture unit, the pass or the technique, use exists(ushort,ushort,ushort) to validate
this method is slow because it loops over texture units to count them

Definition at line 484 of file PMaterial.h.

References _mat, getPass(), getTechnique(), getTextureUnitCount(), and print().

Referenced by setTexture().

Here is the call graph for this function:

uint PMaterial::getTextureUnitCount ( ushort  technique = 0,
ushort  pass = 0 
)

get the number of Ogre::TextureUnitState in a pass

Parameters
ushort: technique ID
ushort: pass ID
Returns
uint : number of texture unit(s)
Remarks
this method is slow because it loops over texture units to count them

Definition at line 439 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Referenced by exists(), and getTextureUnit().

Here is the call graph for this function:

bool PMaterial::load ( const std::string &  groupname,
const std::string &  materialname 
)

loading or retrieval of an existing Ogre::Material

Parameters
std::string,nameof the resource group
std::string,nameof the new material
Returns
bool : true if the material has been successfully loaded
Remarks
this method does not duplicate Ogre::Material, if it is already loaded, a new pointer is retrieved and stored
once successfully loaded, a PMaterial can not be loaded again

Definition at line 164 of file PMaterial.cpp.

References _group, _mat, _name, and polymorph::PUtil::getMaterial().

Here is the call graph for this function:

bool PMaterial::load ( Ogre::MaterialPtr  ptr)

loading of an existing Ogre::Material

Parameters
Ogre::MaterialPtr,pointerto the Ogre::Material to store
Returns
bool : true if the material has been successfully loaded
Remarks
once successfully loaded, a PMaterial can not be loaded again

Definition at line 190 of file PMaterial.cpp.

References _group, _mat, and _name.

void PMaterial::print ( bool  full = false)

print material info in console

Parameters
bool: set to true for full report: techniques, passes & texture units

Definition at line 486 of file PMaterial.cpp.

References _group, _mat, _name, and polymorph::PUtil::str().

Referenced by getTextureUnit().

Here is the call graph for this function:

bool PMaterial::setTexture ( std::string  groupname,
std::string  imagename,
ushort  technique = 0,
ushort  pass = 0,
ushort  textureunit = 0 
)

shortcut to load texture in a texture unit

Parameters
std::string,nameof the resource group
std::string,nameof the new material
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
ushort: texture unit ID, 0 by default
Returns
bool : true if success
Remarks
this method checks existence of texture unit, technique and pass before loading the texture

Definition at line 399 of file PMaterial.cpp.

References _mat, exists(), polymorph::PUtil::getTexture(), and getTextureUnit().

Referenced by fogColor().

Here is the call graph for this function:

bool PMaterial::setTexture ( const Ogre::TexturePtr &  ptr,
ushort  technique = 0,
ushort  pass = 0,
ushort  textureunit = 0 
)

shortcut to load texture pointer in a texture unit

Parameters
Ogre::TexturePtr,texturepointer
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
ushort: texture unit ID, 0 by default
Returns
bool : true if success
Remarks
this method checks existence of texture unit, technique and pass before loading the texture

Definition at line 420 of file PMaterial.cpp.

References _mat, exists(), and getTextureUnit().

Here is the call graph for this function:

void polymorph::PMaterial::specular ( Ogre::Real  r,
Ogre::Real  g,
Ogre::Real  b,
Ogre::Real  a = 1,
ushort  technique = 0,
ushort  pass = 0 
)
inline

shortcut to set specular color

Parameters
Ogre::Real: red channel, in range [0,1]
Ogre::Real: green channel, in range [0,1]
Ogre::Real: blue channel, in range [0,1]
Ogre::Real: alpha channel, in range [0,1], 1 by default
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this is a helper method, use specular( Ogre::ColourValue ) for better performance

Definition at line 162 of file PMaterial.h.

void PMaterial::specular ( const Ogre::ColourValue &  colour,
ushort  technique = 0,
ushort  pass = 0 
)

shortcut to set specular color

Parameters
Ogre::ColourValue: color value
ushort: technique ID, 0 by default
ushort: pass ID, 0 by default
Remarks
this method checks existence of technique and pass before applying the color

Definition at line 242 of file PMaterial.cpp.

References _mat, exists(), and getPass().

Here is the call graph for this function:

Member Data Documentation

std::string polymorph::PMaterial::_group
private

resource group name

Definition at line 519 of file PMaterial.h.

Referenced by create(), getGroup(), load(), PMaterial(), and print().

Ogre::MaterialPtr polymorph::PMaterial::_mat
private
std::string polymorph::PMaterial::_name
private

material name

Definition at line 523 of file PMaterial.h.

Referenced by create(), getName(), load(), PMaterial(), and print().


The documentation for this class was generated from the following files: