3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
26 #include "../Utilities.h"
\r
28 #include "BlendStateDescription.h"
\r
30 using namespace System;
\r
31 using namespace System::Collections::Generic;
\r
32 using namespace System::Collections::ObjectModel;
\r
36 namespace Direct3D10
\r
38 BlendStateDescription::BlendStateDescription( const D3D10_BLEND_DESC& native )
\r
40 m_AlphaToCoverageEnable = native.AlphaToCoverageEnable ? true : false;
\r
41 m_SrcBlend = static_cast<BlendOption>( native.SrcBlend );
\r
42 m_DestBlend = static_cast<BlendOption>( native.DestBlend );
\r
43 m_BlendOp = static_cast<Direct3D10::BlendOperation>( native.BlendOp );
\r
44 m_SrcBlendAlpha = static_cast<BlendOption>( native.SrcBlendAlpha );
\r
45 m_DestBlendAlpha = static_cast<BlendOption>( native.DestBlendAlpha );
\r
46 m_BlendOpAlpha = static_cast<Direct3D10::BlendOperation>( native.BlendOpAlpha );
\r
48 ConstructLazyProperties();
\r
49 for(int index = 0; index < 8; ++index)
\r
51 m_BlendEnable[ index ] = (native.BlendEnable[ index ] > 0);
\r
52 m_RenderTargetWriteMask[ index ] = static_cast<ColorWriteMaskFlags>( native.RenderTargetWriteMask[ index ] );
\r
56 D3D10_BLEND_DESC BlendStateDescription::CreateNativeVersion()
\r
58 D3D10_BLEND_DESC native;
\r
59 native.AlphaToCoverageEnable = m_AlphaToCoverageEnable;
\r
60 native.SrcBlend = static_cast<D3D10_BLEND>( m_SrcBlend );
\r
61 native.DestBlend = static_cast<D3D10_BLEND>( m_DestBlend );
\r
62 native.BlendOp = static_cast<D3D10_BLEND_OP>( m_BlendOp );
\r
63 native.SrcBlendAlpha = static_cast<D3D10_BLEND>( m_SrcBlendAlpha );
\r
64 native.DestBlendAlpha = static_cast<D3D10_BLEND>( m_DestBlendAlpha );
\r
65 native.BlendOpAlpha = static_cast<D3D10_BLEND_OP>( m_BlendOpAlpha );
\r
67 ConstructLazyProperties();
\r
68 for(int index = 0; index < 8; ++index)
\r
70 native.BlendEnable[ index ] = m_BlendEnable[ index ];
\r
71 native.RenderTargetWriteMask[ index ] = static_cast<UINT8>( m_RenderTargetWriteMask[ index ] );
\r
77 bool BlendStateDescription::IsAlphaToCoverageEnabled::get()
\r
79 return m_AlphaToCoverageEnable;
\r
82 void BlendStateDescription::IsAlphaToCoverageEnabled::set( bool value )
\r
84 m_AlphaToCoverageEnable = value;
\r
87 BlendOption BlendStateDescription::SourceBlend::get()
\r
92 void BlendStateDescription::SourceBlend::set( BlendOption value )
\r
97 BlendOption BlendStateDescription::DestinationBlend::get()
\r
102 void BlendStateDescription::DestinationBlend::set( BlendOption value )
\r
104 m_DestBlend = value;
\r
107 Direct3D10::BlendOperation BlendStateDescription::BlendOperation::get()
\r
112 void BlendStateDescription::BlendOperation::set( Direct3D10::BlendOperation value )
\r
117 BlendOption BlendStateDescription::SourceAlphaBlend::get()
\r
119 return m_SrcBlendAlpha;
\r
122 void BlendStateDescription::SourceAlphaBlend::set( BlendOption value )
\r
124 m_SrcBlendAlpha = value;
\r
127 BlendOption BlendStateDescription::DestinationAlphaBlend::get()
\r
129 return m_DestBlendAlpha;
\r
132 void BlendStateDescription::DestinationAlphaBlend::set( BlendOption value )
\r
134 m_DestBlendAlpha = value;
\r
137 Direct3D10::BlendOperation BlendStateDescription::AlphaBlendOperation::get()
\r
139 return m_BlendOpAlpha;
\r
142 void BlendStateDescription::AlphaBlendOperation::set( Direct3D10::BlendOperation value )
\r
144 m_BlendOpAlpha = value;
\r
147 bool BlendStateDescription::GetBlendEnable( UInt32 index )
\r
149 ConstructLazyProperties();
\r
150 return m_BlendEnable[ index ];
\r
153 void BlendStateDescription::SetBlendEnable( UInt32 index, bool value )
\r
155 ConstructLazyProperties();
\r
156 m_BlendEnable[ index ] = value;
\r
159 ColorWriteMaskFlags BlendStateDescription::GetWriteMask( UInt32 index )
\r
161 ConstructLazyProperties();
\r
162 return m_RenderTargetWriteMask[ index ];
\r
165 void BlendStateDescription::SetWriteMask( UInt32 index, ColorWriteMaskFlags value )
\r
167 ConstructLazyProperties();
\r
168 m_RenderTargetWriteMask[ index ] = value;
\r
171 void BlendStateDescription::ConstructLazyProperties()
\r
173 if( m_BlendEnable == nullptr )
\r
175 m_BlendEnable = gcnew array<bool>(8);
\r
176 m_RenderTargetWriteMask = gcnew array<ColorWriteMaskFlags>(8);
\r
177 for(int index = 0; index < 8; ++index)
\r
179 m_BlendEnable[ index ] = false;
\r
180 m_RenderTargetWriteMask[ index ] = ColorWriteMaskFlags::All;
\r
185 bool BlendStateDescription::operator == ( BlendStateDescription left, BlendStateDescription right )
\r
187 return BlendStateDescription::Equals( left, right );
\r
190 bool BlendStateDescription::operator != ( BlendStateDescription left, BlendStateDescription right )
\r
192 return !BlendStateDescription::Equals( left, right );
\r
195 int BlendStateDescription::GetHashCode()
\r
197 ConstructLazyProperties();
\r
199 m_AlphaToCoverageEnable.GetHashCode() +
\r
200 m_BlendEnable->GetHashCode() +
\r
201 m_SrcBlend.GetHashCode() +
\r
202 m_DestBlend.GetHashCode() +
\r
203 m_BlendOp.GetHashCode() +
\r
204 m_SrcBlendAlpha.GetHashCode() +
\r
205 m_DestBlendAlpha.GetHashCode() +
\r
206 m_BlendOpAlpha.GetHashCode() +
\r
207 m_RenderTargetWriteMask->GetHashCode()
\r
211 bool BlendStateDescription::Equals( Object^ value )
\r
213 if( value == nullptr )
\r
216 if( value->GetType() != GetType() )
\r
219 return Equals( safe_cast<BlendStateDescription>( value ) );
\r
222 bool BlendStateDescription::Equals( BlendStateDescription value )
\r
224 ConstructLazyProperties();
\r
225 value.ConstructLazyProperties();
\r
227 m_AlphaToCoverageEnable == value.m_AlphaToCoverageEnable &&
\r
228 Utilities::CheckElementEquality( m_BlendEnable, value.m_BlendEnable ) &&
\r
229 m_SrcBlend == value.m_SrcBlend &&
\r
230 m_DestBlend == value.m_DestBlend &&
\r
231 m_BlendOp == value.m_BlendOp &&
\r
232 m_SrcBlendAlpha == value.m_SrcBlendAlpha &&
\r
233 m_DestBlendAlpha == value.m_DestBlendAlpha &&
\r
234 m_BlendOpAlpha == value.m_BlendOpAlpha &&
\r
235 Utilities::CheckElementEquality( m_RenderTargetWriteMask, value.m_RenderTargetWriteMask )
\r
239 bool BlendStateDescription::Equals( BlendStateDescription% value1, BlendStateDescription% value2 )
\r
241 value1.ConstructLazyProperties();
\r
242 value2.ConstructLazyProperties();
\r
244 value1.m_AlphaToCoverageEnable == value2.m_AlphaToCoverageEnable &&
\r
245 Utilities::CheckElementEquality( value1.m_BlendEnable, value2.m_BlendEnable ) &&
\r
246 value1.m_SrcBlend == value2.m_SrcBlend &&
\r
247 value1.m_DestBlend == value2.m_DestBlend &&
\r
248 value1.m_BlendOp == value2.m_BlendOp &&
\r
249 value1.m_SrcBlendAlpha == value2.m_SrcBlendAlpha &&
\r
250 value1.m_DestBlendAlpha == value2.m_DestBlendAlpha &&
\r
251 value1.m_BlendOpAlpha == value2.m_BlendOpAlpha &&
\r
252 Utilities::CheckElementEquality( value1.m_RenderTargetWriteMask, value2.m_RenderTargetWriteMask )
\r