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 "../Utilities.h"
\r
25 #include "../stack_array.h"
\r
27 #include "Direct3D11Exception.h"
\r
29 #include "EffectResourceVariable11.h"
\r
30 #include "ShaderResourceView11.h"
\r
32 using namespace System;
\r
36 namespace Direct3D11
\r
38 EffectResourceVariable::EffectResourceVariable( ID3DX11EffectShaderResourceVariable* pointer )
\r
39 : EffectVariable( pointer )
\r
41 m_Pointer = pointer;
\r
44 EffectResourceVariable::EffectResourceVariable( IntPtr pointer )
\r
45 : EffectVariable( pointer )
\r
47 m_Pointer = reinterpret_cast<ID3DX11EffectShaderResourceVariable*>( pointer.ToPointer() );
\r
50 ShaderResourceView^ EffectResourceVariable::GetResource()
\r
52 ID3D11ShaderResourceView* view = 0;
\r
53 if( RECORD_D3D11( m_Pointer->GetResource( &view ) ).IsFailure )
\r
56 return ShaderResourceView::FromPointer( view );
\r
59 Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views)
\r
61 return GetResourceArray(views, 0, views->Length);
\r
64 Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views, int offset, int count)
\r
66 Utilities::CheckArrayBounds(views, offset, count);
\r
68 stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
\r
69 HRESULT hr = m_Pointer->GetResourceArray(&nativeViews[0], 0, count);
\r
70 if (RECORD_D3D11(hr).IsFailure)
\r
71 return Result::Last;
\r
73 for (int i = 0; i < count; i++)
\r
74 views[i + offset] = ShaderResourceView::FromPointer(nativeViews[i]);
\r
76 return Result::Last;
\r
79 Result EffectResourceVariable::SetResource( ShaderResourceView^ view )
\r
81 if( view == nullptr )
\r
82 return RECORD_D3D11( m_Pointer->SetResource( 0 ) );
\r
84 return RECORD_D3D11( m_Pointer->SetResource( static_cast<ID3D11ShaderResourceView*>( view->InternalPointer ) ) );
\r
87 Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views )
\r
89 return SetResourceArray(views, 0, views->Length);
\r
92 Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views, int offset, int count )
\r
94 Utilities::CheckArrayBounds(views, offset, count);
\r
96 stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
\r
97 for (int i = 0; i < count; i++)
\r
98 nativeViews[i] = views[i + offset]->InternalPointer;
\r
100 HRESULT hr = m_Pointer->SetResourceArray(&nativeViews[0], 0, count);
\r
101 return RECORD_D3D11(hr);
\r