diff -Naur Irrlicht/CD3D8Texture.cpp Irrlicht.new/CD3D8Texture.cpp --- Irrlicht/CD3D8Texture.cpp 2005-11-06 14:25:18.000000000 +0100 +++ Irrlicht.new/CD3D8Texture.cpp 2005-12-06 15:13:28.885269898 +0100 @@ -28,7 +28,7 @@ CD3D8Texture::CD3D8Texture(IDirect3DDevice8* device, core::dimension2d size) : Image(0), Device(device), TextureSize(size), Texture(0), Pitch(0), ImageSize(size), HasMipMaps(0), - IsRenderTarget(true) + IsRenderTarget(true), RTTSurface(0) { #ifdef _DEBUG setDebugName("CD3D8Texture"); @@ -45,7 +45,8 @@ CD3D8Texture::CD3D8Texture(IImage* image, IDirect3DDevice8* device, u32 flags) : Image(image), Device(device), TextureSize(0,0), -Texture(0), Pitch(0), ImageSize(0,0), HasMipMaps(false), IsRenderTarget(false) +Texture(0), Pitch(0), ImageSize(0,0), HasMipMaps(false), IsRenderTarget(false), +RTTSurface(0) { #ifdef _DEBUG setDebugName("CD3D8Texture"); @@ -368,6 +369,9 @@ if (Texture) Texture->Release(); + + if (RTTSurface) + RTTSurface->Release(); } @@ -378,8 +382,47 @@ if (!Texture) return 0; + HRESULT hr; D3DLOCKED_RECT rect; - HRESULT hr = Texture->LockRect(0, &rect, 0, 0); + if(!IsRenderTarget) + { + hr = Texture->LockRect(0, &rect, 0, 0); + } + else + { + D3DSURFACE_DESC desc; + Texture->GetLevelDesc(0, &desc); + if (!RTTSurface) + { + hr = Device->CreateImageSurface(desc.Width, desc.Height, desc.Format, &RTTSurface); + if (FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D8 Texture.", ELL_ERROR); + return 0; + } + } + + IDirect3DSurface8 *surface = NULL; + hr = Texture->GetSurfaceLevel(0, &surface); + if (FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D8 Texture.", ELL_ERROR); + return 0; + } + hr = Device->CopyRects(surface, NULL, 0, RTTSurface, NULL); + if(FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D8 Texture.", ELL_ERROR); + return 0; + } + hr = RTTSurface->LockRect(&rect, NULL, 0); + if(FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D8 Texture.", ELL_ERROR); + return 0; + } + return rect.pBits; + } if (FAILED(hr)) { os::Printer::log("Could not lock DIRECT3D8 Texture.", ELL_ERROR); @@ -397,7 +440,10 @@ if (!Texture) return; - Texture->UnlockRect(0); + if (!IsRenderTarget) + Texture->UnlockRect(0); + else if (RTTSurface) + RTTSurface->UnlockRect(); } diff -Naur Irrlicht/CD3D8Texture.h Irrlicht.new/CD3D8Texture.h --- Irrlicht/CD3D8Texture.h 2005-11-05 09:49:40.000000000 +0100 +++ Irrlicht.new/CD3D8Texture.h 2005-12-03 12:15:35.000000000 +0100 @@ -102,6 +102,7 @@ IImage* Image; IDirect3DDevice8* Device; IDirect3DTexture8* Texture; + IDirect3DSurface8* RTTSurface; core::dimension2d TextureSize; core::dimension2d ImageSize; s32 Pitch; diff -Naur Irrlicht/CD3D9Texture.cpp Irrlicht.new/CD3D9Texture.cpp --- Irrlicht/CD3D9Texture.cpp 2005-11-06 14:25:04.000000000 +0100 +++ Irrlicht.new/CD3D9Texture.cpp 2005-12-06 15:14:09.708506201 +0100 @@ -21,7 +21,7 @@ CD3D9Texture::CD3D9Texture(IDirect3DDevice9* device, core::dimension2d size) : Image(0), Device(device), TextureSize(size), Texture(0), Pitch(0), ImageSize(size), HasMipMaps(0), HardwareMipMaps(0), - IsRenderTarget(true) + IsRenderTarget(true), RTTSurface(0) { #ifdef _DEBUG setDebugName("CD3D9Texture"); @@ -39,7 +39,7 @@ u32 flags) : Image(image), Device(device), TextureSize(0,0), Texture(0), Pitch(0), ImageSize(0,0), HasMipMaps(false), HardwareMipMaps(false), -IsRenderTarget(false) +IsRenderTarget(false), RTTSurface(0) { #ifdef _DEBUG setDebugName("CD3D9Texture"); @@ -534,6 +534,9 @@ if (Texture) Texture->Release(); + + if (RTTSurface) + RTTSurface->Release(); } @@ -544,8 +547,47 @@ if (!Texture) return 0; + HRESULT hr; D3DLOCKED_RECT rect; - HRESULT hr = Texture->LockRect(0, &rect, 0, 0); + if(!IsRenderTarget) + { + hr = Texture->LockRect(0, &rect, 0, 0); + } + else + { + D3DSURFACE_DESC desc; + Texture->GetLevelDesc(0, &desc); + if (!RTTSurface) + { + hr = Device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &RTTSurface, NULL); + if (FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); + return 0; + } + } + + IDirect3DSurface9 *surface = NULL; + hr = Texture->GetSurfaceLevel(0, &surface); + if (FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); + return 0; + } + hr = Device->GetRenderTargetData(surface, RTTSurface); + if(FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); + return 0; + } + hr = RTTSurface->LockRect(&rect, NULL, 0); + if(FAILED(hr)) + { + os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); + return 0; + } + return rect.pBits; + } if (FAILED(hr)) { os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); @@ -563,7 +609,10 @@ if (!Texture) return; - Texture->UnlockRect(0); + if (!IsRenderTarget) + Texture->UnlockRect(0); + else if (RTTSurface) + RTTSurface->UnlockRect(); } diff -Naur Irrlicht/CD3D9Texture.h Irrlicht.new/CD3D9Texture.h --- Irrlicht/CD3D9Texture.h 2005-11-05 09:50:06.000000000 +0100 +++ Irrlicht.new/CD3D9Texture.h 2005-12-03 12:15:37.000000000 +0100 @@ -102,6 +102,7 @@ IImage* Image; IDirect3DDevice9* Device; IDirect3DTexture9* Texture; + IDirect3DSurface9* RTTSurface; core::dimension2d TextureSize; core::dimension2d ImageSize; s32 Pitch;