+++ /dev/null
-#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
-\r
-#include <d3d11.h>\r
-\r
-#include "../stack_array.h"\r
-#include "../DataBox.h"\r
-#include "../DataStream.h"\r
-\r
-#include "Direct3D11Exception.h"\r
-\r
-#include "Device11.h"\r
-#include "DeviceContext11.h"\r
-#include "Texture3D11.h"\r
-#include "Texture3DDescription11.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D11\r
-{ \r
- Texture3D::Texture3D( SlimDX::Direct3D11::Device^ device, Texture3DDescription description )\r
- {\r
- Construct( Build( device, description, 0 ) );\r
- }\r
-\r
- Texture3D::Texture3D( SlimDX::Direct3D11::Device^ device, Texture3DDescription description, DataBox^ data )\r
- {\r
- if( data != nullptr )\r
- {\r
- D3D11_SUBRESOURCE_DATA initialData;\r
- initialData.pSysMem = data->Data->PositionPointer;\r
- initialData.SysMemPitch = data->RowPitch;\r
- initialData.SysMemSlicePitch = data->SlicePitch;\r
- Construct( Build( device, description, &initialData ) ); \r
- }\r
- else \r
- {\r
- Construct( Build( device, description, 0 ) ); \r
- }\r
- }\r
- \r
- Texture3D::Texture3D( SlimDX::Direct3D11::Device^ device, Texture3DDescription description, array<DataBox^>^ data )\r
- {\r
- if( data != nullptr )\r
- {\r
- stack_array<D3D11_SUBRESOURCE_DATA> initialData = stackalloc( D3D11_SUBRESOURCE_DATA, data->Length );\r
- for( size_t dataIndex = 0; dataIndex < initialData.size(); ++dataIndex ) \r
- {\r
- initialData[dataIndex].pSysMem = data[static_cast<int>( dataIndex )]->Data->PositionPointer;\r
- initialData[dataIndex].SysMemPitch = data[static_cast<int>( dataIndex )]->RowPitch;\r
- initialData[dataIndex].SysMemSlicePitch = data[static_cast<int>( dataIndex )]->SlicePitch;\r
- }\r
- \r
- Construct( Build( device, description, &initialData[0] ) ); \r
- } \r
- else\r
- {\r
- Construct( Build( device, description, 0 ) ); \r
- }\r
- }\r
- \r
- ID3D11Texture3D* Texture3D::Build( SlimDX::Direct3D11::Device^ device, Texture3DDescription description, D3D11_SUBRESOURCE_DATA* data )\r
- {\r
- ID3D11Texture3D* texture = 0;\r
- D3D11_TEXTURE3D_DESC nativeDescription = description.CreateNativeVersion();\r
- \r
- if( RECORD_D3D11( device->InternalPointer->CreateTexture3D( &nativeDescription, data, &texture ) ).IsFailure )\r
- throw gcnew Direct3D11Exception( Result::Last );\r
- \r
- return texture;\r
- } \r
- \r
- Texture3DDescription Texture3D::Description::get()\r
- {\r
- D3D11_TEXTURE3D_DESC nativeDescription;\r
- InternalPointer->GetDesc( &nativeDescription );\r
- return Texture3DDescription( nativeDescription );\r
- }\r
- \r
- Texture3D^ Texture3D::FromFile( SlimDX::Direct3D11::Device^ device, String^ fileName )\r
- {\r
- ID3D11Resource* resource = Resource::ConstructFromFile( device, fileName, 0 );\r
- if( resource == 0 )\r
- return nullptr;\r
- \r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
- \r
- Texture3D^ Texture3D::FromMemory( SlimDX::Direct3D11::Device^ device, array<Byte>^ memory )\r
- {\r
- ID3D11Resource* resource = Resource::ConstructFromMemory( device, memory, 0 );\r
- if( resource == 0 )\r
- return nullptr;\r
- \r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
- \r
- Texture3D^ Texture3D::FromStream( SlimDX::Direct3D11::Device^ device, Stream^ stream, int sizeInBytes )\r
- {\r
- ID3D11Resource* resource = Resource::ConstructFromStream( device, stream, sizeInBytes, 0 );\r
- if( resource == 0 )\r
- return nullptr;\r
- \r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
- \r
- Texture3D^ Texture3D::FromFile( SlimDX::Direct3D11::Device^ device, String^ fileName, ImageLoadInformation loadInfo )\r
- {\r
- D3DX11_IMAGE_LOAD_INFO info = loadInfo.CreateNativeVersion();\r
- ID3D11Resource* resource = Resource::ConstructFromFile( device, fileName, &info );\r
- if( resource == 0 )\r
- return nullptr;\r
-\r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
-\r
- Texture3D^ Texture3D::FromMemory( SlimDX::Direct3D11::Device^ device, array<Byte>^ memory, ImageLoadInformation loadInfo )\r
- {\r
- D3DX11_IMAGE_LOAD_INFO info = loadInfo.CreateNativeVersion();\r
- ID3D11Resource* resource = Resource::ConstructFromMemory( device, memory, &info );\r
- if( resource == 0 )\r
- return nullptr;\r
-\r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
-\r
- Texture3D^ Texture3D::FromStream( SlimDX::Direct3D11::Device^ device, Stream^ stream, int sizeInBytes, ImageLoadInformation loadInfo )\r
- {\r
- D3DX11_IMAGE_LOAD_INFO info = loadInfo.CreateNativeVersion();\r
- ID3D11Resource* resource = Resource::ConstructFromStream( device, stream, sizeInBytes, &info );\r
- if( resource == 0 )\r
- return nullptr;\r
-\r
- D3D11_RESOURCE_DIMENSION type;\r
- resource->GetType( &type );\r
- if( type != D3D11_RESOURCE_DIMENSION_TEXTURE3D )\r
- throw gcnew InvalidOperationException( "Could not load file as 3D texture." );\r
-\r
- return Texture3D::FromPointer( static_cast<ID3D11Texture3D*>( resource ) );\r
- }\r
-\r
- Result Texture3D::ToFile( DeviceContext^ context, Texture3D^ texture, ImageFileFormat format, String^ fileName )\r
- {\r
- pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
- HRESULT hr = D3DX11SaveTextureToFile( context->InternalPointer, texture->InternalPointer, static_cast<D3DX11_IMAGE_FILE_FORMAT>( format ), pinnedName );\r
- return RECORD_D3D11( hr );\r
- }\r
-\r
- Result Texture3D::ToStream( DeviceContext^ context, Texture3D^ texture, ImageFileFormat format, Stream^ stream )\r
- {\r
- ID3D10Blob* blob = 0;\r
- HRESULT hr = D3DX11SaveTextureToMemory( context->InternalPointer, texture->InternalPointer, static_cast<D3DX11_IMAGE_FILE_FORMAT>( format ), &blob, 0 );\r
- if( RECORD_D3D11( hr ).IsFailure )\r
- return Result::Last;\r
- \r
- // Write byte-by-byte to avoid allocating a managed byte[] that will wastefully persist.\r
- unsigned char* bytes = reinterpret_cast<unsigned char*>( blob->GetBufferPointer() );\r
- for(SIZE_T byteIndex = 0; byteIndex < blob->GetBufferSize(); ++byteIndex)\r
- stream->WriteByte( bytes[byteIndex] );\r
- \r
- blob->Release();\r
- return Result::Last;\r
- }\r
-}\r
-}\r