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