Graphics Reference
In-Depth Information
5.
Next, we will implement our CreateDeviceDependentResources method
override as described in the Creating the device dependent resources recipe.
Within this method, we will begin by calling the base implementation, releasing
existing references, and retrieving our Direct3D device and immediate context:
base.CreateDeviceDependentResources(deviceManager);
// Release all resources
RemoveAndDispose(ref vertexShader);
RemoveAndDispose(ref vertexShaderBytecode);
RemoveAndDispose(ref pixelShader);
RemoveAndDispose(ref pixelShaderBytecode);
RemoveAndDispose(ref vertexLayout);
RemoveAndDispose(ref worldViewProjectionBuffer);
RemoveAndDispose(ref depthStencilState);
// Get a reference to the Device1 instance and context
var device = deviceManager.Direct3DDevice;
var context = deviceManager.Direct3DContext;
6.
Next, we will compile our HLSL source code into a vertex and pixel shader.
We will enabling the debug flag if we are using the Debug build configuration:
ShaderFlags shaderFlags = ShaderFlags.None;
#if DEBUG
shaderFlags = ShaderFlags.Debug;
#endif
// Compile and create the vertex shader
vertexShaderBytecode = ToDispose(ShaderBytecode.
CompileFromFile("Simple.hlsl", "VSMain", "vs_5_0", shaderFlags));
vertexShader = ToDispose(new VertexShader(device,
vertexShaderBytecode));
// Compile and create the pixel shader
pixelShaderBytecode = ToDispose(ShaderBytecode.
CompileFromFile("Simple.hlsl", "PSMain", "ps_5_0", shaderFlags));
pixelShader = ToDispose(new PixelShader(device,
pixelShaderBytecode));
7. Next, initialize a vertex layout to match the structure defined in our HLSL
vertex shader.
// Layout from VertexShader input signature
vertexLayout = ToDispose(new InputLayout(device,
vertexShaderBytecode.GetPart(
 
Search WWH ::




Custom Search