-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShaderProgram.cs
36 lines (25 loc) · 1.06 KB
/
ShaderProgram.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
namespace drawing;
public unsafe class ShaderProgram
{
public static string VERSION = "#version 330\n";
public ShaderProgram(string vertexShaderSource, string fragmentShaderSource)
{
// Create shaders
var vertexShader = new Shader(ShaderType.VertexShader, VERSION + vertexShaderSource);
var fragmentShader = new Shader(ShaderType.FragmentShader, VERSION + fragmentShaderSource);
// Create a shader program
programHandle = Gl.CreateProgram();
// Attach the shaders to the program
Gl.AttachShader(programHandle, vertexShader.shaderHandle);
Gl.AttachShader(programHandle, fragmentShader.shaderHandle);
Gl.LinkProgram(programHandle);
Gl.DetachShader(programHandle, vertexShader.shaderHandle);
Gl.DetachShader(programHandle, fragmentShader.shaderHandle);
}
public virtual void UseProgram()
{
Gl.UseProgram(programHandle);
}
public int GetUniformLocation(string name) => Gl.GetUniformLocation(programHandle, name);
protected uint programHandle;
}