00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef _Material_H__ 00029 #define _Material_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 00033 #include "OgreResource.h" 00034 #include "OgreIteratorWrappers.h" 00035 #include "OgreCommon.h" 00036 #include "OgreColourValue.h" 00037 #include "OgreBlendMode.h" 00038 00039 namespace Ogre { 00040 00041 // Forward declaration 00042 class MaterialPtr; 00043 class LodStrategy; 00044 00088 class _OgreExport Material : public Resource 00089 { 00090 friend class SceneManager; 00091 friend class MaterialManager; 00092 00093 public: 00095 typedef vector<Real>::type LodValueList; 00096 typedef ConstVectorIterator<LodValueList> LodValueIterator; 00097 protected: 00098 00099 00102 void applyDefaults(void); 00103 00104 typedef vector<Technique*>::type Techniques; 00106 Techniques mTechniques; 00108 Techniques mSupportedTechniques; 00109 typedef map<unsigned short, Technique*>::type LodTechniques; 00110 typedef map<unsigned short, LodTechniques*>::type BestTechniquesBySchemeList; 00115 BestTechniquesBySchemeList mBestTechniquesBySchemeList; 00116 00117 LodValueList mUserLodValues; 00118 LodValueList mLodValues; 00119 const LodStrategy *mLodStrategy; 00120 bool mReceiveShadows; 00121 bool mTransparencyCastsShadows; 00123 bool mCompilationRequired; 00125 String mUnsupportedReasons; 00126 00128 void insertSupportedTechnique(Technique* t); 00129 00132 void clearBestTechniqueList(void); 00133 00136 void prepareImpl(void); 00137 00140 void unprepareImpl(void); 00141 00144 void loadImpl(void); 00145 00150 void unloadImpl(void); 00152 size_t calculateSize(void) const { return 0; } // TODO 00153 public: 00154 00157 Material(ResourceManager* creator, const String& name, ResourceHandle handle, 00158 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00159 00160 ~Material(); 00163 Material& operator=( const Material& rhs ); 00164 00168 bool isTransparent(void) const; 00169 00183 void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; } 00185 bool getReceiveShadows(void) const { return mReceiveShadows; } 00186 00195 void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; } 00197 bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; } 00198 00213 Technique* createTechnique(void); 00215 Technique* getTechnique(unsigned short index); 00219 Technique* getTechnique(const String& name); 00221 unsigned short getNumTechniques(void) const; 00223 void removeTechnique(unsigned short index); 00225 void removeAllTechniques(void); 00226 typedef VectorIterator<Techniques> TechniqueIterator; 00228 TechniqueIterator getTechniqueIterator(void); 00235 TechniqueIterator getSupportedTechniqueIterator(void); 00236 00238 Technique* getSupportedTechnique(unsigned short index); 00240 unsigned short getNumSupportedTechniques(void) const; 00242 const String& getUnsupportedTechniquesExplanation() const { return mUnsupportedReasons; } 00243 00249 unsigned short getNumLodLevels(unsigned short schemeIndex) const; 00255 unsigned short getNumLodLevels(const String& schemeName) const; 00256 00272 Technique* getBestTechnique(unsigned short lodIndex = 0, const Renderable* rend = 0); 00273 00274 00280 MaterialPtr clone(const String& newName, bool changeGroup = false, 00281 const String& newGroup = StringUtil::BLANK) const; 00282 00287 void copyDetailsTo(MaterialPtr& mat) const; 00288 00304 void compile(bool autoManageTextureUnits = true); 00305 00306 // ------------------------------------------------------------------------------- 00307 // The following methods are to make migration from previous versions simpler 00308 // and to make code easier to write when dealing with simple materials 00309 // They set the properties which have been moved to Pass for all Techniques and all Passes 00310 00320 void setPointSize(Real ps); 00321 00331 void setAmbient(Real red, Real green, Real blue); 00332 00342 void setAmbient(const ColourValue& ambient); 00343 00353 void setDiffuse(Real red, Real green, Real blue, Real alpha); 00354 00364 void setDiffuse(const ColourValue& diffuse); 00365 00375 void setSpecular(Real red, Real green, Real blue, Real alpha); 00376 00386 void setSpecular(const ColourValue& specular); 00387 00397 void setShininess(Real val); 00398 00408 void setSelfIllumination(Real red, Real green, Real blue); 00409 00419 void setSelfIllumination(const ColourValue& selfIllum); 00420 00430 void setDepthCheckEnabled(bool enabled); 00431 00441 void setDepthWriteEnabled(bool enabled); 00442 00452 void setDepthFunction( CompareFunction func ); 00453 00463 void setColourWriteEnabled(bool enabled); 00464 00474 void setCullingMode( CullingMode mode ); 00475 00485 void setManualCullingMode( ManualCullingMode mode ); 00486 00496 void setLightingEnabled(bool enabled); 00497 00507 void setShadingMode( ShadeOptions mode ); 00508 00518 void setFog( 00519 bool overrideScene, 00520 FogMode mode = FOG_NONE, 00521 const ColourValue& colour = ColourValue::White, 00522 Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 ); 00523 00533 void setDepthBias(float constantBias, float slopeScaleBias); 00534 00543 void setTextureFiltering(TextureFilterOptions filterType); 00552 void setTextureAnisotropy(int maxAniso); 00553 00563 void setSceneBlending( const SceneBlendType sbt ); 00564 00574 void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta ); 00575 00585 void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 00586 00596 void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha); 00597 00599 void _notifyNeedsRecompile(void); 00600 00615 void setLodLevels(const LodValueList& lodValues); 00616 00624 LodValueIterator getLodValueIterator(void) const; 00625 00633 LodValueIterator getUserLodValueIterator(void) const; 00634 00640 ushort getLodIndex(Real value) const; 00641 00643 const LodStrategy *getLodStrategy() const; 00645 void setLodStrategy(LodStrategy *lodStrategy); 00646 00649 void touch(void) 00650 { 00651 if (mCompilationRequired) 00652 compile(); 00653 // call superclass 00654 Resource::touch(); 00655 } 00656 00668 bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const; 00669 00673 bool getCompilationRequired() const 00674 { 00675 return mCompilationRequired; 00676 } 00677 00678 00679 }; 00680 00687 class _OgreExport MaterialPtr : public SharedPtr<Material> 00688 { 00689 public: 00690 MaterialPtr() : SharedPtr<Material>() {} 00691 explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {} 00692 MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {} 00693 MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>() 00694 { 00695 // lock & copy other mutex pointer 00696 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00697 { 00698 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00699 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00700 pRep = static_cast<Material*>(r.getPointer()); 00701 pUseCount = r.useCountPointer(); 00702 if (pUseCount) 00703 { 00704 ++(*pUseCount); 00705 } 00706 } 00707 } 00708 00710 MaterialPtr& operator=(const ResourcePtr& r) 00711 { 00712 if (pRep == static_cast<Material*>(r.getPointer())) 00713 return *this; 00714 release(); 00715 // lock & copy other mutex pointer 00716 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00717 { 00718 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00719 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00720 pRep = static_cast<Material*>(r.getPointer()); 00721 pUseCount = r.useCountPointer(); 00722 if (pUseCount) 00723 { 00724 ++(*pUseCount); 00725 } 00726 } 00727 else 00728 { 00729 // RHS must be a null pointer 00730 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00731 setNull(); 00732 } 00733 return *this; 00734 } 00735 }; 00739 } //namespace 00740 00741 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012