Added an easy way to get attribute location for shaders.

This commit is contained in:
Harrison Deng 2020-02-17 02:25:13 -05:00
parent 60fa54ccf9
commit c62ec58c8f

View File

@ -39,10 +39,15 @@ namespace RecrownedGTK.Graphics.Render.Shader {
if ((log = GL.GetShaderInfoLog(fragShader)) == "") {
throw new ArgumentException("Error while compiling fragment shader: " + log, "fragmentPath");
}
//Creates the shader program.
handle = GL.CreateProgram();
//Attaches shader to program and links it.
GL.AttachShader(handle, vertShader);
GL.AttachShader(handle, fragShader);
GL.LinkProgram(handle);
GL.DetachShader(handle, vertShader);
GL.DetachShader(handle, fragShader);
GL.DeleteShader(vertShader);
@ -53,6 +58,10 @@ namespace RecrownedGTK.Graphics.Render.Shader {
GL.UseProgram(handle);
}
public int GetAttribLocation(string attributeName) {
return GL.GetAttribLocation(handle, attributeName);
}
protected virtual void Dispose(bool disposing) {
if (IsDisposed) {
return;
@ -72,7 +81,7 @@ namespace RecrownedGTK.Graphics.Render.Shader {
~Shader() {
Dispose(false);
}
public static Shader CreateBasic2D() {
public static Shader CreateBasicShader() {
Shader shader = new Shader("Graphics/Render/Shader/default.vert", "Graphics/Render/Shader/default.frag");
return shader;
}