Before we issue drawing commands to the graphics device we need to set the pipeline state needed for drawing.
To be able to send our vertex data to an effect we need to create an input layout object to map vertex data into shader inputs.
#include
{
...
// Previously created:
EffectHandle effectHandle;
VertexFormat vertexFormat;
// Get a pointer to the buffer management interface.
auto buffers = device->getBuffers();
auto inputLayoutHandle = buffers->loadInputLayout(&vertexFormat, 1, effectHandle);
...
}
#include
struct Vector4;
struct Matrix4;
{
...
// Previously created:
EffectHandle effectHandle;
VertexBufferHandle vertexBufferHandle;
InputLayoutHandle inputLayoutHandle;
// Create our projection matrix.
Matrix4 projectionMatrix = createProjectionMatrix();
// Get a pointer to the devices immediate rendering context used to issue rendering commands.
auto context = device->getImmediateContext();
// Render to the default render target.
context->setRenderTarget(NoHandle, NoHandle);
// Clear the color and depth buffers.
Vector4 clearColor(0.25f, 0.25f, 0.25f, 1);
context->clearRenderTarget(&clearColor));
context->clearDepth();
// Set the effect we want to use when drawing.
context->setEffect(effectHandle);
// Set the projection matrix we want to use in the shaders.
context->setMatrixVariable("projectionMatrix", &projectionMatrix);
// Set the vertex buffers we want to use. Only using a single buffer in this example.
context->setVertexBuffers(&vertexBufferHandle, 1);
// Set the input layout, mapping the contents of our vertex buffer to the input attributes
// of the effect.
context->setInputLayout(inputLayoutHandle);
// We are now ready to issue drawing commands to the graphics device.
...
}