Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreMaterial.cpp @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 25.4 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreMaterial.h"
32
33#include "OgreSceneManagerEnumerator.h"
34#include "OgreMaterialManager.h"
35#include "OgreIteratorWrappers.h"
36#include "OgreTechnique.h"
37#include "OgreLogManager.h"
38#include "OgreException.h"
39#include "OgreStringConverter.h"
40
41namespace Ogre {
42
43    //-----------------------------------------------------------------------
44        Material::Material(ResourceManager* creator, const String& name, ResourceHandle handle,
45                const String& group, bool isManual, ManualResourceLoader* loader)
46                :Resource(creator, name, handle, group, isManual, loader),
47         mReceiveShadows(true),
48         mTransparencyCastsShadows(false),
49         mCompilationRequired(true)
50    {
51                // Override isManual, not applicable for Material (we always want to call loadImpl)
52                if(isManual)
53                {
54                        mIsManual = false;
55                        LogManager::getSingleton().logMessage("Material " + name + 
56                                " was requested with isManual=true, but this is not applicable " 
57                                "for materials; the flag has been reset to false");
58                }
59
60                mLodDistances.push_back(0.0f);
61
62                applyDefaults();
63
64                /* For consistency with StringInterface, but we don't add any parameters here
65                That's because the Resource implementation of StringInterface is to
66                list all the options that need to be set before loading, of which
67                we have none as such. Full details can be set through scripts.
68                */ 
69                createParamDictionary("Material");
70    }
71    //-----------------------------------------------------------------------
72    Material::~Material()
73    {
74        removeAllTechniques();
75        // have to call this here reather than in Resource destructor
76        // since calling virtual methods in base destructors causes crash
77        unload(); 
78    }
79    //-----------------------------------------------------------------------
80    Material& Material::operator=(const Material& rhs)
81    {
82            mName = rhs.mName;
83                mGroup = rhs.mGroup;
84                mCreator = rhs.mCreator;
85                mIsManual = rhs.mIsManual;
86                mLoader = rhs.mLoader;
87            mHandle = rhs.mHandle;
88        mSize = rhs.mSize;
89        mReceiveShadows = rhs.mReceiveShadows;
90        mTransparencyCastsShadows = rhs.mTransparencyCastsShadows;
91
92        mLoadingState = rhs.mLoadingState;
93                mIsBackgroundLoaded = rhs.mIsBackgroundLoaded;
94
95        // Copy Techniques
96        this->removeAllTechniques();
97        Techniques::const_iterator i, iend;
98        iend = rhs.mTechniques.end();
99        for(i = rhs.mTechniques.begin(); i != iend; ++i)
100        {
101            Technique* t = this->createTechnique();
102            *t = *(*i);
103            if ((*i)->isSupported())
104            {
105                                insertSupportedTechnique(t);
106            }
107        }
108
109                // Also copy LOD information
110                mLodDistances = rhs.mLodDistances;
111        mCompilationRequired = rhs.mCompilationRequired;
112        // illumination passes are not compiled right away so
113        // mIsLoaded state should still be the same as the original material
114        assert(isLoaded() == rhs.isLoaded());
115
116            return *this;
117    }
118
119
120    //-----------------------------------------------------------------------
121    void Material::loadImpl(void)
122    {
123                // compile if required
124        if (mCompilationRequired)
125            compile();
126
127        // Load all supported techniques
128        Techniques::iterator i, iend;
129        iend = mSupportedTechniques.end();
130        for (i = mSupportedTechniques.begin(); i != iend; ++i)
131        {
132            (*i)->_load();
133        }
134
135    }
136    //-----------------------------------------------------------------------
137    void Material::unloadImpl(void)
138    {
139        // Unload all supported techniques
140        Techniques::iterator i, iend;
141        iend = mSupportedTechniques.end();
142        for (i = mSupportedTechniques.begin(); i != iend; ++i)
143        {
144            (*i)->_unload();
145        }
146    }
147    //-----------------------------------------------------------------------
148    MaterialPtr Material::clone(const String& newName, bool changeGroup, 
149                const String& newGroup) const
150    {
151                MaterialPtr newMat;
152                if (changeGroup)
153                {
154                        newMat = MaterialManager::getSingleton().create(newName, newGroup);
155                }
156                else
157                {
158                        newMat = MaterialManager::getSingleton().create(newName, mGroup);
159                }
160       
161
162        // Keep handle (see below, copy overrides everything)
163        ResourceHandle newHandle = newMat->getHandle();
164        // Assign values from this
165        *newMat = *this;
166                // Restore new group if required, will have been overridden by operator
167                if (changeGroup)
168                {
169                        newMat->mGroup = newGroup;
170                }
171               
172        // Correct the name & handle, they get copied too
173        newMat->mName = newName;
174        newMat->mHandle = newHandle;
175
176        return newMat;
177
178
179
180    }
181    //-----------------------------------------------------------------------
182    void Material::copyDetailsTo(MaterialPtr& mat) const
183    {
184        // Keep handle (see below, copy overrides everything)
185        ResourceHandle savedHandle = mat->mHandle;
186        String savedName = mat->mName;
187        String savedGroup = mat->mGroup;
188                ManualResourceLoader* savedLoader = mat->mLoader;
189                bool savedManual = mat->mIsManual;
190        // Assign values from this
191        *mat = *this;
192        // Correct the name & handle, they get copied too
193        mat->mName = savedName;
194        mat->mHandle = savedHandle;
195        mat->mGroup = savedGroup;
196                mat->mIsManual = savedManual;
197                mat->mLoader = savedLoader;
198
199    }
200    //-----------------------------------------------------------------------
201    void Material::applyDefaults(void)
202    {
203                MaterialPtr defaults = MaterialManager::getSingleton().getDefaultSettings();
204
205                if (!defaults.isNull())
206                {
207            // save name & handle
208            String savedName = mName;
209            String savedGroup = mGroup;
210            ResourceHandle savedHandle = mHandle;
211                        ManualResourceLoader *savedLoader = mLoader;
212                        bool savedManual = mIsManual;
213                        *this = *defaults;
214            // restore name & handle
215            mName = savedName;
216            mHandle = savedHandle;
217            mGroup = savedGroup;
218                        mLoader = savedLoader;
219                        mIsManual = savedManual;
220                }
221        mCompilationRequired = true;
222
223    }
224    //-----------------------------------------------------------------------
225    Technique* Material::createTechnique(void)
226    {
227        Technique *t = new Technique(this);
228        mTechniques.push_back(t);
229        mCompilationRequired = true;
230        return t;
231    }
232    //-----------------------------------------------------------------------
233    Technique* Material::getTechnique(unsigned short index)
234    {
235        assert (index < mTechniques.size() && "Index out of bounds.");
236        return mTechniques[index];
237    }
238    //-----------------------------------------------------------------------
239    Technique* Material::getTechnique(const String& name)
240    {
241        Techniques::iterator i    = mTechniques.begin();
242        Techniques::iterator iend = mTechniques.end();
243        Technique* foundTechnique = 0;
244
245        // iterate through techniques to find a match
246        while (i != iend)
247        {
248            if ( (*i)->getName() == name )
249            {
250                foundTechnique = (*i);
251                break;
252            }
253            ++i;
254        }
255
256        return foundTechnique;
257    }
258    //-----------------------------------------------------------------------   
259    unsigned short Material::getNumTechniques(void) const
260    {
261                return static_cast<unsigned short>(mTechniques.size());
262    }
263        //-----------------------------------------------------------------------
264    Technique* Material::getSupportedTechnique(unsigned short index)
265    {
266        assert (index < mSupportedTechniques.size() && "Index out of bounds.");
267        return mSupportedTechniques[index];
268    }
269    //-----------------------------------------------------------------------   
270    unsigned short Material::getNumSupportedTechniques(void) const
271    {
272                return static_cast<unsigned short>(mSupportedTechniques.size());
273    }
274        //-----------------------------------------------------------------------
275        unsigned short Material::getNumLodLevels(unsigned short schemeIndex) const
276        {
277                // Safety check - empty list?
278                if (mBestTechniquesBySchemeList.empty())
279                        return 0;
280
281                BestTechniquesBySchemeList::const_iterator i = 
282                        mBestTechniquesBySchemeList.find(schemeIndex);
283                if (i == mBestTechniquesBySchemeList.end())
284                {
285                        // get the first item, will be 0 (the default) if default
286                        // scheme techniques exist, otherwise the earliest defined
287                        i = mBestTechniquesBySchemeList.begin();
288                }
289
290                return static_cast<unsigned short>(i->second->size());
291        }
292        //-----------------------------------------------------------------------
293        unsigned short Material::getNumLodLevels(const String& schemeName) const
294        {
295                return getNumLodLevels(
296                        MaterialManager::getSingleton()._getSchemeIndex(schemeName));
297        }
298        //-----------------------------------------------------------------------
299        void Material::insertSupportedTechnique(Technique* t)
300        {
301                mSupportedTechniques.push_back(t);
302                // get scheme
303                unsigned short schemeIndex = t->_getSchemeIndex();
304                BestTechniquesBySchemeList::iterator i =
305                        mBestTechniquesBySchemeList.find(schemeIndex);
306                LodTechniques* lodtechs = 0;
307                if (i == mBestTechniquesBySchemeList.end())
308                {
309                        lodtechs = new LodTechniques();
310                        mBestTechniquesBySchemeList[schemeIndex] = lodtechs;
311                }
312                else
313                {
314                        lodtechs = i->second;
315                }
316
317                // Insert won't replace if supported technique for this scheme/lod is
318                // already there, which is what we want
319                lodtechs->insert(LodTechniques::value_type(t->getLodIndex(), t));
320
321        }
322        //-----------------------------------------------------------------------------
323    Technique* Material::getBestTechnique(unsigned short lodIndex)
324    {
325        if (mSupportedTechniques.empty())
326        {
327            return NULL;
328        }
329        else
330        {
331                        Technique* ret = 0;
332                        // get scheme
333                        BestTechniquesBySchemeList::iterator si = 
334                                mBestTechniquesBySchemeList.find(
335                                MaterialManager::getSingleton()._getActiveSchemeIndex());
336                        // scheme not found?
337                        if (si == mBestTechniquesBySchemeList.end())
338                        {
339                                // get the first item, will be 0 (the default) if default
340                                // scheme techniques exist, otherwise the earliest defined
341                                si = mBestTechniquesBySchemeList.begin();
342                        }
343
344                        // get LOD
345                        LodTechniques::iterator li = si->second->find(lodIndex);
346                        // LOD not found?
347                        if (li == si->second->end())
348                        {
349                                // Use the next LOD level up
350                                for (LodTechniques::reverse_iterator rli = si->second->rbegin(); 
351                                        rli != si->second->rend(); ++rli)
352                                {
353                                        if (rli->second->getLodIndex() < lodIndex)
354                                        {
355                                                ret = rli->second;
356                                                break;
357                                        }
358
359                                }
360                                if (!ret)
361                                {
362                                        // shouldn't ever hit this really, unless user defines no LOD 0
363                                        // pick the first LOD we have (must be at least one to have a scheme entry)
364                                        ret = si->second->begin()->second;
365                                }
366
367                        }
368                        else
369                        {
370                                // LOD found
371                                ret = li->second;
372                        }
373
374                        return ret;
375
376        }
377    }
378    //-----------------------------------------------------------------------
379    void Material::removeTechnique(unsigned short index)
380    {
381        assert (index < mTechniques.size() && "Index out of bounds.");
382        Techniques::iterator i = mTechniques.begin() + index;
383        delete(*i);
384        mTechniques.erase(i);
385        mSupportedTechniques.clear();
386                clearBestTechniqueList();
387        mCompilationRequired = true;
388    }
389    //-----------------------------------------------------------------------
390    void Material::removeAllTechniques(void)
391    {
392        Techniques::iterator i, iend;
393        iend = mTechniques.end();
394        for (i = mTechniques.begin(); i != iend; ++i)
395        {
396            delete(*i);
397        }
398        mTechniques.clear();
399        mSupportedTechniques.clear();
400        clearBestTechniqueList();
401        mCompilationRequired = true;
402    }
403    //-----------------------------------------------------------------------
404    Material::TechniqueIterator Material::getTechniqueIterator(void) 
405    {
406        return TechniqueIterator(mTechniques.begin(), mTechniques.end());
407    }
408    //-----------------------------------------------------------------------
409    Material::TechniqueIterator Material::getSupportedTechniqueIterator(void)
410    {
411        return TechniqueIterator(mSupportedTechniques.begin(), mSupportedTechniques.end());
412    }
413    //-----------------------------------------------------------------------
414    bool Material::isTransparent(void) const
415        {
416                // Check each technique
417                Techniques::const_iterator i, iend;
418                iend = mTechniques.end();
419                for (i = mTechniques.begin(); i != iend; ++i)
420                {
421                        if ( (*i)->isTransparent() )
422                                return true;
423                }
424                return false;
425        }
426    //-----------------------------------------------------------------------
427    void Material::compile(bool autoManageTextureUnits)
428    {
429        // Compile each technique, then add it to the list of supported techniques
430        mSupportedTechniques.clear();
431                clearBestTechniqueList();
432                mUnsupportedReasons.clear();
433
434
435        Techniques::iterator i, iend;
436        iend = mTechniques.end();
437                size_t techNo = 0;
438        for (i = mTechniques.begin(); i != iend; ++i, ++techNo)
439        {
440            String compileMessages = (*i)->_compile(autoManageTextureUnits);
441            if ( (*i)->isSupported() )
442            {
443                                insertSupportedTechnique(*i);
444            }
445                        else
446                        {
447                                // Log informational
448                                StringUtil::StrStreamType str;
449                                str << "Material " << mName << " Technique " << techNo;
450                                if (!(*i)->getName().empty())
451                                        str << "(" << (*i)->getName() << ")";
452                                str << " is not supported. " << compileMessages;
453                                LogManager::getSingleton().logMessage(str.str(), LML_TRIVIAL);
454                                mUnsupportedReasons += compileMessages;
455                        }
456        }
457
458        mCompilationRequired = false;
459
460        // Did we find any?
461        if (mSupportedTechniques.empty())
462        {
463                        StringUtil::StrStreamType str;
464                        str << "WARNING: material " << mName << " has no supportable "
465                                "Techniques and will be blank. Explanation: " << std::endl << mUnsupportedReasons;
466            LogManager::getSingleton().logMessage(str.str());               
467        }
468    }
469        //-----------------------------------------------------------------------
470        void Material::clearBestTechniqueList(void)
471        {
472                for (BestTechniquesBySchemeList::iterator i = mBestTechniquesBySchemeList.begin();
473                        i != mBestTechniquesBySchemeList.end(); ++i)
474                {
475                        delete i->second;
476                }
477                mBestTechniquesBySchemeList.clear();
478        }
479    //-----------------------------------------------------------------------
480    void Material::setPointSize(Real ps)
481    {
482        Techniques::iterator i, iend;
483        iend = mTechniques.end();
484        for (i = mTechniques.begin(); i != iend; ++i)
485        {
486            (*i)->setPointSize(ps);
487        }
488
489    }
490    //-----------------------------------------------------------------------
491    void Material::setAmbient(Real red, Real green, Real blue)
492    {
493        Techniques::iterator i, iend;
494        iend = mTechniques.end();
495        for (i = mTechniques.begin(); i != iend; ++i)
496        {
497            (*i)->setAmbient(red, green, blue);
498        }
499
500    }
501    //-----------------------------------------------------------------------
502    void Material::setAmbient(const ColourValue& ambient)
503    {
504        setAmbient(ambient.r, ambient.g, ambient.b);
505    }
506    //-----------------------------------------------------------------------
507    void Material::setDiffuse(Real red, Real green, Real blue, Real alpha)
508    {
509        Techniques::iterator i, iend;
510        iend = mTechniques.end();
511        for (i = mTechniques.begin(); i != iend; ++i)
512        {
513            (*i)->setDiffuse(red, green, blue, alpha);
514        }
515    }
516    //-----------------------------------------------------------------------
517    void Material::setDiffuse(const ColourValue& diffuse)
518    {
519        setDiffuse(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
520    }
521    //-----------------------------------------------------------------------
522    void Material::setSpecular(Real red, Real green, Real blue, Real alpha)
523    {
524        Techniques::iterator i, iend;
525        iend = mTechniques.end();
526        for (i = mTechniques.begin(); i != iend; ++i)
527        {
528            (*i)->setSpecular(red, green, blue, alpha);
529        }
530    }
531    //-----------------------------------------------------------------------
532    void Material::setSpecular(const ColourValue& specular)
533    {
534        setSpecular(specular.r, specular.g, specular.b, specular.a);
535    }
536    //-----------------------------------------------------------------------
537    void Material::setShininess(Real val)
538    {
539        Techniques::iterator i, iend;
540        iend = mTechniques.end();
541        for (i = mTechniques.begin(); i != iend; ++i)
542        {
543            (*i)->setShininess(val);
544        }
545    }
546    //-----------------------------------------------------------------------
547    void Material::setSelfIllumination(Real red, Real green, Real blue)
548    {
549        Techniques::iterator i, iend;
550        iend = mTechniques.end();
551        for (i = mTechniques.begin(); i != iend; ++i)
552        {
553            (*i)->setSelfIllumination(red, green, blue);
554        }
555    }
556    //-----------------------------------------------------------------------
557    void Material::setSelfIllumination(const ColourValue& selfIllum)
558    {
559        setSelfIllumination(selfIllum.r, selfIllum.g, selfIllum.b);
560    }
561    //-----------------------------------------------------------------------
562    void Material::setDepthCheckEnabled(bool enabled)
563    {
564        Techniques::iterator i, iend;
565        iend = mTechniques.end();
566        for (i = mTechniques.begin(); i != iend; ++i)
567        {
568            (*i)->setDepthCheckEnabled(enabled);
569        }
570    }
571    //-----------------------------------------------------------------------
572    void Material::setDepthWriteEnabled(bool enabled)
573    {
574        Techniques::iterator i, iend;
575        iend = mTechniques.end();
576        for (i = mTechniques.begin(); i != iend; ++i)
577        {
578            (*i)->setDepthWriteEnabled(enabled);
579        }
580    }
581    //-----------------------------------------------------------------------
582    void Material::setDepthFunction( CompareFunction func )
583    {
584        Techniques::iterator i, iend;
585        iend = mTechniques.end();
586        for (i = mTechniques.begin(); i != iend; ++i)
587        {
588            (*i)->setDepthFunction(func);
589        }
590    }
591    //-----------------------------------------------------------------------
592        void Material::setColourWriteEnabled(bool enabled)
593    {
594        Techniques::iterator i, iend;
595        iend = mTechniques.end();
596        for (i = mTechniques.begin(); i != iend; ++i)
597        {
598            (*i)->setColourWriteEnabled(enabled);
599        }
600    }
601    //-----------------------------------------------------------------------
602    void Material::setCullingMode( CullingMode mode )
603    {
604        Techniques::iterator i, iend;
605        iend = mTechniques.end();
606        for (i = mTechniques.begin(); i != iend; ++i)
607        {
608            (*i)->setCullingMode(mode);
609        }
610    }
611    //-----------------------------------------------------------------------
612    void Material::setManualCullingMode( ManualCullingMode mode )
613    {
614        Techniques::iterator i, iend;
615        iend = mTechniques.end();
616        for (i = mTechniques.begin(); i != iend; ++i)
617        {
618            (*i)->setManualCullingMode(mode);
619        }
620    }
621    //-----------------------------------------------------------------------
622    void Material::setLightingEnabled(bool enabled)
623    {
624        Techniques::iterator i, iend;
625        iend = mTechniques.end();
626        for (i = mTechniques.begin(); i != iend; ++i)
627        {
628            (*i)->setLightingEnabled(enabled);
629        }
630    }
631    //-----------------------------------------------------------------------
632    void Material::setShadingMode( ShadeOptions mode )
633    {
634        Techniques::iterator i, iend;
635        iend = mTechniques.end();
636        for (i = mTechniques.begin(); i != iend; ++i)
637        {
638            (*i)->setShadingMode(mode);
639        }
640    }
641    //-----------------------------------------------------------------------
642    void Material::setFog(bool overrideScene, FogMode mode, const ColourValue& colour,
643        Real expDensity, Real linearStart, Real linearEnd)
644    {
645        Techniques::iterator i, iend;
646        iend = mTechniques.end();
647        for (i = mTechniques.begin(); i != iend; ++i)
648        {
649            (*i)->setFog(overrideScene, mode, colour, expDensity, linearStart, linearEnd);
650        }
651    }
652    //-----------------------------------------------------------------------
653    void Material::setDepthBias(float constantBias, float slopeScaleBias)
654    {
655        Techniques::iterator i, iend;
656        iend = mTechniques.end();
657        for (i = mTechniques.begin(); i != iend; ++i)
658        {
659            (*i)->setDepthBias(constantBias, slopeScaleBias);
660        }
661    }
662    //-----------------------------------------------------------------------
663    void Material::setTextureFiltering(TextureFilterOptions filterType)
664    {
665        Techniques::iterator i, iend;
666        iend = mTechniques.end();
667        for (i = mTechniques.begin(); i != iend; ++i)
668        {
669            (*i)->setTextureFiltering(filterType);
670        }
671    }
672    // --------------------------------------------------------------------
673    void Material::setTextureAnisotropy(int maxAniso)
674    {
675        Techniques::iterator i, iend;
676        iend = mTechniques.end();
677        for (i = mTechniques.begin(); i != iend; ++i)
678        {
679            (*i)->setTextureAnisotropy(maxAniso);
680        }
681    }
682    // --------------------------------------------------------------------
683    void Material::setSceneBlending( const SceneBlendType sbt )
684    {
685        Techniques::iterator i, iend;
686        iend = mTechniques.end();
687        for (i = mTechniques.begin(); i != iend; ++i)
688        {
689            (*i)->setSceneBlending(sbt);
690        }
691    }
692    // --------------------------------------------------------------------
693    void Material::setSceneBlending( const SceneBlendFactor sourceFactor, 
694        const SceneBlendFactor destFactor)
695    {
696        Techniques::iterator i, iend;
697        iend = mTechniques.end();
698        for (i = mTechniques.begin(); i != iend; ++i)
699        {
700            (*i)->setSceneBlending(sourceFactor, destFactor);
701        }
702    }
703    // --------------------------------------------------------------------
704    void Material::_notifyNeedsRecompile(void)
705    {
706        mCompilationRequired = true;
707        // Also need to unload to ensure we loaded any new items
708                if (isLoaded()) // needed to stop this being called in 'loading' state
709                        unload();
710    }
711    // --------------------------------------------------------------------
712    void Material::setLodLevels(const LodDistanceList& lodDistances)
713    {
714        // Square the distances for the internal list
715                LodDistanceList::const_iterator i, iend;
716                iend = lodDistances.end();
717                // First, clear and add single zero entry
718                mLodDistances.clear();
719                mLodDistances.push_back(0.0f);
720                for (i = lodDistances.begin(); i != iend; ++i)
721                {
722                        mLodDistances.push_back((*i) * (*i));
723                }
724               
725    }
726    // --------------------------------------------------------------------
727    unsigned short Material::getLodIndex(Real d) const
728    {
729        return getLodIndexSquaredDepth(d * d);
730    }
731    // --------------------------------------------------------------------
732    unsigned short Material::getLodIndexSquaredDepth(Real squaredDistance) const
733    {
734                LodDistanceList::const_iterator i, iend;
735                iend = mLodDistances.end();
736                unsigned short index = 0;
737                for (i = mLodDistances.begin(); i != iend; ++i, ++index)
738                {
739                        if (*i > squaredDistance)
740                        {
741                                return index - 1;
742                        }
743                }
744
745                // If we fall all the way through, use the highest value
746                return static_cast<ushort>(mLodDistances.size() - 1);
747    }
748    // --------------------------------------------------------------------
749    Material::LodDistanceIterator Material::getLodDistanceIterator(void) const
750    {
751        return LodDistanceIterator(mLodDistances.begin(), mLodDistances.end());
752    }
753
754    //-----------------------------------------------------------------------
755    bool Material::applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply) const
756    {
757        // iterate through all techniques and apply texture aliases
758                Techniques::const_iterator i, iend;
759                iend = mTechniques.end();
760        bool testResult = false;
761
762                for (i = mTechniques.begin(); i != iend; ++i)
763                {
764            if ((*i)->applyTextureAliases(aliasList, apply))
765                testResult = true;
766                }
767
768        return testResult;
769    }
770}
Note: See TracBrowser for help on using the repository browser.