OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d11 / EffectResourceVariable11.cpp
1 /*
2 * Copyright (c) 2007-2010 SlimDX Group
3
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:
10
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13
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
20 * THE SOFTWARE.
21 */
22 #include "stdafx.h"
23
24 #include "../Utilities.h"
25 #include "../stack_array.h"
26
27 #include "Direct3D11Exception.h"
28
29 #include "EffectResourceVariable11.h"
30 #include "ShaderResourceView11.h"
31
32 using namespace System;
33
34 namespace SlimDX
35 {
36 namespace Direct3D11
37
38         EffectResourceVariable::EffectResourceVariable( ID3DX11EffectShaderResourceVariable* pointer )
39         : EffectVariable( pointer )
40         {
41                 m_Pointer = pointer;
42         }
43         
44         EffectResourceVariable::EffectResourceVariable( IntPtr pointer )
45         : EffectVariable( pointer )
46         {
47                 m_Pointer = reinterpret_cast<ID3DX11EffectShaderResourceVariable*>( pointer.ToPointer() );
48         }
49
50         ShaderResourceView^ EffectResourceVariable::GetResource()
51         {
52                 ID3D11ShaderResourceView* view = 0;
53                 if( RECORD_D3D11( m_Pointer->GetResource( &view ) ).IsFailure )
54                         return nullptr;
55                         
56                 return ShaderResourceView::FromPointer( view );
57         }
58
59         Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views)
60         {
61                 return GetResourceArray(views, 0, views->Length);
62         }
63
64         Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views, int offset, int count)
65         {
66                 Utilities::CheckArrayBounds(views, offset, count);
67
68                 stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
69                 HRESULT hr = m_Pointer->GetResourceArray(&nativeViews[0], 0, count);
70                 if (RECORD_D3D11(hr).IsFailure)
71                         return Result::Last;
72
73                 for (int i = 0; i < count; i++)
74                         views[i + offset] = ShaderResourceView::FromPointer(nativeViews[i]);
75
76                 return Result::Last;
77         }
78         
79         Result EffectResourceVariable::SetResource( ShaderResourceView^ view )
80         {
81                 if( view == nullptr )
82                         return RECORD_D3D11( m_Pointer->SetResource( 0 ) );
83                 else
84                         return RECORD_D3D11( m_Pointer->SetResource( static_cast<ID3D11ShaderResourceView*>( view->InternalPointer ) ) );
85         }
86
87         Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views )
88         {
89                 return SetResourceArray(views, 0, views->Length);
90         }
91
92         Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views, int offset, int count )
93         {
94                 Utilities::CheckArrayBounds(views, offset, count);
95
96                 stack_array<ID3D11ShaderResourceView*> nativeViews = stackalloc(ID3D11ShaderResourceView*, count);
97                 for (int i = 0; i < count; i++)
98                         nativeViews[i] = views[i + offset]->InternalPointer;
99
100                 HRESULT hr = m_Pointer->SetResourceArray(&nativeViews[0], 0, count);
101                 return RECORD_D3D11(hr);
102         }
103 }
104 }