Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
MaterialManager.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://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
38namespace Hydrax
39{
40 class Hydrax;
41
45 {
46 public:
51 {
52 // Water material
54 // Depth material
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
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
316 void updateAnimatedTextures(float dt);
317
318 private:
324 bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const;
325
330 bool _createWaterMaterial(const HydraxComponent &Components, const Options &Options);
331
336 bool _createDepthMaterial(const HydraxComponent &Components, const Options &Options);
337
344 bool _createDepthTextureGPUPrograms(const HydraxComponent &Components, const Options &Options, const Ogre::String& AlphaChannel);
345
350 bool _createUnderwaterMaterial(const HydraxComponent &Components, const Options &Options);
351
356 bool _createUnderwaterCompositor(const HydraxComponent &Components, const Options &Options);
357
358 bool _createSimpleColorMaterial(const Ogre::ColourValue& MaterialColor, const MaterialType& MT, const Ogre::String& MaterialName, const bool& DepthCheck = true, const bool& DepthWrite = true);
359
363 Ogre::MaterialPtr mMaterials[6];
365 Ogre::CompositorPtr mCompositors[1];
371 std::vector<Ogre::Technique*> mDepthTechniques;
381 std::vector<Ogre::TextureUnitState*> mCausticsAnimTexVec;
385 };
386};
387
390
391#endif
void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
On material render.
MaterialManager * mMaterialManager
Material manager parent pointer.
void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
On material setup.
Material/Shader manager class.
bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const
Is component in the given list?
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.
bool _createDepthTextureGPUPrograms(const HydraxComponent &Components, const Options &Options, const Ogre::String &AlphaChannel)
Create depth texture gpu programs.
void removeCompositor()
Remove compositor.
Options mOptions
Actual material options.
bool _createWaterMaterial(const HydraxComponent &Components, const Options &Options)
Create water material.
float mCausticsAnimCurrentFrameElapsedTime
Time spent on current animation frame, cumulative.
Ogre::CompositorPtr mCompositors[1]
Hydrax compositors vector.
bool _createUnderwaterMaterial(const HydraxComponent &Components, const Options &Options)
Create underwater material.
bool mCompositorsNeedToBeReloaded[1]
Hydrax compositors boolean: Need to be reloaded?
void reload(const MaterialType &Material)
Reload material.
const bool & isCompositorEnable(const CompositorType &Compositor) const
Is the compositor enable?
bool _createUnderwaterCompositor(const HydraxComponent &Components, const Options &Options)
Create underwater compositor.
Ogre::MaterialPtr & getMaterial(const MaterialType &Material)
Get material.
bool _createSimpleColorMaterial(const Ogre::ColourValue &MaterialColor, const MaterialType &MT, const Ogre::String &MaterialName, const bool &DepthCheck=true, const bool &DepthWrite=true)
bool mCompositorsEnable[1]
Hydrax compostor enable vector.
Ogre::CompositorPtr & getCompositor(const CompositorType &Compositor)
Get compositor.
std::vector< Ogre::TextureUnitState * > mCausticsAnimTexVec
Caustics animated texture, for manual updating.
std::vector< Ogre::Technique * > mDepthTechniques
Technique vector for addDepthTechnique(...)
void setCompositorEnable(const CompositorType &Compositor, const bool &Enable)
Set a compositor enable/disable.
bool createMaterials(const HydraxComponent &Components, const Options &Options)
Create materials.
bool mCreated
Is createMaterials() already called?
const Options & getLastOptions() const
Get the last MaterialManager::Options used in a material generation.
HydraxComponent mComponents
Actual material components.
const bool & isCreated() const
Is createMaterials() already called?
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.
void removeMaterials()
Remove materials.
CompositorType
Compositor type enum.
GpuProgram
Gpu program enum.
NormalMode
Normal generation mode.
std::vector< Ogre::Technique * > & getDepthTechniques()
Get external depth techniques.
Hydrax * mHydrax
Hydrax main pointer.
void addDepthTechnique(Ogre::Technique *Technique, const bool &AutoUpdate=true)
Add depth technique to an especified material.
bool createGpuProgram(const Ogre::String &Name, const ShaderMode &SM, const GpuProgram &GPUP, const Ogre::String &EntryPoint, const Ogre::String &Data)
Create GPU program.
Ogre::MaterialPtr mMaterials[6]
Hydrax materials vector.
MaterialType
Material type enum.
bool _createDepthMaterial(const HydraxComponent &Components, const Options &Options)
Create depth material.
unsigned int mCausticsAnimCurrentFrame
void updateAnimatedTextures(float dt)
Animated textures must be updated manually to account for variable simulation time.
void setGpuProgramParameter(const GpuProgram &GpuP, const MaterialType &MType, const Ogre::String &Name, const Ogre::Real &Value)
Set gpu program Ogre::Real parameter.
UnderwaterCompositorListener mUnderwaterCompositorListener
Underwater compositor listener.
HydraxComponent
Hydrax flags to select components wich we want to use.
Definition Enums.h:58
NormalMode NM
Normal map generation mode.
Options(const ShaderMode &_SM, const NormalMode &_NM)
Constructor.