forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectObject.hlsl.cs
63 lines (54 loc) · 2.24 KB
/
EffectObject.hlsl.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Linq;
namespace TwoMGFX
{
partial class EffectObject
{
public static byte[] CompileHLSL(ShaderInfo shaderInfo, string shaderFunction, string shaderProfile, ref string errorsAndWarnings)
{
SharpDX.D3DCompiler.ShaderBytecode shaderByteCode;
try
{
SharpDX.D3DCompiler.ShaderFlags shaderFlags = 0;
// While we never allow preshaders, this flag is invalid for
// the DX11 shader compiler which doesn't allow preshaders
// in the first place.
//shaderFlags |= SharpDX.D3DCompiler.ShaderFlags.NoPreshader;
if (shaderInfo.Profile == ShaderProfile.DirectX_11)
shaderFlags |= SharpDX.D3DCompiler.ShaderFlags.EnableBackwardsCompatibility;
if (shaderInfo.Debug)
{
shaderFlags |= SharpDX.D3DCompiler.ShaderFlags.SkipOptimization;
shaderFlags |= SharpDX.D3DCompiler.ShaderFlags.Debug;
}
else
{
shaderFlags |= SharpDX.D3DCompiler.ShaderFlags.OptimizationLevel3;
}
// Compile the shader into bytecode.
var result = SharpDX.D3DCompiler.ShaderBytecode.Compile(
shaderInfo.FileContent,
shaderFunction,
shaderProfile,
shaderFlags,
0,
null,
null,
shaderInfo.FilePath);
// Store all the errors and warnings to log out later.
errorsAndWarnings += result.Message;
if (result.Bytecode == null)
throw new ShaderCompilerException();
shaderByteCode = result.Bytecode;
//var source = shaderByteCode.Disassemble();
}
catch (SharpDX.CompilationException ex)
{
errorsAndWarnings += ex.Message;
throw new ShaderCompilerException();
}
// Return a copy of the shader bytecode.
return shaderByteCode.Data.ToArray();
}
}
}