00001 #ifndef __D3D8TEXTURE_H__ 00002 #define __D3D8TEXTURE_H__ 00003 00004 #include "OgreD3D9Prerequisites.h" 00005 #include "OgreTexture.h" 00006 #include "OgreRenderTarget.h" 00007 #include "OgreRenderTexture.h" 00008 #include "OgreRenderTargetListener.h" 00009 00010 #include "OgreNoMemoryMacros.h" 00011 #include <d3d9.h> 00012 #include <d3dx9.h> 00013 #include <dxerr9.h> 00014 #include "OgreMemoryMacros.h" 00015 00016 namespace Ogre { 00017 00018 class D3D9Texture : public Texture 00019 { 00020 protected: 00021 LPDIRECT3DDEVICE9 mpD3DDevice; 00022 LPDIRECT3DTEXTURE9 mpTexture; //< The actual texture surface 00023 LPDIRECT3DSURFACE9 mpRenderZBuffer; //< The z-buffer for the render surface. 00024 LPDIRECT3DTEXTURE9 mpTempTexture; //< This is just a temporary texture to create the real one from 00025 00026 protected: 00027 void createTexture(); 00028 void copyMemoryToTexture( unsigned char* pBuffer ); 00029 void getColourMasks( D3DFORMAT format, DWORD* pdwRed, DWORD* pdwGreen, DWORD* pdwBlue, DWORD* pdwAlpha, DWORD* pdwRGBBitCount ); 00030 00031 public: 00032 D3D9Texture( String name, LPDIRECT3DDEVICE9 pD3DDevice, TextureUsage usage ); 00033 D3D9Texture( 00034 String name, 00035 IDirect3DDevice9 *device, 00036 uint width, 00037 uint height, 00038 uint num_mips, 00039 PixelFormat format, 00040 TextureUsage usage ); 00041 virtual ~D3D9Texture(); 00042 00043 virtual void blitImage(const Image& src, const Image::Rect imgRect, const Image::Rect texRect ); 00044 virtual void blitToTexture( const Image &src, unsigned uStartX, unsigned uStartY ); 00045 virtual void copyToTexture( Texture * target ); 00046 00047 virtual void load(); 00048 virtual void loadImage( const Image &img ); 00049 virtual void unload(); 00050 00051 virtual void getCustomAttribute( String name, void* pData ); 00052 virtual void outputText( int x, int y, const String& text ) {} 00053 00054 IDirect3DTexture9 * getD3DTexture() { return mpTexture; } 00055 IDirect3DSurface9 * getDepthStencil() { return mpRenderZBuffer; } 00056 }; 00057 00058 class D3D9RenderTexture : public RenderTexture 00059 { 00060 public: 00061 D3D9RenderTexture( const String & name, uint width, uint height ) 00062 : RenderTexture( name, width, height ) 00063 { 00064 } 00065 00066 virtual ~D3D9RenderTexture() 00067 { 00068 mPrivateTex->unload(); 00069 delete mPrivateTex; 00070 } 00071 00072 virtual void getCustomAttribute( String name, void* pData ) 00073 { 00074 if( name == "DDBACKBUFFER" ) 00075 { 00076 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00077 ((D3D9Texture*)mPrivateTex)->getD3DTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00078 (*pSurf)->Release(); 00079 return; 00080 } 00081 else if( name == "D3DZBUFFER" ) 00082 { 00083 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00084 *pSurf = ((D3D9Texture*)mPrivateTex)->getDepthStencil(); 00085 return; 00086 } 00087 else if( name == "DDFRONTBUFFER" ) 00088 { 00089 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData; 00090 ((D3D9Texture*)mPrivateTex)->getD3DTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00091 (*pSurf)->Release(); 00092 return; 00093 } 00094 else if( name == "HWND" ) 00095 { 00096 HWND *pHwnd = (HWND*)pData; 00097 *pHwnd = NULL; 00098 return; 00099 } 00100 else if( name == "isTexture" ) 00101 { 00102 bool *b = reinterpret_cast< bool * >( pData ); 00103 *b = true; 00104 return; 00105 } 00106 } 00107 00108 bool requiresTextureFlipping() const { return true; } 00109 virtual void writeContentsToFile( const String & filename ) {} 00110 virtual void outputText(int x, int y, const String& text) {} 00111 }; 00112 } 00113 00114 #endif
Copyright © 2002 by The OGRE Team