2 * Copyright (c) 2007-2010 SlimDX Group
\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
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\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
24 #include "../stack_array.h"
\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
33 using namespace System;
\r
37 namespace Direct3D11
\r
39 GeometryShaderWrapper::GeometryShaderWrapper( ID3D11DeviceContext* device )
\r
42 throw gcnew ArgumentNullException( "deviceContext" );
\r
43 deviceContext = device;
\r
46 void GeometryShaderWrapper::Set( GeometryShader^ shader )
\r
48 Set( shader, nullptr );
\r
51 void GeometryShaderWrapper::Set( GeometryShader^ shader, array<ClassInstance^>^ classInstances )
\r
53 ID3D11GeometryShader *nativeShader = shader == nullptr ? NULL : shader->InternalPointer;
\r
54 ID3D11ClassInstance** instancePtr = NULL;
\r
55 stack_array<ID3D11ClassInstance*> instances;
\r
58 if( classInstances != nullptr && classInstances->Length > 0 )
\r
60 instances = stack_array<ID3D11ClassInstance*>( classInstances->Length );
\r
61 instancePtr = &instances[0];
\r
62 count = classInstances->Length;
\r
64 for( int i = 0; i < classInstances->Length; i++ )
\r
65 instances[i] = classInstances[i]->InternalPointer;
\r
68 deviceContext->GSSetShader( nativeShader, instancePtr, count );
\r
71 GeometryShader^ GeometryShaderWrapper::Get()
\r
73 return Get( nullptr );
\r
76 GeometryShader^ GeometryShaderWrapper::Get( array<ClassInstance^>^ classInstances )
\r
78 ID3D11GeometryShader *shader = NULL;
\r
79 ID3D11ClassInstance** instancePtr = NULL;
\r
80 stack_array<ID3D11ClassInstance*> instances;
\r
83 if( classInstances != nullptr && classInstances->Length > 0 )
\r
85 instances = stack_array<ID3D11ClassInstance*>( classInstances->Length );
\r
86 instancePtr = &instances[0];
\r
87 count = classInstances->Length;
\r
90 deviceContext->GSGetShader( &shader, instancePtr, &count );
\r
92 for( UINT i = 0; i < count; i++ )
\r
93 classInstances[i] = ClassInstance::FromPointer( instances[i] );
\r
95 return shader == NULL ? nullptr : GeometryShader::FromPointer( shader );
\r
98 array<Buffer^>^ GeometryShaderWrapper::GetConstantBuffers( int startSlot, int count )
\r
100 array<Buffer^>^ buffers = gcnew array<Buffer^>( count );
\r
101 stack_array<ID3D11Buffer*> results = stackalloc( ID3D11Buffer*, count );
\r
103 deviceContext->GSGetConstantBuffers( startSlot, count, &results[0] );
\r
105 for( int i = 0; i < count; i++ )
\r
106 buffers[i] = Buffer::FromPointer( results[i] );
\r
111 array<SamplerState^>^ GeometryShaderWrapper::GetSamplers( int startSlot, int count )
\r
113 array<SamplerState^>^ samplers = gcnew array<SamplerState^>( count );
\r
114 stack_array<ID3D11SamplerState*> results = stackalloc( ID3D11SamplerState*, count );
\r
116 deviceContext->GSGetSamplers( startSlot, count, &results[0] );
\r
118 for( int i = 0; i < count; i++ )
\r
119 samplers[i] = SamplerState::FromPointer( results[i] );
\r
124 array<ShaderResourceView^>^ GeometryShaderWrapper::GetShaderResources( int startSlot, int count )
\r
126 array<ShaderResourceView^>^ resources = gcnew array<ShaderResourceView^>( count );
\r
127 stack_array<ID3D11ShaderResourceView*> results = stackalloc( ID3D11ShaderResourceView*, count );
\r
129 deviceContext->GSGetShaderResources( startSlot, count, &results[0] );
\r
131 for( int i = 0; i < count; i++ )
\r
132 resources[i] = ShaderResourceView::FromPointer( results[i] );
\r
137 void GeometryShaderWrapper::SetConstantBuffer( Buffer^ constantBuffer, int slot )
\r
139 ID3D11Buffer *buffer = constantBuffer == nullptr ? NULL : constantBuffer->InternalPointer;
\r
140 deviceContext->GSSetConstantBuffers( slot, 1, &buffer );
\r
143 void GeometryShaderWrapper::SetConstantBuffers( array<Buffer^>^ constantBuffers, int startSlot, int count )
\r
145 if( count > constantBuffers->Length )
\r
146 throw gcnew ArgumentOutOfRangeException( "count" );
\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
152 deviceContext->GSSetConstantBuffers( startSlot, count, &input[0] );
\r
155 void GeometryShaderWrapper::SetSampler( SamplerState^ sampler, int slot )
\r
157 ID3D11SamplerState *pointer = sampler == nullptr ? NULL : sampler->InternalPointer;
\r
158 deviceContext->GSSetSamplers( slot, 1, &pointer );
\r
161 void GeometryShaderWrapper::SetSamplers( array<SamplerState^>^ samplers, int startSlot, int count )
\r
163 if( count > samplers->Length )
\r
164 throw gcnew ArgumentOutOfRangeException( "count" );
\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
170 deviceContext->GSSetSamplers( startSlot, count, &input[0] );
\r
173 void GeometryShaderWrapper::SetShaderResource( ShaderResourceView^ resourceView, int slot )
\r
175 ID3D11ShaderResourceView *resource = resourceView == nullptr ? NULL : resourceView->InternalPointer;
\r
176 deviceContext->GSSetShaderResources( slot, 1, &resource );
\r
179 void GeometryShaderWrapper::SetShaderResources( array<ShaderResourceView^>^ resourceViews, int startSlot, int count )
\r
181 if( count > resourceViews->Length )
\r
182 throw gcnew ArgumentOutOfRangeException( "count" );
\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
188 deviceContext->GSSetShaderResources( startSlot, count, &input[0] );
\r