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

Revision 657, 6.7 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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    //-----------------------------------------------------------------------
52    MaterialManager::MaterialManager()
53    {
54            mDefaultMinFilter = FO_LINEAR;
55            mDefaultMagFilter = FO_LINEAR;
56            mDefaultMipFilter = FO_POINT;
57                mDefaultMaxAniso = 1;
58
59        // Loading order
60        mLoadOrder = 100.0f;
61                // Scripting is supported by this manager
62                mScriptPatterns.push_back("*.program");
63                mScriptPatterns.push_back("*.material");
64                ResourceGroupManager::getSingleton()._registerScriptLoader(this);
65
66                // Resource type
67                mResourceType = "Material";
68
69                // Register with resource group manager
70                ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
71
72    }
73    //-----------------------------------------------------------------------
74    MaterialManager::~MaterialManager()
75    {
76        mDefaultSettings.setNull();
77            // Resources cleared by superclass
78                // Unregister with resource group manager
79                ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
80                ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
81    }
82        //-----------------------------------------------------------------------
83        Resource* MaterialManager::createImpl(const String& name, ResourceHandle handle,
84                const String& group, bool isManual, ManualResourceLoader* loader,
85        const NameValuePairList* params)
86        {
87                return new Material(this, name, handle, group, isManual, loader);
88        }
89    //-----------------------------------------------------------------------
90        void MaterialManager::initialise(void)
91        {
92                // Set up default material - don't use name contructor as we want to avoid applying defaults
93                mDefaultSettings = create("DefaultSettings", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
94        // Add a single technique and pass, non-programmable
95        mDefaultSettings->createTechnique()->createPass();
96
97            // Set up a lit base white material
98            create("BaseWhite", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
99            // Set up an unlit base white material
100        MaterialPtr baseWhiteNoLighting = create("BaseWhiteNoLighting",
101                        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
102        baseWhiteNoLighting->setLightingEnabled(false);
103
104        }
105    //-----------------------------------------------------------------------
106    void MaterialManager::parseScript(DataStreamPtr& stream, const String& groupName)
107    {
108        // Delegate to serializer
109        mSerializer.parseScript(stream, groupName);
110    }
111    //-----------------------------------------------------------------------
112        void MaterialManager::setDefaultTextureFiltering(TextureFilterOptions fo)
113        {
114        switch (fo)
115        {
116        case TFO_NONE:
117            setDefaultTextureFiltering(FO_POINT, FO_POINT, FO_NONE);
118            break;
119        case TFO_BILINEAR:
120            setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT);
121            break;
122        case TFO_TRILINEAR:
123            setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);
124            break;
125        case TFO_ANISOTROPIC:
126            setDefaultTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
127            break;
128        }
129        }
130    //-----------------------------------------------------------------------
131        void MaterialManager::setDefaultAnisotropy(unsigned int maxAniso)
132        {
133                mDefaultMaxAniso = maxAniso;
134        }
135    //-----------------------------------------------------------------------
136        unsigned int MaterialManager::getDefaultAnisotropy() const
137        {
138                return mDefaultMaxAniso;
139        }
140    //-----------------------------------------------------------------------
141    void MaterialManager::setDefaultTextureFiltering(FilterType ftype, FilterOptions opts)
142    {
143        switch (ftype)
144        {
145        case FT_MIN:
146            mDefaultMinFilter = opts;
147            break;
148        case FT_MAG:
149            mDefaultMagFilter = opts;
150            break;
151        case FT_MIP:
152            mDefaultMipFilter = opts;
153            break;
154        }
155    }
156    //-----------------------------------------------------------------------
157    void MaterialManager::setDefaultTextureFiltering(FilterOptions minFilter,
158        FilterOptions magFilter, FilterOptions mipFilter)
159    {
160        mDefaultMinFilter = minFilter;
161        mDefaultMagFilter = magFilter;
162        mDefaultMipFilter = mipFilter;
163    }
164    //-----------------------------------------------------------------------
165    FilterOptions MaterialManager::getDefaultTextureFiltering(FilterType ftype) const
166    {
167        switch (ftype)
168        {
169        case FT_MIN:
170            return mDefaultMinFilter;
171        case FT_MAG:
172            return mDefaultMagFilter;
173        case FT_MIP:
174            return mDefaultMipFilter;
175        }
176        // to keep compiler happy
177        return mDefaultMinFilter;
178    }
179}
Note: See TracBrowser for help on using the repository browser.