RigsofRods
Soft-body Physics Simulation
Data Structures | Public Types | Public Member Functions | Private Member Functions | Private Attributes
Hydrax::MaterialManager Class Reference

Material/Shader manager class. More...

#include <MaterialManager.h>

+ Collaboration diagram for Hydrax::MaterialManager:

Data Structures

struct  Options
 Material options. More...
 
class  UnderwaterCompositorListener
 Underwater compositor listener. More...
 

Public Types

enum  MaterialType {
  MAT_WATER = 0, MAT_DEPTH = 1, MAT_UNDERWATER = 2, MAT_UNDERWATER_COMPOSITOR = 3,
  MAT_SIMPLE_RED = 4, MAT_SIMPLE_BLACK = 5
}
 Material type enum. More...
 
enum  CompositorType { COMP_UNDERWATER = 0 }
 Compositor type enum. More...
 
enum  GpuProgram { GPUP_VERTEX = 0, GPUP_FRAGMENT = 1 }
 Gpu program enum. More...
 
enum  ShaderMode { SM_HLSL = 0, SM_CG = 1, SM_GLSL = 2 }
 Shader mode. More...
 
enum  NormalMode { NM_TEXTURE = 0, NM_VERTEX = 1, NM_RTT = 2 }
 Normal generation mode. More...
 

Public Member Functions

 MaterialManager (Hydrax *h)
 Constructor. More...
 
 ~MaterialManager ()
 Destructor. More...
 
bool createMaterials (const HydraxComponent &Components, const Options &Options)
 Create materials. More...
 
void removeMaterials ()
 Remove materials. More...
 
void removeCompositor ()
 Remove compositor. More...
 
void reload (const MaterialType &Material)
 Reload material. More...
 
bool fillGpuProgramsToPass (Ogre::Pass *Pass, const Ogre::String GpuProgramNames[2], const ShaderMode &SM, const Ogre::String EntryPoints[2], const Ogre::String Data[2])
 Fill GPU vertex and fragment program to a pass. More...
 
bool createGpuProgram (const Ogre::String &Name, const ShaderMode &SM, const GpuProgram &GPUP, const Ogre::String &EntryPoint, const Ogre::String &Data)
 Create GPU program. More...
 
const bool & isCreated () const
 Is createMaterials() already called? More...
 
Ogre::MaterialPtr & getMaterial (const MaterialType &Material)
 Get material. More...
 
Ogre::CompositorPtr & getCompositor (const CompositorType &Compositor)
 Get compositor. More...
 
const bool & isCompositorEnable (const CompositorType &Compositor) const
 Is the compositor enable? More...
 
void setCompositorEnable (const CompositorType &Compositor, const bool &Enable)
 Set a compositor enable/disable. More...
 
const OptionsgetLastOptions () const
 Get the last MaterialManager::Options used in a material generation. More...
 
void addDepthTechnique (Ogre::Technique *Technique, const bool &AutoUpdate=true)
 Add depth technique to an especified material. More...
 
void addDepthTextureTechnique (Ogre::Technique *Technique, const Ogre::String &TextureName, const Ogre::String &AlphaChannel="w", const bool &AutoUpdate=true)
 Add depth texture technique to an especified material. More...
 
std::vector< Ogre::Technique * > & getDepthTechniques ()
 Get external depth techniques. More...
 
void setGpuProgramParameter (const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Real &Value)
 Set gpu program Ogre::Real parameter. More...
 
void setGpuProgramParameter (const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Vector2 &Value)
 Set gpu program Ogre::Vector2 parameter. More...
 
void setGpuProgramParameter (const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Vector3 &Value)
 Set gpu program Ogre::Vector3 parameter. More...
 

Private Member Functions

bool _isComponent (const HydraxComponent &List, const HydraxComponent &ToCheck) const
 Is component in the given list? More...
 
bool _createWaterMaterial (const HydraxComponent &Components, const Options &Options)
 Create water material. More...
 
bool _createDepthMaterial (const HydraxComponent &Components, const Options &Options)
 Create depth material. More...
 
bool _createDepthTextureGPUPrograms (const HydraxComponent &Components, const Options &Options, const Ogre::String &AlphaChannel)
 Create depth texture gpu programs. More...
 
bool _createUnderwaterMaterial (const HydraxComponent &Components, const Options &Options)
 Create underwater material. More...
 
bool _createUnderwaterCompositor (const HydraxComponent &Components, const Options &Options)
 Create underwater compositor. More...
 
bool _createSimpleColorMaterial (const Ogre::ColourValue &MaterialColor, const MaterialType &MT, const Ogre::String &MaterialName, const bool &DepthCheck=true, const bool &DepthWrite=true)
 

