| 15 | } |
| 16 | |
| 17 | DX11InputLayout::DX11InputLayout(ID3D11Device* device, |
| 18 | VertexBuffer const* vbuffer, Shader const* vshader) |
| 19 | : |
| 20 | mLayout(nullptr), |
| 21 | mNumElements(0) |
| 22 | { |
| 23 | LogAssert(vbuffer != nullptr && vshader != nullptr, "Invalid inputs."); |
| 24 | |
| 25 | std::memset(&mElements[0], 0, VAConstant::MAX_ATTRIBUTES*sizeof(mElements[0])); |
| 26 | |
| 27 | VertexFormat const& format = vbuffer->GetFormat(); |
| 28 | mNumElements = format.GetNumAttributes(); |
| 29 | for (int32_t i = 0; i < mNumElements; ++i) |
| 30 | { |
| 31 | VASemantic semantic{}; |
| 32 | DFType type{}; |
| 33 | uint32_t unit{}, offset{}; |
| 34 | format.GetAttribute(i, semantic, type, unit, offset); |
| 35 | |
| 36 | D3D11_INPUT_ELEMENT_DESC& element = mElements[i]; |
| 37 | element.SemanticName = msSemantic[semantic]; |
| 38 | element.SemanticIndex = unit; |
| 39 | element.Format = static_cast<DXGI_FORMAT>(type); |
| 40 | element.InputSlot = 0; // TODO: Streams not yet supported. |
| 41 | element.AlignedByteOffset = offset; |
| 42 | element.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; |
| 43 | element.InstanceDataStepRate = 0; |
| 44 | } |
| 45 | |
| 46 | auto const& compiledCode = vshader->GetCompiledCode(); |
| 47 | DX11Log(device->CreateInputLayout(mElements, (UINT)mNumElements, |
| 48 | &compiledCode[0], compiledCode.size(), &mLayout)); |
| 49 | } |
| 50 | |
| 51 | void DX11InputLayout::Enable(ID3D11DeviceContext* context) |
| 52 | { |
nothing calls this directly
no test coverage detected