OgreMaterial.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _Material_H__
29 #define _Material_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreResource.h"
34 #include "OgreIteratorWrappers.h"
35 #include "OgreCommon.h"
36 #include "OgreColourValue.h"
37 #include "OgreBlendMode.h"
38 #include "OgreHeaderPrefix.h"
39 
40 namespace Ogre {
41 
42  // Forward declaration
43  class LodStrategy;
44 
88  class _OgreExport Material : public Resource
89  {
90  friend class SceneManager;
91  friend class MaterialManager;
92 
93  public:
97  protected:
98 
99 
102  void applyDefaults(void);
103 
116 
126 
129 
133 
136  void prepareImpl(void);
137 
140  void unprepareImpl(void);
141 
144  void loadImpl(void);
145 
150  void unloadImpl(void);
152  size_t calculateSize(void) const;
153  public:
154 
157  Material(ResourceManager* creator, const String& name, ResourceHandle handle,
158  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
159 
163  Material& operator=( const Material& rhs );
164 
168  bool isTransparent(void) const;
169 
183  void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
185  bool getReceiveShadows(void) const { return mReceiveShadows; }
186 
195  void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
197  bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
198 
215  Technique* getTechnique(unsigned short index);
221  unsigned short getNumTechniques(void) const;
223  void removeTechnique(unsigned short index);
236 
238  Technique* getSupportedTechnique(unsigned short index);
240  unsigned short getNumSupportedTechniques(void) const;
242  const String& getUnsupportedTechniquesExplanation() const { return mUnsupportedReasons; }
243 
249  unsigned short getNumLodLevels(unsigned short schemeIndex) const;
255  unsigned short getNumLodLevels(const String& schemeName) const;
256 
272  Technique* getBestTechnique(unsigned short lodIndex = 0, const Renderable* rend = 0);
273 
274 
280  MaterialPtr clone(const String& newName, bool changeGroup = false,
281  const String& newGroup = StringUtil::BLANK) const;
282 
287  void copyDetailsTo(MaterialPtr& mat) const;
288 
304  void compile(bool autoManageTextureUnits = true);
305 
306  // -------------------------------------------------------------------------------
307  // The following methods are to make migration from previous versions simpler
308  // and to make code easier to write when dealing with simple materials
309  // They set the properties which have been moved to Pass for all Techniques and all Passes
310 
320  void setPointSize(Real ps);
321 
331  void setAmbient(Real red, Real green, Real blue);
332 
342  void setAmbient(const ColourValue& ambient);
343 
353  void setDiffuse(Real red, Real green, Real blue, Real alpha);
354 
364  void setDiffuse(const ColourValue& diffuse);
365 
375  void setSpecular(Real red, Real green, Real blue, Real alpha);
376 
386  void setSpecular(const ColourValue& specular);
387 
397  void setShininess(Real val);
398 
408  void setSelfIllumination(Real red, Real green, Real blue);
409 
419  void setSelfIllumination(const ColourValue& selfIllum);
420 
430  void setDepthCheckEnabled(bool enabled);
431 
441  void setDepthWriteEnabled(bool enabled);
442 
453 
463  void setColourWriteEnabled(bool enabled);
464 
475 
486 
496  void setLightingEnabled(bool enabled);
497 
508 
518  void setFog(
519  bool overrideScene,
520  FogMode mode = FOG_NONE,
521  const ColourValue& colour = ColourValue::White,
522  Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
523 
533  void setDepthBias(float constantBias, float slopeScaleBias);
534 
552  void setTextureAnisotropy(int maxAniso);
553 
563  void setSceneBlending( const SceneBlendType sbt );
564 
575 
585  void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
586 
596  void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha);
597 
600 
615  void setLodLevels(const LodValueList& lodValues);
616 
625 
634 
640  ushort getLodIndex(Real value) const;
641 
643  const LodStrategy *getLodStrategy() const;
645  void setLodStrategy(LodStrategy *lodStrategy);
646 
649  void touch(void)
650  {
651  if (mCompilationRequired)
652  compile();
653  // call superclass
654  Resource::touch();
655  }
656 
668  bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
669 
674  {
675  return mCompilationRequired;
676  }
677 
678 
679  };
683 } //namespace
684 
685 #include "OgreHeaderSuffix.h"
686 
687 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
Class representing colour.
static const ColourValue White
Concrete IteratorWrapper for const access to the underlying container.
Strategy for determining level of detail.
Interface describing a manual resource loader.
Definition: OgreResource.h:515
Class for managing Material settings for Ogre.
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:89
void setShininess(Real val)
Sets the shininess properties of every Pass in every Technique.
bool isTransparent(void) const
Determines if the material has any transparency with the rest of the scene (derived from whether any ...
ConstVectorIterator< LodValueList > LodValueIterator
Definition: OgreMaterial.h:96
void setSeparateSceneBlending(const SceneBlendType sbt, const SceneBlendType sbta)
Sets the kind of blending every pass has with the existing contents of the scene, using individual fa...
bool getCompilationRequired() const
Gets the compilation status of the material.
Definition: OgreMaterial.h:673
map< unsigned short, LodTechniques * >::type BestTechniquesBySchemeList
Definition: OgreMaterial.h:110
const LodStrategy * mLodStrategy
Definition: OgreMaterial.h:119
void setSelfIllumination(Real red, Real green, Real blue)
Sets the amount of self-illumination of every Pass in every Technique.
void unloadImpl(void)
Unloads the material, frees resources etc.
void removeAllTechniques(void)
Removes all the techniques in this Material.
void setSceneBlending(const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor)
Allows very fine control of blending every Pass with the existing contents of the scene.
MaterialPtr clone(const String &newName, bool changeGroup=false, const String &newGroup=StringUtil::BLANK) const
Creates a new copy of this material with the same settings but a new name.
void setSpecular(Real red, Real green, Real blue, Real alpha)
Sets the specular colour reflectance properties of every Pass in every Technique.
void compile(bool autoManageTextureUnits=true)
'Compiles' this Material.
const String & getUnsupportedTechniquesExplanation() const
Gets a string explaining why any techniques are not supported.
Definition: OgreMaterial.h:242
void setTextureFiltering(TextureFilterOptions filterType)
Set texture filtering for every texture unit in every Technique and Pass.
LodValueList mUserLodValues
Definition: OgreMaterial.h:117
void copyDetailsTo(MaterialPtr &mat) const
Copies the details of this material into another, preserving the target's handle and name (unlike ope...
map< unsigned short, Technique * >::type LodTechniques
Definition: OgreMaterial.h:109
void setSelfIllumination(const ColourValue &selfIllum)
Sets the amount of self-illumination of every Pass in every Technique.
TechniqueIterator getTechniqueIterator(void)
Get an iterator over the Techniques in this Material.
void setFog(bool overrideScene, FogMode mode=FOG_NONE, const ColourValue &colour=ColourValue::White, Real expDensity=0.001, Real linearStart=0.0, Real linearEnd=1.0)
Sets the fogging mode applied to each pass.
unsigned short getNumLodLevels(unsigned short schemeIndex) const
Gets the number of levels-of-detail this material has in the given scheme, based on Technique::setLod...
void touch(void)
'Touches' the resource to indicate it has been used.
Definition: OgreMaterial.h:649
Technique * getBestTechnique(unsigned short lodIndex=0, const Renderable *rend=0)
Gets the best supported technique.
bool applyTextureAliases(const AliasTextureNamePairList &aliasList, const bool apply=true) const
Applies texture names to Texture Unit State with matching texture name aliases.
void unprepareImpl(void)
Overridden from Resource.
void setDepthCheckEnabled(bool enabled)
Sets whether or not each Pass renders with depth-buffer checking on or not.
Technique * getTechnique(const String &name)
searches for the named technique.
VectorIterator< Techniques > TechniqueIterator
Definition: OgreMaterial.h:226
vector< Real >::type LodValueList
distance list used to specify LOD
Definition: OgreMaterial.h:95
void setAmbient(Real red, Real green, Real blue)
Sets the ambient colour reflectance properties for every Pass in every Technique.
void setTransparencyCastsShadows(bool enabled)
Sets whether objects using this material be classified as opaque to the shadow caster system.
Definition: OgreMaterial.h:195
void loadImpl(void)
Overridden from Resource.
void setDepthFunction(CompareFunction func)
Sets the function used to compare depth values when depth checking is on.
void _notifyNeedsRecompile(void)
Tells the material that it needs recompilation.
void setLodLevels(const LodValueList &lodValues)
Sets the distance at which level-of-detail (LOD) levels come into effect.
unsigned short getNumTechniques(void) const
Retrieves the number of techniques.
Techniques mSupportedTechniques
Supported techniques of any sort.
Definition: OgreMaterial.h:108
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
void setLightingEnabled(bool enabled)
Sets whether or not dynamic lighting is enabled for every Pass.
bool getReceiveShadows(void) const
Returns whether or not objects using this material will receive shadows.
Definition: OgreMaterial.h:185
void insertSupportedTechnique(Technique *t)
Insert a supported technique into the local collections.
void setLodStrategy(LodStrategy *lodStrategy)
Set the LOD strategy used by this material.
void setCullingMode(CullingMode mode)
Sets the culling mode for each pass based on the 'vertex winding'.
void removeTechnique(unsigned short index)
Removes the technique at the given index.
void setPointSize(Real ps)
Sets the point size properties for every Pass in every Technique.
void setSceneBlending(const SceneBlendType sbt)
Sets the kind of blending every pass has with the existing contents of the scene.
unsigned short getNumLodLevels(const String &schemeName) const
Gets the number of levels-of-detail this material has in the given scheme, based on Technique::setLod...
TechniqueIterator getSupportedTechniqueIterator(void)
Gets an iterator over all the Techniques which are supported by the current card.
String mUnsupportedReasons
Text description of why any techniques are not supported.
Definition: OgreMaterial.h:125
bool mCompilationRequired
Does this material require compilation?
Definition: OgreMaterial.h:123
void applyDefaults(void)
Internal method which sets the material up from the default settings.
void setTextureAnisotropy(int maxAniso)
Sets the anisotropy level to be used for all textures.
void setSeparateSceneBlending(const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha)
Allows very fine control of blending every Pass with the existing contents of the scene,...
LodValueIterator getUserLodValueIterator(void) const
Gets an iterator over the user-defined list of values which are internally transfomed by the LodStrat...
bool getTransparencyCastsShadows(void) const
Returns whether or not objects using this material be classified as opaque to the shadow caster syste...
Definition: OgreMaterial.h:197
void setColourWriteEnabled(bool enabled)
Sets whether or not colour buffer writing is enabled for each Pass.
Technique * getTechnique(unsigned short index)
Gets the indexed technique.
void setDepthWriteEnabled(bool enabled)
Sets whether or not each Pass renders with depth-buffer writing on or not.
void setReceiveShadows(bool enabled)
Sets whether objects using this material will receive shadows.
Definition: OgreMaterial.h:183
void setShadingMode(ShadeOptions mode)
Sets the type of light shading required.
BestTechniquesBySchemeList mBestTechniquesBySchemeList
Map of scheme -> list of LOD techniques.
Definition: OgreMaterial.h:115
void setDiffuse(const ColourValue &diffuse)
Sets the diffuse colour reflectance properties of every Pass in every Technique.
void setSpecular(const ColourValue &specular)
Sets the specular colour reflectance properties of every Pass in every Technique.
void clearBestTechniqueList(void)
Clear the best technique list.
void prepareImpl(void)
Overridden from Resource.
void setDepthBias(float constantBias, float slopeScaleBias)
Sets the depth bias to be used for each Pass.
const LodStrategy * getLodStrategy() const
Get LOD strategy used by this material.
Technique * getSupportedTechnique(unsigned short index)
Gets the indexed supported technique.
void setManualCullingMode(ManualCullingMode mode)
Sets the manual culling mode, performed by CPU rather than hardware.
Material & operator=(const Material &rhs)
Assignment operator to allow easy copying between materials.
unsigned short getNumSupportedTechniques(void) const
Retrieves the number of supported techniques.
Techniques mTechniques
All techniques, supported and unsupported.
Definition: OgreMaterial.h:106
Material(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
Constructor - use resource manager's create method rather than this.
LodValueList mLodValues
Definition: OgreMaterial.h:118
void setDiffuse(Real red, Real green, Real blue, Real alpha)
Sets the diffuse colour reflectance properties of every Pass in every Technique.
bool mTransparencyCastsShadows
Definition: OgreMaterial.h:121
void setAmbient(const ColourValue &ambient)
Sets the ambient colour reflectance properties for every Pass in every Technique.
Technique * createTechnique(void)
Creates a new Technique for this Material.
ushort getLodIndex(Real value) const
Gets the LOD index to use at the given value.
LodValueIterator getLodValueIterator(void) const
Gets an iterator over the list of values transformed by the LodStrategy at which each LOD comes into ...
vector< Technique * >::type Techniques
Definition: OgreMaterial.h:104
Abstract class defining the interface all renderable objects must implement.
Defines a generic resource handler.
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:80
virtual void touch(void)
'Touches' the resource to indicate it has been used.
Manages the organisation and rendering of a 'scene' i.e.
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:54
Concrete IteratorWrapper for nonconst access to the underlying container.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:65
ManualCullingMode
Manual culling modes based on vertex normals.
Definition: OgreCommon.h:151
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:553
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition: OgreCommon.h:79
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:114
FogMode
Fog modes.
Definition: OgreCommon.h:122
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:136
@ FOG_NONE
No fog. Duh.
Definition: OgreCommon.h:124
SceneBlendFactor
Blending factors for manually blending objects with the scene.
SceneBlendType
Types of blending that you can specify between an object and the existing contents of the scene.
float Real
Software floating point type.
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
_StringBase String
unsigned short ushort
std::map< K, V, P, A > type

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.