00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2005 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef __D3D8TEXTURE_H__ 00026 #define __D3D8TEXTURE_H__ 00027 00028 #include "OgreD3D9Prerequisites.h" 00029 #include "OgreTexture.h" 00030 #include "OgreRenderTexture.h" 00031 #include "OgreImage.h" 00032 #include "OgreException.h" 00033 #include "OgreD3D9HardwarePixelBuffer.h" 00034 00035 #include "OgreNoMemoryMacros.h" 00036 #include <d3d9.h> 00037 #include <d3dx9.h> 00038 #include <dxerr9.h> 00039 #include "OgreMemoryMacros.h" 00040 00041 namespace Ogre { 00042 class D3D9Texture : public Texture 00043 { 00044 protected: 00046 IDirect3DDevice9 *mpDev; 00048 IDirect3D9 *mpD3D; 00050 IDirect3DTexture9 *mpNormTex; 00052 IDirect3DCubeTexture9 *mpCubeTex; 00054 IDirect3DVolumeTexture9 *mpVolumeTex; 00056 IDirect3DBaseTexture9 *mpTex; 00057 00059 String mCubeFaceNames[6]; 00061 D3DDEVICE_CREATION_PARAMETERS mDevCreParams; 00063 D3DFORMAT mBBPixelFormat; 00065 D3DPOOL mD3DPool; 00067 D3DCAPS9 mDevCaps; 00068 // Dynamic textures? 00069 bool mDynamicTextures; 00071 typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList; 00072 SurfaceList mSurfaceList; 00073 00075 void _initDevice(void); 00077 void _loadCubeTex(); 00079 void _loadNormTex(); 00081 void _loadVolumeTex(); 00082 00084 void _createNormTex(); 00086 void _createCubeTex(); 00088 void _createVolumeTex(); 00089 00091 D3DFORMAT _chooseD3DFormat(); 00092 00094 void createInternalResourcesImpl(void); 00096 void freeInternalResourcesImpl(void); 00098 void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00100 void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00102 D3DTEXTUREFILTERTYPE _getBestFilterMethod(); 00104 bool _canUseDynamicTextures(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat); 00106 bool _canAutoGenMipmaps(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat); 00107 00109 String _getCubeFaceName(unsigned char face) const 00110 { assert(face < 6); return mCubeFaceNames[face]; } 00111 00114 void _createSurfaceList(void); 00115 00117 void loadImpl(); 00118 public: 00120 D3D9Texture(ResourceManager* creator, const String& name, ResourceHandle handle, 00121 const String& group, bool isManual, ManualResourceLoader* loader, 00122 IDirect3DDevice9 *pD3DDevice); 00124 ~D3D9Texture(); 00125 00127 void copyToTexture( TexturePtr& target ); 00129 void loadImage( const Image &img ); 00130 00131 00133 HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap); 00134 00136 IDirect3DBaseTexture9 *getTexture() 00137 { assert(mpTex); return mpTex; } 00139 IDirect3DTexture9 *getNormTexture() 00140 { assert(mpNormTex); return mpNormTex; } 00142 IDirect3DCubeTexture9 *getCubeTexture() 00143 { assert(mpCubeTex); return mpCubeTex; } 00144 00145 00146 00148 bool releaseIfDefaultPool(void); 00150 bool recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev); 00151 00152 }; 00153 00160 class D3D9TexturePtr : public SharedPtr<D3D9Texture> 00161 { 00162 public: 00163 D3D9TexturePtr() : SharedPtr<D3D9Texture>() {} 00164 explicit D3D9TexturePtr(D3D9Texture* rep) : SharedPtr<D3D9Texture>(rep) {} 00165 D3D9TexturePtr(const D3D9TexturePtr& r) : SharedPtr<D3D9Texture>(r) {} 00166 D3D9TexturePtr(const ResourcePtr& r) : SharedPtr<D3D9Texture>() 00167 { 00168 // lock & copy other mutex pointer 00169 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00170 { 00171 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00172 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00173 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00174 pUseCount = r.useCountPointer(); 00175 if (pUseCount) 00176 { 00177 ++(*pUseCount); 00178 } 00179 } 00180 } 00181 00183 D3D9TexturePtr& operator=(const ResourcePtr& r) 00184 { 00185 if (pRep == static_cast<D3D9Texture*>(r.getPointer())) 00186 return *this; 00187 release(); 00188 // lock & copy other mutex pointer 00189 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00190 { 00191 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00192 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00193 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00194 pUseCount = r.useCountPointer(); 00195 if (pUseCount) 00196 { 00197 ++(*pUseCount); 00198 } 00199 } 00200 return *this; 00201 } 00203 D3D9TexturePtr& operator=(const TexturePtr& r) 00204 { 00205 if (pRep == static_cast<D3D9Texture*>(r.getPointer())) 00206 return *this; 00207 release(); 00208 // lock & copy other mutex pointer 00209 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00210 { 00211 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00212 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00213 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00214 pUseCount = r.useCountPointer(); 00215 if (pUseCount) 00216 { 00217 ++(*pUseCount); 00218 } 00219 } 00220 return *this; 00221 } 00222 }; 00223 00225 class D3D9RenderTexture : public RenderTexture 00226 { 00227 public: 00228 D3D9RenderTexture(const String &name, D3D9HardwarePixelBuffer *buffer): 00229 RenderTexture(buffer, 0) 00230 { 00231 mName = name; 00232 } 00233 ~D3D9RenderTexture() {} 00234 00235 void rebind(D3D9HardwarePixelBuffer *buffer) 00236 { 00237 mBuffer = buffer; 00238 mWidth = mBuffer->getWidth(); 00239 mHeight = mBuffer->getHeight(); 00240 mColourDepth = Ogre::PixelUtil::getNumElemBits(mBuffer->getFormat()); 00241 } 00242 00243 virtual void update(void); 00244 00245 virtual void getCustomAttribute( const String& name, void *pData ) 00246 { 00247 if(name == "DDBACKBUFFER") 00248 { 00249 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00250 *pSurf = static_cast<D3D9HardwarePixelBuffer*>(mBuffer)->getSurface(); 00251 return; 00252 } 00253 else if(name == "HWND") 00254 { 00255 HWND *pHwnd = (HWND*)pData; 00256 *pHwnd = NULL; 00257 return; 00258 } 00259 else if(name == "BUFFER") 00260 { 00261 *static_cast<HardwarePixelBuffer**>(pData) = mBuffer; 00262 return; 00263 } 00264 } 00265 00266 bool requiresTextureFlipping() const { return false; } 00267 }; 00268 00269 } 00270 00271 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 17 15:39:08 2006