-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathShader.cs
More file actions
89 lines (75 loc) · 2.21 KB
/
Shader.cs
File metadata and controls
89 lines (75 loc) · 2.21 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Numerics;
using Unity.Mathematics;
namespace OpenGL_Demo
{
public class Shader : IDisposable
{
protected uint _handle;
public void Use()
{
Program.GL.UseProgram(_handle);
}
public int GetUniformLocation(string name)
{
int location = Program.GL.GetUniformLocation(_handle, name);
//if (location == -1)
//{
// throw new Exception($"{name} uniform not found on shader.");
//}
return location;
}
public void SetBool(int location, bool value)
{
Program.GL.Uniform1(location, value ? 1 : 0);
}
public void SetInt(int location, int value)
{
Program.GL.Uniform1(location, value);
}
public void SetFloat(int location, float value)
{
Program.GL.Uniform1(location, value);
}
public void SetVector(int location, float2 value)
{
Program.GL.Uniform2(location, value.x, value.y);
}
public void SetVector(int location, float3 value)
{
Program.GL.Uniform3(location, value.x, value.y, value.z);
}
public void SetVector(int location, float4 value)
{
Program.GL.Uniform4(location, value.x, value.y, value.z, value.w);
}
public unsafe void SetMatrix(int location, float4x4 value)
{
Program.GL.UniformMatrix4(location, 1, false, (float*)&value);
}
public unsafe void SetMatrix(int location, Matrix4x4 value)
{
Program.GL.UniformMatrix4(location, 1, false, (float*)&value);
}
public void Dispose()
{
Program.GL.DeleteProgram(_handle);
}
public override bool Equals(object obj)
{
if ((obj == null) || !GetType().Equals(obj.GetType()))
{
return false;
}
else
{
Shader t = (Shader)obj;
return _handle == t._handle;
}
}
public override int GetHashCode()
{
return _handle.GetHashCode();
}
}
}