3 * Copyright (c) 2007-2010 SlimDX Group
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
28 #include "InputAssemblerWrapper11.h"
29 #include "InputLayout11.h"
31 using namespace System;
37 InputAssemblerWrapper::InputAssemblerWrapper( ID3D11DeviceContext* device )
40 throw gcnew ArgumentNullException( "device" );
41 deviceContext = device;
44 Direct3D11::InputLayout^ InputAssemblerWrapper::InputLayout::get()
46 ID3D11InputLayout *layout;
47 deviceContext->IAGetInputLayout( &layout );
49 return layout == NULL ? nullptr : Direct3D11::InputLayout::FromPointer( layout );
52 void InputAssemblerWrapper::InputLayout::set( Direct3D11::InputLayout^ value )
54 if( value == nullptr )
55 deviceContext->IASetInputLayout( 0 );
57 deviceContext->IASetInputLayout( value->InternalPointer );
60 Direct3D11::PrimitiveTopology InputAssemblerWrapper::PrimitiveTopology::get()
62 D3D11_PRIMITIVE_TOPOLOGY topo;
63 deviceContext->IAGetPrimitiveTopology( &topo );
65 return static_cast<Direct3D11::PrimitiveTopology>( topo );
68 void InputAssemblerWrapper::PrimitiveTopology::set( Direct3D11::PrimitiveTopology value )
70 deviceContext->IASetPrimitiveTopology( static_cast<D3D11_PRIMITIVE_TOPOLOGY>( value ) );
73 void InputAssemblerWrapper::SetIndexBuffer( Buffer^ indexBuffer, DXGI::Format format, int offset )
75 if( indexBuffer == nullptr )
77 deviceContext->IASetIndexBuffer( 0, DXGI_FORMAT_UNKNOWN, 0 );
81 deviceContext->IASetIndexBuffer( static_cast<ID3D11Buffer*>( indexBuffer->InternalPointer ), static_cast<DXGI_FORMAT>( format ), offset );
85 void InputAssemblerWrapper::GetIndexBuffer( [Out] Buffer^ %indexBuffer, [Out] DXGI::Format %format, [Out] int %offset )
88 DXGI_FORMAT nativeFormat;
91 deviceContext->IAGetIndexBuffer( &buffer, &nativeFormat, &nativeOffset );
93 indexBuffer = Buffer::FromPointer( buffer );
94 format = static_cast<DXGI::Format>( nativeFormat );
95 offset = nativeOffset;
98 void InputAssemblerWrapper::SetVertexBuffers( int slot, VertexBufferBinding vertexBufferBinding )
100 ID3D11Buffer* buffers[] = { static_cast<ID3D11Buffer*>( vertexBufferBinding.Buffer == nullptr ? 0 : vertexBufferBinding.Buffer->InternalPointer ) };
101 UINT strides[] = { vertexBufferBinding.Stride };
102 UINT offsets[] = { vertexBufferBinding.Offset };
104 deviceContext->IASetVertexBuffers( slot, 1, buffers, strides, offsets );
107 void InputAssemblerWrapper::SetVertexBuffers( int firstSlot, ... array<VertexBufferBinding>^ vertexBufferBinding )
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];
113 for( int i = 0; i < vertexBufferBinding->Length; ++i )
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;
120 deviceContext->IASetVertexBuffers( firstSlot, vertexBufferBinding->Length, buffers, strides, offsets );
123 array<VertexBufferBinding>^ InputAssemblerWrapper::GetVertexBuffers( int firstSlot, int count )
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 );
130 deviceContext->IAGetVertexBuffers( firstSlot, count, buffers, strides, offsets );
132 for( int i = 0; i < count; ++i )
134 results[i].Buffer = buffers[i] == NULL ? nullptr : Buffer::FromPointer( buffers[i] );
135 results[i].Stride = strides[i];
136 results[i].Offset = offsets[i];