OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d10 / GeometryShaderWrapper.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 "Buffer.h"
27 #include "SamplerState.h"
28 #include "ShaderResourceView.h"
29 #include "GeometryShaderWrapper.h"
30 #include "GeometryShader.h"
31
32 using namespace System;
33
34 namespace SlimDX
35 {
36 namespace Direct3D10
37
38         GeometryShaderWrapper::GeometryShaderWrapper( ID3D10Device* device )
39         {
40                 if( device == 0 )
41                         throw gcnew ArgumentNullException( "device" );
42                 m_Device = device;
43         }
44
45         void GeometryShaderWrapper::Set( GeometryShader^ shader )
46         {
47                 m_Device->GSSetShader( shader == nullptr ? 0 : shader->InternalPointer );
48         }
49
50         GeometryShader^ GeometryShaderWrapper::Get()
51         {
52                 ID3D10GeometryShader* shader = 0;
53                 m_Device->GSGetShader( &shader );
54
55                 return shader == 0 ? nullptr : GeometryShader::FromPointer( shader );
56         }
57
58         array<Buffer^>^ GeometryShaderWrapper::GetConstantBuffers( int startSlot, int count )
59         {
60                 array<Buffer^>^ buffers = gcnew array<Buffer^>( count );
61                 stack_array<ID3D10Buffer*> results = stackalloc( ID3D10Buffer*, count );
62
63                 m_Device->GSGetConstantBuffers( startSlot, count, &results[0] );
64
65                 for( int i = 0; i < count; i++ )
66                         buffers[i] = Buffer::FromPointer( results[i] );
67
68                 return buffers;
69         }
70
71         array<SamplerState^>^ GeometryShaderWrapper::GetSamplers( int startSlot, int count )
72         {
73                 array<SamplerState^>^ samplers = gcnew array<SamplerState^>( count );
74                 stack_array<ID3D10SamplerState*> results = stackalloc( ID3D10SamplerState*, count );
75
76                 m_Device->GSGetSamplers( startSlot, count, &results[0] );
77
78                 for( int i = 0; i < count; i++ )
79                         samplers[i] = SamplerState::FromPointer( results[i] );
80
81                 return samplers;
82         }
83
84         array<ShaderResourceView^>^ GeometryShaderWrapper::GetShaderResources( int startSlot, int count )
85         {
86                 array<ShaderResourceView^>^ resources = gcnew array<ShaderResourceView^>( count );
87                 stack_array<ID3D10ShaderResourceView*> results = stackalloc( ID3D10ShaderResourceView*, count );
88
89                 m_Device->GSGetShaderResources( startSlot, count, &results[0] );
90
91                 for( int i = 0; i < count; i++ )
92                         resources[i] = ShaderResourceView::FromPointer( results[i] );
93
94                 return resources;
95         }
96
97         void GeometryShaderWrapper::SetConstantBuffer( Buffer^ constantBuffer, int slot )
98         {
99                 ID3D10Buffer *buffer = constantBuffer == nullptr ? NULL : constantBuffer->InternalPointer;
100                 m_Device->GSSetConstantBuffers( slot, 1, &buffer );
101         }
102
103         void GeometryShaderWrapper::SetConstantBuffers( array<Buffer^>^ constantBuffers, int startSlot, int count )
104         {
105                 if( count > constantBuffers->Length )
106                         throw gcnew ArgumentOutOfRangeException( "count" );
107
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;
111
112                 m_Device->GSSetConstantBuffers( startSlot, count, &input[0] );
113         }
114
115         void GeometryShaderWrapper::SetSampler( SamplerState^ sampler, int slot )
116         {
117                 ID3D10SamplerState *pointer = sampler == nullptr ? NULL : sampler->InternalPointer;
118                 m_Device->GSSetSamplers( slot, 1, &pointer );
119         }
120
121         void GeometryShaderWrapper::SetSamplers( array<SamplerState^>^ samplers, int startSlot, int count )
122         {
123                 if( count > samplers->Length )
124                         throw gcnew ArgumentOutOfRangeException( "count" );
125
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;
129
130                 m_Device->GSSetSamplers( startSlot, count, &input[0] );
131         }
132
133         void GeometryShaderWrapper::SetShaderResource( ShaderResourceView^ resourceView, int slot )
134         {
135                 ID3D10ShaderResourceView *resource = resourceView == nullptr ? NULL : resourceView->InternalPointer;
136                 m_Device->GSSetShaderResources( slot, 1, &resource );
137         }
138
139         void GeometryShaderWrapper::SetShaderResources( array<ShaderResourceView^>^ resourceViews, int startSlot, int count )
140         {
141                 if( count > resourceViews->Length )
142                         throw gcnew ArgumentOutOfRangeException( "count" );
143
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;
147
148                 m_Device->GSSetShaderResources( startSlot, count, &input[0] );
149         }
150 }
151 }