OSDN Git Service

Merge branch 'feature/#36529_SlimDXからSharpDXへの移行' into develop
[dtxmania/dtxmania.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d11 / Resource11.cpp
diff --git a/SlimDXc_Jun2010(VC++2008)/source/direct3d11/Resource11.cpp b/SlimDXc_Jun2010(VC++2008)/source/direct3d11/Resource11.cpp
deleted file mode 100644 (file)
index 3e14a1b..0000000
+++ /dev/null
@@ -1,238 +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
-\r
-#include <d3d11.h>\r
-#include <d3dx11.h>\r
-\r
-#include "../DataStream.h"\r
-\r
-#include "Direct3D11Exception.h"\r
-\r
-#include "Device11.h"\r
-#include "Resource11.h"\r
-#include "Buffer11.h"\r
-#include "Texture1D11.h"\r
-#include "Texture2D11.h"\r
-#include "Texture3D11.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-using namespace System::Reflection;\r
-using namespace System::Globalization;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D11\r
-{\r
-       SlimDX::DXGI::Surface^ Resource::AsSurface()\r
-       {\r
-               IDXGISurface* unknown = 0;\r
-               GUID guid = Utilities::GetNativeGuidForType( SlimDX::DXGI::Surface::typeid );\r
-               HRESULT hr = InternalPointer->QueryInterface(guid, reinterpret_cast<void**>(&unknown));\r
-               if(RECORD_D3D11(hr).IsFailure)\r
-                       return nullptr;\r
-\r
-               SlimDX::DXGI::Surface^ result = gcnew SlimDX::DXGI::Surface(unknown, nullptr);\r
-\r
-               return result;\r
-       }\r
-\r
-       generic< class T > where T : Resource, ref class\r
-               T Resource::FromSwapChain( SlimDX::DXGI::SwapChain^ swapChain, int index )\r
-       {\r
-               IUnknown* unknown = 0;\r
-               GUID guid = Utilities::GetNativeGuidForType( T::typeid );\r
-               RECORD_D3D11( swapChain->InternalPointer->GetBuffer( index, guid, reinterpret_cast<void**>( &unknown ) ) );\r
-               if( Result::Last.IsFailure )\r
-                       return T();\r
-\r
-               BindingFlags flags = BindingFlags::Static | BindingFlags::InvokeMethod | BindingFlags::NonPublic;\r
-               array<System::Object^>^ args = gcnew array<System::Object^>( 1 );\r
-               args[ 0 ] = IntPtr( unknown );\r
-\r
-               // Trying to invoke "FromPointer" directly will choose the IntPtr overload since it's more\r
-               // cumbersome to pass a native pointer as an argument here. The IntPtr overload is intended\r
-               // to be the user-pointer overload, however, which isn't what we want; thus the thunk.\r
-               T result = safe_cast<T>( T::typeid->InvokeMember( "FromPointerReflectionThunk", flags, nullptr, nullptr, args, CultureInfo::InvariantCulture ) );\r
-               return result;\r
-       }\r
-\r
-       Resource^ Resource::FromPointer( ID3D11Resource* pointer )\r
-       {\r
-               if( pointer == NULL )\r
-                       return nullptr;\r
-\r
-               Resource^ tableEntry = safe_cast<Resource^>( SlimDX::ObjectTable::Find( static_cast<System::IntPtr>( pointer ) ) );\r
-               if( tableEntry != nullptr )\r
-               {\r
-                       pointer->Release();\r
-                       return tableEntry;\r
-               }\r
-\r
-               //not in the table, find out what this thing actually is\r
-               D3D11_RESOURCE_DIMENSION type;\r
-               pointer->GetType( &type );\r
-\r
-               // chain to the correct ctor (not the fastest way to do this, but good enough for now)\r
-               switch(type)\r
-               {\r
-               case D3D11_RESOURCE_DIMENSION_BUFFER:\r
-                       return Buffer::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE1D:\r
-                       return Texture1D::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE2D:\r
-                       return Texture2D::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE3D:\r
-                       return Texture3D::FromPointer( pointer );\r
-\r
-               default:\r
-                       throw gcnew InvalidCastException( "Unrecognized resource type." );\r
-               }\r
-       }\r
-\r
-       Resource^ Resource::FromPointer( System::IntPtr pointer )\r
-       {\r
-               if( pointer == System::IntPtr::Zero )\r
-                       throw gcnew System::ArgumentNullException( "pointer" );\r
-\r
-               Resource^ tableEntry = safe_cast<Resource^>( SlimDX::ObjectTable::Find( pointer ) );\r
-               if( tableEntry != nullptr )\r
-                       return tableEntry;\r
-\r
-               void* result = 0;\r
-               IUnknown* unknown = static_cast<IUnknown*>( pointer.ToPointer() );\r
-               HRESULT hr = unknown->QueryInterface(IID_ID3D11Resource, &result);\r
-               if( FAILED( hr ) )\r
-                       throw gcnew InvalidCastException( "Failed to QueryInterface on user-supplied pointer." );\r
-\r
-               // find out what this thing actually is\r
-               ID3D11Resource* resource = static_cast<ID3D11Resource*>( unknown );\r
-               D3D11_RESOURCE_DIMENSION type;\r
-               resource->GetType( &type );\r
-               resource->Release();\r
-\r
-               // chain to the correct ctor (not the fastest way to do this, but good enough for now)\r
-               switch(type)\r
-               {\r
-               case D3D11_RESOURCE_DIMENSION_BUFFER:\r
-                       return Buffer::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE1D:\r
-                       return Texture1D::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE2D:\r
-                       return Texture2D::FromPointer( pointer );\r
-               case D3D11_RESOURCE_DIMENSION_TEXTURE3D:\r
-                       return Texture3D::FromPointer( pointer );\r
-\r
-               default:\r
-                       throw gcnew InvalidCastException( "Unrecognized resource type." );\r
-               }\r
-       }\r
-\r
-       DXGI::ResourcePriority Resource::EvictionPriority::get()\r
-       {\r
-               return static_cast<DXGI::ResourcePriority>( InternalPointer->GetEvictionPriority() );\r
-       }\r
-       \r
-       void Resource::EvictionPriority::set( DXGI::ResourcePriority value )\r
-       {\r
-               InternalPointer->SetEvictionPriority( static_cast<UINT>( value ) );\r
-       }\r
-       \r
-       ResourceDimension Resource::Dimension::get()\r
-       {\r
-               D3D11_RESOURCE_DIMENSION type;\r
-               InternalPointer->GetType(&type);\r
-               return static_cast<ResourceDimension>( type );\r
-       }\r
-\r
-       int Resource::CalculateSubresourceIndex( int mipSlice, int arraySlice, int mipLevels )\r
-       {\r
-               return D3D11CalcSubresource( static_cast<UINT>( mipSlice ), static_cast<UINT>( arraySlice ), static_cast<UINT>( mipLevels ) );\r
-       }\r
-       \r
-       int Resource::GetMipSize( int mipSlice, int baseSliceSize )\r
-       {\r
-               float size = static_cast<float>( baseSliceSize );\r
-               \r
-               while( mipSlice > 0 )\r
-               {\r
-                       size = std::floorf(size / 2.0f);\r
-                       --mipSlice;\r
-               }\r
-               \r
-               return (static_cast< int >(size));\r
-       }\r
-\r
-       Result Resource::LoadTextureFromTexture(DeviceContext^ context, Resource^ source, Resource^ destination, TextureLoadInformation loadInformation)\r
-       {\r
-               HRESULT hr = D3DX11LoadTextureFromTexture(context->InternalPointer, source->InternalPointer, reinterpret_cast<D3DX11_TEXTURE_LOAD_INFO*>(&loadInformation), destination->InternalPointer);\r
-               return RECORD_D3D11(hr);\r
-       }\r
-\r
-       Result Resource::FilterTexture(DeviceContext^ context, Resource^ texture, int sourceLevel, FilterFlags mipFilter)\r
-       {\r
-               HRESULT hr = D3DX11FilterTexture(context->InternalPointer, texture->InternalPointer, sourceLevel, static_cast<UINT>(mipFilter));\r
-               return RECORD_D3D11(hr);\r
-       }\r
-       \r
-       ID3D11Resource* Resource::ConstructFromFile( SlimDX::Direct3D11::Device^ device, String^ fileName, D3DX11_IMAGE_LOAD_INFO* info )\r
-       {       \r
-               ID3D11Resource* resource = 0;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-               HRESULT hr = D3DX11CreateTextureFromFile( device->InternalPointer, pinnedName, info, 0, &resource, 0 );\r
-               RECORD_D3D11( hr );\r
-               \r
-               return resource;\r
-       }\r
-       \r
-       ID3D11Resource* Resource::ConstructFromMemory( SlimDX::Direct3D11::Device^ device, array<Byte>^ memory, D3DX11_IMAGE_LOAD_INFO* info )\r
-       {\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               \r
-               ID3D11Resource* resource = 0;\r
-               HRESULT hr = D3DX11CreateTextureFromMemory( device->InternalPointer, pinnedMemory, memory->Length, info, 0, &resource, 0 ); \r
-               RECORD_D3D11( hr );\r
-               \r
-               return resource;\r
-       }\r
-       \r
-       ID3D11Resource* Resource::ConstructFromStream( SlimDX::Direct3D11::Device^ device, Stream^ stream, int sizeInBytes, D3DX11_IMAGE_LOAD_INFO* info )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ memory = SlimDX::Utilities::ReadStream( stream, sizeInBytes, &ds );\r
-               \r
-               if( memory == nullptr )\r
-               {\r
-                       ID3D11Resource* resource = NULL;\r
-                       SIZE_T size = static_cast<SIZE_T>( ds->RemainingLength );\r
-                       HRESULT hr = D3DX11CreateTextureFromMemory( device->InternalPointer, ds->SeekToEnd(), size,\r
-                               info, NULL, &resource, NULL );\r
-                       RECORD_D3D11( hr );\r
-\r
-                       return resource;\r
-               }\r
-\r
-               return ConstructFromMemory( device, memory, info );\r
-       }\r
-}\r
-}\r