Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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