2 * Copyright (c) 2007-2010 SlimDX Group
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "../Utilities.h"
25 #include "../stack_array.h"
27 #include "Direct3D11Exception.h"
29 #include "EffectRenderTargetViewVariable11.h"
30 #include "RenderTargetView11.h"
32 using namespace System;
38 EffectRenderTargetViewVariable::EffectRenderTargetViewVariable( ID3DX11EffectRenderTargetViewVariable* pointer )
39 : EffectVariable( pointer )
44 EffectRenderTargetViewVariable::EffectRenderTargetViewVariable( IntPtr pointer )
45 : EffectVariable( pointer )
47 m_Pointer = reinterpret_cast<ID3DX11EffectRenderTargetViewVariable*>( pointer.ToPointer() );
50 RenderTargetView^ EffectRenderTargetViewVariable::GetView()
52 ID3D11RenderTargetView* view = 0;
53 if( RECORD_D3D11( m_Pointer->GetRenderTarget( &view ) ).IsFailure )
56 return RenderTargetView::FromPointer( view );
59 Result EffectRenderTargetViewVariable::GetViewArray(array<RenderTargetView^>^ views)
61 return GetViewArray(views, 0, views->Length);
64 Result EffectRenderTargetViewVariable::GetViewArray(array<RenderTargetView^>^ views, int offset, int count)
66 Utilities::CheckArrayBounds(views, offset, count);
68 stack_array<ID3D11RenderTargetView*> nativeViews = stackalloc(ID3D11RenderTargetView*, count);
69 HRESULT hr = m_Pointer->GetRenderTargetArray(&nativeViews[0], 0, count);
70 if (RECORD_D3D11(hr).IsFailure)
73 for (int i = 0; i < count; i++)
74 views[i + offset] = RenderTargetView::FromPointer(nativeViews[i]);
79 Result EffectRenderTargetViewVariable::SetView( RenderTargetView^ view )
82 return RECORD_D3D11( m_Pointer->SetRenderTarget( 0 ) );
84 return RECORD_D3D11( m_Pointer->SetRenderTarget( static_cast<ID3D11RenderTargetView*>( view->InternalPointer ) ) );
87 Result EffectRenderTargetViewVariable::SetViewArray( array<RenderTargetView^>^ views )
89 return SetViewArray(views, 0, views->Length);
92 Result EffectRenderTargetViewVariable::SetViewArray( array<RenderTargetView^>^ views, int offset, int count )
94 Utilities::CheckArrayBounds(views, offset, count);
96 stack_array<ID3D11RenderTargetView*> nativeViews = stackalloc(ID3D11RenderTargetView*, count);
97 for (int i = 0; i < count; i++)
98 nativeViews[i] = views[i + offset]->InternalPointer;
100 HRESULT hr = m_Pointer->SetRenderTargetArray(&nativeViews[0], 0, count);
101 return RECORD_D3D11(hr);