source: OGRE/trunk/ogrenew/OgreMain/include/OgreMaterial.h @ 692

Revision 692, 32.2 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#ifndef _Material_H__
26#define _Material_H__
27
28#include "OgrePrerequisites.h"
29
30#include "OgreResource.h"
31#include "OgreIteratorWrappers.h"
32#include "OgreCommon.h"
33#include "OgreColourValue.h"
34#include "OgreBlendMode.h"
35
36
37namespace Ogre {
38
39        // Forward declaration
40        class MaterialPtr;
41
42        /** Class encapsulates rendering properties of an object.
43    @remarks
44    Ogre's material class encapsulates ALL aspects of the visual appearance,
45    of an object. It also includes other flags which
46    might not be traditionally thought of as material properties such as
47    culling modes and depth buffer settings, but these affect the
48    appearance of the rendered object and are convenient to attach to the
49    material since it keeps all the settings in one place. This is
50    different to Direct3D which treats a material as just the colour
51    components (diffuse, specular) and not texture maps etc. An Ogre
52    Material can be thought of as equivalent to a 'Shader'.
53    @par
54    A Material can be rendered in multiple different ways depending on the
55    hardware available. You may configure a Material to use high-complexity
56    fragment shaders, but these won't work on every card; therefore a Technique
57    is an approach to creating the visual effect you are looking for. You are advised
58    to create fallback techniques with lower hardware requirements if you decide to
59    use advanced features. In addition, you also might want lower-detail techniques
60    for distant geometry.
61    @par
62    Each technique can be made up of multiple passes. A fixed-function pass
63    may combine multiple texture layers using multitexrtuing, but Ogre can
64    break that into multiple passes automatically if the active card cannot
65    handle that many simultaneous textures. Programmable passes, however, cannot
66    be split down automatically, so if the active graphics card cannot handle the
67    technique which contains these passes, OGRE will try to find another technique
68    which the card can do. If, at the end of the day, the card cannot handle any of the
69    techniques which are listed for the material, the engine will render the
70    geometry plain white, which should alert you to the problem.
71    @par
72    Ogre comes configured with a number of default settings for a newly
73    created material. These can be changed if you wish by retrieving the
74    default material settings through
75    SceneManager::getDefaultMaterialSettings. Any changes you make to the
76    Material returned from this method will apply to any materials created
77    from this point onward.
78    */
79    class _OgreExport Material : public Resource
80    {
81        friend class SceneManager;
82        friend class MaterialManager;
83
84    public:
85        /// distance list used to specify LOD
86        typedef std::vector<Real> LodDistanceList;
87        typedef ConstVectorIterator<LodDistanceList> LodDistanceIterator;
88    protected:
89
90
91        /** Internal method which sets the material up from the default settings.
92        */
93        void applyDefaults(void);
94
95        typedef std::vector<Technique*> Techniques;
96                /// All techniques, supported and unsupported
97        Techniques mTechniques;
98                /// Supported techniques of any sort
99        Techniques mSupportedTechniques;
100                typedef std::map<unsigned short, Technique*> LodTechniques;
101        typedef std::map<unsigned short, LodTechniques*> BestTechniquesBySchemeList;
102                /** Map of scheme -> list of LOD techniques.
103                        Current scheme is set on MaterialManager,
104                        and can be set per Viewport for auto activation.
105                */
106        BestTechniquesBySchemeList mBestTechniquesBySchemeList;
107
108        LodDistanceList mLodDistances;
109        bool mReceiveShadows;
110                bool mTransparencyCastsShadows;
111        /// Does this material require compilation?
112        bool mCompilationRequired;
113
114                /** Insert a supported technique into the local collections. */
115                void insertSupportedTechnique(Technique* t);
116
117                /** Clear the best technique list.
118                */
119                void clearBestTechniqueList(void);
120
121                /** Overridden from Resource.
122                */
123                void loadImpl(void);
124
125                /** Unloads the material, frees resources etc.
126                @see
127                Resource
128                */
129                void unloadImpl(void);
130                /// @copydoc Resource::calculateSize
131                size_t calculateSize(void) const { return 0; } // TODO
132    public:
133
134        /** Constructor - use resource manager's create method rather than this.
135        */
136                Material(ResourceManager* creator, const String& name, ResourceHandle handle,
137                        const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
138
139        ~Material();
140        /** Assignment operator to allow easy copying between materials.
141        */
142        Material& operator=( const Material& rhs );
143
144        /** Determines if the material has any transparency with the rest of the scene (derived from
145            whether any Techniques say they involve transparency).
146        */
147        bool isTransparent(void) const;
148
149        /** Sets whether objects using this material will receive shadows.
150        @remarks
151            This method allows a material to opt out of receiving shadows, if
152            it would otherwise do so. Shadows will not be cast on any objects
153            unless the scene is set up to support shadows
154            (@see SceneManager::setShadowTechnique), and not all techniques cast
155            shadows on all objects. In any case, if you have a need to prevent
156            shadows being received by material, this is the method you call to
157            do it.
158        @note
159            Transparent materials never receive shadows despite this setting.
160            The default is to receive shadows.
161        */
162        void setReceiveShadows(bool enabled) { mReceiveShadows = enabled; }
163        /** Returns whether or not objects using this material will receive shadows. */
164        bool getReceiveShadows(void) const { return mReceiveShadows; }
165
166                /** Sets whether objects using this material be classified as opaque to the shadow caster system.
167                @remarks
168                This method allows a material to cast a shadow, even if it is transparent.
169                By default, transparent materials neither cast nor receive shadows. Shadows
170                will not be cast on any objects unless the scene is set up to support shadows
171                (@see SceneManager::setShadowTechnique), and not all techniques cast
172                shadows on all objects.
173                */
174                void setTransparencyCastsShadows(bool enabled) { mTransparencyCastsShadows = enabled; }
175                /** Returns whether or not objects using this material be classified as opaque to the shadow caster system. */
176                bool getTransparencyCastsShadows(void) const { return mTransparencyCastsShadows; }
177
178        /** Creates a new Technique for this Material.
179        @remarks
180            A Technique is a single way of rendering geometry in order to achieve the effect
181            you are intending in a material. There are many reason why you would want more than
182            one - the main one being to handle variable graphics card abilities; you might have
183            one technique which is impressive but only runs on 4th-generation graphics cards,
184            for example. In this case you will want to create at least one fallback Technique.
185            OGRE will work out which Techniques a card can support and pick the best one.
186        @par
187            If multiple Techniques are available, the order in which they are created is
188            important - the engine will consider lower-indexed Techniques to be preferable
189            to higher-indexed Techniques, ie when asked for the 'best' technique it will
190            return the first one in the technique list which is supported by the hardware.
191        */
192        Technique* createTechnique(void);
193        /** Gets the indexed technique. */
194        Technique* getTechnique(unsigned short index);
195        /** searches for the named technique.
196            Return 0 if technique with name is not found
197        */
198        Technique* getTechnique(const String& name);
199                /** Retrieves the number of techniques. */
200        unsigned short getNumTechniques(void) const;
201        /** Removes the technique at the given index. */               
202        void removeTechnique(unsigned short index);             
203        /** Removes all the techniques in this Material. */
204        void removeAllTechniques(void);
205        typedef VectorIterator<Techniques> TechniqueIterator;
206        /** Get an iterator over the Techniques in this Material. */
207        TechniqueIterator getTechniqueIterator(void);
208        /** Gets an iterator over all the Techniques which are supported by the current card.
209        @remarks
210            The supported technique list is only available after this material has been compiled,
211            which typically happens on loading the material. Therefore, if this method returns
212            an empty list, try calling Material::load.
213        */
214        TechniqueIterator getSupportedTechniqueIterator(void);
215               
216                /** Gets the indexed supported technique. */
217        Technique* getSupportedTechnique(unsigned short index);
218                /** Retrieves the number of supported techniques. */
219        unsigned short getNumSupportedTechniques(void) const;
220
221        /** Gets the number of levels-of-detail this material has in the
222                        given scheme, based on Technique::setLodIndex.
223        @remarks
224            Note that this will not be up to date until the material has been compiled.
225        */
226        unsigned short getNumLodLevels(unsigned short schemeIndex) const;
227        /** Gets the number of levels-of-detail this material has in the
228                        given scheme, based on Technique::setLodIndex.
229        @remarks
230            Note that this will not be up to date until the material has been compiled.
231        */
232        unsigned short getNumLodLevels(const String& schemeName) const;
233
234        /** Gets the best supported technique.
235        @remarks
236            This method returns the lowest-index supported Technique in this material
237            (since lower-indexed Techniques are considered to be better than higher-indexed
238            ones).
239        @par
240            The best supported technique is only available after this material has been compiled,
241            which typically happens on loading the material. Therefore, if this method returns
242            NULL, try calling Material::load.
243                @param lodIndex The material lod index to use
244        */
245        Technique* getBestTechnique(unsigned short lodIndex = 0);
246
247
248        /** Creates a new copy of this material with the same settings but a new name.
249                @param newName The name for the cloned material
250                @param changeGroup If true, the resource group of the clone is changed
251                @param newGroup Only required if changeGroup is true; the new group to assign
252        */
253        MaterialPtr clone(const String& newName, bool changeGroup = false,
254                        const String& newGroup = StringUtil::BLANK) const;
255
256        /** Copies the details of this material into another, preserving the target's handle and name
257        (unlike operator=) but copying everything else.
258        @param mat Weak reference to material which will receive this material's settings.
259        */
260        void copyDetailsTo(MaterialPtr& mat) const;
261
262        /** 'Compiles' this Material.
263        @remarks
264            Compiling a material involves determining which Techniques are supported on the
265            card on which OGRE is currently running, and for fixed-function Passes within those
266            Techniques, splitting the passes down where they contain more TextureUnitState
267            instances than the current card has texture units.
268        @par
269            This process is automatically done when the Material is loaded, but may be
270            repeated if you make some procedural changes.
271        @param
272            autoManageTextureUnits If true, when a fixed function pass has too many TextureUnitState
273                entries than the card has texture units, the Pass in question will be split into
274                more than one Pass in order to emulate the Pass. If you set this to false and
275                this situation arises, an Exception will be thrown.
276        */
277        void compile(bool autoManageTextureUnits = true);
278
279        // -------------------------------------------------------------------------------
280        // The following methods are to make migration from previous versions simpler
281        // and to make code easier to write when dealing with simple materials
282        // They set the properties which have been moved to Pass for all Techniques and all Passes
283
284        /** Sets the point size properties for every Pass in every Technique.
285        @note
286            This property has been moved to the Pass class, which is accessible via the
287            Technique. For simplicity, this method allows you to set these properties for
288            every current Technique, and for every current Pass within those Techniques. If
289            you need more precision, retrieve the Technique and Pass instances and set the
290            property there.
291        @see Pass::setPointSize
292        */
293        void setPointSize(Real ps);
294
295        /** Sets the ambient colour reflectance properties for every Pass in every Technique.
296        @note
297            This property has been moved to the Pass class, which is accessible via the
298            Technique. For simplicity, this method allows you to set these properties for
299            every current Technique, and for every current Pass within those Techniques. If
300            you need more precision, retrieve the Technique and Pass instances and set the
301            property there.
302        @see Pass::setAmbient
303        */
304        void setAmbient(Real red, Real green, Real blue);
305
306        /** Sets the ambient colour reflectance properties for every Pass in every Technique.
307        @note
308            This property has been moved to the Pass class, which is accessible via the
309            Technique. For simplicity, this method allows you to set these properties for
310            every current Technique, and for every current Pass within those Techniques. If
311            you need more precision, retrieve the Technique and Pass instances and set the
312            property there.
313        @see Pass::setAmbient
314        */
315        void setAmbient(const ColourValue& ambient);
316
317        /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
318        @note
319            This property has been moved to the Pass class, which is accessible via the
320            Technique. For simplicity, this method allows you to set these properties for
321            every current Technique, and for every current Pass within those Techniques. If
322            you need more precision, retrieve the Technique and Pass instances and set the
323            property there.
324        @see Pass::setDiffuse
325        */
326        void setDiffuse(Real red, Real green, Real blue, Real alpha);
327
328        /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
329        @note
330            This property has been moved to the Pass class, which is accessible via the
331            Technique. For simplicity, this method allows you to set these properties for
332            every current Technique, and for every current Pass within those Techniques. If
333            you need more precision, retrieve the Technique and Pass instances and set the
334            property there.
335        @see Pass::setDiffuse
336        */
337        void setDiffuse(const ColourValue& diffuse);
338
339        /** Sets the specular colour reflectance properties of every Pass in every Technique.
340        @note
341            This property has been moved to the Pass class, which is accessible via the
342            Technique. For simplicity, this method allows you to set these properties for
343            every current Technique, and for every current Pass within those Techniques. If
344            you need more precision, retrieve the Technique and Pass instances and set the
345            property there.
346        @see Pass::setSpecular
347        */
348        void setSpecular(Real red, Real green, Real blue, Real alpha);
349
350        /** Sets the specular colour reflectance properties of every Pass in every Technique.
351        @note
352            This property has been moved to the Pass class, which is accessible via the
353            Technique. For simplicity, this method allows you to set these properties for
354            every current Technique, and for every current Pass within those Techniques. If
355            you need more precision, retrieve the Technique and Pass instances and set the
356            property there.
357        @see Pass::setSpecular
358        */
359        void setSpecular(const ColourValue& specular);
360
361        /** Sets the shininess properties of every Pass in every Technique.
362        @note
363            This property has been moved to the Pass class, which is accessible via the
364            Technique. For simplicity, this method allows you to set these properties for
365            every current Technique, and for every current Pass within those Techniques. If
366            you need more precision, retrieve the Technique and Pass instances and set the
367            property there.
368        @see Pass::setShininess
369        */
370        void setShininess(Real val);
371
372        /** Sets the amount of self-illumination of every Pass in every Technique.
373        @note
374            This property has been moved to the Pass class, which is accessible via the
375            Technique. For simplicity, this method allows you to set these properties for
376            every current Technique, and for every current Pass within those Techniques. If
377            you need more precision, retrieve the Technique and Pass instances and set the
378            property there.
379        @see Pass::setSelfIllumination
380        */
381        void setSelfIllumination(Real red, Real green, Real blue);
382
383        /** Sets the amount of self-illumination of every Pass in every Technique.
384        @note
385            This property has been moved to the Pass class, which is accessible via the
386            Technique. For simplicity, this method allows you to set these properties for
387            every current Technique, and for every current Pass within those Techniques. If
388            you need more precision, retrieve the Technique and Pass instances and set the
389            property there.
390        @see Pass::setSelfIllumination
391        */
392        void setSelfIllumination(const ColourValue& selfIllum);
393
394                /** Sets whether or not each Pass renders with depth-buffer checking on or not.
395        @note
396            This property has been moved to the Pass class, which is accessible via the
397            Technique. For simplicity, this method allows you to set these properties for
398            every current Technique, and for every current Pass within those Techniques. If
399            you need more precision, retrieve the Technique and Pass instances and set the
400            property there.
401        @see Pass::setDepthCheckEnabled
402        */
403        void setDepthCheckEnabled(bool enabled);
404
405        /** Sets whether or not each Pass renders with depth-buffer writing on or not.
406        @note
407            This property has been moved to the Pass class, which is accessible via the
408            Technique. For simplicity, this method allows you to set these properties for
409            every current Technique, and for every current Pass within those Techniques. If
410            you need more precision, retrieve the Technique and Pass instances and set the
411            property there.
412        @see Pass::setDepthWriteEnabled
413        */
414        void setDepthWriteEnabled(bool enabled);
415
416        /** Sets the function used to compare depth values when depth checking is on.
417        @note
418            This property has been moved to the Pass class, which is accessible via the
419            Technique. For simplicity, this method allows you to set these properties for
420            every current Technique, and for every current Pass within those Techniques. If
421            you need more precision, retrieve the Technique and Pass instances and set the
422            property there.
423        @see Pass::setDepthFunction
424        */
425        void setDepthFunction( CompareFunction func );
426
427                /** Sets whether or not colour buffer writing is enabled for each Pass.
428        @note
429            This property has been moved to the Pass class, which is accessible via the
430            Technique. For simplicity, this method allows you to set these properties for
431            every current Technique, and for every current Pass within those Techniques. If
432            you need more precision, retrieve the Technique and Pass instances and set the
433            property there.
434        @see Pass::setColourWriteEnabled
435                */
436                void setColourWriteEnabled(bool enabled);
437
438        /** Sets the culling mode for each pass  based on the 'vertex winding'.
439        @note
440            This property has been moved to the Pass class, which is accessible via the
441            Technique. For simplicity, this method allows you to set these properties for
442            every current Technique, and for every current Pass within those Techniques. If
443            you need more precision, retrieve the Technique and Pass instances and set the
444            property there.
445        @see Pass::setCullingMode
446        */
447        void setCullingMode( CullingMode mode );
448
449        /** Sets the manual culling mode, performed by CPU rather than hardware.
450        @note
451            This property has been moved to the Pass class, which is accessible via the
452            Technique. For simplicity, this method allows you to set these properties for
453            every current Technique, and for every current Pass within those Techniques. If
454            you need more precision, retrieve the Technique and Pass instances and set the
455            property there.
456        @see Pass::setManualCullingMode
457        */
458        void setManualCullingMode( ManualCullingMode mode );
459
460        /** Sets whether or not dynamic lighting is enabled for every Pass.
461        @note
462            This property has been moved to the Pass class, which is accessible via the
463            Technique. For simplicity, this method allows you to set these properties for
464            every current Technique, and for every current Pass within those Techniques. If
465            you need more precision, retrieve the Technique and Pass instances and set the
466            property there.
467        @see Pass::setLightingEnabled
468        */
469        void setLightingEnabled(bool enabled);
470
471        /** Sets the type of light shading required
472        @note
473            This property has been moved to the Pass class, which is accessible via the
474            Technique. For simplicity, this method allows you to set these properties for
475            every current Technique, and for every current Pass within those Techniques. If
476            you need more precision, retrieve the Technique and Pass instances and set the
477            property there.
478        @see Pass::setShadingMode
479        */
480        void setShadingMode( ShadeOptions mode );
481
482        /** Sets the fogging mode applied to each pass.
483        @note
484            This property has been moved to the Pass class, which is accessible via the
485            Technique. For simplicity, this method allows you to set these properties for
486            every current Technique, and for every current Pass within those Techniques. If
487            you need more precision, retrieve the Technique and Pass instances and set the
488            property there.
489        @see Pass::setFog
490        */
491        void setFog(
492            bool overrideScene,
493            FogMode mode = FOG_NONE,
494            const ColourValue& colour = ColourValue::White,
495            Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
496
497        /** Sets the depth bias to be used for each Pass.
498        @note
499            This property has been moved to the Pass class, which is accessible via the
500            Technique. For simplicity, this method allows you to set these properties for
501            every current Technique, and for every current Pass within those Techniques. If
502            you need more precision, retrieve the Technique and Pass instances and set the
503            property there.
504        @see Pass::setDepthBias
505        */
506        void setDepthBias(ushort bias);
507
508        /** Set texture filtering for every texture unit in every Technique and Pass
509        @note
510            This property has been moved to the TextureUnitState class, which is accessible via the
511            Technique and Pass. For simplicity, this method allows you to set these properties for
512            every current TeextureUnitState, If you need more precision, retrieve the Technique,
513            Pass and TextureUnitState instances and set the property there.
514        @see TextureUnitState::setTextureFiltering
515        */
516        void setTextureFiltering(TextureFilterOptions filterType);
517        /** Sets the anisotropy level to be used for all textures.
518        @note
519            This property has been moved to the TextureUnitState class, which is accessible via the
520            Technique and Pass. For simplicity, this method allows you to set these properties for
521            every current TeextureUnitState, If you need more precision, retrieve the Technique,
522            Pass and TextureUnitState instances and set the property there.
523        @see TextureUnitState::setTextureAnisotropy
524        */
525        void setTextureAnisotropy(int maxAniso);
526
527        /** Sets the kind of blending every pass has with the existing contents of the scene.
528        @note
529            This property has been moved to the Pass class, which is accessible via the
530            Technique. For simplicity, this method allows you to set these properties for
531            every current Technique, and for every current Pass within those Techniques. If
532            you need more precision, retrieve the Technique and Pass instances and set the
533            property there.
534        @see Pass::setSceneBlending
535        */
536        void setSceneBlending( const SceneBlendType sbt );
537
538        /** Allows very fine control of blending every Pass with the existing contents of the scene.
539        @note
540            This property has been moved to the Pass class, which is accessible via the
541            Technique. For simplicity, this method allows you to set these properties for
542            every current Technique, and for every current Pass within those Techniques. If
543            you need more precision, retrieve the Technique and Pass instances and set the
544            property there.
545        @see Pass::setSceneBlending
546        */
547        void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
548
549
550        /** Tells the material that it needs recompilation. */
551        void _notifyNeedsRecompile(void);
552
553        /** Sets the distance at which level-of-detail (LOD) levels come into effect.
554        @remarks
555            You should only use this if you have assigned LOD indexes to the Technique
556            instances attached to this Material. If you have done so, you should call this
557            method to determine the distance at which the lowe levels of detail kick in.
558            The decision about what distance is actually used is a combination of this
559            and the LOD bias applied to both the current Camera and the current Entity.
560        @param lodDistances A vector of Reals which indicate the distance at which to
561            switch to lower details. They are listed in LOD index order, starting at index
562            1 (ie the first level down from the highest level 0, which automatically applies
563            from a distance of 0).
564        */
565        void setLodLevels(const LodDistanceList& lodDistances);
566        /** Gets an iterator over the list of distances at which each LOD comes into effect.
567        @remarks
568            Note that the iterator returned from this method is not totally anagolous to
569            the one passed in by calling setLodLevels - the list includes a zero
570            entry at the start (since the highest LOD starts at distance 0), and
571            the other distances are held as their squared value for efficiency.
572        */
573        LodDistanceIterator getLodDistanceIterator(void) const;
574
575        /** Gets the LOD index to use at the given distance. */
576        unsigned short getLodIndex(Real d) const;
577        /** Gets the LOD index to use at the given squared distance. */
578        unsigned short getLodIndexSquaredDepth(Real squaredDepth) const;
579
580        /** @copydoc Resource::touch
581        */
582        void touch(void)
583        {
584            if (mCompilationRequired)
585                compile();
586            // call superclass
587            Resource::touch();
588        }
589       
590        /** Applies texture names to Texture Unit State with matching texture name aliases.
591            All techniques, passes, and Texture Unit States within the material are checked.
592            If matching texture aliases are found then true is returned.
593
594        @param
595            aliasList is a map container of texture alias, texture name pairs
596        @param
597            apply set true to apply the texture aliases else just test to see if texture alias matches are found.
598        @return
599            True if matching texture aliases were found in the material.
600        */
601        bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
602
603            /** Gets the compilation status of the material.
604        @return True if the material needs recompilation.
605        */
606            bool getCompilationRequired() const
607            {
608                    return mCompilationRequired;
609            }
610
611
612    };
613
614        /** Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr
615        @note Has to be a subclass since we need operator=.
616        We could templatise this instead of repeating per Resource subclass,
617        except to do so requires a form VC6 does not support i.e.
618        ResourceSubclassPtr<T> : public SharedPtr<T>
619        */
620        class _OgreExport MaterialPtr : public SharedPtr<Material>
621        {
622        public:
623                MaterialPtr() : SharedPtr<Material>() {}
624                explicit MaterialPtr(Material* rep) : SharedPtr<Material>(rep) {}
625                MaterialPtr(const MaterialPtr& r) : SharedPtr<Material>(r) {}
626                MaterialPtr(const ResourcePtr& r) : SharedPtr<Material>()
627                {
628                        // lock & copy other mutex pointer
629                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
630                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
631                        pRep = static_cast<Material*>(r.getPointer());
632                        pUseCount = r.useCountPointer();
633                        if (pUseCount)
634                        {
635                                ++(*pUseCount);
636                        }
637                }
638
639                /// Operator used to convert a ResourcePtr to a MaterialPtr
640                MaterialPtr& operator=(const ResourcePtr& r)
641                {
642                        if (pRep == static_cast<Material*>(r.getPointer()))
643                                return *this;
644                        release();
645                        // lock & copy other mutex pointer
646                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
647                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
648                        pRep = static_cast<Material*>(r.getPointer());
649                        pUseCount = r.useCountPointer();
650                        if (pUseCount)
651                        {
652                                ++(*pUseCount);
653                        }
654                        return *this;
655                }
656        };
657
658} //namespace
659
660#endif
Note: See TracBrowser for help on using the repository browser.