OSDN Git Service

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