Private Attributes

bool mCreated
 Is createMaterials() already called? More...
 
Ogre::MaterialPtr mMaterials [6]
 Hydrax materials vector. More...
 
Ogre::CompositorPtr mCompositors [1]
 Hydrax compositors vector. More...
 
bool mCompositorsNeedToBeReloaded [1]
 Hydrax compositors boolean: Need to be reloaded? More...
 
bool mCompositorsEnable [1]
 Hydrax compostor enable vector. More...
 
std::vector< Ogre::Technique * > mDepthTechniques
 Technique vector for addDepthTechnique(...) More...
 
HydraxComponent mComponents
 Actual material components. More...
 
Options mOptions
 Actual material options. More...
 
UnderwaterCompositorListener mUnderwaterCompositorListener
 Underwater compositor listener. More...
 
HydraxmHydrax
 Hydrax main pointer. More...
 

Detailed Description

Material/Shader manager class.

Definition at line 44 of file MaterialManager.h.

Member Enumeration Documentation

◆ CompositorType

Compositor type enum.

Remarks
Use in getCompositor(CompositorType)
Enumerator
COMP_UNDERWATER 

Definition at line 69 of file MaterialManager.h.

◆ GpuProgram

Gpu program enum.

Remarks
Use in setGpuProgramParameter()
Enumerator
GPUP_VERTEX 
GPUP_FRAGMENT 

Definition at line 78 of file MaterialManager.h.

◆ MaterialType

Material type enum.

Remarks
Use in getMaterial(MaterialType)
Enumerator
MAT_WATER 
MAT_DEPTH 
MAT_UNDERWATER 
MAT_UNDERWATER_COMPOSITOR 
MAT_SIMPLE_RED 
MAT_SIMPLE_BLACK 

Definition at line 50 of file MaterialManager.h.

◆ NormalMode

Normal generation mode.

Enumerator
NM_TEXTURE 
NM_VERTEX 
NM_RTT 

Definition at line 100 of file MaterialManager.h.

◆ ShaderMode

Shader mode.

Enumerator
SM_HLSL 
SM_CG 
SM_GLSL 

Definition at line 88 of file MaterialManager.h.

Constructor & Destructor Documentation

◆ MaterialManager()

Hydrax::MaterialManager::MaterialManager ( Hydrax h)

Constructor.

Parameters
hHydrax pointer

Definition at line 62 of file MaterialManager.cpp.

◆ ~MaterialManager()

Hydrax::MaterialManager::~MaterialManager ( )

Destructor.

Definition at line 81 of file MaterialManager.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ _createDepthMaterial()

bool Hydrax::MaterialManager::_createDepthMaterial ( const HydraxComponent Components,
const Options Options 
)
private

Create depth material.

Parameters
ComponentsComponents of the shader
OptionsMaterial options

Definition at line 1202 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createDepthTextureGPUPrograms()

bool Hydrax::MaterialManager::_createDepthTextureGPUPrograms ( const HydraxComponent Components,
const Options Options,
const Ogre::String &  AlphaChannel 
)
private

Create depth texture gpu programs.

Parameters
ComponentsComponents of the sahder
OptionsMaterial options
AlphaChannel"x","y","z","w" or "r","g","b","a" (Channel where alpha information is stored)
Returns
true if no problems had happend, false if yes

Definition at line 1542 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createSimpleColorMaterial()

bool Hydrax::MaterialManager::_createSimpleColorMaterial ( const Ogre::ColourValue &  MaterialColor,
const MaterialType MT,
const Ogre::String &  MaterialName,
const bool &  DepthCheck = true,
const bool &  DepthWrite = true 
)
private

Definition at line 3123 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createUnderwaterCompositor()

bool Hydrax::MaterialManager::_createUnderwaterCompositor ( const HydraxComponent Components,
const Options Options 
)
private

Create underwater compositor.

Parameters
ComponentsComponents of the shader
OptionsMaterial options

Definition at line 2740 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createUnderwaterMaterial()

bool Hydrax::MaterialManager::_createUnderwaterMaterial ( const HydraxComponent Components,
const Options Options 
)
private

Create underwater material.

Parameters
ComponentsComponents of the shader
OptionsMaterial options

Definition at line 1781 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createWaterMaterial()

bool Hydrax::MaterialManager::_createWaterMaterial ( const HydraxComponent Components,
const Options Options 
)
private

Create water material.

Parameters
ComponentsComponents of the shader
OptionsMaterial options

Definition at line 349 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _isComponent()

bool Hydrax::MaterialManager::_isComponent ( const HydraxComponent List,
const HydraxComponent ToCheck 
) const
private

