OGRE  1.9.0
OgreMaterial.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _Material_H__
29#define _Material_H__
30
31#include "OgrePrerequisites.h"
32
33#include "OgreResource.h"
35#include "OgreCommon.h"
36#include "OgreColourValue.h"
37#include "OgreBlendMode.h"
38#include "OgreHeaderPrefix.h"
39
40namespace Ogre {
41
42 // Forward declaration
43 class LodStrategy;
44
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
164
168 bool isTransparent(void) const;
169
183 void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
185 bool getReceiveShadows(void) const { return mReceiveShadows; }
186
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;
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
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
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
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
645 void setLodStrategy(LodStrategy *lodStrategy);
646
649 void touch(void)
650 {
652 compile();
653 // call superclass
655 }
656
668 bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
669
674 {
676 }
677
678
679 };
680
682
683} //namespace
684
685#include "OgreHeaderSuffix.h"
686
687#endif
#define _OgreExport
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.
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 ...
friend class MaterialManager
ConstVectorIterator< LodValueList > LodValueIterator
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.
const LodStrategy * mLodStrategy
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.
void setTextureFiltering(TextureFilterOptions filterType)
Set texture filtering for every texture unit in every Technique and Pass.
LodValueList mUserLodValues
void copyDetailsTo(MaterialPtr &mat) const
Copies the details of this material into another, preserving the target's handle and name (unlike ope...
void setSelfIllumination(const ColourValue &selfIllum)
Sets the amount of self-illumination of every Pass in every Technique.
friend class SceneManager
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.
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(unsigned short index)
Gets the indexed technique.
VectorIterator< Techniques > TechniqueIterator
vector< Real >::type LodValueList
distance list used to specify LOD
map< unsignedshort, LodTechniques * >::type BestTechniquesBySchemeList
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.
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.
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.
void insertSupportedTechnique(Technique *t)
Insert a supported technique into the local collections.
Technique * getTechnique(const String &name)
searches for the named technique.
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.
bool mCompilationRequired
Does this material require compilation?
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,...
Technique * getSupportedTechnique(unsigned short index)
Gets the indexed supported technique.
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...
void setColourWriteEnabled(bool enabled)
Sets whether or not colour buffer writing is enabled for each Pass.
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.
void setShadingMode(ShadeOptions mode)
Sets the type of light shading required.
BestTechniquesBySchemeList mBestTechniquesBySchemeList
Map of scheme -> list of LOD techniques.
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.
const String & getUnsupportedTechniquesExplanation() const
Gets a string explaining why any techniques are not supported.
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.
void setManualCullingMode(ManualCullingMode mode)
Sets the manual culling mode, performed by CPU rather than hardware.
unsigned short getNumSupportedTechniques(void) const
Retrieves the number of supported techniques.
Material & operator=(const Material &rhs)
Assignment operator to allow easy copying between materials.
Techniques mTechniques
All techniques, supported and unsupported.
Technique * createTechnique(void)
Creates a new Technique for this 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.
LodValueList mLodValues
void setDiffuse(Real red, Real green, Real blue, Real alpha)
Sets the diffuse colour reflectance properties of every Pass in every Technique.
bool mTransparencyCastsShadows
void setAmbient(const ColourValue &ambient)
Sets the ambient colour reflectance properties for every Pass in every Technique.
ushort getLodIndex(Real value) const
Gets the LOD index to use at the given value.
map< unsignedshort, Technique * >::type LodTechniques
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
Technique * getBestTechnique(unsigned short lodIndex=0, const Renderable *rend=0)
Gets the best supported technique.
Abstract class defining the interface all renderable objects must implement.
Defines a generic resource handler.
virtual void touch(void)
'Touches' the resource to indicate it has been used.
Resource()
Protected unnamed constructor to prevent default construction.
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.
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
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition OgreCommon.h:79
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition OgreCommon.h:553
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.
SharedPtr< Material > MaterialPtr
float Real
Software floating point type.
unsigned long long int ResourceHandle
_StringBase String
unsigned short ushort
std::map< K, V, P, A > type
std::vector< T, A > type