# 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;
    00097         Techniques mTechniques;
    00099         Techniques mSupportedTechniques;
    00100         typedef std::map<unsigned short, Technique*> LodTechniques;
    00101         typedef std::map<unsigned short, LodTechniques*> BestTechniquesBySchemeList;
    00106         BestTechniquesBySchemeList mBestTechniquesBySchemeList;
    00107
    00108         LodDistanceList mLodDistances;
    00109         bool mReceiveShadows;
    00110         bool mTransparencyCastsShadows;
    00112         bool mCompilationRequired;
    00113
    00115         void insertSupportedTechnique(Technique* t);
    00116
    00119         void clearBestTechniqueList(void);
    00120
    00123         void loadImpl(void);
    00124
    00129         void unloadImpl(void);
    00131         size_t calculateSize(void) const { return 0; } // TODO
    00132     public:
    00133
    00136         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
    00137             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00138
    00139         ~Material();
    00142         Material& operator=( const Material& rhs );
    00143
    00147         bool isTransparent(void) const;
    00148
    00162         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
    00164         bool getReceiveShadows(void) const { return mReceiveShadows; }
    00165
    00174         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
    00176         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
    00177
    00192         Technique* createTechnique(void);
    00194         Technique* getTechnique(unsigned short index);
    00198         Technique* getTechnique(const String& name);
    00200         unsigned short getNumTechniques(void) const;
    00202         void removeTechnique(unsigned short index);
    00204         void removeAllTechniques(void);
    00205         typedef VectorIterator<Techniques> TechniqueIterator;
    00207         TechniqueIterator getTechniqueIterator(void);
    00214         TechniqueIterator getSupportedTechniqueIterator(void);
    00215
    00217         Technique* getSupportedTechnique(unsigned short index);
    00219         unsigned short getNumSupportedTechniques(void) const;
    00220
    00226         unsigned short getNumLodLevels(unsigned short schemeIndex) const;
    00232         unsigned short getNumLodLevels(const String& schemeName) const;
    00233
    00245         Technique* getBestTechnique(unsigned short lodIndex = 0);
    00246
    00247
    00253         MaterialPtr clone(const String& newName, bool changeGroup = false,
    00254             const String& newGroup = StringUtil::BLANK) const;
    00255
    00260         void copyDetailsTo(MaterialPtr& mat) const;
    00261
    00277         void compile(bool autoManageTextureUnits = true);
    00278
    00279         // -------------------------------------------------------------------------------
    00280         // The following methods are to make migration from previous versions simpler
    00281         // and to make code easier to write when dealing with simple materials
    00282         // They set the properties which have been moved to Pass for all Techniques and all Passes
    00283
    00293         void setPointSize(Real ps);
    00294
    00304         void setAmbient(Real red, Real green, Real blue);
    00305
    00315         void setAmbient(const ColourValue& ambient);
    00316
    00326         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00327
    00337         void setDiffuse(const ColourValue& diffuse);
    00338
    00348         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00349
    00359         void setSpecular(const ColourValue& specular);
    00360
    00370         void setShininess(Real val);
    00371
    00381         void setSelfIllumination(Real red, Real green, Real blue);
    00382
    00392         void setSelfIllumination(const ColourValue& selfIllum);
    00393
    00403         void setDepthCheckEnabled(bool enabled);
    00404
    00414         void setDepthWriteEnabled(bool enabled);
    00415
    00425         void setDepthFunction( CompareFunction func );
    00426
    00436         void setColourWriteEnabled(bool enabled);
    00437
    00447         void setCullingMode( CullingMode mode );
    00448
    00458         void setManualCullingMode( ManualCullingMode mode );
    00459
    00469         void setLightingEnabled(bool enabled);
    00470
    00480         void setShadingMode( ShadeOptions mode );
    00481
    00491         void setFog(
    00492             bool overrideScene,
    00493             FogMode mode = FOG_NONE,
    00494             const ColourValue& colour = ColourValue::White,
    00495             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00496
    00506         void setDepthBias(ushort bias);
    00507
    00516         void setTextureFiltering(TextureFilterOptions filterType);
    00525         void setTextureAnisotropy(int maxAniso);
    00526
    00536         void setSceneBlending( const SceneBlendType sbt );
    00537
    00547         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00548
    00549
    00551         void _notifyNeedsRecompile(void);
    00552
    00565         void setLodLevels(const LodDistanceList& lodDistances);
    00573         LodDistanceIterator getLodDistanceIterator(void) const;
    00574
    00576         unsigned short getLodIndex(Real d) const;
    00578         unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
    00579
    00582         void touch(void)
    00583         {
    00584             if (mCompilationRequired)
    00585                 compile();
    00586             // call superclass
    00587             Resource::touch();
    00588         }
    00589
    00601         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
    00602
    00606         bool getCompilationRequired() const
    00607         {
    00608             return mCompilationRequired;
    00609         }
    00610
    00611
    00612     };
    00613
    00620     class _OgreExport MaterialPtr : public SharedPtr<Material>
    00621     {
    00622     public:
    00623         MaterialPtr() : SharedPtr<Material>() {}
    00624         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
    00625         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
    00626         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
    00627         {
    00628             // lock & copy other mutex pointer
    00629             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00630             {
    00631                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00632                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00633                 pRep = static_cast<Material*>(r.getPointer());
    00634                 pUseCount = r.useCountPointer();
    00635                 if (pUseCount)
    00636                 {
    00637                     ++(*pUseCount);
    00638                 }
    00639             }
    00640         }
    00641
    00643         MaterialPtr& operator=(const ResourcePtr& r)
    00644         {
    00645             if (pRep == static_cast<Material*>(r.getPointer()))
    00646                 return *this;
    00647             release();
    00648             // lock & copy other mutex pointer
    00649             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00650             {
    00651                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00652                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00653                 pRep = static_cast<Material*>(r.getPointer());
    00654                 pUseCount = r.useCountPointer();
    00655                 if (pUseCount)
    00656                 {
    00657                     ++(*pUseCount);
    00658                 }
    00659             }
    00660             return *this;
    00661         }
    00662     };
    00663
    00664 } //namespace
    00665
    00666 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 17 15:39:09 2006