source: OGRE/trunk/ogrenew/RenderSystems/Direct3D9/src/OgreD3D9TextureManager.cpp @ 692

Revision 692, 4.2 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#include "OgreD3D9TextureManager.h"
26#include "OgreD3D9Texture.h"
27#include "OgreException.h"
28#include "OgreLogManager.h"
29#include "OgreStringConverter.h"
30#include "OgreD3D9Mappings.h"
31
32namespace Ogre
33{
34        D3D9TextureManager::D3D9TextureManager( LPDIRECT3DDEVICE9 pD3DDevice ) : TextureManager()
35        {
36                mpD3DDevice = pD3DDevice;
37                if( !mpD3DDevice )
38                        OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Invalid Direct3DDevice passed", "D3D9TextureManager::D3D9TextureManager" );
39        // register with group manager
40        ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
41        }
42
43        D3D9TextureManager::~D3D9TextureManager()
44        {
45        // unregister with group manager
46        ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
47
48        }
49
50    Resource* D3D9TextureManager::createImpl(const String& name,
51        ResourceHandle handle, const String& group, bool isManual,
52        ManualResourceLoader* loader, const NameValuePairList* createParams)
53    {
54        return new D3D9Texture(this, name, handle, group, isManual, loader, mpD3DDevice);
55    }
56
57        void D3D9TextureManager::releaseDefaultPoolResources(void)
58        {
59                size_t count = 0;
60
61                ResourceMap::iterator r, rend;
62                rend = mResources.end();
63                for (r = mResources.begin(); r != rend; ++r)
64                {
65                        D3D9TexturePtr t = r->second;
66                        if (t->releaseIfDefaultPool())
67                                count++;
68                }
69                LogManager::getSingleton().logMessage("D3D9TextureManager released:");
70                LogManager::getSingleton().logMessage(
71                        StringConverter::toString(count) + " unmanaged textures");
72        }
73
74        void D3D9TextureManager::recreateDefaultPoolResources(void)
75        {
76                size_t count = 0;
77
78                ResourceMap::iterator r, rend;
79                rend = mResources.end();
80                for (r = mResources.begin(); r != rend; ++r)
81                {
82                        D3D9TexturePtr t = r->second;
83                        if(t->recreateIfDefaultPool(mpD3DDevice))
84                                count++;
85                }
86                LogManager::getSingleton().logMessage("D3D9TextureManager recreated:");
87                LogManager::getSingleton().logMessage(
88                        StringConverter::toString(count) + " unmanaged textures");
89        }
90
91
92        PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
93        {
94                // Basic filtering
95                D3DFORMAT d3dPF = D3D9Mappings::_getPF(D3D9Mappings::_getClosestSupportedPF(format));
96
97                // Calculate usage
98                DWORD d3dusage = 0;
99                D3DPOOL pool = D3DPOOL_MANAGED;
100                if (usage & TU_RENDERTARGET)
101                {
102                        d3dusage |= D3DUSAGE_RENDERTARGET;
103                        pool = D3DPOOL_DEFAULT;
104                }
105                if (usage & TU_DYNAMIC)
106                {
107                        d3dusage |= D3DUSAGE_DYNAMIC;
108                        pool = D3DPOOL_DEFAULT;
109                }
110
111                // Use D3DX to adjust pixel format
112                switch(ttype)
113                {
114                case TEX_TYPE_1D:
115                case TEX_TYPE_2D:
116                        D3DXCheckTextureRequirements(mpD3DDevice, NULL, NULL, NULL, d3dusage, &d3dPF, pool);
117                        break;
118                case TEX_TYPE_3D:
119                        D3DXCheckVolumeTextureRequirements(mpD3DDevice, NULL, NULL, NULL, NULL, d3dusage, &d3dPF, pool);
120                        break;
121                case TEX_TYPE_CUBE_MAP:
122                        D3DXCheckCubeTextureRequirements(mpD3DDevice, NULL, NULL, d3dusage, &d3dPF, pool);
123                        break;
124                };
125
126                return D3D9Mappings::_getPF(d3dPF);
127
128
129        }
130
131
132}
Note: See TracBrowser for help on using the repository browser.