OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / direct3d11 / GeometryShaderWrapper11.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 "../stack_array.h"\r
25 \r
26 #include "Buffer11.h"\r
27 #include "SamplerState11.h"\r
28 #include "ShaderResourceView11.h"\r
29 #include "GeometryShaderWrapper11.h"\r
30 #include "GeometryShader11.h"\r
31 #include "ClassInstance11.h"\r
32 \r
33 using namespace System;\r
34 \r
35 namespace SlimDX\r
36 {\r
37 namespace Direct3D11\r
38\r
39         GeometryShaderWrapper::GeometryShaderWrapper( ID3D11DeviceContext* device )\r
40         {\r
41                 if( device == 0 )\r
42                         throw gcnew ArgumentNullException( "deviceContext" );\r
43                 deviceContext = device;\r
44         }\r
45 \r
46         void GeometryShaderWrapper::Set( GeometryShader^ shader )\r
47         {\r
48                 Set( shader, nullptr );\r
49         }\r
50 \r
51         void GeometryShaderWrapper::Set( GeometryShader^ shader, array<ClassInstance^>^ classInstances )\r
52         {\r
53                 ID3D11GeometryShader *nativeShader = shader == nullptr ? NULL : shader->InternalPointer;\r
54                 ID3D11ClassInstance** instancePtr = NULL;\r
55                 stack_array<ID3D11ClassInstance*> instances;\r
56                 UINT count = 0;\r
57 \r
58                 if( classInstances != nullptr && classInstances->Length > 0 )\r
59                 {\r
60                         instances = stack_array<ID3D11ClassInstance*>( classInstances->Length );\r
61                         instancePtr = &instances[0];\r
62                         count = classInstances->Length;\r
63 \r
64                         for( int i = 0; i < classInstances->Length; i++ )\r
65                                 instances[i] = classInstances[i]->InternalPointer;\r
66                 }\r
67 \r
68                 deviceContext->GSSetShader( nativeShader, instancePtr, count );\r
69         }\r
70 \r
71         GeometryShader^ GeometryShaderWrapper::Get()\r
72         {\r
73                 return Get( nullptr );\r
74         }\r
75 \r
76         GeometryShader^ GeometryShaderWrapper::Get( array<ClassInstance^>^ classInstances )\r
77         {\r
78                 ID3D11GeometryShader *shader = NULL;\r
79                 ID3D11ClassInstance** instancePtr = NULL;\r
80                 stack_array<ID3D11ClassInstance*> instances;\r
81                 UINT count = 0;\r
82 \r
83                 if( classInstances != nullptr && classInstances->Length > 0 )\r
84                 {\r
85                         instances = stack_array<ID3D11ClassInstance*>( classInstances->Length );\r
86                         instancePtr = &instances[0];\r
87                         count = classInstances->Length;\r
88                 }\r
89 \r
90                 deviceContext->GSGetShader( &shader, instancePtr, &count );\r
91 \r
92                 for( UINT i = 0; i < count; i++ )\r
93                         classInstances[i] = ClassInstance::FromPointer( instances[i] );\r
94 \r
95                 return shader == NULL ? nullptr : GeometryShader::FromPointer( shader );\r
96         }\r
97 \r
98         array<Buffer^>^ GeometryShaderWrapper::GetConstantBuffers( int startSlot, int count )\r
99         {\r
100                 array<Buffer^>^ buffers = gcnew array<Buffer^>( count );\r
101                 stack_array<ID3D11Buffer*> results = stackalloc( ID3D11Buffer*, count );\r
102 \r
103                 deviceContext->GSGetConstantBuffers( startSlot, count, &results[0] );\r
104 \r
105                 for( int i = 0; i < count; i++ )\r
106                         buffers[i] = Buffer::FromPointer( results[i] );\r
107 \r
108                 return buffers;\r
109         }\r
110 \r
111         array<SamplerState^>^ GeometryShaderWrapper::GetSamplers( int startSlot, int count )\r
112         {\r
113                 array<SamplerState^>^ samplers = gcnew array<SamplerState^>( count );\r
114                 stack_array<ID3D11SamplerState*> results = stackalloc( ID3D11SamplerState*, count );\r
115 \r
116                 deviceContext->GSGetSamplers( startSlot, count, &results[0] );\r
117 \r
118                 for( int i = 0; i < count; i++ )\r
119                         samplers[i] = SamplerState::FromPointer( results[i] );\r
120 \r
121                 return samplers;\r
122         }\r
123 \r
124         array<ShaderResourceView^>^ GeometryShaderWrapper::GetShaderResources( int startSlot, int count )\r
125         {\r
126                 array<ShaderResourceView^>^ resources = gcnew array<ShaderResourceView^>( count );\r
127                 stack_array<ID3D11ShaderResourceView*> results = stackalloc( ID3D11ShaderResourceView*, count );\r
128 \r
129                 deviceContext->GSGetShaderResources( startSlot, count, &results[0] );\r
130 \r
131                 for( int i = 0; i < count; i++ )\r
132                         resources[i] = ShaderResourceView::FromPointer( results[i] );\r
133 \r
134                 return resources;\r
135         }\r
136 \r
137         void GeometryShaderWrapper::SetConstantBuffer( Buffer^ constantBuffer, int slot )\r
138         {\r
139                 ID3D11Buffer *buffer = constantBuffer == nullptr ? NULL : constantBuffer->InternalPointer;\r
140                 deviceContext->GSSetConstantBuffers( slot, 1, &buffer );\r
141         }\r
142 \r
143         void GeometryShaderWrapper::SetConstantBuffers( array<Buffer^>^ constantBuffers, int startSlot, int count )\r
144         {\r
145                 if( count > constantBuffers->Length )\r
146                         throw gcnew ArgumentOutOfRangeException( "count" );\r
147 \r
148                 stack_array<ID3D11Buffer*> input = stackalloc( ID3D11Buffer*, count );\r
149                 for( int i = 0; i < count; i++ )\r
150                         input[i] = constantBuffers[i] == nullptr ? NULL : constantBuffers[i]->InternalPointer;\r
151 \r
152                 deviceContext->GSSetConstantBuffers( startSlot, count, &input[0] );\r
153         }\r
154 \r
155         void GeometryShaderWrapper::SetSampler( SamplerState^ sampler, int slot )\r
156         {\r
157                 ID3D11SamplerState *pointer = sampler == nullptr ? NULL : sampler->InternalPointer;\r
158                 deviceContext->GSSetSamplers( slot, 1, &pointer );\r
159         }\r
160 \r
161         void GeometryShaderWrapper::SetSamplers( array<SamplerState^>^ samplers, int startSlot, int count )\r
162         {\r
163                 if( count > samplers->Length )\r
164                         throw gcnew ArgumentOutOfRangeException( "count" );\r
165 \r
166                 stack_array<ID3D11SamplerState*> input = stackalloc( ID3D11SamplerState*, count );\r
167                 for( int i = 0; i < count; i++ )\r
168                         input[i] = samplers[i] == nullptr ? NULL : samplers[i]->InternalPointer;\r
169 \r
170                 deviceContext->GSSetSamplers( startSlot, count, &input[0] );\r
171         }\r
172 \r
173         void GeometryShaderWrapper::SetShaderResource( ShaderResourceView^ resourceView, int slot )\r
174         {\r
175                 ID3D11ShaderResourceView *resource = resourceView == nullptr ? NULL : resourceView->InternalPointer;\r
176                 deviceContext->GSSetShaderResources( slot, 1, &resource );\r
177         }\r
178 \r
179         void GeometryShaderWrapper::SetShaderResources( array<ShaderResourceView^>^ resourceViews, int startSlot, int count )\r
180         {\r
181                 if( count > resourceViews->Length )\r
182                         throw gcnew ArgumentOutOfRangeException( "count" );\r
183 \r
184                 stack_array<ID3D11ShaderResourceView*> input = stackalloc( ID3D11ShaderResourceView*, count );\r
185                 for( int i = 0; i < count; i++ )\r
186                         input[i] = resourceViews[i] == nullptr ? NULL : resourceViews[i]->InternalPointer;\r
187 \r
188                 deviceContext->GSSetShaderResources( startSlot, count, &input[0] );\r
189         }\r
190 }\r
191 }\r