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 _D3DTexture_H__ 00026 #define _D3DTexture_H__ 00027 00028 #include "OgreD3D7Prerequisites.h" 00029 #include "OgreTexture.h" 00030 #include "OgreRenderTarget.h" 00031 #include "OgreRenderTexture.h" 00032 #include "OgreRenderTargetListener.h" 00033 00034 namespace Ogre { 00035 00038 class D3DTexture : public Texture 00039 { 00040 public: 00041 // Constructor, called from D3DTextureManager 00042 D3DTexture( const String& name, TextureType texType, IDirect3DDevice7 * lpDirect3dDevice, TextureUsage usage ); 00044 D3DTexture( 00045 const String& name, 00046 TextureType texType, 00047 IDirect3DDevice7 * lpDirect3dDevice, 00048 uint width, 00049 uint height, 00050 uint num_mips, 00051 PixelFormat format, 00052 TextureUsage usage ); 00053 virtual ~D3DTexture(); 00054 00055 virtual void load(void); 00056 virtual void loadImage( const Image &img ); 00057 virtual void loadImage3D( const Image imgs[]); 00058 virtual void blitToTexture( const Image &src, unsigned uStartX, unsigned uStartY ); 00059 virtual void blitImage( const Image& src, 00060 const Image::Rect imgRect, const Image::Rect texRect ); 00061 virtual void blitImage3D(const Image src[], 00062 const Image::Rect imgRect, const Image::Rect texRect ); 00063 virtual void unload(void); 00064 virtual void copyToTexture( Texture * target ); 00065 00067 LPDIRECTDRAWSURFACE7 getDDSurface(void); 00068 00069 protected: 00070 IDirect3DDevice7 * mD3DDevice; 00071 IDirectDrawSurface7 * mSurface; 00072 00073 String mCubeFaceNames[6]; 00074 00075 00076 void createSurface(void); 00077 void createSurface2D(void); 00078 void createSurface3D(void); 00079 00081 void _chooseD3DFormat(DDPIXELFORMAT &ddpf); 00082 00084 void _constructCubeFaceNames(const String name); 00085 00087 String _getCubeFaceName(unsigned char face) const 00088 { assert(face < 6); return mCubeFaceNames[face]; } 00090 static unsigned short _getPFBpp(PixelFormat ogrePF) 00091 { return Image::getNumElemBits(ogrePF); } 00092 }; 00093 00094 class D3D7RenderTexture : public RenderTexture 00095 { 00096 public: 00097 D3D7RenderTexture( const String & name, uint width, uint height ) 00098 : RenderTexture( name, width, height ) 00099 { 00100 mPrivateTex = TextureManager::getSingleton().createManual( mName + 00101 "_PRIVATE##", TEX_TYPE_2D, mWidth, mHeight, 0, PF_R8G8B8, TU_RENDERTARGET ); 00102 } 00103 00104 virtual ~D3D7RenderTexture() 00105 { 00106 mPrivateTex->unload(); 00107 delete mPrivateTex; 00108 } 00109 00110 bool requiresTextureFlipping() const { return false; } 00111 00112 virtual void getCustomAttribute( const String& name, void* pData ) 00113 { 00114 if( name == "DDBACKBUFFER" ) 00115 { 00116 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData; 00117 00118 *pSurf = ((D3DTexture*)mPrivateTex)->getDDSurface(); 00119 return; 00120 } 00121 else if( name == "DDFRONTBUFFER" ) 00122 { 00123 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData; 00124 00125 *pSurf = ((D3DTexture*)mPrivateTex)->getDDSurface(); 00126 return; 00127 } 00128 else if( name == "HWND" ) 00129 { 00130 HWND *pHwnd = (HWND*)pData; 00131 00132 *pHwnd = NULL; 00133 return; 00134 } 00135 else if( name == "isTexture" ) 00136 { 00137 bool *b = reinterpret_cast< bool * >( pData ); 00138 *b = true; 00139 00140 return; 00141 } 00142 } 00143 virtual void writeContentsToFile( const String & filename ) {} 00144 virtual void outputText(int x, int y, const String& text) {} 00145 00146 protected: 00148 Texture * mPrivateTex; 00149 00150 protected: 00151 virtual void _copyToTexture() 00152 { 00153 // Copy the newly-rendered data to the public texture surface. 00154 mPrivateTex->copyToTexture( mTexture ); 00155 } 00156 }; 00157 } 00158 00159 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:01 2004