Graphics Reference
In-Depth Information
The previous layout tells the input assembler that the
COLOR
component will be located
after the 16 bytes of the
SV_Position
component. In the preceding code, we can see that
the name and format of the input layout matches the type and input semantics (the name)
used in the
Simple.hlsl
shader.
struct VertexShaderInput
{
float4
Position :
SV_Position
;
float4
Color :
COLOR
;
};
Next, we will create our constant buffer to store the WVP matrix. A second buffer for
updating the per-frame information, such as light position, direction, and color, is another
common resource.
new SharpDX.Direct3D11.Buffer(device, Utilities.SizeOf<Matrix>(),
ResourceUsage.Default,
BindFlags.ConstantBuffer
, CpuAccessFlags.None,
ResourceOptionFlags.None, 0)
Here we created a buffer that is the size of a single
Matrix
structure. This buffer that is
available for read/write on the GPU (
ResourceUsage.Default
) is a constant buffer, and it
will not be accessible directly from the CPU. There are no additional options set, and as it is
only representing a single object there is no structure byte stride.
Next, we will create our
DepthStencilState
class which is used to control how the OM
stage will behave when determining whether to keep or discard a fragment based on depth
(recall that we created our depth buffer in
D3DApplicationBase
). The state object created
here enables depth testing, disables the stencil, and will choose pixels that are closer to the
camera over pixels that are further away. There is little need to change this state, other than
to enable the stencil.
context.InputAssembler.InputLayout = vertexLayout;
context.VertexShader.SetConstantBuffer(0, worldViewProjectionBuffer);
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
context.OutputMerger.DepthStencilState = depthStencilState;