OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2011 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 
39 namespace Ogre {
40 
41  // Forward declaration
42  class MaterialPtr;
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 
128  void insertSupportedTechnique(Technique* t);
129 
132  void clearBestTechniqueList(void);
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 { return 0; } // TODO
153  public:
154 
157  Material(ResourceManager* creator, const String& name, ResourceHandle handle,
158  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
159 
160  ~Material();
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 
213  Technique* createTechnique(void);
215  Technique* getTechnique(unsigned short index);
219  Technique* getTechnique(const String& name);
221  unsigned short getNumTechniques(void) const;
223  void removeTechnique(unsigned short index);
225  void removeAllTechniques(void);
228  TechniqueIterator getTechniqueIterator(void);
235  TechniqueIterator getSupportedTechniqueIterator(void);
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 
452  void setDepthFunction( CompareFunction func );
453 
463  void setColourWriteEnabled(bool enabled);
464 
474  void setCullingMode( CullingMode mode );
475 
485  void setManualCullingMode( ManualCullingMode mode );
486 
496  void setLightingEnabled(bool enabled);
497 
507  void setShadingMode( ShadeOptions mode );
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 
543  void setTextureFiltering(TextureFilterOptions filterType);
552  void setTextureAnisotropy(int maxAniso);
553 
563  void setSceneBlending( const SceneBlendType sbt );
564 
574  void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta );
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 
599  void _notifyNeedsRecompile(void);
600 
615  void setLodLevels(const LodValueList& lodValues);
623  LodValueIterator getLodValueIterator(void) const;
624 
630  ushort getLodIndex(Real value) const;
631 
633  const LodStrategy *getLodStrategy() const;
635  void setLodStrategy(LodStrategy *lodStrategy);
636 
639  void touch(void)
640  {
641  if (mCompilationRequired)
642  compile();
643  // call superclass
644  Resource::touch();
645  }
646 
658  bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
659 
664  {
665  return mCompilationRequired;
666  }
667 
668 
669  };
670 
677  class _OgreExport MaterialPtr : public SharedPtr<Material>
678  {
679  public:
681  explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
684  {
685  // lock & copy other mutex pointer
686  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
687  {
688  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
689  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
690  pRep = static_cast<Material*>(r.getPointer());
691  pUseCount = r.useCountPointer();
692  if (pUseCount)
693  {
694  ++(*pUseCount);
695  }
696  }
697  }
698 
701  {
702  if (pRep == static_cast<Material*>(r.getPointer()))
703  return *this;
704  release();
705  // lock & copy other mutex pointer
706  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
707  {
708  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
709  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
710  pRep = static_cast<Material*>(r.getPointer());
711  pUseCount = r.useCountPointer();
712  if (pUseCount)
713  {
714  ++(*pUseCount);
715  }
716  }
717  else
718  {
719  // RHS must be a null pointer
720  assert(r.isNull() && "RHS must be null if it has no mutex!");
721  setNull();
722  }
723  return *this;
724  }
725  };
729 } //namespace
730 
731 #endif
Techniques mSupportedTechniques
Supported techniques of any sort.
Definition: OgreMaterial.h:108
String mUnsupportedReasons
Text description of why any techniques are not supported.
Definition: OgreMaterial.h:125
const String & getUnsupportedTechniquesExplanation() const
Gets a string explaining why any techniques are not supported.
Definition: OgreMaterial.h:242
T * getPointer() const
ManualCullingMode
Manual culling modes based on vertex normals.
Definition: OgreCommon.h:151
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:203
FogMode
Fog modes.
Definition: OgreCommon.h:122
#define OGRE_MUTEX_CONDITIONAL(name)
Class representing colour.
static const ColourValue White
MaterialPtr(Material *rep)
Definition: OgreMaterial.h:681
Manages the organisation and rendering of a 'scene' i.e.
vector< Technique * >::type Techniques
Definition: OgreMaterial.h:104
VectorIterator< Techniques > TechniqueIterator
Definition: OgreMaterial.h:226
void setReceiveShadows(bool enabled)
Sets whether objects using this material will receive shadows.
Definition: OgreMaterial.h:183
SceneBlendType
Types of blending that you can specify between an object and the existing contents of the scene...
Class encapsulates rendering properties of an object.
Definition: OgreMaterial.h:88
const LodStrategy * mLodStrategy
Definition: OgreMaterial.h:119
Interface describing a manual resource loader.
Definition: OgreResource.h:512
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
Strategy for determining level of detail.
vector< Real >::type LodValueList
distance list used to specify LOD
Definition: OgreMaterial.h:95
SceneBlendFactor
Blending factors for manually blending objects with the scene.
LodValueList mLodValues
Definition: OgreMaterial.h:118
ConstVectorIterator< LodValueList > LodValueIterator
Definition: OgreMaterial.h:96
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:136
Abstract class defining the interface all renderable objects must implement.
No fog. Duh.
Definition: OgreCommon.h:125
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
Class for managing Material settings for Ogre.
bool mTransparencyCastsShadows
Definition: OgreMaterial.h:121
virtual void touch(void)
'Touches' the resource to indicate it has been used.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:114
void setTransparencyCastsShadows(bool enabled)
Sets whether objects using this material be classified as opaque to the shadow caster system...
Definition: OgreMaterial.h:195
Concrete IteratorWrapper for const access to the underlying container.
MaterialPtr(const ResourcePtr &r)
Definition: OgreMaterial.h:683
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition: OgreMaterial.h:152
MaterialPtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a MaterialPtr.
Definition: OgreMaterial.h:700
std::map< K, V, P, A > type
unsigned short ushort
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:180
#define OGRE_LOCK_MUTEX(name)
Defines a generic resource handler.
unsigned int * useCountPointer() const
void touch(void)
'Touches' the resource to indicate it has been used.
Definition: OgreMaterial.h:639
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:60
LodValueList mUserLodValues
Definition: OgreMaterial.h:117
_StringBase String
Techniques mTechniques
All techniques, supported and unsupported.
Definition: OgreMaterial.h:106
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
Concrete IteratorWrapper for nonconst access to the underlying container.
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:527
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:65
map< unsigned short, LodTechniques * >::type BestTechniquesBySchemeList
Definition: OgreMaterial.h:110
BestTechniquesBySchemeList mBestTechniquesBySchemeList
Map of scheme -> list of LOD techniques.
Definition: OgreMaterial.h:115
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
bool getCompilationRequired() const
Gets the compilation status of the material.
Definition: OgreMaterial.h:663
bool getReceiveShadows(void) const
Returns whether or not objects using this material will receive shadows.
Definition: OgreMaterial.h:185
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition: OgreCommon.h:79
bool isNull(void) const
bool mCompilationRequired
Does this material require compilation?
Definition: OgreMaterial.h:123
map< unsigned short, Technique * >::type LodTechniques
Definition: OgreMaterial.h:109
MaterialPtr(const MaterialPtr &r)
Definition: OgreMaterial.h:682