RigsofRods
Soft-body Physics Simulation
MaterialManager.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #ifndef _Hydrax_MaterialManager_H_
26 #define _Hydrax_MaterialManager_H_
27 
28 #include "Prerequisites.h"
29 
30 #include "Enums.h"
31 
34 
37 
38 namespace Hydrax
39 {
40  class Hydrax;
41 
45  {
46  public:
51  {
52  // Water material
53  MAT_WATER = 0,
54  // Depth material
55  MAT_DEPTH = 1,
56  // Underwater material
58  // Compositor material(material wich is used in underwater compositor)
60  // Simple red material
62  // Simple black material
64  };
65 
70  {
71  // Underwater compositor
73  };
74 
79  {
80  // Vertex program
82  // Fragment program
84  };
85 
89  {
90  // HLSL
91  SM_HLSL = 0,
92  // Cg
93  SM_CG = 1,
94  // GLSL
95  SM_GLSL = 2
96  };
97 
101  {
102  // Normal map from precomputed texture(CPU)
104  // Normal map from vertex(CPU)
106  // Normal map from RTT(GPU)
107  NM_RTT = 2
108  };
109 
112  struct Options
113  {
117  : SM(SM_HLSL)
118  , NM(NM_TEXTURE)
119  {
120  }
121 
126  Options(const ShaderMode &_SM,
127  const NormalMode &_NM)
128  : SM(_SM)
129  , NM(_NM)
130  {
131  }
132 
137  };
138 
141  class UnderwaterCompositorListener : public Ogre::CompositorInstance::Listener
142  {
143  public:
145  void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat);
146 
148  void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat);
149 
152  };
153 
158 
162 
167  bool createMaterials(const HydraxComponent &Components, const Options &Options);
168 
172  void removeMaterials();
173 
176  void removeCompositor();
177 
181  void reload(const MaterialType &Material);
182 
190  bool fillGpuProgramsToPass(Ogre::Pass* Pass,
191  const Ogre::String GpuProgramNames[2],
192  const ShaderMode& SM,
193  const Ogre::String EntryPoints[2],
194  const Ogre::String Data[2]);
195 
203  bool createGpuProgram(const Ogre::String &Name,
204  const ShaderMode& SM,
205  const GpuProgram& GPUP,
206  const Ogre::String& EntryPoint,
207  const Ogre::String& Data);
208 
212  inline const bool& isCreated() const
213  {
214  return mCreated;
215  }
216 
221  inline Ogre::MaterialPtr &getMaterial(const MaterialType &Material)
222  {
223  return mMaterials[static_cast<int>(Material)];
224  }
225 
230  inline Ogre::CompositorPtr &getCompositor(const CompositorType &Compositor)
231  {
232  return mCompositors[static_cast<int>(Compositor)];
233  }
234 
239  inline const bool& isCompositorEnable(const CompositorType &Compositor) const
240  {
241  return mCompositorsEnable[static_cast<int>(Compositor)];
242  }
243 
248  void setCompositorEnable(const CompositorType &Compositor, const bool &Enable);
249 
253  inline const Options &getLastOptions() const
254  {
255  return mOptions;
256  }
257 
267  void addDepthTechnique(Ogre::Technique *Technique, const bool& AutoUpdate = true);
268 
280  void addDepthTextureTechnique(Ogre::Technique *Technique, const Ogre::String& TextureName, const Ogre::String& AlphaChannel = "w", const bool& AutoUpdate = true);
281 
285  inline std::vector<Ogre::Technique*> &getDepthTechniques()
286  {
287  return mDepthTechniques;
288  }
289 
296  void setGpuProgramParameter(const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Real &Value);
297 
304  void setGpuProgramParameter(const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Vector2 &Value);
305 
312  void setGpuProgramParameter(const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Vector3 &Value);
313 
314  private:
320  bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const;
321 
326  bool _createWaterMaterial(const HydraxComponent &Components, const Options &Options);
327 
332  bool _createDepthMaterial(const HydraxComponent &Components, const Options &Options);
333 
340  bool _createDepthTextureGPUPrograms(const HydraxComponent &Components, const Options &Options, const Ogre::String& AlphaChannel);
341 
346  bool _createUnderwaterMaterial(const HydraxComponent &Components, const Options &Options);
347 
352  bool _createUnderwaterCompositor(const HydraxComponent &Components, const Options &Options);
353 
354  bool _createSimpleColorMaterial(const Ogre::ColourValue& MaterialColor, const MaterialType& MT, const Ogre::String& MaterialName, const bool& DepthCheck = true, const bool& DepthWrite = true);
355 
357  bool mCreated;
359  Ogre::MaterialPtr mMaterials[6];
361  Ogre::CompositorPtr mCompositors[1];
367  std::vector<Ogre::Technique*> mDepthTechniques;
376  };
377 };
378 
381 
382 #endif
Hydrax::MaterialManager::removeCompositor
void removeCompositor()
Remove compositor.
Definition: MaterialManager.cpp:147
Hydrax::MaterialManager::MAT_UNDERWATER
@ MAT_UNDERWATER
Definition: MaterialManager.h:57
Hydrax::MaterialManager::NM_TEXTURE
@ NM_TEXTURE
Definition: MaterialManager.h:103
Hydrax::MaterialManager::mOptions
Options mOptions
Actual material options.
Definition: MaterialManager.h:371
Hydrax::MaterialManager::mMaterials
Ogre::MaterialPtr mMaterials[6]
Hydrax materials vector.
Definition: MaterialManager.h:359
Hydrax::MaterialManager::mCompositors
Ogre::CompositorPtr mCompositors[1]
Hydrax compositors vector.
Definition: MaterialManager.h:361
Hydrax::MaterialManager::UnderwaterCompositorListener
Underwater compositor listener.
Definition: MaterialManager.h:141
Hydrax::MaterialManager::SM_GLSL
@ SM_GLSL
Definition: MaterialManager.h:95
Hydrax::MaterialManager::getMaterial
Ogre::MaterialPtr & getMaterial(const MaterialType &Material)
Get material.
Definition: MaterialManager.h:221
Hydrax::MaterialManager::_createDepthMaterial
bool _createDepthMaterial(const HydraxComponent &Components, const Options &Options)
Create depth material.
Definition: MaterialManager.cpp:1202
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::MaterialManager::_createUnderwaterCompositor
bool _createUnderwaterCompositor(const HydraxComponent &Components, const Options &Options)
Create underwater compositor.
Definition: MaterialManager.cpp:2740
Hydrax::MaterialManager::MaterialType
MaterialType
Material type enum.
Definition: MaterialManager.h:50
Hydrax::MaterialManager::mCompositorsNeedToBeReloaded
bool mCompositorsNeedToBeReloaded[1]
Hydrax compositors boolean: Need to be reloaded?
Definition: MaterialManager.h:363
Hydrax::MaterialManager::_createDepthTextureGPUPrograms
bool _createDepthTextureGPUPrograms(const HydraxComponent &Components, const Options &Options, const Ogre::String &AlphaChannel)
Create depth texture gpu programs.
Definition: MaterialManager.cpp:1542
Hydrax::MaterialManager
Material/Shader manager class.
Definition: MaterialManager.h:44
Hydrax::MaterialManager::mHydrax
Hydrax * mHydrax
Hydrax main pointer.
Definition: MaterialManager.h:375
Hydrax::MaterialManager::getDepthTechniques
std::vector< Ogre::Technique * > & getDepthTechniques()
Get external depth techniques.
Definition: MaterialManager.h:285
Hydrax::MaterialManager::MAT_DEPTH
@ MAT_DEPTH
Definition: MaterialManager.h:55
Hydrax::MaterialManager::COMP_UNDERWATER
@ COMP_UNDERWATER
Definition: MaterialManager.h:72
Hydrax::MaterialManager::Options
Material options.
Definition: MaterialManager.h:112
Enums.h
Hydrax::MaterialManager::createMaterials
bool createMaterials(const HydraxComponent &Components, const Options &Options)
Create materials.
Definition: MaterialManager.cpp:163
Hydrax::MaterialManager::MAT_SIMPLE_BLACK
@ MAT_SIMPLE_BLACK
Definition: MaterialManager.h:63
Hydrax::MaterialManager::_createUnderwaterMaterial
bool _createUnderwaterMaterial(const HydraxComponent &Components, const Options &Options)
Create underwater material.
Definition: MaterialManager.cpp:1781
Hydrax::MaterialManager::UnderwaterCompositorListener::notifyMaterialRender
void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
On material render.
Definition: MaterialManager.cpp:3710
Hydrax::MaterialManager::mCreated
bool mCreated
Is createMaterials() already called?
Definition: MaterialManager.h:357
Hydrax::MaterialManager::fillGpuProgramsToPass
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.
Definition: MaterialManager.cpp:239
Hydrax::MaterialManager::SM_HLSL
@ SM_HLSL
Definition: MaterialManager.h:91
Hydrax::MaterialManager::setCompositorEnable
void setCompositorEnable(const CompositorType &Compositor, const bool &Enable)
Set a compositor enable/disable.
Definition: MaterialManager.cpp:3492
Hydrax::MaterialManager::addDepthTextureTechnique
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.
Definition: MaterialManager.cpp:3424
Hydrax::MaterialManager::UnderwaterCompositorListener::mMaterialManager
MaterialManager * mMaterialManager
Material manager parent pointer.
Definition: MaterialManager.h:151
Hydrax::MaterialManager::removeMaterials
void removeMaterials()
Remove materials.
Definition: MaterialManager.cpp:86
Hydrax::MaterialManager::getLastOptions
const Options & getLastOptions() const
Get the last MaterialManager::Options used in a material generation.
Definition: MaterialManager.h:253
Hydrax::MaterialManager::NormalMode
NormalMode
Normal generation mode.
Definition: MaterialManager.h:100
Hydrax::MaterialManager::mUnderwaterCompositorListener
UnderwaterCompositorListener mUnderwaterCompositorListener
Underwater compositor listener.
Definition: MaterialManager.h:373
Hydrax::MaterialManager::GPUP_FRAGMENT
@ GPUP_FRAGMENT
Definition: MaterialManager.h:83
Hydrax::MaterialManager::setGpuProgramParameter
void setGpuProgramParameter(const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Real &Value)
Set gpu program Ogre::Real parameter.
Definition: MaterialManager.cpp:3527
Hydrax::MaterialManager::MAT_SIMPLE_RED
@ MAT_SIMPLE_RED
Definition: MaterialManager.h:61
Hydrax::MaterialManager::isCreated
const bool & isCreated() const
Is createMaterials() already called?
Definition: MaterialManager.h:212
Hydrax::MaterialManager::reload
void reload(const MaterialType &Material)
Reload material.
Definition: MaterialManager.cpp:3143
Hydrax::MaterialManager::NM_RTT
@ NM_RTT
Definition: MaterialManager.h:107
Hydrax::MaterialManager::addDepthTechnique
void addDepthTechnique(Ogre::Technique *Technique, const bool &AutoUpdate=true)
Add depth technique to an especified material.
Definition: MaterialManager.cpp:3371
Prerequisites.h
Hydrax::MaterialManager::_createSimpleColorMaterial
bool _createSimpleColorMaterial(const Ogre::ColourValue &MaterialColor, const MaterialType &MT, const Ogre::String &MaterialName, const bool &DepthCheck=true, const bool &DepthWrite=true)
Definition: MaterialManager.cpp:3123
Hydrax::MaterialManager::mComponents
HydraxComponent mComponents
Actual material components.
Definition: MaterialManager.h:369
Hydrax::MaterialManager::createGpuProgram
bool createGpuProgram(const Ogre::String &Name, const ShaderMode &SM, const GpuProgram &GPUP, const Ogre::String &EntryPoint, const Ogre::String &Data)
Create GPU program.
Definition: MaterialManager.cpp:261
Hydrax::MaterialManager::MAT_WATER
@ MAT_WATER
Definition: MaterialManager.h:53
Hydrax::HydraxComponent
HydraxComponent
Hydrax flags to select components wich we want to use.
Definition: Enums.h:57
Hydrax::MaterialManager::MAT_UNDERWATER_COMPOSITOR
@ MAT_UNDERWATER_COMPOSITOR
Definition: MaterialManager.h:59
Hydrax::MaterialManager::Options::NM
NormalMode NM
Normal map generation mode.
Definition: MaterialManager.h:136
Hydrax::MaterialManager::Options::Options
Options(const ShaderMode &_SM, const NormalMode &_NM)
Constructor.
Definition: MaterialManager.h:126
Hydrax::MaterialManager::~MaterialManager
~MaterialManager()
Destructor.
Definition: MaterialManager.cpp:81
Hydrax::MaterialManager::SM_CG
@ SM_CG
Definition: MaterialManager.h:93
Hydrax::MaterialManager::_isComponent
bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const
Is component in the given list?
Definition: MaterialManager.cpp:3507
Hydrax::MaterialManager::Options::SM
ShaderMode SM
Shader mode.
Definition: MaterialManager.h:134
Hydrax::MaterialManager::mDepthTechniques
std::vector< Ogre::Technique * > mDepthTechniques
Technique vector for addDepthTechnique(...)
Definition: MaterialManager.h:367
Hydrax::MaterialManager::ShaderMode
ShaderMode
Shader mode.
Definition: MaterialManager.h:88
Hydrax::MaterialManager::Options::Options
Options()
Default constructor.
Definition: MaterialManager.h:116
Hydrax::MaterialManager::GpuProgram
GpuProgram
Gpu program enum.
Definition: MaterialManager.h:78
Hydrax::MaterialManager::getCompositor
Ogre::CompositorPtr & getCompositor(const CompositorType &Compositor)
Get compositor.
Definition: MaterialManager.h:230
Hydrax::MaterialManager::_createWaterMaterial
bool _createWaterMaterial(const HydraxComponent &Components, const Options &Options)
Create water material.
Definition: MaterialManager.cpp:349
Hydrax::MaterialManager::UnderwaterCompositorListener::notifyMaterialSetup
void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
On material setup.
Definition: MaterialManager.cpp:3701
Hydrax::MaterialManager::GPUP_VERTEX
@ GPUP_VERTEX
Definition: MaterialManager.h:81
Hydrax::MaterialManager::CompositorType
CompositorType
Compositor type enum.
Definition: MaterialManager.h:69
Hydrax::MaterialManager::mCompositorsEnable
bool mCompositorsEnable[1]
Hydrax compostor enable vector.
Definition: MaterialManager.h:365
Hydrax::MaterialManager::MaterialManager
MaterialManager(Hydrax *h)
Constructor.
Definition: MaterialManager.cpp:62
Hydrax::MaterialManager::isCompositorEnable
const bool & isCompositorEnable(const CompositorType &Compositor) const
Is the compositor enable?
Definition: MaterialManager.h:239
Hydrax::MaterialManager::NM_VERTEX
@ NM_VERTEX
Definition: MaterialManager.h:105