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

Revision 692, 9.9 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 __MATERIALMANAGER_H__
26#define __MATERIALMANAGER_H__
27
28#include "OgrePrerequisites.h"
29
30#include "OgreSingleton.h"
31#include "OgreResourceManager.h"
32#include "OgreMaterial.h"
33#include "OgreStringVector.h"
34#include "OgreMaterialSerializer.h"
35
36namespace Ogre {
37
38
39    /** Class for managing Material settings for Ogre.
40        @remarks
41            Materials control the eventual surface rendering properties of geometry. This class
42            manages the library of materials, dealing with programmatic registrations and lookups,
43            as well as loading predefined Material settings from scripts.
44        @par
45            When loaded from a script, a Material is in an 'unloaded' state and only stores the settings
46            required. It does not at that stage load any textures. This is because the material settings may be
47            loaded 'en masse' from bulk material script files, but only a subset will actually be required.
48        @par
49            Because this is a subclass of ResourceManager, any files loaded will be searched for in any path or
50            archive added to the resource paths/archives. See ResourceManager for details.
51        @par
52            For a definition of the material script format, see the Tutorials/MaterialScript.html file.
53    */
54    class _OgreExport MaterialManager : public ResourceManager, public Singleton<MaterialManager>
55    {
56    protected:
57
58        /// Default Texture filtering - minification
59        FilterOptions mDefaultMinFilter;
60        /// Default Texture filtering - magnification
61        FilterOptions mDefaultMagFilter;
62        /// Default Texture filtering - mipmapping
63        FilterOptions mDefaultMipFilter;
64        /// Default Texture anisotropy
65        unsigned int mDefaultMaxAniso;
66
67        /// Serializer
68        MaterialSerializer mSerializer;
69                /// Default settings
70                MaterialPtr mDefaultSettings;
71                /// Overridden from ResourceManager
72                Resource* createImpl(const String& name, ResourceHandle handle,
73                        const String& group, bool isManual, ManualResourceLoader* loader,
74            const NameValuePairList* params);
75
76                /// Scheme name -> index. Never shrinks! Should be pretty static anyway
77                typedef std::map<String, unsigned short> SchemeMap;
78                /// List of material schemes
79                SchemeMap mSchemes;
80                /// Current material scheme
81                String mActiveSchemeName;
82                /// Current material scheme
83                unsigned short mActiveSchemeIndex;
84
85    public:
86                /// Default material scheme
87                static String DEFAULT_SCHEME_NAME;
88               
89        /** Default constructor.
90        */
91        MaterialManager();
92
93        /** Default destructor.
94        */
95        virtual ~MaterialManager();
96
97                /** Intialises the material manager, which also triggers it to
98                 * parse all available .program and .material scripts. */
99                void initialise(void);
100       
101                /** @see ScriptLoader::parseScript
102        */
103        void parseScript(DataStreamPtr& stream, const String& groupName);
104
105
106        /** Sets the default texture filtering to be used for loaded textures, for when textures are
107            loaded automatically (e.g. by Material class) or when 'load' is called with the default
108            parameters by the application.
109            @note
110                The default value is TFO_BILINEAR.
111        */
112        virtual void setDefaultTextureFiltering(TextureFilterOptions fo);
113        /** Sets the default texture filtering to be used for loaded textures, for when textures are
114            loaded automatically (e.g. by Material class) or when 'load' is called with the default
115            parameters by the application.
116        */
117        virtual void setDefaultTextureFiltering(FilterType ftype, FilterOptions opts);
118        /** Sets the default texture filtering to be used for loaded textures, for when textures are
119            loaded automatically (e.g. by Material class) or when 'load' is called with the default
120            parameters by the application.
121        */
122        virtual void setDefaultTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
123
124                /// get the default texture filtering
125        virtual FilterOptions getDefaultTextureFiltering(FilterType ftype) const;
126
127        /** Sets the default anisotropy level to be used for loaded textures, for when textures are
128            loaded automatically (e.g. by Material class) or when 'load' is called with the default
129            parameters by the application.
130            @note
131                The default value is 1 (no anisotropy).
132        */
133                void setDefaultAnisotropy(unsigned int maxAniso);
134                /// get the default maxAnisotropy
135                unsigned int getDefaultAnisotropy() const;
136
137        /** Returns a pointer to the default Material settings.
138            @remarks
139                Ogre comes configured with a set of defaults for newly created
140                materials. If you wish to have a different set of defaults,
141                simply call this method and change the returned Material's
142                settings. All materials created from then on will be configured
143                with the new defaults you have specified.
144            @par
145                The default settings begin as a single Technique with a single, non-programmable Pass:
146                <ul>
147                <li>ambient = ColourValue::White</li>
148                <li>diffuse = ColourValue::White</li>
149                <li>specular = ColourValue::Black</li>
150                <li>emmissive = ColourValue::Black</li>
151                <li>shininess = 0</li>
152                <li>No texture unit settings (& hence no textures)</li>
153                <li>SourceBlendFactor = SBF_ONE</li>
154                <li>DestBlendFactor = SBF_ZERO (no blend, replace with new
155                  colour)</li>
156                <li>Depth buffer checking on</li>
157                <li>Depth buffer writing on</li>
158                <li>Depth buffer comparison function = CMPF_LESS_EQUAL</li>
159                <li>Colour buffer writing on for all channels</li>
160                <li>Culling mode = CULL_CLOCKWISE</li>
161                <li>Ambient lighting = ColourValue(0.5, 0.5, 0.5) (mid-grey)</li>
162                <li>Dynamic lighting enabled</li>
163                <li>Gourad shading mode</li>
164                <li>Bilinear texture filtering</li>
165                </ul>
166        */
167                virtual MaterialPtr getDefaultSettings(void) const { return mDefaultSettings; }
168
169                /** Internal method - returns index for a given material scheme name.
170                @see Technique::setSchemeName
171                */
172                virtual unsigned short _getSchemeIndex(const String& name);
173                /** Internal method - returns name for a given material scheme index.
174                @see Technique::setSchemeName
175                */
176                virtual const String& _getSchemeName(unsigned short index);
177                /** Internal method - returns the active scheme index.
178                @see Technique::setSchemeName
179                */
180                virtual unsigned short _getActiveSchemeIndex(void) const;
181
182                /** Returns the name of the active material scheme.
183                @see Technique::setSchemeName
184                */
185                virtual const String& getActiveScheme(void) const;
186               
187                /** Sets the name of the active material scheme.
188                @see Technique::setSchemeName
189                */
190                virtual void setActiveScheme(const String& schemeName);
191
192        /** Override standard Singleton retrieval.
193        @remarks
194        Why do we do this? Well, it's because the Singleton
195        implementation is in a .h file, which means it gets compiled
196        into anybody who includes it. This is needed for the
197        Singleton template to work, but we actually only want it
198        compiled into the implementation of the class based on the
199        Singleton, not all of them. If we don't change this, we get
200        link errors when trying to use the Singleton-based class from
201        an outside dll.
202        @par
203        This method just delegates to the template version anyway,
204        but the implementation stays in this single compilation unit,
205        preventing link errors.
206        */
207        static MaterialManager& getSingleton(void);
208        /** Override standard Singleton retrieval.
209        @remarks
210        Why do we do this? Well, it's because the Singleton
211        implementation is in a .h file, which means it gets compiled
212        into anybody who includes it. This is needed for the
213        Singleton template to work, but we actually only want it
214        compiled into the implementation of the class based on the
215        Singleton, not all of them. If we don't change this, we get
216        link errors when trying to use the Singleton-based class from
217        an outside dll.
218        @par
219        This method just delegates to the template version anyway,
220        but the implementation stays in this single compilation unit,
221        preventing link errors.
222        */
223        static MaterialManager* getSingletonPtr(void);
224
225    };
226
227}
228
229#endif
Note: See TracBrowser for help on using the repository browser.