OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d11 / InputAssemblerWrapper11.cpp
1 #include "stdafx.h"
2 /*
3 * Copyright (c) 2007-2010 SlimDX Group
4
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24 #include <d3d11.h>
25 #include <d3dx11.h>
26
27 #include "Buffer11.h"
28 #include "InputAssemblerWrapper11.h"
29 #include "InputLayout11.h"
30
31 using namespace System;
32
33 namespace SlimDX
34 {
35 namespace Direct3D11
36
37         InputAssemblerWrapper::InputAssemblerWrapper( ID3D11DeviceContext* device )
38         {
39                 if( device == 0 )
40                         throw gcnew ArgumentNullException( "device" );
41                 deviceContext = device;
42         }
43
44         Direct3D11::InputLayout^ InputAssemblerWrapper::InputLayout::get()
45         {
46                 ID3D11InputLayout *layout;
47                 deviceContext->IAGetInputLayout( &layout );
48
49                 return layout == NULL ? nullptr : Direct3D11::InputLayout::FromPointer( layout );
50         }
51
52         void InputAssemblerWrapper::InputLayout::set( Direct3D11::InputLayout^ value )
53         {
54                 if( value == nullptr )
55                         deviceContext->IASetInputLayout( 0 );
56                 else
57                         deviceContext->IASetInputLayout( value->InternalPointer );
58         }
59
60         Direct3D11::PrimitiveTopology InputAssemblerWrapper::PrimitiveTopology::get()
61         {
62                 D3D11_PRIMITIVE_TOPOLOGY topo;
63                 deviceContext->IAGetPrimitiveTopology( &topo );
64
65                 return static_cast<Direct3D11::PrimitiveTopology>( topo );
66         }
67         
68         void InputAssemblerWrapper::PrimitiveTopology::set( Direct3D11::PrimitiveTopology value )
69         {
70                 deviceContext->IASetPrimitiveTopology( static_cast<D3D11_PRIMITIVE_TOPOLOGY>( value ) );
71         }
72         
73         void InputAssemblerWrapper::SetIndexBuffer( Buffer^ indexBuffer, DXGI::Format format, int offset )
74         {
75                 if( indexBuffer == nullptr )
76                 {
77                         deviceContext->IASetIndexBuffer( 0, DXGI_FORMAT_UNKNOWN, 0 );
78                 }
79                 else
80                 {
81                         deviceContext->IASetIndexBuffer( static_cast<ID3D11Buffer*>( indexBuffer->InternalPointer ), static_cast<DXGI_FORMAT>( format ), offset );
82                 }
83         }
84
85         void InputAssemblerWrapper::GetIndexBuffer( [Out] Buffer^ %indexBuffer, [Out] DXGI::Format %format, [Out] int %offset )
86         {
87                 ID3D11Buffer *buffer;
88                 DXGI_FORMAT nativeFormat;
89                 UINT nativeOffset;
90
91                 deviceContext->IAGetIndexBuffer( &buffer, &nativeFormat, &nativeOffset );
92
93                 indexBuffer = Buffer::FromPointer( buffer );
94                 format = static_cast<DXGI::Format>( nativeFormat );
95                 offset = nativeOffset;
96         }
97         
98         void InputAssemblerWrapper::SetVertexBuffers( int slot, VertexBufferBinding vertexBufferBinding )
99         {
100                 ID3D11Buffer* buffers[] = { static_cast<ID3D11Buffer*>( vertexBufferBinding.Buffer == nullptr ? 0 : vertexBufferBinding.Buffer->InternalPointer ) };
101                 UINT strides[] = { vertexBufferBinding.Stride };
102                 UINT offsets[] = { vertexBufferBinding.Offset };
103                 
104                 deviceContext->IASetVertexBuffers( slot, 1, buffers, strides, offsets );
105         }
106         
107         void InputAssemblerWrapper::SetVertexBuffers( int firstSlot, ... array<VertexBufferBinding>^ vertexBufferBinding )
108         {
109                 ID3D11Buffer* buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
110                 UINT strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
111                 UINT offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
112                 
113                 for( int i = 0; i < vertexBufferBinding->Length; ++i )
114                 {
115                         buffers[i] = vertexBufferBinding[ i ].Buffer == nullptr ? 0 : static_cast<ID3D11Buffer*>( vertexBufferBinding[ i ].Buffer->InternalPointer );
116                         strides[i] = vertexBufferBinding[ i ].Stride;
117                         offsets[i] = vertexBufferBinding[ i ].Offset;
118                 }
119                 
120                 deviceContext->IASetVertexBuffers( firstSlot, vertexBufferBinding->Length, buffers, strides, offsets );
121         }
122
123         array<VertexBufferBinding>^ InputAssemblerWrapper::GetVertexBuffers( int firstSlot, int count )
124         {
125                 ID3D11Buffer* buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
126                 UINT strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
127                 UINT offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
128                 array<VertexBufferBinding>^ results = gcnew array<VertexBufferBinding>( count );
129                 
130                 deviceContext->IAGetVertexBuffers( firstSlot, count, buffers, strides, offsets );
131
132                 for( int i = 0; i < count; ++i )
133                 {
134                         results[i].Buffer = buffers[i] == NULL ? nullptr : Buffer::FromPointer( buffers[i] );
135                         results[i].Stride = strides[i];
136                         results[i].Offset = offsets[i];
137                 }
138
139                 return results;
140         }
141 }
142 }