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

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

added ogre dependencies and patched ogre sources

RevLine 
[657]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 "OgreTextureManager.h"
27#include "OgreException.h"
28
29namespace Ogre {
30    //-----------------------------------------------------------------------
31    template<> TextureManager* Singleton<TextureManager>::ms_Singleton = 0;
32    TextureManager* TextureManager::getSingletonPtr(void)
33    {
34        return ms_Singleton;
35    }
36    TextureManager& TextureManager::getSingleton(void)
37    { 
38        assert( ms_Singleton );  return ( *ms_Singleton ); 
39    }
40    TextureManager::TextureManager(bool enable32Bit)
41         : mIs32Bit(enable32Bit), mDefaultNumMipmaps(MIP_UNLIMITED)
42    {
43        mResourceType = "Texture";
44        mLoadOrder = 75.0f;
45
46        // Subclasses should register (when this is fully constructed)
47    }
48    //-----------------------------------------------------------------------
49    TextureManager::~TextureManager()
50    {
51        // subclasses should unregister with resource group manager
52
53    }
54    //-----------------------------------------------------------------------
55    TexturePtr TextureManager::load(const String &name, const String& group,
56        TextureType texType, int numMipmaps, Real gamma)
57    {
58        TexturePtr tex = getByName(name);
59
60        if(tex.isNull())
61        {
62            tex = create(name, group);
63            tex->setTextureType(texType);
64            tex->setNumMipmaps((numMipmaps == -1)? mDefaultNumMipmaps :
65                                static_cast<size_t>(numMipmaps));
66            tex->setGamma(gamma);
67            tex->enable32Bit(mIs32Bit);
68        }
69        tex->load();
70
71        return tex;
72    }
73
74    //-----------------------------------------------------------------------
75    TexturePtr TextureManager::loadImage( const String &name, const String& group,
76        const Image &img, TextureType texType, int numMipmaps, Real gamma)
77    {
78        TexturePtr tex = create(name, group, true);
79
80        tex->setTextureType(texType);
81        tex->setNumMipmaps((numMipmaps == -1)? mDefaultNumMipmaps :
82                        static_cast<size_t>(numMipmaps));
83        tex->setGamma(gamma);
84        tex->enable32Bit(mIs32Bit);
85        tex->loadImage(img);
86
87        return tex;
88    }
89    //-----------------------------------------------------------------------
90    TexturePtr TextureManager::loadRawData(const String &name, const String& group,
91        DataStreamPtr& stream, ushort uWidth, ushort uHeight,
92        PixelFormat format, TextureType texType,
93        int numMipmaps, Real gamma)
94        {
95        TexturePtr tex = create(name, group, true);
96
97        tex->setTextureType(texType);
98        tex->setNumMipmaps((numMipmaps == -1)? mDefaultNumMipmaps :
99                        static_cast<size_t>(numMipmaps));
100        tex->setGamma(gamma);
101        tex->enable32Bit(mIs32Bit);
102                tex->loadRawData(stream, uWidth, uHeight, format);
103               
104        return tex;
105        }
106    //-----------------------------------------------------------------------
107    TexturePtr TextureManager::createManual(const String & name, const String& group,
108        TextureType texType, uint width, uint height, uint depth, int numMipmaps,
109        PixelFormat format, int usage, ManualResourceLoader* loader)
110    {
111        TexturePtr ret = create(name, group, true, loader);
112        ret->setTextureType(texType);
113        ret->setWidth(width);
114        ret->setHeight(height);
115                ret->setDepth(depth);
116        ret->setNumMipmaps((numMipmaps == -1)? mDefaultNumMipmaps :
117                        static_cast<size_t>(numMipmaps));
118        ret->setFormat(format);
119        ret->setUsage(usage);
120        ret->enable32Bit(mIs32Bit);
121                ret->createInternalResources();
122                return ret;
123    }
124    //-----------------------------------------------------------------------
125    void TextureManager::enable32BitTextures( bool setting )
126    {
127        mIs32Bit = setting;
128
129        // Iterate throught all textures
130        for( ResourceMap::iterator it = mResources.begin(); it != mResources.end(); ++it )
131        {
132            Texture* texture = static_cast<Texture*>(it->second.get());
133            // Reload loaded and reloadable texture only
134            if (texture->isLoaded() && texture->isReloadable())
135            {
136                texture->unload();
137                texture->enable32Bit(setting);
138                texture->load();
139            }
140            else
141            {
142                texture->enable32Bit(setting);
143            }
144        }
145    }
146    //-----------------------------------------------------------------------
147    void TextureManager::setDefaultNumMipmaps( size_t num )
148    {
149        mDefaultNumMipmaps = num;
150    }
151}
Note: See TracBrowser for help on using the repository browser.