Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreMaterial.h @ 1

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