Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 22.8 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 __Technique_H__
30#define __Technique_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreIteratorWrappers.h"
34#include "OgreBlendMode.h"
35#include "OgreCommon.h"
36#include "OgrePass.h"
37
38namespace Ogre {
39    /** Class representing an approach to rendering this particular Material.
40    @remarks
41        Ogre will attempt to use the best technique supported by the active hardware,
42        unless you specifically request a lower detail technique (say for distant
43        rendering).
44    */
45    class _OgreExport Technique
46    {
47    protected:
48        // illumination pass state type
49        enum IlluminationPassesState
50        {
51            IPS_COMPILE_DISABLED = -1,
52            IPS_NOT_COMPILED = 0,
53            IPS_COMPILED = 1
54        };
55
56        typedef std::vector<Pass*> Passes;
57        /// List of primary passes
58        Passes mPasses;
59        /// List of derived passes, categorised into IlluminationStage (ordered)
60        IlluminationPassList mIlluminationPasses;
61        Material* mParent; // raw pointer since we don't want child to stop parent's destruction
62        bool mIsSupported;
63        IlluminationPassesState mIlluminationPassesCompilationPhase;
64                /// LOD level
65        unsigned short mLodIndex;
66                /** Scheme index, derived from scheme name but the names are held on
67                        MaterialManager, for speed an index is used here.
68                */
69                unsigned short mSchemeIndex;
70        String mName; // optional name for the technique
71
72        /// Internal method for clearing illumination pass list
73        void clearIlluminationPasses(void);
74    public:
75        /// Constructor
76        Technique(Material* parent);
77        /// Copy constructor
78        Technique(Material* parent, const Technique& oth);
79        ~Technique();
80        /** Indicates if this technique is supported by the current graphics card.
81        @remarks
82            This will only be correct after the Technique has been compiled, which is
83            usually done from Material::compile.
84        */
85        bool isSupported(void) const;
86        /** Internal compilation method; see Material::compile.
87                @returns Any information explaining problems with the compile.
88                */
89        String _compile(bool autoManageTextureUnits);
90        /** Internal method for splitting the passes into illumination passes. */       
91        void _compileIlluminationPasses(void);
92
93
94        /** Creates a new Pass for this Technique.
95        @remarks
96            A Pass is a single rendering pass, ie a single draw of the given material.
97            Note that if you create a pass without a fragment program, during compilation of the
98            material the pass may be split into multiple passes if the graphics card cannot
99            handle the number of texture units requested. For passes with fragment programs, however,
100            the number of passes you create will never be altered, so you have to make sure
101            that you create an alternative fallback Technique for if a card does not have
102            enough facilities for what you're asking for.
103        */
104        Pass* createPass(void);
105        /** Retrieves the Pass with the given index. */
106        Pass* getPass(unsigned short index);
107        /** Retrieves the Pass matching name.
108            Returns 0 if name match is not found.
109        */
110        Pass* getPass(const String& name);
111        /** Retrieves the number of passes. */
112        unsigned short getNumPasses(void) const;
113        /** Removes the Pass with the given index. */
114        void removePass(unsigned short index);
115        /** Removes all Passes from this Technique. */
116        void removeAllPasses(void);
117        /** Move a pass from source index to destination index.
118            If successful then returns true.
119        */
120        bool movePass(const unsigned short sourceIndex, const unsigned short destinationIndex);
121        typedef VectorIterator<Passes> PassIterator;
122        /** Gets an iterator over the passes in this Technique. */
123        const PassIterator getPassIterator(void);
124        typedef VectorIterator<IlluminationPassList> IlluminationPassIterator;
125        /** Gets an iterator over the illumination-stage categorised passes. */
126        const IlluminationPassIterator getIlluminationPassIterator(void);
127        /// Gets the parent Material
128        Material* getParent(void) const { return mParent; }
129
130        /** Overloaded operator to copy on Technique to another. */
131        Technique& operator=(const Technique& rhs);
132
133                /// Gets the resource group of the ultimate parent Material
134                const String& getResourceGroup(void) const;
135
136                /** Returns true if this Technique involves transparency.
137                @remarks
138                        This basically boils down to whether the first pass
139                        has a scene blending factor. Even if the other passes
140                        do not, the base colour, including parts of the original
141                        scene, may be used for blending, therefore we have to treat
142                        the whole Technique as transparent.
143                */
144                bool isTransparent(void) const;
145
146        /** Internal load method, derived from call to Material::load. */
147        void _load(void);
148        /** Internal unload method, derived from call to Material::unload. */
149        void _unload(void);
150
151        // Is this loaded?
152        bool isLoaded(void) const;
153
154        /** Tells the technique that it needs recompilation. */
155        void _notifyNeedsRecompile(void);
156
157
158        // -------------------------------------------------------------------------------
159        // The following methods are to make migration from previous versions simpler
160        // and to make code easier to write when dealing with simple materials
161        // They set the properties which have been moved to Pass for all Techniques and all Passes
162
163        /** Sets the point size properties for every Pass in this Technique.
164        @note
165            This property actually exists on the Pass class. For simplicity, this method allows
166            you to set these properties for every current Pass within this Technique. If
167            you need more precision, retrieve the Pass instance and set the
168            property there.
169        @see Pass::setPointSize
170        */
171        void setPointSize(Real ps);
172
173        /** Sets the ambient colour reflectance properties for every Pass in every Technique.
174        @note
175            This property actually exists on the Pass class. For simplicity, this method allows
176            you to set these properties for every current Pass within this Technique. If
177            you need more precision, retrieve the Pass instance and set the
178            property there.
179        @see Pass::setAmbient
180        */
181        void setAmbient(Real red, Real green, Real blue);
182
183        /** Sets the ambient colour reflectance properties for every Pass in every Technique.
184        @note
185            This property actually exists on the Pass class. For simplicity, this method allows
186            you to set these properties for every current Pass within this Technique. If
187            you need more precision, retrieve the Pass instance and set the
188            property there.
189        @see Pass::setAmbient
190        */
191        void setAmbient(const ColourValue& ambient);
192
193        /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
194        @note
195            This property actually exists on the Pass class. For simplicity, this method allows
196            you to set these properties for every current Pass within this Technique. If
197            you need more precision, retrieve the Pass instance and set the
198            property there.
199        @see Pass::setDiffuse
200        */
201        void setDiffuse(Real red, Real green, Real blue, Real alpha);
202
203        /** Sets the diffuse colour reflectance properties of every Pass in every Technique.
204        @note
205            This property actually exists on the Pass class. For simplicity, this method allows
206            you to set these properties for every current Pass within this Technique. If
207            you need more precision, retrieve the Pass instance and set the
208            property there.
209        @see Pass::setDiffuse
210        */
211        void setDiffuse(const ColourValue& diffuse);
212
213        /** Sets the specular colour reflectance properties of every Pass in every Technique.
214        @note
215            This property actually exists on the Pass class. For simplicity, this method allows
216            you to set these properties for every current Pass within this Technique. If
217            you need more precision, retrieve the Pass instance and set the
218            property there.
219        @see Pass::setSpecular
220        */
221        void setSpecular(Real red, Real green, Real blue, Real alpha);
222
223        /** Sets the specular colour reflectance properties of every Pass in every Technique.
224        @note
225            This property actually exists on the Pass class. For simplicity, this method allows
226            you to set these properties for every current Pass within this Technique. If
227            you need more precision, retrieve the Pass instance and set the
228            property there.
229        @see Pass::setSpecular
230        */
231        void setSpecular(const ColourValue& specular);
232
233        /** Sets the shininess properties of every Pass in every Technique.
234        @note
235            This property actually exists on the Pass class. For simplicity, this method allows
236            you to set these properties for every current Pass within this Technique. If
237            you need more precision, retrieve the Pass instance and set the
238            property there.
239        @see Pass::setShininess
240        */
241        void setShininess(Real val);
242
243        /** Sets the amount of self-illumination of every Pass in every Technique.
244        @note
245            This property actually exists on the Pass class. For simplicity, this method allows
246            you to set these properties for every current Pass within this Technique. If
247            you need more precision, retrieve the Pass instance and set the
248            property there.
249        @see Pass::setSelfIllumination
250        */
251        void setSelfIllumination(Real red, Real green, Real blue);
252
253        /** Sets the amount of self-illumination of every Pass in every Technique.
254        @note
255            This property actually exists on the Pass class. For simplicity, this method allows
256            you to set these properties for every current Pass within this Technique. If
257            you need more precision, retrieve the Pass instance and set the
258            property there.
259        @see Pass::setSelfIllumination
260        */
261        void setSelfIllumination(const ColourValue& selfIllum);
262
263                /** Sets whether or not each Pass renders with depth-buffer checking on or not.
264        @note
265            This property actually exists on the Pass class. For simplicity, this method allows
266            you to set these properties for every current Pass within this Technique. If
267            you need more precision, retrieve the Pass instance and set the
268            property there.
269        @see Pass::setDepthCheckEnabled
270        */
271        void setDepthCheckEnabled(bool enabled);
272
273        /** Sets whether or not each Pass renders with depth-buffer writing on or not.
274        @note
275            This property actually exists on the Pass class. For simplicity, this method allows
276            you to set these properties for every current Pass within this Technique. If
277            you need more precision, retrieve the Pass instance and set the
278            property there.
279        @see Pass::setDepthWriteEnabled
280        */
281        void setDepthWriteEnabled(bool enabled);
282
283        /** Sets the function used to compare depth values when depth checking is on.
284        @note
285            This property actually exists on the Pass class. For simplicity, this method allows
286            you to set these properties for every current Pass within this Technique. If
287            you need more precision, retrieve the Pass instance and set the
288            property there.
289        @see Pass::setDepthFunction
290        */
291        void setDepthFunction( CompareFunction func );
292
293                /** Sets whether or not colour buffer writing is enabled for each Pass.
294        @note
295            This property actually exists on the Pass class. For simplicity, this method allows
296            you to set these properties for every current Pass within this Technique. If
297            you need more precision, retrieve the Pass instance and set the
298            property there.
299        @see Pass::setColourWriteEnabled
300                */
301                void setColourWriteEnabled(bool enabled);
302
303        /** Sets the culling mode for each pass  based on the 'vertex winding'.
304        @note
305            This property actually exists on the Pass class. For simplicity, this method allows
306            you to set these properties for every current Pass within this Technique. If
307            you need more precision, retrieve the Pass instance and set the
308            property there.
309        @see Pass::setCullingMode
310        */
311        void setCullingMode( CullingMode mode );
312
313        /** Sets the manual culling mode, performed by CPU rather than hardware.
314        @note
315            This property actually exists on the Pass class. For simplicity, this method allows
316            you to set these properties for every current Pass within this Technique. If
317            you need more precision, retrieve the Pass instance and set the
318            property there.
319        @see Pass::setManualCullingMode
320        */
321        void setManualCullingMode( ManualCullingMode mode );
322
323        /** Sets whether or not dynamic lighting is enabled for every Pass.
324        @note
325            This property actually exists on the Pass class. For simplicity, this method allows
326            you to set these properties for every current Pass within this Technique. If
327            you need more precision, retrieve the Pass instance and set the
328            property there.
329        @see Pass::setLightingEnabled
330        */
331        void setLightingEnabled(bool enabled);
332
333        /** Sets the type of light shading required
334        @note
335            This property actually exists on the Pass class. For simplicity, this method allows
336            you to set these properties for every current Pass within this Technique. If
337            you need more precision, retrieve the Pass instance and set the
338            property there.
339        @see Pass::setShadingMode
340        */
341        void setShadingMode( ShadeOptions mode );
342
343        /** Sets the fogging mode applied to each pass.
344        @note
345            This property actually exists on the Pass class. For simplicity, this method allows
346            you to set these properties for every current Pass within this Technique. If
347            you need more precision, retrieve the Pass instance and set the
348            property there.
349        @see Pass::setFog
350        */
351        void setFog(
352            bool overrideScene,
353            FogMode mode = FOG_NONE,
354            const ColourValue& colour = ColourValue::White,
355            Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0 );
356
357        /** Sets the depth bias to be used for each Pass.
358        @note
359            This property actually exists on the Pass class. For simplicity, this method allows
360            you to set these properties for every current Pass within this Technique. If
361            you need more precision, retrieve the Pass instance and set the
362            property there.
363        @see Pass::setDepthBias
364        */
365        void setDepthBias(float constantBias, float slopeScaleBias);
366
367        /** Set texture filtering for every texture unit in every Pass
368        @note
369            This property actually exists on the TextureUnitState class
370            For simplicity, this method allows you to set these properties for
371            every current TeextureUnitState, If you need more precision, retrieve the 
372            Pass and TextureUnitState instances and set the property there.
373        @see TextureUnitState::setTextureFiltering
374        */
375        void setTextureFiltering(TextureFilterOptions filterType);
376        /** Sets the anisotropy level to be used for all textures.
377        @note
378            This property has been moved to the TextureUnitState class, which is accessible via the
379            Technique and Pass. For simplicity, this method allows you to set these properties for
380            every current TeextureUnitState, If you need more precision, retrieve the Technique,
381            Pass and TextureUnitState instances and set the property there.
382        @see TextureUnitState::setTextureAnisotropy
383        */
384        void setTextureAnisotropy(unsigned int maxAniso);
385
386        /** Sets the kind of blending every pass has with the existing contents of the scene.
387        @note
388            This property actually exists on the Pass class. For simplicity, this method allows
389            you to set these properties for every current Pass within this Technique. If
390            you need more precision, retrieve the Pass instance and set the
391            property there.
392        @see Pass::setSceneBlending
393        */
394        void setSceneBlending( const SceneBlendType sbt );
395
396        /** Allows very fine control of blending every Pass with the existing contents of the scene.
397        @note
398            This property actually exists on the Pass class. For simplicity, this method allows
399            you to set these properties for every current Pass within this Technique. If
400            you need more precision, retrieve the Pass instance and set the
401            property there.
402        @see Pass::setSceneBlending
403        */
404        void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
405
406        /** Assigns a level-of-detail (LOD) index to this Technique.
407        @remarks
408            As noted previously, as well as providing fallback support for various
409            graphics cards, multiple Technique objects can also be used to implement
410            material LOD, where the detail of the material diminishes with distance to
411            save rendering power.
412        @par
413            By default, all Techniques have a LOD index of 0, which means they are the highest
414            level of detail. Increasing LOD indexes are lower levels of detail. You can
415            assign more than one Technique to the same LOD index, meaning that the best
416            Technique that is supported at that LOD index is used.
417        @par
418            You should not leave gaps in the LOD sequence; Ogre will allow you to do this
419            and will continue to function as if the LODs were sequential, but it will
420            confuse matters.
421        */
422        void setLodIndex(unsigned short index);
423        /** Gets the level-of-detail index assigned to this Technique. */
424        unsigned short getLodIndex(void) const { return mLodIndex; }
425
426                /** Set the 'scheme name' for this technique.
427                @remarks
428                        Material schemes are used to control top-level switching from one
429                        set of techniques to another. For example, you might use this to
430                        define 'high', 'medium' and 'low' complexity levels on materials
431                    to allow a user to pick a performance / quality ratio. Another
432                        possibility is that you have a fully HDR-enabled pipeline for top
433                        machines, rendering all objects using unclamped shaders, and a
434                        simpler pipeline for others; this can be implemented using
435                        schemes.
436                @par
437                        Every technique belongs to a scheme - if you don't specify one, the
438                        Technique belongs to the scheme called 'Default', which is also the
439                        scheme used to render by default. The active scheme is set one of
440                        two ways - either by calling Viewport::setMaterialScheme, or
441                        by manually calling MaterialManager::setActiveScheme.
442                */
443                void setSchemeName(const String& schemeName);
444                /** Returns the scheme to which this technique is assigned.
445                        @see Technique::setSchemeName
446                */
447                const String& getSchemeName(void) const;
448               
449                /// Internal method for getting the scheme index
450                unsigned short _getSchemeIndex(void) const;
451                       
452        /** Is depth writing going to occur on this technique? */
453        bool isDepthWriteEnabled(void) const;
454
455        /** Is depth checking going to occur on this technique? */
456        bool isDepthCheckEnabled(void) const;
457
458        /** Exists colour writing disabled pass on this technique? */
459        bool hasColourWriteDisabled(void) const;
460
461        /** Set the name of the technique.
462        @remarks
463        The use of technique name is optional.  Its usefull in material scripts where a material could inherit
464        from another material and only want to modify a particalar technique.
465        */
466        void setName(const String& name);
467        /// Gets the name of the technique
468        const String& getName(void) const { return mName; }
469
470        /** Applies texture names to Texture Unit State with matching texture name aliases.
471            All passes, and Texture Unit States within the technique are checked.
472            If matching texture aliases are found then true is returned.
473
474        @param
475            aliasList is a map container of texture alias, texture name pairs
476        @param
477            apply set true to apply the texture aliases else just test to see if texture alias matches are found.
478        @return
479            True if matching texture aliases were found in the Technique.
480        */
481        bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true) const;
482
483
484    };
485
486
487}
488#endif
Note: See TracBrowser for help on using the repository browser.