OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / direct3d11 / EffectResourceVariable11.cpp
1 /*\r
2 * Copyright (c) 2007-2010 SlimDX Group\r
3\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
10\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
13\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
20 * THE SOFTWARE.\r
21 */\r
22 #include "stdafx.h"\r
23 \r
24 #include "../Utilities.h"\r
25 #include "../stack_array.h"\r
26 \r
27 #include "Direct3D11Exception.h"\r
28 \r
29 #include "EffectResourceVariable11.h"\r
30 #include "ShaderResourceView11.h"\r
31 \r
32 using namespace System;\r
33 \r
34 namespace SlimDX\r
35 {\r
36 namespace Direct3D11\r
37\r
38         EffectResourceVariable::EffectResourceVariable( ID3DX11EffectShaderResourceVariable* pointer )\r
39         : EffectVariable( pointer )\r
40         {\r
41                 m_Pointer = pointer;\r
42         }\r
43         \r
44         EffectResourceVariable::EffectResourceVariable( IntPtr pointer )\r
45         : EffectVariable( pointer )\r
46         {\r
47                 m_Pointer = reinterpret_cast<ID3DX11EffectShaderResourceVariable*>( pointer.ToPointer() );\r
48         }\r
49 \r
50         ShaderResourceView^ EffectResourceVariable::GetResource()\r
51         {\r
52                 ID3D11ShaderResourceView* view = 0;\r
53                 if( RECORD_D3D11( m_Pointer->GetResource( &view ) ).IsFailure )\r
54                         return nullptr;\r
55                         \r
56                 return ShaderResourceView::FromPointer( view );\r
57         }\r
58 \r
59         Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views)\r
60         {\r
61                 return GetResourceArray(views, 0, views->Length);\r
62         }\r
63 \r
64         Result EffectResourceVariable::GetResourceArray(array<ShaderResourceView^>^ views, int offset, int count)\r
65         {\r
66                 Utilities::CheckArrayBounds(views, offset, count);\r
67 \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
72 \r
73                 for (int i = 0; i < count; i++)\r
74                         views[i + offset] = ShaderResourceView::FromPointer(nativeViews[i]);\r
75 \r
76                 return Result::Last;\r
77         }\r
78         \r
79         Result EffectResourceVariable::SetResource( ShaderResourceView^ view )\r
80         {\r
81                 if( view == nullptr )\r
82                         return RECORD_D3D11( m_Pointer->SetResource( 0 ) );\r
83                 else\r
84                         return RECORD_D3D11( m_Pointer->SetResource( static_cast<ID3D11ShaderResourceView*>( view->InternalPointer ) ) );\r
85         }\r
86 \r
87         Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views )\r
88         {\r
89                 return SetResourceArray(views, 0, views->Length);\r
90         }\r
91 \r
92         Result EffectResourceVariable::SetResourceArray( array<ShaderResourceView^>^ views, int offset, int count )\r
93         {\r
94                 Utilities::CheckArrayBounds(views, offset, count);\r
95 \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
99 \r
100                 HRESULT hr = m_Pointer->SetResourceArray(&nativeViews[0], 0, count);\r
101                 return RECORD_D3D11(hr);\r
102         }\r
103 }\r
104 }\r