From c62ec58c8f86e747e9e2ec4bd58b55924ca25f24 Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 17 Feb 2020 02:25:13 -0500 Subject: [PATCH] Added an easy way to get attribute location for shaders. --- RecrownedGTK/Graphics/Render/Shader/Shader.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/RecrownedGTK/Graphics/Render/Shader/Shader.cs b/RecrownedGTK/Graphics/Render/Shader/Shader.cs index 6260138..9a23c36 100644 --- a/RecrownedGTK/Graphics/Render/Shader/Shader.cs +++ b/RecrownedGTK/Graphics/Render/Shader/Shader.cs @@ -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; }