-
Notifications
You must be signed in to change notification settings - Fork 6
/
Shader.cs
46 lines (41 loc) · 1.78 KB
/
Shader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using SharpDX.D3DCompiler;
using SharpDX.Direct3D11;
using System;
namespace Undistort
{
public class Shader : IDisposable
{
public InputLayout inputLayout;
public InputElement[] inputElements;
public ShaderBytecode vertexShaderByteCode;
public ShaderBytecode pixelShaderByteCode;
public VertexShader vertexShader;
public PixelShader pixelShader;
public Shader(Device device, string vsEntry, string psEntry, InputElement[] inputElems)
{
inputElements = inputElems;
vertexShaderByteCode = ShaderBytecode.Compile(Properties.Resources.Shaders, vsEntry, "vs_5_0", ShaderFlags.Debug | ShaderFlags.OptimizationLevel0);
pixelShaderByteCode = ShaderBytecode.Compile(Properties.Resources.Shaders, psEntry, "ps_5_0", ShaderFlags.Debug | ShaderFlags.OptimizationLevel0);
vertexShader = new VertexShader(device, vertexShaderByteCode);
pixelShader = new PixelShader(device, pixelShaderByteCode);
inputLayout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
}
public void Dispose()
{
inputLayout.Dispose();
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
pixelShader.Dispose();
vertexShader.Dispose();
}
public void Apply(DeviceContext context)
{
context.InputAssembler.InputLayout = inputLayout;
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
context.GeometryShader.Set(null);
context.DomainShader.Set(null);
context.HullShader.Set(null);
}
}
}