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
OgreHeaderSuffix.h
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::Material::Techniques
vector< Technique * >::type Techniques
Definition: OgreMaterial.h:104
Ogre::Material::setSelfIllumination
void setSelfIllumination(const ColourValue &selfIllum)
Sets the amount of self-illumination of every Pass in every Technique.
Ogre::Material::getTechnique
Technique * getTechnique(unsigned short index)
Gets the indexed technique.
Ogre::Material::LodValueIterator
ConstVectorIterator< LodValueList > LodValueIterator
Definition: OgreMaterial.h:96
Ogre::Material::setSpecular
void setSpecular(const ColourValue &specular)
Sets the specular colour reflectance properties of every Pass in every Technique.
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::Material::getLodStrategy
const LodStrategy * getLodStrategy() const
Get LOD strategy used by this material.
Ogre::Material::getNumSupportedTechniques
unsigned short getNumSupportedTechniques(void) const
Retrieves the number of supported techniques.
Ogre::Material::TechniqueIterator
VectorIterator< Techniques > TechniqueIterator
Definition: OgreMaterial.h:226
Ogre::map
Definition: OgrePrerequisites.h:534
Ogre::Material::applyDefaults
void applyDefaults(void)
Internal method which sets the material up from the default settings.
Ogre::Material::~Material
~Material()
Ogre::ushort
unsigned short ushort
Definition: OgrePrerequisites.h:113
Ogre::Material::mSupportedTechniques
Techniques mSupportedTechniques
Supported techniques of any sort.
Definition: OgreMaterial.h:108
Ogre::Material::LodTechniques
map< unsigned short, Technique * >::type LodTechniques
Definition: OgreMaterial.h:109
Ogre::Material::getSupportedTechniqueIterator
TechniqueIterator getSupportedTechniqueIterator(void)
Gets an iterator over all the Techniques which are supported by the current card.
Ogre::Material::mCompilationRequired
bool mCompilationRequired
Does this material require compilation?
Definition: OgreMaterial.h:123
Ogre::Material::getLodIndex
ushort getLodIndex(Real value) const
Gets the LOD index to use at the given value.
Ogre::Material::compile
void compile(bool autoManageTextureUnits=true)
'Compiles' this Material.
Ogre::Material::mUnsupportedReasons
String mUnsupportedReasons
Text description of why any techniques are not supported.
Definition: OgreMaterial.h:125
Ogre::Material::mReceiveShadows
bool mReceiveShadows
Definition: OgreMaterial.h:120
Ogre::Material::copyDetailsTo
void copyDetailsTo(MaterialPtr &mat) const
Copies the details of this material into another, preserving the target's handle and name (unlike ope...
Ogre::Material::calculateSize
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Ogre::Material::loadImpl
void loadImpl(void)
Overridden from Resource.
Ogre::VectorIterator
Concrete IteratorWrapper for nonconst access to the underlying container.
Definition: OgreIteratorWrapper.h:186
Ogre::FogMode
FogMode
Fog modes.
Definition: OgreCommon.h:122
Ogre::Resource::touch
virtual void touch(void)
'Touches' the resource to indicate it has been used.
Ogre::MaterialManager
Class for managing Material settings for Ogre.
Definition: OgreMaterialManager.h:65
Ogre::Material::removeTechnique
void removeTechnique(unsigned short index)
Removes the technique at the given index.
Ogre::Material
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:89
Ogre::Material::setSceneBlending
void setSceneBlending(const SceneBlendType sbt)
Sets the kind of blending every pass has with the existing contents of the scene.
Ogre::Material::setLodLevels
void setLodLevels(const LodValueList &lodValues)
Sets the distance at which level-of-detail (LOD) levels come into effect.
Ogre::Material::setDiffuse
void setDiffuse(Real red, Real green, Real blue, Real alpha)
Sets the diffuse colour reflectance properties of every Pass in every Technique.
Ogre::Material::setDepthCheckEnabled
void setDepthCheckEnabled(bool enabled)
Sets whether or not each Pass renders with depth-buffer checking on or not.
Ogre::Material::setTextureFiltering
void setTextureFiltering(TextureFilterOptions filterType)
Set texture filtering for every texture unit in every Technique and Pass.
Ogre::TextureFilterOptions
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition: OgreCommon.h:79
Ogre::Material::getUnsupportedTechniquesExplanation
const String & getUnsupportedTechniquesExplanation() const
Gets a string explaining why any techniques are not supported.
Definition: OgreMaterial.h:242
Ogre::Material::getTransparencyCastsShadows
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
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Technique
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:54
Ogre::Material::getSupportedTechnique
Technique * getSupportedTechnique(unsigned short index)
Gets the indexed supported technique.
Ogre::Material::setSelfIllumination
void setSelfIllumination(Real red, Real green, Real blue)
Sets the amount of self-illumination of every Pass in every Technique.
Ogre::Material::clearBestTechniqueList
void clearBestTechniqueList(void)
Clear the best technique list.
Ogre::CompareFunction
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:65
Ogre::Material::setDiffuse
void setDiffuse(const ColourValue &diffuse)
Sets the diffuse colour reflectance properties of every Pass in every Technique.
Ogre::Material::setCullingMode
void setCullingMode(CullingMode mode)
Sets the culling mode for each pass based on the 'vertex winding'.
Ogre::Material::getUserLodValueIterator
LodValueIterator getUserLodValueIterator(void) const
Gets an iterator over the user-defined list of values which are internally transfomed by the LodStrat...
Ogre::Material::setLightingEnabled
void setLightingEnabled(bool enabled)
Sets whether or not dynamic lighting is enabled for every Pass.
Ogre::Material::setSceneBlending
void setSceneBlending(const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor)
Allows very fine control of blending every Pass with the existing contents of the scene.
Ogre::LodStrategy
Strategy for determining level of detail.
Definition: OgreLodStrategy.h:55
Ogre::Material::getTechnique
Technique * getTechnique(const String &name)
searches for the named technique.
Ogre::Material::setTransparencyCastsShadows
void setTransparencyCastsShadows(bool enabled)
Sets whether objects using this material be classified as opaque to the shadow caster system.
Definition: OgreMaterial.h:195
Ogre::StringUtil::BLANK
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
Ogre::Material::mUserLodValues
LodValueList mUserLodValues
Definition: OgreMaterial.h:117
OgreHeaderPrefix.h
Ogre::Material::getLodValueIterator
LodValueIterator getLodValueIterator(void) const
Gets an iterator over the list of values transformed by the LodStrategy at which each LOD comes into ...
Ogre::Material::setShininess
void setShininess(Real val)
Sets the shininess properties of every Pass in every Technique.
Ogre::SceneBlendFactor
SceneBlendFactor
Blending factors for manually blending objects with the scene.
Definition: OgreBlendMode.h:235
Ogre::Material::unloadImpl
void unloadImpl(void)
Unloads the material, frees resources etc.
Ogre::SceneManager
Manages the organisation and rendering of a 'scene' i.e.
Definition: OgreSceneManager.h:144
Ogre::Material::BestTechniquesBySchemeList
map< unsigned short, LodTechniques * >::type BestTechniquesBySchemeList
Definition: OgreMaterial.h:110
Ogre::Material::setFog
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.
OgrePrerequisites.h
Ogre::Material::mLodStrategy
const LodStrategy * mLodStrategy
Definition: OgreMaterial.h:119
Ogre::Material::LodValueList
vector< Real >::type LodValueList
distance list used to specify LOD
Definition: OgreMaterial.h:95
Ogre::Material::setSeparateSceneBlending
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...
Ogre::Material::setDepthBias
void setDepthBias(float constantBias, float slopeScaleBias)
Sets the depth bias to be used for each Pass.
Ogre::Material::applyTextureAliases
bool applyTextureAliases(const AliasTextureNamePairList &aliasList, const bool apply=true) const
Applies texture names to Texture Unit State with matching texture name aliases.
Ogre::AliasTextureNamePairList
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:553
Ogre::Material::_notifyNeedsRecompile
void _notifyNeedsRecompile(void)
Tells the material that it needs recompilation.
Ogre::Material::prepareImpl
void prepareImpl(void)
Overridden from Resource.
OgreResource.h
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Material::setPointSize
void setPointSize(Real ps)
Sets the point size properties for every Pass in every Technique.
OgreCommon.h
Ogre::Material::setShadingMode
void setShadingMode(ShadeOptions mode)
Sets the type of light shading required.
Ogre::CullingMode
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:136
Ogre::Material::setSpecular
void setSpecular(Real red, Real green, Real blue, Real alpha)
Sets the specular colour reflectance properties of every Pass in every Technique.
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:123
Ogre::Material::setManualCullingMode
void setManualCullingMode(ManualCullingMode mode)
Sets the manual culling mode, performed by CPU rather than hardware.
Ogre::Material::mLodValues
LodValueList mLodValues
Definition: OgreMaterial.h:118
Ogre::Material::clone
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.
Ogre::Material::getNumLodLevels
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...
Ogre::Material::setColourWriteEnabled
void setColourWriteEnabled(bool enabled)
Sets whether or not colour buffer writing is enabled for each Pass.
Ogre::ColourValue::White
static const ColourValue White
Definition: OgreColourValue.h:62
Ogre::Material::getNumTechniques
unsigned short getNumTechniques(void) const
Retrieves the number of techniques.
Ogre::Material::setAmbient
void setAmbient(Real red, Real green, Real blue)
Sets the ambient colour reflectance properties for every Pass in every Technique.
Ogre::Material::unprepareImpl
void unprepareImpl(void)
Overridden from Resource.
Ogre::SharedPtr< Material >
Ogre::Material::getTechniqueIterator
TechniqueIterator getTechniqueIterator(void)
Get an iterator over the Techniques in this Material.
Ogre::Material::mTransparencyCastsShadows
bool mTransparencyCastsShadows
Definition: OgreMaterial.h:121
OgreIteratorWrappers.h
Ogre::FOG_NONE
@ FOG_NONE
No fog. Duh.
Definition: OgreCommon.h:124
Ogre::Material::setReceiveShadows
void setReceiveShadows(bool enabled)
Sets whether objects using this material will receive shadows.
Definition: OgreMaterial.h:183
Ogre::Resource
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:80
Ogre::Material::setTextureAnisotropy
void setTextureAnisotropy(int maxAniso)
Sets the anisotropy level to be used for all textures.
Ogre::Material::removeAllTechniques
void removeAllTechniques(void)
Removes all the techniques in this Material.
Ogre::Material::mTechniques
Techniques mTechniques
All techniques, supported and unsupported.
Definition: OgreMaterial.h:106
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
OgreBlendMode.h
OgreColourValue.h
Ogre::ColourValue
Class representing colour.
Definition: OgreColourValue.h:58
Ogre::Material::setSeparateSceneBlending
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,...
Ogre::Renderable
Abstract class defining the interface all renderable objects must implement.
Definition: OgreRenderable.h:64
Ogre::Material::setDepthWriteEnabled
void setDepthWriteEnabled(bool enabled)
Sets whether or not each Pass renders with depth-buffer writing on or not.
Ogre::ShadeOptions
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:114
Ogre::Material::operator=
Material & operator=(const Material &rhs)
Assignment operator to allow easy copying between materials.
Ogre::Material::createTechnique
Technique * createTechnique(void)
Creates a new Technique for this Material.
Ogre::Material::touch
void touch(void)
'Touches' the resource to indicate it has been used.
Definition: OgreMaterial.h:649
Ogre::ManualCullingMode
ManualCullingMode
Manual culling modes based on vertex normals.
Definition: OgreCommon.h:151
Ogre::Material::getBestTechnique
Technique * getBestTechnique(unsigned short lodIndex=0, const Renderable *rend=0)
Gets the best supported technique.
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Material::getReceiveShadows
bool getReceiveShadows(void) const
Returns whether or not objects using this material will receive shadows.
Definition: OgreMaterial.h:185
Ogre::Material::getCompilationRequired
bool getCompilationRequired() const
Gets the compilation status of the material.
Definition: OgreMaterial.h:673
Ogre::Material::insertSupportedTechnique
void insertSupportedTechnique(Technique *t)
Insert a supported technique into the local collections.
Ogre::Material::Material
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.
Ogre::Material::mBestTechniquesBySchemeList
BestTechniquesBySchemeList mBestTechniquesBySchemeList
Map of scheme -> list of LOD techniques.
Definition: OgreMaterial.h:115
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::Material::setDepthFunction
void setDepthFunction(CompareFunction func)
Sets the function used to compare depth values when depth checking is on.
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:515
Ogre::Material::getNumLodLevels
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...
Ogre::Material::setAmbient
void setAmbient(const ColourValue &ambient)
Sets the ambient colour reflectance properties for every Pass in every Technique.
Ogre::ConstVectorIterator
Concrete IteratorWrapper for const access to the underlying container.
Definition: OgreIteratorWrapper.h:217
Ogre::Material::isTransparent
bool isTransparent(void) const
Determines if the material has any transparency with the rest of the scene (derived from whether any ...
Ogre::SceneBlendType
SceneBlendType
Types of blending that you can specify between an object and the existing contents of the scene.
Definition: OgreBlendMode.h:216
Ogre::Material::setLodStrategy
void setLodStrategy(LodStrategy *lodStrategy)
Set the LOD strategy used by this material.

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