Is component in the given list?

Parameters
ListComponents list
ToCheckComponent to check
Returns
true if the component is in the given list.

Definition at line 3507 of file MaterialManager.cpp.

+ Here is the caller graph for this function:

◆ addDepthTechnique()

void Hydrax::MaterialManager::addDepthTechnique ( Ogre::Technique *  Technique,
const bool &  AutoUpdate = true 
)

Add depth technique to an especified material.

Parameters
TechniqueTechnique where depth technique will be added
AutoUpdateThe technique will be automatically updated when water parameters change
Remarks
Call it after Hydrax::create()/Hydrax::setComponents(...)
     The technique will be automatically updated when water parameters change if parameter AutoUpdate == true
     Add depth technique when a material is not an Ogre::Entity, such terrains, PLSM2 materials, etc.
     This depth technique will be added with "HydraxDepth" scheme in ordeto can use it in the Depth RTT.

Definition at line 3371 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addDepthTextureTechnique()

void Hydrax::MaterialManager::addDepthTextureTechnique ( Ogre::Technique *  Technique,
const Ogre::String &  TextureName,
const Ogre::String &  AlphaChannel = "w",
const bool &  AutoUpdate = true 
)

Add depth texture technique to an especified material.

Parameters
TechniqueTechnique where depth technique will be added
TextureNameTexture name
AlphaChannel"x","y","z","w" or "r","g","b","a" (Channel where alpha information is stored)
AutoUpdateThe technique will be automatically updated when water parameters change
Remarks
Call it after Hydrax::create()/Hydrax::setComponents(...)
     The technique will be automatically updated when water parameters change if parameter AutoUpdate == true
     Add depth technique when a material is not an Ogre::Entity, such terrains, PLSM2 materials, etc.
     This depth technique will be added with "HydraxDepth" scheme in ordeto can use it in the Depth RTT.

Definition at line 3424 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createGpuProgram()

bool Hydrax::MaterialManager::createGpuProgram ( const Ogre::String &  Name,
const ShaderMode SM,
const GpuProgram GPUP,
const Ogre::String &  EntryPoint,
const Ogre::String &  Data 
)

Create GPU program.

Parameters
NameHighLevelGpuProgram name
SMShader mode
GPUPGpuProgram type
EntryPointEntry point
Data

Definition at line 261 of file MaterialManager.cpp.

+ Here is the caller graph for this function:

◆ createMaterials()

bool Hydrax::MaterialManager::createMaterials ( const HydraxComponent Components,
const Options Options 
)

Create materials.

Parameters
ComponentsComponents of the shader
OptionsMaterial options

Definition at line 163 of file MaterialManager.cpp.

+ Here is the call graph for this function:

◆ fillGpuProgramsToPass()

bool Hydrax::MaterialManager::fillGpuProgramsToPass ( Ogre::Pass *  Pass,
const Ogre::String  GpuProgramNames[2],
const ShaderMode SM,
const Ogre::String  EntryPoints[2],
const Ogre::String  Data[2] 
)

Fill GPU vertex and fragment program to a pass.

Parameters
PassPass to fill Gpu programs
GpuProgramNames[0]: Vertex program name, [1]: Fragment program name
SMShader mode, note: Provided data strings will correspong with selected shader mode
EntryPoints[0]: Vertex program entry point, [1]: Fragment program entry point
Data[0] Vertex program data, [1]: Fragment program data

Definition at line 239 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCompositor()

Ogre::CompositorPtr& Hydrax::MaterialManager::getCompositor ( const CompositorType Compositor)
inline

Get compositor.

Parameters
Compositorto get
Returns
Compositor to get

Definition at line 230 of file MaterialManager.h.

+ Here is the caller graph for this function:

◆ getDepthTechniques()

std::vector<Ogre::Technique*>& Hydrax::MaterialManager::getDepthTechniques ( )
inline

Get external depth techniques.

Returns
std::vector of external depth techniques

Definition at line 285 of file MaterialManager.h.

◆ getLastOptions()

const Options& Hydrax::MaterialManager::getLastOptions ( ) const
inline

Get the last MaterialManager::Options used in a material generation.

Returns
Last MaterialManager::Options used in a material generation

Definition at line 253 of file MaterialManager.h.

◆ getMaterial()

Ogre::MaterialPtr& Hydrax::MaterialManager::getMaterial ( const MaterialType Material)
inline

Get material.

Parameters
MaterialMaterial to get
Returns
Material to get

Definition at line 221 of file MaterialManager.h.

+ Here is the caller graph for this function:

◆ isCompositorEnable()

const bool& Hydrax::MaterialManager::isCompositorEnable ( const CompositorType Compositor) const
inline

