OSDN Git Service

Merge branch 'feature/#36529_SlimDXからSharpDXへの移行' into develop
[dtxmania/dtxmania.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / BaseEffect.cpp
diff --git a/SlimDXc_Jun2010(VC++2008)/source/direct3d9/BaseEffect.cpp b/SlimDXc_Jun2010(VC++2008)/source/direct3d9/BaseEffect.cpp
deleted file mode 100644 (file)
index 45a82b5..0000000
+++ /dev/null
@@ -1,484 +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
-\r
-#include "../math/Color4.h"\r
-#include "../math/Matrix.h"\r
-#include "../math/Vector2.h"\r
-#include "../math/Vector3.h"\r
-#include "../math/Vector4.h"\r
-\r
-#include "Direct3D9Exception.h"\r
-\r
-#include "Device.h"\r
-#include "Texture.h"\r
-#include "BaseEffect.h"\r
-#include "PixelShader9.h"\r
-#include "VertexShader9.h"\r
-\r
-using namespace System;\r
-using namespace System::Reflection;\r
-using namespace System::Globalization;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
-       EffectHandle^ BaseEffect::GetAnnotation( EffectHandle^ handle, int index )\r
-       {\r
-               D3DXHANDLE parentHandle = handle != nullptr ? handle->InternalHandle : NULL;\r
-               D3DXHANDLE annotation = InternalPointer->GetAnnotation( parentHandle, index );\r
-               GC::KeepAlive(handle);\r
-\r
-               if( annotation == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( annotation );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetAnnotation( EffectHandle^ handle, String^ name )\r
-       {\r
-               array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name );\r
-               pin_ptr<unsigned char> pinnedName = &nameBytes[0];\r
-\r
-               D3DXHANDLE parentHandle = handle != nullptr ? handle->InternalHandle : NULL;\r
-               D3DXHANDLE annotation = InternalPointer->GetAnnotationByName( parentHandle, reinterpret_cast<LPCSTR>( pinnedName ) );\r
-               GC::KeepAlive(handle);\r
-\r
-               if( annotation == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( annotation );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetParameter( EffectHandle^ parameter, int index )\r
-       {\r
-               D3DXHANDLE parentHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               D3DXHANDLE handle = InternalPointer->GetParameter( parentHandle, index );\r
-               GC::KeepAlive( parameter );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetParameter( EffectHandle^ parameter, String^ name )\r
-       {\r
-               array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name );\r
-               pin_ptr<unsigned char> pinnedName = &nameBytes[0];\r
-\r
-               D3DXHANDLE parentHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               D3DXHANDLE handle = InternalPointer->GetParameterByName( parentHandle, reinterpret_cast<const char*>( pinnedName ) );\r
-               GC::KeepAlive( parameter );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetParameterBySemantic( EffectHandle^ parameter, String^ semantic )\r
-       {\r
-               array<Byte>^ semanticBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( semantic );\r
-               pin_ptr<unsigned char> pinnedSemantic = &semanticBytes[0];\r
-\r
-               D3DXHANDLE parentHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               D3DXHANDLE handle = InternalPointer->GetParameterBySemantic( parentHandle, reinterpret_cast<const char*>( pinnedSemantic ) );\r
-               GC::KeepAlive( parameter );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetParameterElement( EffectHandle^ parameter, int index )\r
-       {\r
-               D3DXHANDLE parentHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               D3DXHANDLE handle = InternalPointer->GetParameterElement( parentHandle, index );\r
-               GC::KeepAlive( parameter );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       ParameterDescription BaseEffect::GetParameterDescription( EffectHandle^ parameter )\r
-       {\r
-               D3DXPARAMETER_DESC description;\r
-\r
-               HRESULT hr = InternalPointer->GetParameterDesc( parameter->InternalHandle, &description );\r
-               GC::KeepAlive( parameter );\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return ParameterDescription();\r
-\r
-               ParameterDescription outDesc;\r
-               outDesc.Name = gcnew String( description.Name );\r
-               outDesc.Semantic = gcnew String( description.Semantic );\r
-               outDesc.Class = static_cast<ParameterClass>( description.Class );\r
-               outDesc.Type = static_cast<ParameterType>( description.Type );\r
-               outDesc.Rows = description.Rows;\r
-               outDesc.Columns = description.Columns;\r
-               outDesc.Elements = description.Elements;\r
-               outDesc.Annotations = description.Annotations;\r
-               outDesc.StructMembers = description.StructMembers;\r
-               outDesc.Flags = static_cast<ParameterFlags>( description.Flags );\r
-               outDesc.Bytes = description.Bytes;\r
-\r
-               return outDesc;\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetFunction( int index )\r
-       {\r
-               D3DXHANDLE handle = InternalPointer->GetFunction( index );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetFunction( String^ name )\r
-       {\r
-               array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name );\r
-               pin_ptr<unsigned char> pinnedName = &nameBytes[0];\r
-\r
-               D3DXHANDLE handle = InternalPointer->GetFunctionByName( reinterpret_cast<const char*>( pinnedName ) );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       FunctionDescription BaseEffect::GetFunctionDescription( EffectHandle^ handle )\r
-       {\r
-               D3DXFUNCTION_DESC description;\r
-\r
-               HRESULT hr = InternalPointer->GetFunctionDesc( handle->InternalHandle, &description );\r
-               GC::KeepAlive(handle);\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return FunctionDescription();\r
-\r
-               FunctionDescription outDesc;\r
-               outDesc.Name = gcnew String( description.Name );\r
-               outDesc.Annotations = description.Annotations;\r
-\r
-               return outDesc;\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetTechnique( int index )\r
-       {\r
-               D3DXHANDLE handle = InternalPointer->GetTechnique( index );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetTechnique( String^ name )\r
-       {\r
-               array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name );\r
-               pin_ptr<unsigned char> pinnedName = &nameBytes[0];\r
-\r
-               D3DXHANDLE handle = InternalPointer->GetTechniqueByName( reinterpret_cast<const char*>( pinnedName ) );\r
-\r
-               if( handle == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( handle );\r
-       }\r
-\r
-       TechniqueDescription BaseEffect::GetTechniqueDescription( EffectHandle^ handle )\r
-       {\r
-               D3DXTECHNIQUE_DESC description;\r
-\r
-               HRESULT hr = InternalPointer->GetTechniqueDesc( handle->InternalHandle, &description );\r
-               GC::KeepAlive(handle);\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return TechniqueDescription();\r
-\r
-               TechniqueDescription outDesc;\r
-               outDesc.Name = gcnew String( description.Name );\r
-               outDesc.Annotations = description.Annotations;\r
-               outDesc.Passes = description.Passes;\r
-\r
-               return outDesc;\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetPass( EffectHandle^ handle, int index )\r
-       {\r
-               D3DXHANDLE nativeHandle = handle != nullptr ? handle->InternalHandle : NULL;\r
-               D3DXHANDLE pass = InternalPointer->GetPass( nativeHandle, index );\r
-               GC::KeepAlive(handle);\r
-\r
-               if( pass == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( pass );\r
-       }\r
-\r
-       EffectHandle^ BaseEffect::GetPass( EffectHandle^ handle, String^ name )\r
-       {\r
-               array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name );\r
-               pin_ptr<unsigned char> pinnedName = &nameBytes[0];\r
-\r
-               D3DXHANDLE nativeHandle = handle != nullptr ? handle->InternalHandle : NULL;\r
-               D3DXHANDLE pass = InternalPointer->GetPassByName( nativeHandle, reinterpret_cast<const char*>( pinnedName ) );\r
-               GC::KeepAlive(handle);\r
-\r
-               if( pass == NULL )\r
-                       return nullptr;\r
-               return gcnew EffectHandle( pass );\r
-       }\r
-\r
-       PassDescription BaseEffect::GetPassDescription( EffectHandle^ handle )\r
-       {\r
-               D3DXPASS_DESC description;\r
-               D3DXHANDLE nativeHandle = handle != nullptr ? handle->InternalHandle : NULL;\r
-\r
-               HRESULT hr = InternalPointer->GetPassDesc( nativeHandle, &description );\r
-               GC::KeepAlive(handle);\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return PassDescription();\r
-\r
-               PassDescription passDesc;\r
-               passDesc.Name = gcnew String( description.Name );\r
-               passDesc.Annotations = description.Annotations;\r
-               passDesc.VertexShaderFunction = IntPtr( const_cast<void*>( static_cast<const void*>( description.pVertexShaderFunction ) ) );\r
-               passDesc.PixelShaderFunction = IntPtr( const_cast<void*>( static_cast<const void*>( description.pPixelShaderFunction ) ) );\r
-\r
-               return passDesc;\r
-       }\r
-\r
-       PixelShader^ BaseEffect::GetPixelShader( EffectHandle^ parameter )\r
-       {\r
-               IDirect3DPixelShader9 *pixelShader;\r
-\r
-               D3DXHANDLE nativeHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               HRESULT hr = InternalPointer->GetPixelShader( nativeHandle, &pixelShader );\r
-               GC::KeepAlive(parameter);\r
-\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return PixelShader::FromPointer( pixelShader );\r
-       }\r
-\r
-       VertexShader^ BaseEffect::GetVertexShader( EffectHandle^ parameter )\r
-       {\r
-               IDirect3DVertexShader9 *vertexShader;\r
-\r
-               D3DXHANDLE nativeHandle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               HRESULT hr = InternalPointer->GetVertexShader( nativeHandle, &vertexShader );\r
-               GC::KeepAlive( parameter );\r
-\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return VertexShader::FromPointer( vertexShader );\r
-       }\r
-\r
-       EffectDescription BaseEffect::Description::get()\r
-       {\r
-               D3DXEFFECT_DESC description;\r
-\r
-               HRESULT hr = InternalPointer->GetDesc( &description );\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return EffectDescription();\r
-\r
-               EffectDescription outDesc;\r
-               outDesc.Creator = gcnew String( description.Creator );\r
-               outDesc.Parameters = description.Parameters;\r
-               outDesc.Techniques = description.Techniques;\r
-               outDesc.Functions = description.Functions;\r
-\r
-               return outDesc;\r
-       }\r
-\r
-       Result BaseEffect::SetTexture( EffectHandle^ parameter, BaseTexture^ value )\r
-       {\r
-               IDirect3DBaseTexture9* texture = NULL;\r
-               if( value != nullptr )\r
-                       texture = value->InternalPointer;\r
-\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               HRESULT hr = InternalPointer->SetTexture( handle, texture );\r
-               GC::KeepAlive( parameter );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result BaseEffect::SetString( EffectHandle^ parameter, String^ value )\r
-       {\r
-               array<unsigned char>^ valueBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( value );\r
-               pin_ptr<unsigned char> pinnedValue = &valueBytes[0];\r
-\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               HRESULT hr = InternalPointer->SetString( handle, reinterpret_cast<LPCSTR>( pinnedValue ) );\r
-               GC::KeepAlive( parameter );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       BaseTexture^ BaseEffect::GetTexture( EffectHandle^ parameter )\r
-       {\r
-               IDirect3DBaseTexture9* texture = NULL;\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               HRESULT hr = InternalPointer->GetTexture( handle, &texture );\r
-               GC::KeepAlive( parameter );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return BaseTexture::FromUnmanaged( texture );\r
-       }\r
-\r
-       String^ BaseEffect::GetString( EffectHandle^ parameter )\r
-       {\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               LPCSTR data = 0;\r
-\r
-               HRESULT hr = InternalPointer->GetString( handle, &data );\r
-               GC::KeepAlive( parameter );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return gcnew String(data);\r
-       }\r
-\r
-       generic<typename T> where T : value class\r
-       Result BaseEffect::SetValue( EffectHandle^ parameter, T value )\r
-       {\r
-               HRESULT hr;\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-\r
-               if( T::typeid == bool::typeid )\r
-               {\r
-                       BOOL newValue = Convert::ToInt32( value, CultureInfo::InvariantCulture );\r
-                       hr = InternalPointer->SetBool( handle, newValue );\r
-               }\r
-               else if( T::typeid == float::typeid )\r
-               {\r
-                       hr = InternalPointer->SetFloat( handle, static_cast<FLOAT>( value ) );\r
-               }\r
-               else if( T::typeid == int::typeid )\r
-               {\r
-                       hr = InternalPointer->SetInt( handle, static_cast<INT>( value ) );\r
-               }\r
-               else if( T::typeid == Matrix::typeid )\r
-               {\r
-                       hr = InternalPointer->SetMatrix( handle, reinterpret_cast<D3DXMATRIX*>( &value ) );\r
-               }\r
-               else if( T::typeid == Vector4::typeid )\r
-               {\r
-                       hr = InternalPointer->SetVector( handle, reinterpret_cast<D3DXVECTOR4*>( &value ) );\r
-               }\r
-               else\r
-               {\r
-                       hr = InternalPointer->SetValue( handle, &value, static_cast<DWORD>( sizeof(T) ) );\r
-               }\r
-\r
-               GC::KeepAlive( parameter );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       generic<typename T> where T : value class\r
-       T BaseEffect::GetValue( EffectHandle^ parameter )\r
-       {\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               T result;\r
-\r
-               HRESULT hr = 0;\r
-               if( T::typeid == bool::typeid)\r
-               {\r
-                       //bool is not the same as BOOL, so convert over appropriately\r
-                       BOOL boolValue = 0;\r
-                       hr = InternalPointer->GetValue( handle, &boolValue, sizeof(BOOL) );\r
-                       result = (T)(boolValue == TRUE);\r
-               }\r
-               else\r
-               {\r
-                       hr = InternalPointer->GetValue( handle, &result, static_cast<DWORD>( sizeof(T) ) );\r
-               }\r
-               GC::KeepAlive( parameter );\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return T();\r
-\r
-               return result;\r
-       }\r
-\r
-       generic<typename T> where T : value class\r
-       Result BaseEffect::SetValue( EffectHandle^ parameter, array<T>^ values )\r
-       {\r
-               HRESULT hr;\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-\r
-               if( T::typeid == bool::typeid )\r
-               {\r
-                       array<BOOL>^ newValues = Array::ConvertAll<bool, int>( safe_cast<array<bool>>( values ), gcnew Converter<bool, int>( Convert::ToInt32 ) );\r
-                       pin_ptr<BOOL> pinnedValues = &newValues[0];\r
-\r
-                       hr = InternalPointer->SetBoolArray( handle, pinnedValues, values->Length );\r
-               }\r
-               else if( T::typeid == float::typeid )\r
-               {\r
-                       pin_ptr<T> pinnedData = &values[0];\r
-                       hr = InternalPointer->SetFloatArray( handle, reinterpret_cast<FLOAT*>( pinnedData ), values->Length );\r
-               }\r
-               else if( T::typeid == int::typeid )\r
-               {\r
-                       pin_ptr<T> pinnedData = &values[0];\r
-                       hr = InternalPointer->SetIntArray( handle, reinterpret_cast<INT*>( pinnedData ), values->Length );\r
-               }\r
-               else if( T::typeid == Matrix::typeid )\r
-               {\r
-                       pin_ptr<T> pinnedData = &values[0];\r
-                       hr = InternalPointer->SetMatrixArray( handle, reinterpret_cast<D3DXMATRIX*>( pinnedData ), values->Length );\r
-               }\r
-               else if( T::typeid == Vector4::typeid )\r
-               {\r
-                       pin_ptr<T> pinnedData = &values[0];\r
-                       hr = InternalPointer->SetVectorArray( handle, reinterpret_cast<D3DXVECTOR4*>( pinnedData ), values->Length );\r
-               }\r
-               else\r
-               {\r
-                       pin_ptr<T> pinnedData = &values[0];\r
-                       hr = InternalPointer->SetValue( handle, pinnedData, static_cast<DWORD>( sizeof(T) ) * values->Length );\r
-               }\r
-\r
-               GC::KeepAlive( parameter );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       generic<typename T> where T : value class\r
-       array<T>^ BaseEffect::GetValue( EffectHandle^ parameter, int count )\r
-       {\r
-               D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;\r
-               array<T>^ results = gcnew array<T>( count );\r
-               pin_ptr<T> pinnedData = &results[0];\r
-\r
-               HRESULT hr = InternalPointer->GetValue( handle, pinnedData, static_cast<DWORD>( sizeof(T) ) * count );\r
-               GC::KeepAlive( parameter );\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return results;\r
-       }\r
-}\r
-}\r