2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "ShaderMacroDC.h"
\r
26 using namespace System;
\r
27 using namespace System::Runtime::InteropServices;
\r
31 namespace D3DCompiler
\r
33 stack_array<D3D10_SHADER_MACRO> ShaderMacro::Marshal( array<ShaderMacro>^ macros, [Out] array<GCHandle>^% handles )
\r
35 if( macros == nullptr )
\r
38 return stack_array<D3D10_SHADER_MACRO>();
\r
41 // this array is null terminated, so we need to patch in an extra value
\r
42 stack_array<D3D10_SHADER_MACRO> result( macros->Length + 1 );
\r
43 handles = gcnew array<GCHandle>( macros->Length * 2 );
\r
45 for( int i = 0; i < macros->Length; ++i )
\r
47 array<Byte>^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( macros[i].Name );
\r
48 array<Byte>^ defBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( macros[i].Value );
\r
50 handles[2 * i] = GCHandle::Alloc( nameBytes, GCHandleType::Pinned );
\r
51 handles[2 * i + 1] = GCHandle::Alloc( defBytes, GCHandleType::Pinned );
\r
53 result[i].Name = reinterpret_cast<LPCSTR>( handles[2 * i].AddrOfPinnedObject().ToPointer() );
\r
54 result[i].Definition = reinterpret_cast<LPCSTR>( handles[2 * i + 1].AddrOfPinnedObject().ToPointer() );
\r
57 result[macros->Length].Name = NULL;
\r
58 result[macros->Length].Definition = NULL;
\r
63 void ShaderMacro::Unmarshal( array<GCHandle>^ handles )
\r
65 if( handles != nullptr )
\r
67 for( int i = 0; i < handles->Length; ++i )
\r
72 ShaderMacro::ShaderMacro( String^ name )
\r
78 ShaderMacro::ShaderMacro( String^ name, String^ value )
\r
84 bool ShaderMacro::operator == ( ShaderMacro left, ShaderMacro right )
\r
86 return ShaderMacro::Equals( left, right );
\r
89 bool ShaderMacro::operator != ( ShaderMacro left, ShaderMacro right )
\r
91 return !ShaderMacro::Equals( left, right );
\r
94 int ShaderMacro::GetHashCode()
\r
96 return Name->GetHashCode() + Value->GetHashCode();
\r
99 bool ShaderMacro::Equals( Object^ value )
\r
101 if( value == nullptr )
\r
104 if( value->GetType() != GetType() )
\r
107 return Equals( safe_cast<ShaderMacro>( value ) );
\r
110 bool ShaderMacro::Equals( ShaderMacro value )
\r
112 return ( Name == value.Name && Value == value.Value );
\r
115 bool ShaderMacro::Equals( ShaderMacro% value1, ShaderMacro% value2 )
\r
117 return ( value1.Name == value2.Name && value1.Value == value2.Value );
\r