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 "SamplerState.h"
28 #include "ShaderResourceView.h"
29 #include "GeometryShaderWrapper.h"
30 #include "GeometryShader.h"
32 using namespace System;
38 GeometryShaderWrapper::GeometryShaderWrapper( ID3D10Device* device )
41 throw gcnew ArgumentNullException( "device" );
45 void GeometryShaderWrapper::Set( GeometryShader^ shader )
47 m_Device->GSSetShader( shader == nullptr ? 0 : shader->InternalPointer );
50 GeometryShader^ GeometryShaderWrapper::Get()
52 ID3D10GeometryShader* shader = 0;
53 m_Device->GSGetShader( &shader );
55 return shader == 0 ? nullptr : GeometryShader::FromPointer( shader );
58 array<Buffer^>^ GeometryShaderWrapper::GetConstantBuffers( int startSlot, int count )
60 array<Buffer^>^ buffers = gcnew array<Buffer^>( count );
61 stack_array<ID3D10Buffer*> results = stackalloc( ID3D10Buffer*, count );
63 m_Device->GSGetConstantBuffers( startSlot, count, &results[0] );
65 for( int i = 0; i < count; i++ )
66 buffers[i] = Buffer::FromPointer( results[i] );
71 array<SamplerState^>^ GeometryShaderWrapper::GetSamplers( int startSlot, int count )
73 array<SamplerState^>^ samplers = gcnew array<SamplerState^>( count );
74 stack_array<ID3D10SamplerState*> results = stackalloc( ID3D10SamplerState*, count );
76 m_Device->GSGetSamplers( startSlot, count, &results[0] );
78 for( int i = 0; i < count; i++ )
79 samplers[i] = SamplerState::FromPointer( results[i] );
84 array<ShaderResourceView^>^ GeometryShaderWrapper::GetShaderResources( int startSlot, int count )
86 array<ShaderResourceView^>^ resources = gcnew array<ShaderResourceView^>( count );
87 stack_array<ID3D10ShaderResourceView*> results = stackalloc( ID3D10ShaderResourceView*, count );
89 m_Device->GSGetShaderResources( startSlot, count, &results[0] );
91 for( int i = 0; i < count; i++ )
92 resources[i] = ShaderResourceView::FromPointer( results[i] );
97 void GeometryShaderWrapper::SetConstantBuffer( Buffer^ constantBuffer, int slot )
99 ID3D10Buffer *buffer = constantBuffer == nullptr ? NULL : constantBuffer->InternalPointer;
100 m_Device->GSSetConstantBuffers( slot, 1, &buffer );
103 void GeometryShaderWrapper::SetConstantBuffers( array<Buffer^>^ constantBuffers, int startSlot, int count )
105 if( count > constantBuffers->Length )
106 throw gcnew ArgumentOutOfRangeException( "count" );
108 stack_array<ID3D10Buffer*> input = stackalloc( ID3D10Buffer*, count );
109 for( int i = 0; i < count; i++ )
110 input[i] = constantBuffers[i] == nullptr ? NULL : constantBuffers[i]->InternalPointer;
112 m_Device->GSSetConstantBuffers( startSlot, count, &input[0] );
115 void GeometryShaderWrapper::SetSampler( SamplerState^ sampler, int slot )
117 ID3D10SamplerState *pointer = sampler == nullptr ? NULL : sampler->InternalPointer;
118 m_Device->GSSetSamplers( slot, 1, &pointer );
121 void GeometryShaderWrapper::SetSamplers( array<SamplerState^>^ samplers, int startSlot, int count )
123 if( count > samplers->Length )
124 throw gcnew ArgumentOutOfRangeException( "count" );
126 stack_array<ID3D10SamplerState*> input = stackalloc( ID3D10SamplerState*, count );
127 for( int i = 0; i < count; i++ )
128 input[i] = samplers[i] == nullptr ? NULL : samplers[i]->InternalPointer;
130 m_Device->GSSetSamplers( startSlot, count, &input[0] );
133 void GeometryShaderWrapper::SetShaderResource( ShaderResourceView^ resourceView, int slot )
135 ID3D10ShaderResourceView *resource = resourceView == nullptr ? NULL : resourceView->InternalPointer;
136 m_Device->GSSetShaderResources( slot, 1, &resource );
139 void GeometryShaderWrapper::SetShaderResources( array<ShaderResourceView^>^ resourceViews, int startSlot, int count )
141 if( count > resourceViews->Length )
142 throw gcnew ArgumentOutOfRangeException( "count" );
144 stack_array<ID3D10ShaderResourceView*> input = stackalloc( ID3D10ShaderResourceView*, count );
145 for( int i = 0; i < count; i++ )
146 input[i] = resourceViews[i] == nullptr ? NULL : resourceViews[i]->InternalPointer;
148 m_Device->GSSetShaderResources( startSlot, count, &input[0] );