-
Notifications
You must be signed in to change notification settings - Fork 35
/
Shader.cs
54 lines (39 loc) · 1.17 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
47
48
49
50
51
52
53
54
namespace meshing;
public class Shader
{
public Shader(ShaderType type, string source)
{
// Create and compile a shader
shaderHandle = Gl.CreateShader(type);
Gl.ShaderSource(shaderHandle, source);
Gl.CompileShader(shaderHandle);
// Check the log
Gl.GetShader(shaderHandle, ShaderParameterName.InfoLogLength, out var logLen);
if (logLen > 0)
{
Gl.GetShaderInfoLog(shaderHandle, (uint)logLen, out _, out string log);
if (!string.IsNullOrEmpty(log))
Console.WriteLine($"Shader compile log:\n{log}");
}
// Check it compiled successfully
Gl.GetShader(shaderHandle, ShaderParameterName.CompileStatus, out var status);
if (status == (int)GLEnum.True)
return;
// Delete it
Gl.DeleteShader(shaderHandle);
shaderHandle = 0;
AssertFalse();
}
public void Dispose()
{
// Already disposed
if (shaderHandle == 0)
{
AssertFalse();
return;
}
Gl.DeleteShader(shaderHandle);
shaderHandle = 0;
}
public uint shaderHandle;
}