source: OGRE/trunk/ogrenew/OgreMain/src/OgreMaterialManager.cpp @ 692

Revision 692, 8.5 KB checked in by mattausch, 18 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#include "OgreStableHeaders.h"
26#include "OgreMaterialManager.h"
27
28#include "OgreMaterial.h"
29#include "OgreStringVector.h"
30#include "OgreLogManager.h"
31#include "OgreArchive.h"
32#include "OgreStringConverter.h"
33#include "OgreBlendMode.h"
34#include "OgreTechnique.h"
35#include "OgrePass.h"
36#include "OgreTextureUnitState.h"
37#include "OgreException.h"
38
39namespace Ogre {
40
41    //-----------------------------------------------------------------------
42    template<> MaterialManager* Singleton<MaterialManager>::ms_Singleton = 0;
43    MaterialManager* MaterialManager::getSingletonPtr(void)
44    {
45        return ms_Singleton;
46    }
47    MaterialManager& MaterialManager::getSingleton(void)
48    { 
49        assert( ms_Singleton );  return ( *ms_Singleton ); 
50    }
51        String MaterialManager::DEFAULT_SCHEME_NAME = "Default";
52    //-----------------------------------------------------------------------
53    MaterialManager::MaterialManager()
54    {
55            mDefaultMinFilter = FO_LINEAR;
56            mDefaultMagFilter = FO_LINEAR;
57            mDefaultMipFilter = FO_POINT;
58                mDefaultMaxAniso = 1;
59
60        // Loading order
61        mLoadOrder = 100.0f;
62                // Scripting is supported by this manager
63                mScriptPatterns.push_back("*.program");
64                mScriptPatterns.push_back("*.material");
65                ResourceGroupManager::getSingleton()._registerScriptLoader(this);
66
67                // Resource type
68                mResourceType = "Material";
69
70                // Register with resource group manager
71                ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
72
73                // Default scheme
74                mActiveSchemeIndex = 0;
75                mActiveSchemeName = DEFAULT_SCHEME_NAME;
76                mSchemes[mActiveSchemeName] = 0;
77
78    }
79    //-----------------------------------------------------------------------
80    MaterialManager::~MaterialManager()
81    {
82        mDefaultSettings.setNull();
83            // Resources cleared by superclass
84                // Unregister with resource group manager
85                ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
86                ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
87    }
88        //-----------------------------------------------------------------------
89        Resource* MaterialManager::createImpl(const String& name, ResourceHandle handle,
90                const String& group, bool isManual, ManualResourceLoader* loader,
91        const NameValuePairList* params)
92        {
93                return new Material(this, name, handle, group, isManual, loader);
94        }
95    //-----------------------------------------------------------------------
96        void MaterialManager::initialise(void)
97        {
98                // Set up default material - don't use name contructor as we want to avoid applying defaults
99                mDefaultSettings = create("DefaultSettings", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
100        // Add a single technique and pass, non-programmable
101        mDefaultSettings->createTechnique()->createPass();
102
103            // Set up a lit base white material
104            create("BaseWhite", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
105            // Set up an unlit base white material
106        MaterialPtr baseWhiteNoLighting = create("BaseWhiteNoLighting",
107                        ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
108        baseWhiteNoLighting->setLightingEnabled(false);
109
110        }
111    //-----------------------------------------------------------------------
112    void MaterialManager::parseScript(DataStreamPtr& stream, const String& groupName)
113    {
114        // Delegate to serializer
115        mSerializer.parseScript(stream, groupName);
116    }
117    //-----------------------------------------------------------------------
118        void MaterialManager::setDefaultTextureFiltering(TextureFilterOptions fo)
119        {
120        switch (fo)
121        {
122        case TFO_NONE:
123            setDefaultTextureFiltering(FO_POINT, FO_POINT, FO_NONE);
124            break;
125        case TFO_BILINEAR:
126            setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT);
127            break;
128        case TFO_TRILINEAR:
129            setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);
130            break;
131        case TFO_ANISOTROPIC:
132            setDefaultTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
133            break;
134        }
135        }
136    //-----------------------------------------------------------------------
137        void MaterialManager::setDefaultAnisotropy(unsigned int maxAniso)
138        {
139                mDefaultMaxAniso = maxAniso;
140        }
141    //-----------------------------------------------------------------------
142        unsigned int MaterialManager::getDefaultAnisotropy() const
143        {
144                return mDefaultMaxAniso;
145        }
146    //-----------------------------------------------------------------------
147    void MaterialManager::setDefaultTextureFiltering(FilterType ftype, FilterOptions opts)
148    {
149        switch (ftype)
150        {
151        case FT_MIN:
152            mDefaultMinFilter = opts;
153            break;
154        case FT_MAG:
155            mDefaultMagFilter = opts;
156            break;
157        case FT_MIP:
158            mDefaultMipFilter = opts;
159            break;
160        }
161    }
162    //-----------------------------------------------------------------------
163    void MaterialManager::setDefaultTextureFiltering(FilterOptions minFilter,
164        FilterOptions magFilter, FilterOptions mipFilter)
165    {
166        mDefaultMinFilter = minFilter;
167        mDefaultMagFilter = magFilter;
168        mDefaultMipFilter = mipFilter;
169    }
170    //-----------------------------------------------------------------------
171    FilterOptions MaterialManager::getDefaultTextureFiltering(FilterType ftype) const
172    {
173        switch (ftype)
174        {
175        case FT_MIN:
176            return mDefaultMinFilter;
177        case FT_MAG:
178            return mDefaultMagFilter;
179        case FT_MIP:
180            return mDefaultMipFilter;
181        }
182        // to keep compiler happy
183        return mDefaultMinFilter;
184    }
185    //-----------------------------------------------------------------------
186        unsigned short MaterialManager::_getSchemeIndex(const String& schemeName)
187        {
188                unsigned short ret = 0;
189                SchemeMap::iterator i = mSchemes.find(schemeName);
190                if (i != mSchemes.end())
191                {
192                        ret = i->second;
193                }
194                else
195                {
196                        // Create new
197                        ret = mSchemes.size();
198                        mSchemes[schemeName] = ret;                     
199                }
200                return ret;
201
202        }
203        //-----------------------------------------------------------------------
204        const String& MaterialManager::_getSchemeName(unsigned short index)
205        {
206                for (SchemeMap::iterator i = mSchemes.begin(); i != mSchemes.end(); ++i)
207                {
208                        if (i->second == index)
209                                return i->first;
210                }
211                return DEFAULT_SCHEME_NAME;
212        }
213    //-----------------------------------------------------------------------
214        unsigned short MaterialManager::_getActiveSchemeIndex(void) const
215        {
216                return mActiveSchemeIndex;
217        }
218    //-----------------------------------------------------------------------
219        const String& MaterialManager::getActiveScheme(void) const
220        {
221                return mActiveSchemeName;
222        }
223    //-----------------------------------------------------------------------
224        void MaterialManager::setActiveScheme(const String& schemeName)
225        {
226                SchemeMap::iterator i = mSchemes.find(schemeName);
227                if (i == mSchemes.end())
228                {
229                        // Invalid scheme, use default
230                        mActiveSchemeName = DEFAULT_SCHEME_NAME;
231                        mActiveSchemeIndex = 0;
232                }
233                else
234                {
235                        mActiveSchemeName = schemeName;
236                        mActiveSchemeIndex = i->second;         
237                }
238
239        }
240    //-----------------------------------------------------------------------
241
242}
Note: See TracBrowser for help on using the repository browser.