OGRE: OgreMaterial.h Source File - OGRE Documentation

# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef _Material_H__
    00029 #define _Material_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreResource.h"
    00034 #include "OgreIteratorWrappers.h"
    00035 #include "OgreCommon.h"
    00036 #include "OgreColourValue.h"
    00037 #include "OgreBlendMode.h"
    00038
    00039 namespace Ogre {
    00040
    00041     // Forward declaration
    00042     class MaterialPtr;
    00043     class LodStrategy;
    00044
    00088     class _OgreExport Material : public Resource
    00089     {
    00090         friend class SceneManager;
    00091         friend class MaterialManager;
    00092
    00093     public:
    00095         typedef vector<Real>::type LodValueList;
    00096         typedef ConstVectorIterator<LodValueList> LodValueIterator;
    00097     protected:
    00098
    00099
    00102         void applyDefaults(void);
    00103
    00104         typedef vector<Technique*>::type Techniques;
    00106         Techniques mTechniques;
    00108         Techniques mSupportedTechniques;
    00109         typedef map<unsigned short, Technique*>::type LodTechniques;
    00110         typedef map<unsigned short, LodTechniques*>::type BestTechniquesBySchemeList;
    00115         BestTechniquesBySchemeList mBestTechniquesBySchemeList;
    00116
    00117         LodValueList mUserLodValues;
    00118         LodValueList mLodValues;
    00119         const LodStrategy *mLodStrategy;
    00120         bool mReceiveShadows;
    00121         bool mTransparencyCastsShadows;
    00123         bool mCompilationRequired;
    00125         String mUnsupportedReasons;
    00126
    00128         void insertSupportedTechnique(Technique* t);
    00129
    00132         void clearBestTechniqueList(void);
    00133
    00136         void prepareImpl(void);
    00137
    00140         void unprepareImpl(void);
    00141
    00144         void loadImpl(void);
    00145
    00150         void unloadImpl(void);
    00152         size_t calculateSize(void) const { return 0; } // TODO
    00153     public:
    00154
    00157         Material(ResourceManager* creator, const String& name, ResourceHandle handle,
    00158             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00159
    00160         ~Material();
    00163         Material& operator=( const Material& rhs );
    00164
    00168         bool isTransparent(void) const;
    00169
    00183         void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
    00185         bool getReceiveShadows(void) const { return mReceiveShadows; }
    00186
    00195         void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
    00197         bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
    00198
    00213         Technique* createTechnique(void);
    00215         Technique* getTechnique(unsigned short index);
    00219         Technique* getTechnique(const String& name);
    00221         unsigned short getNumTechniques(void) const;
    00223         void removeTechnique(unsigned short index);
    00225         void removeAllTechniques(void);
    00226         typedef VectorIterator<Techniques> TechniqueIterator;
    00228         TechniqueIterator getTechniqueIterator(void);
    00235         TechniqueIterator getSupportedTechniqueIterator(void);
    00236
    00238         Technique* getSupportedTechnique(unsigned short index);
    00240         unsigned short getNumSupportedTechniques(void) const;
    00242         const String& getUnsupportedTechniquesExplanation() const { return mUnsupportedReasons; }
    00243
    00249         unsigned short getNumLodLevels(unsigned short schemeIndex) const;
    00255         unsigned short getNumLodLevels(const String& schemeName) const;
    00256
    00272         Technique* getBestTechnique(unsigned short lodIndex = 0, const Renderable* rend = 0);
    00273
    00274
    00280         MaterialPtr clone(const String& newName, bool changeGroup = false,
    00281             const String& newGroup = StringUtil::BLANK) const;
    00282
    00287         void copyDetailsTo(MaterialPtr& mat) const;
    00288
    00304         void compile(bool autoManageTextureUnits = true);
    00305
    00306         // -------------------------------------------------------------------------------
    00307         // The following methods are to make migration from previous versions simpler
    00308         // and to make code easier to write when dealing with simple materials
    00309         // They set the properties which have been moved to Pass for all Techniques and all Passes
    00310
    00320         void setPointSize(Real ps);
    00321
    00331         void setAmbient(Real red, Real green, Real blue);
    00332
    00342         void setAmbient(const ColourValue& ambient);
    00343
    00353         void setDiffuse(Real red, Real green, Real blue, Real alpha);
    00354
    00364         void setDiffuse(const ColourValue& diffuse);
    00365
    00375         void setSpecular(Real red, Real green, Real blue, Real alpha);
    00376
    00386         void setSpecular(const ColourValue& specular);
    00387
    00397         void setShininess(Real val);
    00398
    00408         void setSelfIllumination(Real red, Real green, Real blue);
    00409
    00419         void setSelfIllumination(const ColourValue& selfIllum);
    00420
    00430         void setDepthCheckEnabled(bool enabled);
    00431
    00441         void setDepthWriteEnabled(bool enabled);
    00442
    00452         void setDepthFunction( CompareFunction func );
    00453
    00463         void setColourWriteEnabled(bool enabled);
    00464
    00474         void setCullingMode( CullingMode mode );
    00475
    00485         void setManualCullingMode( ManualCullingMode mode );
    00486
    00496         void setLightingEnabled(bool enabled);
    00497
    00507         void setShadingMode( ShadeOptions mode );
    00508
    00518         void setFog(
    00519             bool overrideScene,
    00520             FogMode mode = FOG_NONE,
    00521             const ColourValue& colour = ColourValue::White,
    00522             Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00523
    00533         void setDepthBias(float constantBias, float slopeScaleBias);
    00534
    00543         void setTextureFiltering(TextureFilterOptions filterType);
    00552         void setTextureAnisotropy(int maxAniso);
    00553
    00563         void setSceneBlending( const SceneBlendType sbt );
    00564
    00574         void setSeparateSceneBlending( const SceneBlendType sbt, const SceneBlendType sbta );
    00575
    00585         void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00586
    00596         void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha);
    00597
    00599         void _notifyNeedsRecompile(void);
    00600
    00615         void setLodLevels(const LodValueList& lodValues);
    00623         LodValueIterator getLodValueIterator(void) const;
    00624
    00630         ushort getLodIndex(Real value) const;
    00631
    00633         const LodStrategy *getLodStrategy() const;
    00635         void setLodStrategy(LodStrategy *lodStrategy);
    00636
    00639         void touch(void)
    00640         {
    00641             if (mCompilationRequired)
    00642                 compile();
    00643             // call superclass
    00644             Resource::touch();
    00645         }
    00646
    00658         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
    00659
    00663         bool getCompilationRequired() const
    00664         {
    00665             return mCompilationRequired;
    00666         }
    00667
    00668
    00669     };
    00670
    00677     class _OgreExport MaterialPtr : public SharedPtr<Material>
    00678     {
    00679     public:
    00680         MaterialPtr() : SharedPtr<Material>() {}
    00681         explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
    00682         MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
    00683         MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
    00684         {
    00685             // lock & copy other mutex pointer
    00686             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00687             {
    00688                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00689                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00690                 pRep = static_cast<Material*>(r.getPointer());
    00691                 pUseCount = r.useCountPointer();
    00692                 if (pUseCount)
    00693                 {
    00694                     ++(*pUseCount);
    00695                 }
    00696             }
    00697         }
    00698
    00700         MaterialPtr& operator=(const ResourcePtr& r)
    00701         {
    00702             if (pRep == static_cast<Material*>(r.getPointer()))
    00703                 return *this;
    00704             release();
    00705             // lock & copy other mutex pointer
    00706             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00707             {
    00708                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00709                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00710                 pRep = static_cast<Material*>(r.getPointer());
    00711                 pUseCount = r.useCountPointer();
    00712                 if (pUseCount)
    00713                 {
    00714                     ++(*pUseCount);
    00715                 }
    00716             }
    00717             else
    00718             {
    00719                 // RHS must be a null pointer
    00720                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00721                 setNull();
    00722             }
    00723             return *this;
    00724         }
    00725     };
    00729 } //namespace
    00730
    00731 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52