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

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