# 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-2005 The OGRE Team
    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 */
    00025 #ifndef _Material_H__
    00026 #define _Material_H__
    00027
    00028 #include "OgrePrerequisites.h"
    00029
    00030 #include "OgreResource.h"
    00031 #include "OgreIteratorWrappers.h"
    00032 #include "OgreCommon.h"
    00033 #include "OgreColourValue.h"
    00034 #include "OgreBlendMode.h"
    00035
    00036
    00037 namespace Ogre {
    00038
    00039     // Forward declaration
    00040     class MaterialPtr;
    00041
    00079     class _OgreExport Material : public Resource
    00080     {
    00081         friend class SceneManager;
    00082         friend class MaterialManager;
    00083
    00084     public:
    00086         typedef std::vector<Real> LodDistanceList;
    00087         typedef ConstVectorIterator<LodDistanceList> LodDistanceIterator;
    00088     protected:
    00089
    00090
    00093         void applyDefaults(void);
    00094
    00095         typedef std::vector<Technique*> Techniques;
    00096         Techniques mTechniques;
    00097         Techniques mSupportedTechniques;
    00098         typedef std::map<unsigned short, Technique*> BestTechniqueList;
    00099         BestTechniqueList mBestTechniqueList;
    00100
    00101         LodDistanceList mLodDistances;
    00102         bool mReceiveShadows;
    00103         bool mTransparencyCastsShadows;
    00105         bool mCompilationRequired;
    00106
    00112         void fixupBestTechniqueList(void);
    00113
    00116         void loadImpl(void);
    00117
    00122         void unloadImpl(void);
    00124         size_t calculateSize(void) const { return 0; } // TODO
    00125     public:
    00126
    00129         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
    00130             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00131
    00132         ~Material();
    00135         Material& operator=( const Material& rhs );
    00136
    00140         bool isTransparent(void) const;
    00141
    00155         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
    00157         bool getReceiveShadows(void) const { return mReceiveShadows; }
    00158
    00167         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
    00169         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
    00170
    00185         Technique* createTechnique(void);
    00187         Technique* getTechnique(unsigned short index);
    00189         unsigned short getNumTechniques(void) const;
    00191         void removeTechnique(unsigned short index);
    00193         void removeAllTechniques(void);
    00194         typedef VectorIterator<Techniques> TechniqueIterator;
    00196         TechniqueIterator getTechniqueIterator(void);
    00203         TechniqueIterator getSupportedTechniqueIterator(void);
    00204
    00206         Technique* getSupportedTechnique(unsigned short index);
    00208         unsigned short getNumSupportedTechniques(void) const;
    00209
    00215         unsigned short getNumLodLevels(void) const {
    00216             return static_cast<unsigned short>(mBestTechniqueList.size()); }
    00217
    00229         Technique* getBestTechnique(unsigned short lodIndex = 0);
    00230
    00231
    00237         MaterialPtr clone(const String& newName, bool changeGroup = false,
    00238             const String& newGroup = StringUtil::BLANK) const;
    00239
    00244         void copyDetailsTo(MaterialPtr& mat) const;
    00245
    00261         void compile(bool autoManageTextureUnits = true);
    00262
    00263         // -------------------------------------------------------------------------------
    00264         // The following methods are to make migration from previous versions simpler
    00265         // and to make code easier to write when dealing with simple materials
    00266         // They set the properties which have been moved to Pass for all Techniques and all Passes
    00267
    00277         void setAmbient(Real red, Real green, Real blue);
    00278
    00288         void setAmbient(const ColourValue& ambient);
    00289
    00299         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00300
    00310         void setDiffuse(const ColourValue& diffuse);
    00311
    00321         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00322
    00332         void setSpecular(const ColourValue& specular);
    00333
    00343         void setShininess(Real val);
    00344
    00354         void setSelfIllumination(Real red, Real green, Real blue);
    00355
    00365         void setSelfIllumination(const ColourValue& selfIllum);
    00366
    00376         void setDepthCheckEnabled(bool enabled);
    00377
    00387         void setDepthWriteEnabled(bool enabled);
    00388
    00398         void setDepthFunction( CompareFunction func );
    00399
    00409         void setColourWriteEnabled(bool enabled);
    00410
    00420         void setCullingMode( CullingMode mode );
    00421
    00431         void setManualCullingMode( ManualCullingMode mode );
    00432
    00442         void setLightingEnabled(bool enabled);
    00443
    00453         void setShadingMode( ShadeOptions mode );
    00454
    00464         void setFog(
    00465             bool overrideScene,
    00466             FogMode mode = FOG_NONE,
    00467             const ColourValue& colour = ColourValue::White,
    00468             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00469
    00479         void setDepthBias(ushort bias);
    00480
    00489         void setTextureFiltering(TextureFilterOptions filterType);
    00498         void setTextureAnisotropy(int maxAniso);
    00499
    00509         void setSceneBlending( const SceneBlendType sbt );
    00510
    00520         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00521
    00522
    00524         void _notifyNeedsRecompile(void);
    00525
    00538         void setLodLevels(const LodDistanceList& lodDistances);
    00546         LodDistanceIterator getLodDistanceIterator(void) const;
    00547
    00549         unsigned short getLodIndex(Real d) const;
    00551         unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
    00552
    00555         void touch(void)
    00556         {
    00557             if (mCompilationRequired)
    00558                 compile();
    00559             // call superclass
    00560             Resource::touch();
    00561         }
    00562
    00566         bool getCompilationRequired() const
    00567         {
    00568             return mCompilationRequired;
    00569         }
    00570
    00571
    00572     };
    00573
    00580     class _OgreExport MaterialPtr : public SharedPtr<Material>
    00581     {
    00582     public:
    00583         MaterialPtr() : SharedPtr<Material>() {}
    00584         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
    00585         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
    00586         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
    00587         {
    00588             // lock & copy other mutex pointer
    00589             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00590             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00591             pRep = static_cast<Material*>(r.getPointer());
    00592             pUseCount = r.useCountPointer();
    00593             if (pUseCount)
    00594             {
    00595                 ++(*pUseCount);
    00596             }
    00597         }
    00598
    00600         MaterialPtr& operator=(const ResourcePtr& r)
    00601         {
    00602             if (pRep == static_cast<Material*>(r.getPointer()))
    00603                 return *this;
    00604             release();
    00605             // lock & copy other mutex pointer
    00606             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00607             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00608             pRep = static_cast<Material*>(r.getPointer());
    00609             pUseCount = r.useCountPointer();
    00610             if (pUseCount)
    00611             {
    00612                 ++(*pUseCount);
    00613             }
    00614             return *this;
    00615         }
    00616     };
    00617
    00618 } //namespace
    00619
    00620 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:36:01 2005