Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/RenderSystems/Direct3D9/src/OgreD3D9TextureManager.cpp @ 48

Last change on this file since 48 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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