OSDN Git Service

Merge branch 'feature/#36529_SlimDXからSharpDXへの移行' into develop
[dtxmania/dtxmania.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / Texture.cpp
diff --git a/SlimDXc_Jun2010(VC++2008)/source/direct3d9/Texture.cpp b/SlimDXc_Jun2010(VC++2008)/source/direct3d9/Texture.cpp
deleted file mode 100644 (file)
index 3360810..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include <d3d9.h>\r
-#include <d3dx9.h>\r
-#include <vcclr.h>\r
-\r
-#include "../DataStream.h"\r
-#include "../ComObject.h"\r
-#include "../Utilities.h"\r
-\r
-#include "../math/Vector2.h"\r
-#include "../math/Color4.h"\r
-\r
-#include "Device.h"\r
-#include "D3DX.h"\r
-#include "Texture.h"\r
-\r
-#include "Direct3D9Exception.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-using namespace System::Runtime::InteropServices;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
-       Texture::Texture( SlimDX::Direct3D9::Device^ device, int width, int height, int numLevels, Usage usage, Format format, Pool pool )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               HRESULT hr = device->InternalPointer->CreateTexture( width, height, numLevels, static_cast<DWORD>( usage ), \r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &texture, NULL );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       throw gcnew Direct3D9Exception( Result::Last );\r
-\r
-               Construct(texture);\r
-               if( pool == Pool::Default )\r
-                       this->IsDefaultPool = true;\r
-       }\r
-\r
-       Texture::Texture( SlimDX::Direct3D9::Device^ device, int width, int height, int numLevels, Usage usage, Format format, Pool pool, IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               HANDLE sharedHandleNative = sharedHandle.ToPointer();\r
-               HRESULT hr = device->InternalPointer->CreateTexture( width, height, numLevels, static_cast<DWORD>( usage ), \r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &texture, &sharedHandleNative );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       throw gcnew Direct3D9Exception( Result::Last );\r
-\r
-               Construct(texture);\r
-               sharedHandle = IntPtr(sharedHandleNative);\r
-               if( pool == Pool::Default )\r
-                       this->IsDefaultPool = true;\r
-       }\r
-\r
-       TextureRequirements Texture::CheckRequirements(SlimDX::Direct3D9::Device^ device, int width, int height,\r
-               int numMipLevels, Usage usage, Format format, Pool pool)\r
-       {\r
-               TextureRequirements result;                                     // Result.\r
-               D3DFORMAT d3dFormat = static_cast<D3DFORMAT>( format ); // Format.\r
-               HRESULT hr;                                                                     // Error code.\r
-\r
-               // Get texture requirements.\r
-               hr = D3DXCheckTextureRequirements(device->InternalPointer, reinterpret_cast<UINT*>( &width ), \r
-                       reinterpret_cast<UINT*>( &height ), reinterpret_cast<UINT*>( &numMipLevels ), static_cast<DWORD>( usage ),\r
-                       &d3dFormat, static_cast<D3DPOOL>( pool ) );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return TextureRequirements();\r
-\r
-               // Return proposed values.\r
-               result.Width = width;\r
-               result.Height = height;\r
-               result.Format = static_cast<Format>( d3dFormat );\r
-               result.MipLevelCount = numMipLevels;\r
-\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromMemory_Internal( SlimDX::Direct3D9::Device^ device, const void* memory, UINT size, int width,\r
-               int height, int numLevels, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, \r
-               ImageInformation* imageInformation, PaletteEntry* palette )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( device->InternalPointer, memory, size, width,\r
-                       height, numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ),\r
-                       static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( imageInformation ), \r
-                       reinterpret_cast<PALETTEENTRY*>( palette ), &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-               {\r
-                       palette = nullptr;\r
-                       return nullptr;\r
-               }\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromMemory( SlimDX::Direct3D9::Device^ device, array<Byte>^ memory, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, \r
-               [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette )\r
-       {\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               palette = gcnew array<PaletteEntry>( 256 );\r
-               pin_ptr<PaletteEntry> pinnedPalette = &palette[0];\r
-               imageInformation = ImageInformation();\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-\r
-               return FromMemory_Internal( device, pinnedMemory, static_cast<UINT>( memory->Length ), width, height, numLevels,\r
-                       usage, format, pool, filter, mipFilter, colorKey, pinnedImageInfo, pinnedPalette );\r
-       }\r
-\r
-       Texture^ Texture::FromMemory( SlimDX::Direct3D9::Device^ device, array<Byte>^ memory, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, \r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               imageInformation = ImageInformation();\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( device->InternalPointer, pinnedMemory, memory->Length, width,\r
-                       height, numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ),\r
-                       static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ), \r
-                       NULL, &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromMemory( SlimDX::Direct3D9::Device^ device, array<Byte>^ memory, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( device->InternalPointer, pinnedMemory, memory->Length, width,\r
-                       height, numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ),\r
-                       static_cast<D3DCOLOR>( colorKey ), 0, 0, &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromMemory( SlimDX::Direct3D9::Device^ device, array<Byte>^ memory, Usage usage, Pool pool )\r
-       {\r
-               return Texture::FromMemory( device, memory, D3DX::Default, D3DX::Default, D3DX::Default,\r
-                       usage, Format::Unknown, pool, Filter::Default, Filter::Default, 0 );\r
-       }\r
-\r
-       Texture^ Texture::FromMemory( SlimDX::Direct3D9::Device^ device, array<Byte>^ memory )\r
-       {\r
-               return Texture::FromMemory( device, memory, Usage::None, Pool::Managed );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream, int sizeBytes, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey,\r
-               [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette )\r
-       {\r
-               DataStream^ ds;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, sizeBytes, &ds );\r
-               \r
-               if( data == nullptr )\r
-               {\r
-                       palette = gcnew array<PaletteEntry>( 256 );\r
-                       pin_ptr<PaletteEntry> pinnedPalette = &palette[0];\r
-                       imageInformation = ImageInformation();\r
-                       pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-\r
-                       Texture^ texture = FromMemory_Internal( device, ds->PositionPointer, sizeBytes, width, height, numLevels,\r
-                               usage, format, pool, filter, mipFilter, colorKey, pinnedImageInfo, pinnedPalette );\r
-\r
-                       ds->Seek( sizeBytes, SeekOrigin::Current );\r
-                       return texture;\r
-               }\r
-\r
-               return Texture::FromMemory( device, data, width, height, numLevels, usage, format, pool, filter, \r
-                       mipFilter, colorKey, imageInformation, palette );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream, int sizeBytes, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey,\r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               DataStream^ ds;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, sizeBytes, &ds );\r
-               \r
-               if( data == nullptr )\r
-               {\r
-                       imageInformation = ImageInformation();\r
-                       pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-\r
-                       Texture^ texture = FromMemory_Internal( device, ds->PositionPointer, sizeBytes, width, height, numLevels,\r
-                               usage, format, pool, filter, mipFilter, colorKey, pinnedImageInfo, NULL );\r
-\r
-                       ds->Seek( sizeBytes, SeekOrigin::Current );\r
-                       return texture;\r
-               }\r
-\r
-               return Texture::FromMemory( device, data, width, height, numLevels, usage, format, pool, filter, \r
-                       mipFilter, colorKey, imageInformation );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream, int sizeBytes, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey )\r
-       {\r
-               DataStream^ ds;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, sizeBytes, &ds );\r
-               \r
-               if( data == nullptr )\r
-               {\r
-                       Texture^ texture = FromMemory_Internal( device, ds->PositionPointer, sizeBytes, width, height, numLevels,\r
-                               usage, format, pool, filter, mipFilter, colorKey, NULL, NULL );\r
-\r
-                       ds->Seek( sizeBytes, SeekOrigin::Current );\r
-                       return texture;\r
-               }\r
-\r
-               return Texture::FromMemory( device, data, width, height, numLevels, usage, format, pool, filter, mipFilter, colorKey );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey )\r
-       {\r
-               return Texture::FromStream( device, stream, 0, width, height, numLevels, usage, format, pool, filter, mipFilter, colorKey );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream, Usage usage, Pool pool )\r
-       {\r
-               return Texture::FromStream( device, stream, D3DX::Default, D3DX::Default, D3DX::Default,\r
-                       usage, Format::Unknown, pool, Filter::Default, Filter::Default, 0 );\r
-       }\r
-\r
-       Texture^ Texture::FromStream( SlimDX::Direct3D9::Device^ device, Stream^ stream )\r
-       {\r
-               return Texture::FromStream( device, stream, Usage::None, Pool::Managed );\r
-       }\r
-\r
-       Texture^ Texture::FromFile( SlimDX::Direct3D9::Device^ device, String^ fileName, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey,\r
-               [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-               imageInformation = ImageInformation();\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-               palette = gcnew array<PaletteEntry>( 256 );\r
-               pin_ptr<PaletteEntry> pinnedPalette = &palette[0];\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileEx( device->InternalPointer, pinnedName, width, height, \r
-                       numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ), \r
-                       colorKey, reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ), reinterpret_cast<PALETTEENTRY*>( pinnedPalette ), &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-               {\r
-                       palette = nullptr;\r
-                       return nullptr;\r
-               }\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromFile( SlimDX::Direct3D9::Device^ device, String^ fileName, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey,\r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileEx( device->InternalPointer, pinnedName, width, height, \r
-                       numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ), \r
-                       colorKey, reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ), NULL, &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromFile( SlimDX::Direct3D9::Device^ device, String^ fileName, int width, int height, int numLevels,\r
-               Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey )\r
-       {\r
-               IDirect3DTexture9* texture = NULL;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
-               HRESULT hr = D3DXCreateTextureFromFileEx( device->InternalPointer, pinnedName, width, height, \r
-                       numLevels, static_cast<DWORD>( usage ), static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), static_cast<DWORD>( filter ), static_cast<DWORD>( mipFilter ), \r
-                       colorKey, NULL, NULL, &texture );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-\r
-               Texture^ result = gcnew Texture( texture, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Texture^ Texture::FromFile( SlimDX::Direct3D9::Device^ device, String^ fileName, Usage usage, Pool pool )\r
-       {\r
-               return Texture::FromFile( device, fileName, D3DX::Default, D3DX::Default, D3DX::Default,\r
-                       usage, Format::Unknown, pool, Filter::Default, Filter::Default, 0 );\r
-       }\r
-\r
-       Texture^ Texture::FromFile( SlimDX::Direct3D9::Device^ device, String^ fileName )\r
-       {\r
-               return Texture::FromFile( device, fileName, Usage::None, Pool::Managed );\r
-       }\r
-\r
-       Result Texture::ComputeNormalMap( Texture^ texture, Texture^ sourceTexture, array<PaletteEntry>^ palette, NormalMapFlags flags, Channel channel, float amplitude )\r
-       {\r
-               pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];\r
-\r
-               HRESULT hr = D3DXComputeNormalMap( texture->InternalPointer, sourceTexture->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ),\r
-                       static_cast<DWORD>( flags ), static_cast<DWORD>( channel ), amplitude );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Texture::ComputeNormalMap( Texture^ texture, Texture^ sourceTexture, NormalMapFlags flags, Channel channel, float amplitude )\r
-       {\r
-               return ComputeNormalMap( texture, sourceTexture, nullptr, flags, channel, amplitude );\r
-       }\r
-\r
-       void WINAPI NativeD3DXFill2D(D3DXVECTOR4 *out, CONST D3DXVECTOR2 *pTexCoord, CONST D3DXVECTOR2 *pTexelSize, LPVOID data)\r
-       {\r
-               Fill2DCallback^ callback = nullptr;\r
-               Vector2 coordinate = Vector2::Vector2(pTexCoord->x, pTexCoord->y);\r
-               Vector2 size = Vector2::Vector2(pTexelSize->x, pTexelSize->y);\r
-               Color4 result;\r
-\r
-               try\r
-               {\r
-                       callback = safe_cast<Fill2DCallback^>(Marshal::GetDelegateForFunctionPointer(IntPtr::IntPtr(data), Fill2DCallback::typeid));                    \r
-                       result = callback(coordinate, size);\r
-               }\r
-               catch( Exception^ )\r
-               {\r
-               }\r
-\r
-               out->x = result.Red;\r
-               out->y = result.Green;\r
-               out->z = result.Blue;\r
-               out->w = result.Alpha;\r
-       }\r
-\r
-       void WINAPI NativeD3DXFill3D(D3DXVECTOR4 *out, CONST D3DXVECTOR3 *pTexCoord, CONST D3DXVECTOR3 *pTexelSize, LPVOID data)\r
-       {\r
-               Fill3DCallback^ callback = nullptr;\r
-               Vector3 coordinate = Vector3(pTexCoord->x, pTexCoord->y, pTexCoord->z);\r
-               Vector3 size = Vector3(pTexelSize->x, pTexelSize->y, pTexelSize->z);\r
-               Color4 result;\r
-\r
-               try\r
-               {\r
-                       callback = safe_cast<Fill3DCallback^>(Marshal::GetDelegateForFunctionPointer(IntPtr::IntPtr(data), Fill3DCallback::typeid));                    \r
-                       result = callback(coordinate, size);\r
-               }\r
-               catch( Exception^ )\r
-               {\r
-               }\r
-\r
-               out->x = result.Red;\r
-               out->y = result.Green;\r
-               out->z = result.Blue;\r
-               out->w = result.Alpha;\r
-       }\r
-\r
-       Result Texture::Fill(Fill2DCallback^ callback)\r
-       {\r
-               HRESULT hr = D3DXFillTexture(InternalPointer, NativeD3DXFill2D, Marshal::GetFunctionPointerForDelegate(callback).ToPointer());\r
-\r
-               return RECORD_D3D9(hr);\r
-       }\r
-\r
-       Result Texture::Fill( TextureShader^ shader )\r
-       {\r
-               HRESULT hr = D3DXFillTextureTX( InternalPointer, shader->InternalPointer );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       DataRectangle^ Texture::LockRectangle( int level, System::Drawing::Rectangle rect, LockFlags flags )\r
-       {\r
-               D3DLOCKED_RECT lockedRect;\r
-               RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
-\r
-               HRESULT hr = InternalPointer->LockRect( level, &lockedRect, &nativeRect, static_cast<DWORD>( flags ) );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-               \r
-               int lockedSize = lockedRect.Pitch * GetLevelDescription( level ).Height;\r
-               \r
-               bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;\r
-               DataRectangle^ outRect = gcnew DataRectangle( lockedRect.Pitch, gcnew DataStream( lockedRect.pBits, lockedSize, true, !readOnly, false ) );\r
-               return outRect;\r
-       }\r
-\r
-       DataRectangle^ Texture::LockRectangle( int level, LockFlags flags )\r
-       {\r
-               D3DLOCKED_RECT lockedRect;\r
-\r
-               HRESULT hr = InternalPointer->LockRect( level, &lockedRect, NULL, static_cast<DWORD>( flags ) );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-               \r
-               int lockedSize = lockedRect.Pitch * GetLevelDescription( level ).Height;\r
-               \r
-               bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;\r
-               DataRectangle^ outRect = gcnew DataRectangle( lockedRect.Pitch, gcnew DataStream( lockedRect.pBits, lockedSize, true, !readOnly, false ) );\r
-               return outRect;\r
-       }\r
-\r
-       Result Texture::UnlockRectangle( int level )\r
-       {\r
-               HRESULT hr = InternalPointer->UnlockRect( level );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Texture::AddDirtyRectangle()\r
-       {\r
-               HRESULT hr = InternalPointer->AddDirtyRect( NULL );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Texture::AddDirtyRectangle( System::Drawing::Rectangle rect )\r
-       {\r
-               RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
-               HRESULT hr = InternalPointer->AddDirtyRect( &nativeRect );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       SurfaceDescription Texture::GetLevelDescription( int level )\r
-       {\r
-               SurfaceDescription description;\r
-               HRESULT hr = InternalPointer->GetLevelDesc( level, reinterpret_cast<D3DSURFACE_DESC*>( &description ) );\r
-               RECORD_D3D9( hr );\r
-               return description;\r
-       }\r
-\r
-       Surface^ Texture::GetSurfaceLevel( int level )\r
-       {\r
-               IDirect3DSurface9* surface;\r
-               HRESULT hr = InternalPointer->GetSurfaceLevel( level, &surface );\r
-               \r
-               if( RECORD_D3D9(hr).IsFailure )\r
-                       return nullptr;\r
-               return Surface::FromPointer( surface, this );\r
-       }\r
-}\r
-}
\ No newline at end of file