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 © 2000-2002 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 00034 #include "OgreNoMemoryMacros.h" 00035 #include <d3d9.h> 00036 #include <d3dx9.h> 00037 #include <dxerr9.h> 00038 #include "OgreMemoryMacros.h" 00039 00040 namespace Ogre { 00041 class D3D9Texture : public Texture 00042 { 00043 private: 00045 IDirect3DDevice9 *mpDev; 00047 IDirect3D9 *mpD3D; 00049 IDirect3DTexture9 *mpNormTex; 00051 IDirect3DCubeTexture9 *mpCubeTex; 00053 IDirect3DVolumeTexture9 *mpVolumeTex; 00055 IDirect3DTexture9 *mpTmpNormTex; 00057 IDirect3DCubeTexture9 *mpTmpCubeTex; 00059 IDirect3DSurface9 *mpZBuff; 00061 IDirect3DBaseTexture9 *mpTex; 00062 00064 String mCubeFaceNames[6]; 00066 D3DDEVICE_CREATION_PARAMETERS mDevCreParams; 00068 D3DFORMAT mBBPixelFormat; 00070 D3DCAPS9 mDevCaps; 00071 00073 void _loadCubeTex(); 00075 void _loadNormTex(); 00077 void _loadVolumeTex(); 00078 00080 void _createTex(); 00082 void _createNormTex(); 00084 void _createCubeTex(); 00085 00087 D3DFORMAT _chooseD3DFormat(); 00089 void _getColorMasks(D3DFORMAT format, DWORD *pdwRed, DWORD *pdwGreen, DWORD *pdwBlue, DWORD *pdwAlpha, DWORD *pdwRGBBitCount); 00091 void _copyMemoryToSurface( const unsigned char *pBuffer, IDirect3DSurface9 *pSurface ); 00093 void _blitImageToNormTex(const Image &srcImage); 00095 void _blitImagesToCubeTex(const Image srcImages[]); 00096 00098 static PixelFormat _getPF(D3DFORMAT d3dPF); 00100 static D3DFORMAT _getPF(PixelFormat ogrePF); 00101 00103 void _freeResources(); 00105 void _initMembers(); 00107 void _setDevice(IDirect3DDevice9 *pDev); 00109 void _constructCubeFaceNames(const String& name); 00111 void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00113 void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00115 D3DTEXTUREFILTERTYPE _getBestFilterMethod(); 00117 bool _canAutoGenMipMaps(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat); 00119 void _createDepthStencil(); 00120 00122 String _getCubeFaceName(unsigned char face) const 00123 { assert(face < 6); return mCubeFaceNames[face]; } 00125 static unsigned short _getPFBpp(PixelFormat ogrePF) 00126 { return Image::getNumElemBits(ogrePF); } 00127 00128 public: 00130 D3D9Texture( const String& name, TextureType texType, IDirect3DDevice9 *pD3DDevice, TextureUsage usage ); 00132 D3D9Texture( const String& name, TextureType texType, IDirect3DDevice9 *pD3DDevice, uint width, uint height, uint numMips, PixelFormat format, TextureUsage usage ); 00134 ~D3D9Texture(); 00135 00137 void blitImage(const Image& src, const Image::Rect imgRect, const Image::Rect texRect ); 00139 void blitToTexture( const Image &src, unsigned uStartX, unsigned uStartY ); 00141 void copyToTexture( Texture * target ); 00143 void loadImage( const Image &img ); 00144 00146 void load(); 00148 void unload(); 00149 00151 IDirect3DBaseTexture9 *getTexture() 00152 { assert(mpTex); return mpTex; } 00154 IDirect3DTexture9 *getNormTexture() 00155 { assert(mpNormTex); return mpNormTex; } 00157 IDirect3DCubeTexture9 *getCubeTexture() 00158 { assert(mpCubeTex); return mpCubeTex; } 00160 IDirect3DSurface9 *getDepthStencil() 00161 { assert(mpZBuff); return mpZBuff; } 00162 }; 00163 00164 class D3D9RenderTexture : public RenderTexture 00165 { 00166 public: 00167 D3D9RenderTexture( const String & name, uint width, uint height, TextureType texType = TEX_TYPE_2D ) : RenderTexture( name, width, height, texType ) 00168 { 00169 mPrivateTex = TextureManager::getSingleton().createManual( mName + "_PRIVATE##", texType, mWidth, mHeight, 0, PF_R8G8B8, TU_RENDERTARGET ); 00170 } 00171 00172 ~D3D9RenderTexture() 00173 { 00174 SAFE_DELETE(mPrivateTex); 00175 } 00176 00177 virtual void getCustomAttribute( const String& name, void *pData ) 00178 { 00179 if( name == "DDBACKBUFFER" ) 00180 { 00181 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00182 if (((D3D9Texture*)mPrivateTex)->getTextureType() == TEX_TYPE_2D) 00183 ((D3D9Texture*)mPrivateTex)->getNormTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00184 else if (((D3D9Texture*)mPrivateTex)->getTextureType() == TEX_TYPE_CUBE_MAP) 00185 ((D3D9Texture*)mPrivateTex)->getCubeTexture()->GetCubeMapSurface( (D3DCUBEMAP_FACES)0, 0, &(*pSurf) ); 00186 else 00187 { 00188 Except( Exception::UNIMPLEMENTED_FEATURE, 00189 "getCustomAttribute is implemented only for 2D and cube textures !!!", 00190 "D3D9RenderTexture::getCustomAttribute" ); 00191 } 00192 (*pSurf)->Release(); 00193 return; 00194 } 00195 else if( name == "D3DZBUFFER" ) 00196 { 00197 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00198 *pSurf = ((D3D9Texture*)mPrivateTex)->getDepthStencil(); 00199 return; 00200 } 00201 else if( name == "DDFRONTBUFFER" ) 00202 { 00203 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00204 if (((D3D9Texture*)mPrivateTex)->getTextureType() == TEX_TYPE_2D) 00205 ((D3D9Texture*)mPrivateTex)->getNormTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00206 else if (((D3D9Texture*)mPrivateTex)->getTextureType() == TEX_TYPE_CUBE_MAP) 00207 ((D3D9Texture*)mPrivateTex)->getCubeTexture()->GetCubeMapSurface( (D3DCUBEMAP_FACES)0, 0, &(*pSurf) ); 00208 else 00209 { 00210 Except( Exception::UNIMPLEMENTED_FEATURE, 00211 "getCustomAttribute is implemented only for 2D and cube textures !!!", 00212 "D3D9RenderTexture::getCustomAttribute" ); 00213 } 00214 (*pSurf)->Release(); 00215 return; 00216 } 00217 else if( name == "HWND" ) 00218 { 00219 HWND *pHwnd = (HWND*)pData; 00220 *pHwnd = NULL; 00221 return; 00222 } 00223 else if( name == "isTexture" ) 00224 { 00225 bool *b = reinterpret_cast< bool * >( pData ); 00226 *b = true; 00227 return; 00228 } 00229 } 00230 00231 bool requiresTextureFlipping() const { return false; } 00232 virtual void writeContentsToFile( const String & filename ) {} 00233 virtual void outputText(int x, int y, const String& text) {} 00234 00235 protected: 00237 Texture * mPrivateTex; 00238 00239 virtual void _copyToTexture() 00240 { 00241 // Copy the newly-rendered data to the public texture surface. 00242 mPrivateTex->copyToTexture( mTexture ); 00243 } 00244 }; 00245 } 00246 00247 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:06 2004