# 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 loadImpl(void);
    00130
    00135         void unloadImpl(void);
    00137         size_t calculateSize(void) const { return 0; } // TODO
    00138     public:
    00139
    00142         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
    00143             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00144
    00145         ~Material();
    00148         Material& operator=( const Material& rhs );
    00149
    00153         bool isTransparent(void) const;
    00154
    00168         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
    00170         bool getReceiveShadows(void) const { return mReceiveShadows; }
    00171
    00180         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
    00182         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
    00183
    00198         Technique* createTechnique(void);
    00200         Technique* getTechnique(unsigned short index);
    00204         Technique* getTechnique(const String& name);
    00206         unsigned short getNumTechniques(void) const;
    00208         void removeTechnique(unsigned short index);
    00210         void removeAllTechniques(void);
    00211         typedef VectorIterator<Techniques> TechniqueIterator;
    00213         TechniqueIterator getTechniqueIterator(void);
    00220         TechniqueIterator getSupportedTechniqueIterator(void);
    00221
    00223         Technique* getSupportedTechnique(unsigned short index);
    00225         unsigned short getNumSupportedTechniques(void) const;
    00227         const String& getUnsupportedTechniquesExplanation() const { return mUnsupportedReasons; }
    00228
    00234         unsigned short getNumLodLevels(unsigned short schemeIndex) const;
    00240         unsigned short getNumLodLevels(const String& schemeName) const;
    00241
    00253         Technique* getBestTechnique(unsigned short lodIndex = 0);
    00254
    00255
    00261         MaterialPtr clone(const String& newName, bool changeGroup = false,
    00262             const String& newGroup = StringUtil::BLANK) const;
    00263
    00268         void copyDetailsTo(MaterialPtr& mat) const;
    00269
    00285         void compile(bool autoManageTextureUnits = true);
    00286
    00287         // -------------------------------------------------------------------------------
    00288         // The following methods are to make migration from previous versions simpler
    00289         // and to make code easier to write when dealing with simple materials
    00290         // They set the properties which have been moved to Pass for all Techniques and all Passes
    00291
    00301         void setPointSize(Real ps);
    00302
    00312         void setAmbient(Real red, Real green, Real blue);
    00313
    00323         void setAmbient(const ColourValue& ambient);
    00324
    00334         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00335
    00345         void setDiffuse(const ColourValue& diffuse);
    00346
    00356         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00357
    00367         void setSpecular(const ColourValue& specular);
    00368
    00378         void setShininess(Real val);
    00379
    00389         void setSelfIllumination(Real red, Real green, Real blue);
    00390
    00400         void setSelfIllumination(const ColourValue& selfIllum);
    00401
    00411         void setDepthCheckEnabled(bool enabled);
    00412
    00422         void setDepthWriteEnabled(bool enabled);
    00423
    00433         void setDepthFunction( CompareFunction func );
    00434
    00444         void setColourWriteEnabled(bool enabled);
    00445
    00455         void setCullingMode( CullingMode mode );
    00456
    00466         void setManualCullingMode( ManualCullingMode mode );
    00467
    00477         void setLightingEnabled(bool enabled);
    00478
    00488         void setShadingMode( ShadeOptions mode );
    00489
    00499         void setFog(
    00500             bool overrideScene,
    00501             FogMode mode = FOG_NONE,
    00502             const ColourValue& colour = ColourValue::White,
    00503             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00504
    00514         void setDepthBias(float constantBias, float slopeScaleBias);
    00515
    00524         void setTextureFiltering(TextureFilterOptions filterType);
    00533         void setTextureAnisotropy(int maxAniso);
    00534
    00544         void setSceneBlending( const SceneBlendType sbt );
    00545
    00555         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00556
    00557
    00559         void _notifyNeedsRecompile(void);
    00560
    00573         void setLodLevels(const LodDistanceList& lodDistances);
    00581         LodDistanceIterator getLodDistanceIterator(void) const;
    00582
    00584         unsigned short getLodIndex(Real d) const;
    00586         unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
    00587
    00590         void touch(void)
    00591         {
    00592             if (mCompilationRequired)
    00593                 compile();
    00594             // call superclass
    00595             Resource::touch();
    00596         }
    00597
    00609         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
    00610
    00614         bool getCompilationRequired() const
    00615         {
    00616             return mCompilationRequired;
    00617         }
    00618
    00619
    00620     };
    00621
    00628     class _OgreExport MaterialPtr : public SharedPtr<Material>
    00629     {
    00630     public:
    00631         MaterialPtr() : SharedPtr<Material>() {}
    00632         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
    00633         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
    00634         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
    00635         {
    00636             // lock & copy other mutex pointer
    00637             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00638             {
    00639                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00640                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00641                 pRep = static_cast<Material*>(r.getPointer());
    00642                 pUseCount = r.useCountPointer();
    00643                 if (pUseCount)
    00644                 {
    00645                     ++(*pUseCount);
    00646                 }
    00647             }
    00648         }
    00649
    00651         MaterialPtr& operator=(const ResourcePtr& r)
    00652         {
    00653             if (pRep == static_cast<Material*>(r.getPointer()))
    00654                 return *this;
    00655             release();
    00656             // lock & copy other mutex pointer
    00657             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00658             {
    00659                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00660                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00661                 pRep = static_cast<Material*>(r.getPointer());
    00662                 pUseCount = r.useCountPointer();
    00663                 if (pUseCount)
    00664                 {
    00665                     ++(*pUseCount);
    00666                 }
    00667             }
    00668             else
    00669             {
    00670                 // RHS must be a null pointer
    00671                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00672                 setNull();
    00673             }
    00674             return *this;
    00675         }
    00676     };
    00677
    00678 } //namespace
    00679
    00680 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat May 10 16:24:59 2008