00001 #ifndef __D3D8TEXTURE_H__ 00002 #define __D3D8TEXTURE_H__ 00003 00004 #include "OgreD3D8Prerequisites.h" 00005 #include "OgreTexture.h" 00006 #include "OgreRenderTarget.h" 00007 #include "OgreRenderTexture.h" 00008 #include "OgreRenderTargetListener.h" 00009 00010 #include "OgreNoMemoryMacros.h" 00011 #include <d3d8.h> 00012 #include <d3dx8.h> 00013 #include <dxerr8.h> 00014 #include "OgreMemoryMacros.h" 00015 00016 namespace Ogre { 00017 00018 class D3D8Texture : public Texture 00019 { 00020 protected: 00021 LPDIRECT3DDEVICE8 mpD3DDevice; 00022 LPDIRECT3DTEXTURE8 mpTexture; //< The actual texture surface 00023 LPDIRECT3DSURFACE8 mpRenderZBuffer; //< The z-buffer for the render surface. 00024 LPDIRECT3DTEXTURE8 mpTempTexture; //< This is just a temporary texture to create the real one from 00025 bool m_bIsRenderTarget; 00026 00027 protected: 00028 void createTexture(); 00029 void copyMemoryToTexture( unsigned char* pBuffer ); 00030 void getColourMasks( D3DFORMAT format, DWORD* pdwRed, DWORD* pdwGreen, DWORD* pdwBlue, DWORD* pdwAlpha, DWORD* pdwRGBBitCount ); 00031 00032 public: 00033 D3D8Texture( String name, LPDIRECT3DDEVICE8 pD3DDevice, TextureUsage usage ); 00034 D3D8Texture( 00035 String name, 00036 IDirect3DDevice8 * device, 00037 uint width, 00038 uint height, 00039 uint num_mips, 00040 PixelFormat format, 00041 TextureUsage usage ); 00042 virtual ~D3D8Texture(); 00043 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 IDirect3DTexture8 * getD3DTexture() { return mpTexture; } 00055 IDirect3DSurface8 * getDepthStencil() { return mpRenderZBuffer; } 00056 }; 00057 00058 class D3D8RenderTexture : public RenderTexture 00059 { 00060 public: 00061 D3D8RenderTexture( const String & name, uint width, uint height ) 00062 : RenderTexture( name, width, height ) 00063 { 00064 } 00065 00066 virtual void getCustomAttribute( String name, void* pData ) 00067 { 00068 if( name == "DDBACKBUFFER" ) 00069 { 00070 IDirect3DSurface8 ** pSurf = (IDirect3DSurface8 **)pData; 00071 00072 ((D3D8Texture*)mPrivateTex)->getD3DTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00073 (*pSurf)->Release(); 00074 return; 00075 } 00076 else if( name == "D3DZBUFFER" ) 00077 { 00078 IDirect3DSurface8 ** pSurf = (IDirect3DSurface8 **)pData; 00079 00080 *pSurf = ((D3D8Texture*)mPrivateTex)->getDepthStencil(); 00081 return; 00082 } 00083 else if( name == "DDFRONTBUFFER" ) 00084 { 00085 IDirect3DSurface8 ** pSurf = (IDirect3DSurface8 **)pData; 00086 00087 ((D3D8Texture*)mPrivateTex)->getD3DTexture()->GetSurfaceLevel( 0, &(*pSurf) ); 00088 (*pSurf)->Release(); 00089 return; 00090 } 00091 else if( name == "HWND" ) 00092 { 00093 HWND *pHwnd = (HWND*)pData; 00094 00095 *pHwnd = NULL; 00096 return; 00097 } 00098 else if( name == "isTexture" ) 00099 { 00100 bool *b = reinterpret_cast< bool * >( pData ); 00101 *b = true; 00102 00103 return; 00104 } 00105 } 00106 00107 bool requiresTextureFlipping() const { return true; } 00108 virtual void writeContentsToFile( const String & filename ) {} 00109 virtual void outputText(int x, int y, const String& text) {} 00110 }; 00111 } 00112 00113 #endif
Copyright © 2002 by The OGRE Team