• Create Account

### #Actualbtower

Posted 13 February 2013 - 02:08 PM

Dynamically generating an input layout based on what you need doesn't need to be complex at all. See below for a quick example.

The exciting part is ensuring a specific input layout is only loaded once and used across multiple meshes. I'm not sure if that's what you were asking?

D3D11_INPUT_ELEMENT_DESC dynamicLayout[MAX_ELEMENTS_YOU_SUPPORT];
int lastIndex = 0;
aiMesh * mesh; // <- assumed that your assimp mesh is in here
// repeat the sample below for normal, texcoord, tangents, etcetera..
if (mesh->HasPosition())
{
dynamicLayout[lastIndex].SemanticName = "POSITION";
dynamicLayout[lastIndex].SemanticIndex = 0;
dynamicLayout[lastIndex].Format = DXGI_FORMAT_R32G32B32_FLOAT;
dynamicLayout[lastIndex].InputSlot = 0;
dynamicLayout[lastIndex].AlignedByteOffset = 0;
dynamicLayout[lastIndex].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
dynamicLayout[lastIndex].InstanceDataStepRate = 0;
++lastIndex;
}
ID3D11InputLayout * layout; // output is stored in here, you need this later on when rendering
HRESULT result = d3ddevice->CreateInputLayout(dynamicLayout, lastIndex, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout);
if (FAILED(result))
{
//error handling
}
// after the input layout is created, you don't need the dynamicLayout array anymore, so it can go out-of-scope or you can delete it if it was dynamically allocated.


### #1btower

Posted 13 February 2013 - 02:07 PM

First of all, dynamically generating an input layout based on what you need doesn't need to be complex at all. See below for a quick example.

The exciting part is ensuring a specific input layout is only loaded once and used across multiple meshes. I'm not sure if that's what you were asking?

D3D11_INPUT_ELEMENT_DESC dynamicLayout[MAX_ELEMENTS_YOU_SUPPORT];
int lastIndex = 0;
aiMesh * mesh; // <- assumed that your assimp mesh is in here
// repeat the sample below for normal, texcoord, tangents, etcetera..
if (mesh->HasPosition())
{
dynamicLayout[lastIndex].SemanticName = "POSITION";
dynamicLayout[lastIndex].SemanticIndex = 0;
dynamicLayout[lastIndex].Format = DXGI_FORMAT_R32G32B32_FLOAT;
dynamicLayout[lastIndex].InputSlot = 0;
dynamicLayout[lastIndex].AlignedByteOffset = 0;
dynamicLayout[lastIndex].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
dynamicLayout[lastIndex].InstanceDataStepRate = 0;
++lastIndex;
}
ID3D11InputLayout * layout; // output is stored in here, you need this later on when rendering
HRESULT result = d3ddevice->CreateInputLayout(dynamicLayout, lastIndex, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout);
if (FAILED(result))
{
//error handling
}
// after the input layout is created, you don't need the dynamicLayout array anymore, so it can go out-of-scope or you can delete it if it was dynamically allocated.


PARTNERS