# OgreMaterial.h

Go to the documentation of this file.

    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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _Material_H__
    00030 #define _Material_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreResource.h"
    00035 #include "OgreIteratorWrappers.h"
    00036 #include "OgreCommon.h"
    00037 #include "OgreColourValue.h"
    00038 #include "OgreBlendMode.h"
    00039
    00040
    00041 namespace Ogre {
    00042
    00043     // Forward declaration
    00044     class MaterialPtr;
    00045
    00083     class _OgreExport Material : public Resource
    00084     {
    00085         friend class SceneManager;
    00086         friend class MaterialManager;
    00087
    00088     public:
    00090         typedef std::vector<Real> LodDistanceList;
    00091         typedef ConstVectorIterator<LodDistanceList> LodDistanceIterator;
    00092     protected:
    00093
    00094
    00097         void applyDefaults(void);
    00098
    00099         typedef std::vector<Technique*> Techniques;
    00101         Techniques mTechniques;
    00103         Techniques mSupportedTechniques;
    00104         typedef std::map<unsigned short, Technique*> LodTechniques;
    00105         typedef std::map<unsigned short, LodTechniques*> BestTechniquesBySchemeList;
    00110         BestTechniquesBySchemeList mBestTechniquesBySchemeList;
    00111
    00112         LodDistanceList mLodDistances;
    00113         bool mReceiveShadows;
    00114         bool mTransparencyCastsShadows;
    00116         bool mCompilationRequired;
    00118         String mUnsupportedReasons;
    00119
    00121         void insertSupportedTechnique(Technique* t);
    00122
    00125         void clearBestTechniqueList(void);
    00126
    00129         void prepareImpl(void);
    00130
    00133         void unprepareImpl(void);
    00134
    00137         void loadImpl(void);
    00138
    00143         void unloadImpl(void);
    00145         size_t calculateSize(void) const { return 0; } // TODO
    00146     public:
    00147
    00150         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
    00151             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00152
    00153         ~Material();
    00156         Material& operator=( const Material& rhs );
    00157
    00161         bool isTransparent(void) const;
    00162
    00176         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
    00178         bool getReceiveShadows(void) const { return mReceiveShadows; }
    00179
    00188         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
    00190         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
    00191
    00206         Technique* createTechnique(void);
    00208         Technique* getTechnique(unsigned short index);
    00212         Technique* getTechnique(const String& name);
    00214         unsigned short getNumTechniques(void) const;
    00216         void removeTechnique(unsigned short index);
    00218         void removeAllTechniques(void);
    00219         typedef VectorIterator<Techniques> TechniqueIterator;
    00221         TechniqueIterator getTechniqueIterator(void);
    00228         TechniqueIterator getSupportedTechniqueIterator(void);
    00229
    00231         Technique* getSupportedTechnique(unsigned short index);
    00233         unsigned short getNumSupportedTechniques(void) const;
    00235         const String& getUnsupportedTechniquesExplanation() const { return mUnsupportedReasons; }
    00236
    00242         unsigned short getNumLodLevels(unsigned short schemeIndex) const;
    00248         unsigned short getNumLodLevels(const String& schemeName) const;
    00249
    00265         Technique* getBestTechnique(unsigned short lodIndex = 0, const Renderable* rend = 0);
    00266
    00267
    00273         MaterialPtr clone(const String& newName, bool changeGroup = false,
    00274             const String& newGroup = StringUtil::BLANK) const;
    00275
    00280         void copyDetailsTo(MaterialPtr& mat) const;
    00281
    00297         void compile(bool autoManageTextureUnits = true);
    00298
    00299         // -------------------------------------------------------------------------------
    00300         // The following methods are to make migration from previous versions simpler
    00301         // and to make code easier to write when dealing with simple materials
    00302         // They set the properties which have been moved to Pass for all Techniques and all Passes
    00303
    00313         void setPointSize(Real ps);
    00314
    00324         void setAmbient(Real red, Real green, Real blue);
    00325
    00335         void setAmbient(const ColourValue& ambient);
    00336
    00346         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00347
    00357         void setDiffuse(const ColourValue& diffuse);
    00358
    00368         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00369
    00379         void setSpecular(const ColourValue& specular);
    00380
    00390         void setShininess(Real val);
    00391
    00401         void setSelfIllumination(Real red, Real green, Real blue);
    00402
    00412         void setSelfIllumination(const ColourValue& selfIllum);
    00413
    00423         void setDepthCheckEnabled(bool enabled);
    00424
    00434         void setDepthWriteEnabled(bool enabled);
    00435
    00445         void setDepthFunction( CompareFunction func );
    00446
    00456         void setColourWriteEnabled(bool enabled);
    00457
    00467         void setCullingMode( CullingMode mode );
    00468
    00478         void setManualCullingMode( ManualCullingMode mode );
    00479
    00489         void setLightingEnabled(bool enabled);
    00490
    00500         void setShadingMode( ShadeOptions mode );
    00501
    00511         void setFog(
    00512             bool overrideScene,
    00513             FogMode mode = FOG_NONE,
    00514             const ColourValue& colour = ColourValue::White,
    00515             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00516
    00526         void setDepthBias(float constantBias, float slopeScaleBias);
    00527
    00536         void setTextureFiltering(TextureFilterOptions filterType);
    00545         void setTextureAnisotropy(int maxAniso);
    00546
    00556         void setSceneBlending( const SceneBlendType sbt );
    00557
    00567         void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta );
    00568
    00578         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00579
    00589         void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha);
    00590
    00592         void _notifyNeedsRecompile(void);
    00593
    00606         void setLodLevels(const LodDistanceList& lodDistances);
    00614         LodDistanceIterator getLodDistanceIterator(void) const;
    00615
    00617         unsigned short getLodIndex(Real d) const;
    00619         unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
    00620
    00623         void touch(void)
    00624         {
    00625             if (mCompilationRequired)
    00626                 compile();
    00627             // call superclass
    00628             Resource::touch();
    00629         }
    00630
    00642         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
    00643
    00647         bool getCompilationRequired() const
    00648         {
    00649             return mCompilationRequired;
    00650         }
    00651
    00652
    00653     };
    00654
    00661     class _OgreExport MaterialPtr : public SharedPtr<Material>
    00662     {
    00663     public:
    00664         MaterialPtr() : SharedPtr<Material>() {}
    00665         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
    00666         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
    00667         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
    00668         {
    00669             // lock & copy other mutex pointer
    00670             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00671             {
    00672                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00673                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00674                 pRep = static_cast<Material*>(r.getPointer());
    00675                 pUseCount = r.useCountPointer();
    00676                 if (pUseCount)
    00677                 {
    00678                     ++(*pUseCount);
    00679                 }
    00680             }
    00681         }
    00682
    00684         MaterialPtr& operator=(const ResourcePtr& r)
    00685         {
    00686             if (pRep == static_cast<Material*>(r.getPointer()))
    00687                 return *this;
    00688             release();
    00689             // lock & copy other mutex pointer
    00690             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00691             {
    00692                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00693                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00694                 pRep = static_cast<Material*>(r.getPointer());
    00695                 pUseCount = r.useCountPointer();
    00696                 if (pUseCount)
    00697                 {
    00698                     ++(*pUseCount);
    00699                 }
    00700             }
    00701             else
    00702             {
    00703                 // RHS must be a null pointer
    00704                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00705                 setNull();
    00706             }
    00707             return *this;
    00708         }
    00709     };
    00710
    00711 } //namespace
    00712
    00713 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:31:05 2009