Graphics Reference
In-Depth Information
buffer and bound to the input assembler. When the draw call is performed, the vertex data
is submitted to the vertex shader one copy at a time, with the transformation matrix being
updated between instances of the model.
If a vertex component is providing per-instance data, it must specify that with the
InputSlotClass parameter. In this case, there is also an option to increment to the next
element in the vertex buffer only after a certain number of instances have been submitted to
the pipeline. This is specified in the InstanceDataStepRate and provides a rough control
for the frequency with which a per-instance parameter is changed. Since this is specified at
the individual attribute level, it is possible to have different attributes to advance to the next
data member at different rates. After all of the desired vertex attributes have been identi-
fied, and an array of description structures has been filled in, the application can create the
ID3DllInputLayout object with the ID3DllDevice: :CreateInputl_ayout() method.
Listing 3.5 demonstrates how this process is performed.
// Create array of elements here for the API call.
D3D11_INPUT_ELEMENT_DESC* pElements = new D3D11_lNPUT_ELEMENT_DESC[elements.
count()];
// Fill in the array of elements (this will vary depending on how they are
// submitted to this method).
for ( int i = 0; i < elements.count(); i++ )
pElements[i] = elements[i]j;
// Attempt to create the input layout from the input information (the
// compiled shader byte code storage will also vary by the data
// structures used).
ID3DBlob* pCompiledShader = m_vShaders[ShaderID]->pCompiledShader;
ID3DllInputtayout* pLayout = 0 ;
II Create the input layout object, and check the HRESULT afterwards.
HRESULT hr = m_pDevice->CreateInputLayout( pElements, elements.count(),
pCompiledShader->GetBufferPointer(), pCompiledShader->GetBufferSize(),
&pLayout );
Listing 3.5. The creation of an input layout object.
Here we can see the array of D3D11_INPUT_ELEMENT_DESC structures being allocated
and then being filled in from an input container object. The first two parameters to ID3D11
Device: :CreateInputLayout() provide the array of descriptions and the number of ele-
ments that exist in the array. The third and fourth parameters are a pointer to the shader
byte code that results from compiling the vertex shader source code, and the size of that
byte code, respectively. This is used to compare the input array of element descriptions
against the HLSL shader that it will be used to supply data to. Comparing these two objects
Search WWH ::




Custom Search