Graphics Reference
In-Depth Information
contextList = new DeviceContext[threadCount];
if (threadCount == 1) {
// Use the immediate context if only 1 thread
contextList[0] = this.DeviceManager
.Direct3DDevice.ImmediateContext;
} else {
for (var i = 0; i < threadCount; i++)
{
contextList[i] = ToDispose(new DeviceContext(
this.DeviceManager.Direct3DDevice));
InitializeContext(contextList[i]);
}
}
4.
Within the previous code snippet, we are initializing the pipeline state for each
new deferred context with a call to a new function named InitializeContext .
Before the new context can be used for Draw calls, it must at least have a viewport
and render target assigned. The following code snippet shows an example for
representing this function in our simplistic, example-rendering framework:
protected void InitializeContext(DeviceContext context)
{
// Tell the IA what the vertices will look like
context.InputAssembler.InputLayout = vertexLayout;
// Set the constant buffers for vertex shader stage
context.VertexShader.SetConstantBuffer(0,
perObjectBuffer);
context.VertexShader.SetConstantBuffer(1,
perFrameBuffer);
context.VertexShader.SetConstantBuffer(2,
perMaterialBuffer);
context.VertexShader.SetConstantBuffer(3,
perArmatureBuffer);
// Set the default vertex shader to run
context.VertexShader.Set(vertexShader);
// Set our pixel shader constant buffers
context.PixelShader
.SetConstantBuffer(1, perFrameBuffer);
context.PixelShader
.SetConstantBuffer(2, perMaterialBuffer);
// Set the default pixel shader to run
context.PixelShader.Set(blinnPhongShader);
// Set our depth stencil state
context.OutputMerger
 
Search WWH ::




Custom Search