Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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 
00102         bool mCompilationRequired;
00103         LodDistanceList mLodDistances;
00104         bool mReceiveShadows;
00105         bool mTransparencyCastsShadows;
00106 
00109         void loadImpl(void);
00110 
00115         void unloadImpl(void);
00117         size_t calculateSize(void) const { return 0; } // TODO 
00118     public:
00119 
00122         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
00123             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00124 
00125         ~Material();
00128         Material& operator=( const Material& rhs );
00129 
00133         bool isTransparent(void) const;
00134 
00148         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
00150         bool getReceiveShadows(void) const { return mReceiveShadows; }
00151 
00160         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
00162         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
00163 
00178         Technique* createTechnique(void);
00180         Technique* getTechnique(unsigned short index);
00182         unsigned short getNumTechniques(void) const;
00184         void removeTechnique(unsigned short index);     
00186         void removeAllTechniques(void);
00187         typedef VectorIterator<Techniques> TechniqueIterator;
00189         TechniqueIterator getTechniqueIterator(void);
00196         TechniqueIterator getSupportedTechniqueIterator(void);
00197         
00199         Technique* getSupportedTechnique(unsigned short index);
00201         unsigned short getNumSupportedTechniques(void) const;
00202 
00208         unsigned short getNumLodLevels(void) const { 
00209             return static_cast<unsigned short>(mBestTechniqueList.size()); }
00210 
00222         Technique* getBestTechnique(unsigned short lodIndex = 0);
00223 
00224 
00230         MaterialPtr clone(const String& newName, bool changeGroup = false, 
00231             const String& newGroup = StringUtil::BLANK) const;
00232 
00237         void copyDetailsTo(MaterialPtr& mat) const;
00238 
00254         void compile(bool autoManageTextureUnits = true);
00255 
00256         // -------------------------------------------------------------------------------
00257         // The following methods are to make migration from previous versions simpler
00258         // and to make code easier to write when dealing with simple materials
00259         // They set the properties which have been moved to Pass for all Techniques and all Passes
00260 
00270         void setAmbient(Real red, Real green, Real blue);
00271 
00281         void setAmbient(const ColourValue& ambient);
00282 
00292         void setDiffuse(Real red, Real green, Real blue, Real alpha);
00293 
00303         void setDiffuse(const ColourValue& diffuse);
00304 
00314         void setSpecular(Real red, Real green, Real blue, Real alpha);
00315 
00325         void setSpecular(const ColourValue& specular);
00326 
00336         void setShininess(Real val);
00337 
00347         void setSelfIllumination(Real red, Real green, Real blue);
00348 
00358         void setSelfIllumination(const ColourValue& selfIllum);
00359 
00369         void setDepthCheckEnabled(bool enabled);
00370 
00380         void setDepthWriteEnabled(bool enabled);
00381 
00391         void setDepthFunction( CompareFunction func );
00392 
00402         void setColourWriteEnabled(bool enabled);
00403 
00413         void setCullingMode( CullingMode mode );
00414 
00424         void setManualCullingMode( ManualCullingMode mode );
00425 
00435         void setLightingEnabled(bool enabled);
00436 
00446         void setShadingMode( ShadeOptions mode );
00447 
00457         void setFog(
00458             bool overrideScene,
00459             FogMode mode = FOG_NONE,
00460             const ColourValue& colour = ColourValue::White,
00461             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
00462 
00472         void setDepthBias(ushort bias);
00473 
00482         void setTextureFiltering(TextureFilterOptions filterType);
00491         void setTextureAnisotropy(int maxAniso);
00492 
00502         void setSceneBlending( const SceneBlendType sbt );
00503 
00513         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00514 
00515 
00517         void _notifyNeedsRecompile(void);
00518 
00531         void setLodLevels(const LodDistanceList& lodDistances);
00539         LodDistanceIterator getLodDistanceIterator(void) const;
00540 
00542         unsigned short getLodIndex(Real d) const;
00544         unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
00545 
00548         void touch(void) 
00549         { 
00550             if (mCompilationRequired) 
00551                 compile();
00552             // call superclass
00553             Resource::touch();
00554         }
00555 
00556 
00557     };
00558 
00565     class _OgreExport MaterialPtr : public SharedPtr<Material> 
00566     {
00567     public:
00568         MaterialPtr() : SharedPtr<Material>() {}
00569         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
00570         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {} 
00571         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
00572         {
00573             // lock & copy other mutex pointer
00574             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00575             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00576             pRep = static_cast<Material*>(r.getPointer());
00577             pUseCount = r.useCountPointer();
00578             if (pUseCount)
00579             {
00580                 ++(*pUseCount);
00581             }
00582         }
00583 
00585         MaterialPtr& operator=(const ResourcePtr& r)
00586         {
00587             if (pRep == static_cast<Material*>(r.getPointer()))
00588                 return *this;
00589             release();
00590             // lock & copy other mutex pointer
00591             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00592             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00593             pRep = static_cast<Material*>(r.getPointer());
00594             pUseCount = r.useCountPointer();
00595             if (pUseCount)
00596             {
00597                 ++(*pUseCount);
00598             }
00599             return *this;
00600         }
00601     };
00602 
00603 } //namespace 
00604 
00605 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Wed Feb 23 00:19:08 2005