Is the compositor enable?

Parameters
Compositorcompositor to check
Returns
true if it's enabled

Definition at line 239 of file MaterialManager.h.

◆ isCreated()

const bool& Hydrax::MaterialManager::isCreated ( ) const
inline

Is createMaterials() already called?

Returns
true If yes

Definition at line 212 of file MaterialManager.h.

+ Here is the caller graph for this function:

◆ reload()

void Hydrax::MaterialManager::reload ( const MaterialType Material)

Reload material.

Parameters
MaterialMaterial to reload

Definition at line 3143 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeCompositor()

void Hydrax::MaterialManager::removeCompositor ( )

Remove compositor.

Definition at line 147 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeMaterials()

void Hydrax::MaterialManager::removeMaterials ( )

Remove materials.

Remarks
removeCompositor() is called too.

Definition at line 86 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCompositorEnable()

void Hydrax::MaterialManager::setCompositorEnable ( const CompositorType Compositor,
const bool &  Enable 
)

Set a compositor enable/disable.

Parameters
Compositorcompositor to change
Enabletrue to enable, false to disable

Definition at line 3492 of file MaterialManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setGpuProgramParameter() [1/3]

void Hydrax::MaterialManager::setGpuProgramParameter ( const GpuProgram GpuP,
const MaterialType MType,
const Ogre::String &  Name,
const Ogre::Real &  Value 
)

Set gpu program Ogre::Real parameter.

Parameters
GpuPGpu program type (Vertex/Fragment)
MTypeWater/Depth material
Nameparam name
Valuevalue

Definition at line 3527 of file MaterialManager.cpp.

+ Here is the call graph for this function:

◆ setGpuProgramParameter() [2/3]

void Hydrax::MaterialManager::setGpuProgramParameter ( const GpuProgram GpuP,
const MaterialType MType,
const Ogre::String &  Name,
const Ogre::Vector2 &  Value 
)

Set gpu program Ogre::Vector2 parameter.

Parameters
GpuPGpu program type (Vertex/Fragment)
MTypeWater/Depth material
Nameparam name
Valuevalue

Definition at line 3585 of file MaterialManager.cpp.

+ Here is the call graph for this function:

◆ setGpuProgramParameter() [3/3]

void Hydrax::MaterialManager::setGpuProgramParameter ( const GpuProgram GpuP,
const MaterialType MType,
const Ogre::String &  Name,
const Ogre::Vector3 &  Value 
)

Set gpu program Ogre::Vector3 parameter.

Parameters
GpuPGpu program type (Vertex/Fragment)
MTypeWater/Depth material
Nameparam name
Valuevalue

Definition at line 3643 of file MaterialManager.cpp.

+ Here is the call graph for this function:

Field Documentation

◆ mComponents

HydraxComponent Hydrax::MaterialManager::mComponents
private

Actual material components.

Definition at line 369 of file MaterialManager.h.

◆ mCompositors

Ogre::CompositorPtr Hydrax::MaterialManager::mCompositors[1]
private

Hydrax compositors vector.

Definition at line 361 of file MaterialManager.h.

◆ mCompositorsEnable

bool Hydrax::MaterialManager::mCompositorsEnable[1]
private

Hydrax compostor enable vector.

Definition at line 365 of file MaterialManager.h.

◆ mCompositorsNeedToBeReloaded

bool Hydrax::MaterialManager::mCompositorsNeedToBeReloaded[1]
private

Hydrax compositors boolean: Need to be reloaded?

Definition at line 363 of file MaterialManager.h.

◆ mCreated

bool Hydrax::MaterialManager::mCreated
private

Is createMaterials() already called?

Definition at line 357 of file MaterialManager.h.

◆ mDepthTechniques

std::vector<Ogre::Technique*> Hydrax::MaterialManager::mDepthTechniques
private

Technique vector for addDepthTechnique(...)

Definition at line 367 of file MaterialManager.h.

◆ mHydrax

Hydrax* Hydrax::MaterialManager::mHydrax
private

Hydrax main pointer.

Definition at line 375 of file MaterialManager.h.

◆ mMaterials

Ogre::MaterialPtr Hydrax::MaterialManager::mMaterials[6]
private

Hydrax materials vector.

Definition at line 359 of file MaterialManager.h.

◆ mOptions

Options Hydrax::MaterialManager::mOptions
private

Actual material options.

Definition at line 371 of file MaterialManager.h.

◆ mUnderwaterCompositorListener

UnderwaterCompositorListener Hydrax::MaterialManager::mUnderwaterCompositorListener
private

Underwater compositor listener.

Definition at line 373 of file MaterialManager.h.


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